You are on page 1of 56

A* Search Algorithm

CSE318 July ’21 Semester


A* Search
●  Graph traversal algorithm
○ BFS
○ DFS
○ Bellman-Ford
○ Floyd- Warshall
○ Dijkstra
● Finds the optimal path between two nodes of a graph
● Best-First Search Algorithm
○ Greedy approach
○ Evaluation function  Estimate of the total cost
○ Expands the node n with the smallest
Dijkstra Algorithm

● Greedy technique like A*


● Visits the nearest node
● Visits too many nodes
Dijkstra

Oradea
71 Neamt

Zerind 87
75 151
Arad Iasi

140 92
Sibiu Faragas
118 99
Vaslui
80
Timisoara Rimnicu Vilcea

142
111 Pitesi 211
Lugoj 97
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87
Zerind
75 151
Arad Iasi

140 92
Sibiu Faragas
118 99
Vaslui
80
Timisoara Rimnicu Vilcea

End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Sibiu
Zerind
75 151 Timisoara
Iasi Zerind
Arad
140 92
Sibiu Faragas
118 99
Vaslui
80
Timisoara Rimnicu Vilcea

End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Sibiu
Zerind
75 151 Timisoara
Iasi Zerind
Arad
140 92
Sibiu Faragas
118 99
Vaslui
80
Timisoara Rimnicu Vilcea

End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Sibiu
Iasi Timisoara
Arad
Oradea
140 92
Sibiu Faragas
118 99
Vaslui
80
Timisoara Rimnicu Vilcea

End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu
Arad
Oradea
140 92 Lugoj
Sibiu Faragas
118 99
Vaslui
80
Timisoara Rimnicu Vilcea

End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea
140 92 Lugoj
Sibiu Faragas
99 Faragas
118
Vaslui Rimnicu Vilcea
80
Timisoara Rimnicu Vilcea

End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Lugoj
Sibiu Faragas
99 Faragas
118
Vaslui Rimnicu Vilcea
80
Timisoara Rimnicu Vilcea

End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj
118
Vaslui Faragas
80 Pitesi
Timisoara Rimnicu Vilcea Craiova
End 142
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas
80 Pitesi
Timisoara Rimnicu Vilcea Craiova
End 142 Mehadia
111 Pitesi 211
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Pitesi
Timisoara Rimnicu Vilcea Craiova
End 142 Mehadia
111 Pitesi 211 Bucharest
Lugoj 97 Node
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Mehadia 299 (118+111+70)
Timisoara Rimnicu Vilcea Pitesi
End 142 Craiova
111 Pitesi 211 Bucharest
Lugoj 97 Node
Dobreta
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Mehadia 299 (118+111+70)
Timisoara Rimnicu Vilcea Pitesi 317 (140+80+97)
End 142 Craiova
111 Pitesi 211 Bucharest
Lugoj 97 Node
Dobreta
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Mehadia 299 (118+111+70)
Timisoara Rimnicu Vilcea Pitesi 317 (140+80+97)
End 142 Craiova 366 (140+80+146)
111 Pitesi 211 Bucharest
Lugoj 97 Node
Dobreta
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Mehadia 299 (118+111+70)
Timisoara Rimnicu Vilcea Pitesi 317 (140+80+97)
End 142 Craiova 366 (140+80+146)
111 Pitesi 211 Dobreta 374 (118+111+70+75)
Lugoj 97 Node
Bucharest
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Mehadia 299 (118+111+70)
Timisoara Rimnicu Vilcea Pitesi 317 (140+80+97)
End 142 Craiova 366 (140+80+146)
111 Pitesi 211 Dobreta 374 (118+111+70+75)
Lugoj 97 Node
Bucharest 418 (140+80+97+101)
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra
11 intermediate nodes expanded !! 😔

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Mehadia 299 (118+111+70)
Timisoara Rimnicu Vilcea Pitesi 317 (140+80+97)
End 142 Craiova 366 (140+80+146)
111 Pitesi 211 Dobreta 374 (118+111+70+75)
Lugoj 97 Node
Bucharest 418 (140+80+97+101)
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Dijkstra
  Single Cost Function:
real cost value from source to each node 

Oradea Node Expanded by Dijkstra

Start 71 Neamt Arad


Node 87 Zerind 75
Zerind
75 151 Timisoara 118
Iasi Sibiu 140
Arad
Oradea 146 (75 + 71)
140 92 Rimnicu Vilcea 220 (140+80)
Sibiu Faragas
99 Lugoj 229 (118+111)
118
Vaslui Faragas 239 (140+99)
80 Mehadia 299 (118+111+70)
Timisoara Rimnicu Vilcea Pitesi 317 (140+80+97)
End 142 Craiova 366 (140+80+146)
111 Pitesi 211 Dobreta 374 (118+111+70+75)
Lugoj 97 Node
Bucharest 418 (140+80+97+101)
70 98
Hirsova
Mehadia 146 85
101 Urziceni
75 138 Bucharest 86
Dobreta 120 90
Craiova Eforie
Giurhiu
Heuristic


●  Guided Search  Use a heuristic
○ estimation of how to search for a solution
● Updated Evaluation Function

○ g(n) = cost so far to reach n  similar to Dijkstra


○ h(n) = estimated cost from n to goal  extra information
○ f(n) = estimated total cost of path through n to goal
Summary

●   Search Algorithm
A*
○ Use of heuristic to guide the search

● Dijkstra Algorithm

● Generic Best-First Search Algorithm


A* Search

Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
A* Search

Arad

Sibiu Timisoara Zerind


Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Sibiu: f(n) = g(n) + h(n) = 140 + 253 = 393

Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Sibiu: f(n) = g(n) + h(n) = 140 + 253 = 393

Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Sibiu: f(n) = g(n) + h(n) = 140 + 253 = 393

Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Sibiu: f(n) = g(n) + h(n) = 140 + 253 = 393

Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Sibiu: f(n) = g(n) + h(n) = 140 + 253 = 393

Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
A* Search

Arad

Sibiu Timisoara Zerind


140 + 253 = 393 118 + 329 = 447 75 + 374 = 449
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Faragas: f(n) = g(n) + h(n) = (140 + 99) + 176 = 415
Rimnicu Vilcea: f(n) = g(n) + h(n) = (140 + 80) + 193 = 413
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Faragas: f(n) = g(n) + h(n) = (140 + 99) + 176 = 415
Rimnicu Vilcea: f(n) = g(n) + h(n) = (140 + 80) + 193 = 413
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
280 + 366 = 646 239 + 176 = 415 291 + 380 = 671 220 + 193 = 413
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
280 + 366 = 646 239 + 176 = 415 291 + 380 = 671

Craiova Pitesi Sibiu


Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Faragas: f(n) = g(n) + h(n) = (140 + 99) + 176 = 415
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Pitesi: f(n) = g(n) + h(n) = (140 + 80 + 97) + 100 = 417
Straight Line distance to Bucharest
Oradea Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526
Start 71 Sibiu: Neamt Arad 366
Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Faragas: f(n) = g(n) + h(n) = (140 + 99) + 176 = 415
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Pitesi: f(n) = g(n) + h(n) = (140 + 80 + 97) + 100 = 417
Straight Line distance to Bucharest
Oradea Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526
Start 71 Sibiu: Neamt Arad 366
Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
280 + 366 = 646 239 + 176 = 415 291 + 380 = 671

Craiova Pitesi Sibiu


366 + 160 = 526 317 + 100 = 417 300 + 253 = 553
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
280 + 366 = 646 291 + 380 = 671

Sibiu Bucharest Craiova Pitesi Sibiu


366 + 160 = 526 317 + 100 = 417 300 + 253 = 553
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Pitesi: f(n) = g(n) + h(n) = (140 + 80 + 97) + 100 = 417 Through Faragas
Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526
Straight Line distance to Bucharest
Oradea Bucharest: f(n) = g(n) + h(n) = (140 + 99 + 211) + 0 = 450
Start 71 Sibiu: Neamt Arad 366
Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Pitesi: f(n) = g(n) + h(n) = (140 + 80 + 97) + 100 = 417 Through Faragas
Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526
Straight Line distance to Bucharest
Oradea Bucharest: f(n) = g(n) + h(n) = (140 + 99 + 211) + 0 = 450
Start 71 Sibiu: Neamt Arad 366
Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Pitesi: f(n) = g(n) + h(n) = (140 + 80 + 97) + 100 = 417 Through Faragas
Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526
Straight Line distance to Bucharest
Oradea Bucharest: f(n) = g(n) + h(n) = (140 + 99 + 211) + 0 = 450
Start 71 Sibiu: Neamt Arad 366
Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646
Pitesi: f(n) = g(n) + h(n) = (140 + 80 + 97) + 100 = 417 Through Faragas
Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526
Straight Line distance to Bucharest
Oradea Bucharest: f(n) = g(n) + h(n) = (140 + 99 + 211) + 0 = 450
Start 71 Sibiu: Neamt Arad 366
Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
280 + 366 = 646 291 + 380 = 671

Sibiu Bucharest Craiova Pitesi Sibiu


338 + 253 = 591 450 + 0 = 450 366 + 160 = 526 317 + 100 = 417 300 + 253 = 553
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
280 + 366 = 646 291 + 380 = 671

Sibiu Bucharest Craiova Pitesi Sibiu


338 + 253 = 591 450 + 0 = 450 366 + 160 = 526 300 + 253 = 553

Rimnicu
Bucharest Craiova Vilcia
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646 Through Faragas
Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526 Through Pitesi
Bucharest: f(n) = g(n) + h(n) = (140 + 99 + 211) + 0 = 450
Straight Line distance to Bucharest
Oradea Bucharest: f(n) = g(n) + h(n) = (140 + 80 + 97+101) + 0 = 418
Start 71 Craiova: Neamt Arad 366
Node Rimnicu Vilcea: Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
Zerind: f(n) = g(n) + h(n) = 75 + 374 = 449
A* Search Timisoara: f(n) = g(n) + h(n) = 118 + 329 = 447
Oradea: f(n) = g(n) + h(n) = (140 + 151) + 380 = 671
Arad: f(n) = g(n) + h(n) = (140 + 140) + 366 = 646 Through Faragas
Craiova: f(n) = g(n) + h(n) = (140 + 80 + 146) + 160 = 526 Through Pitesi
Bucharest: f(n) = g(n) + h(n) = (140 + 99 + 211) + 0 = 450
Straight Line distance to Bucharest
Oradea Bucharest: f(n) = g(n) + h(n) = (140 + 80 + 97+101) + 0 = 418
Start 71 Craiova: Neamt Arad 366
Node Rimnicu Vilcea: Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
A* Search

Arad

Sibiu Timisoara Zerind


118 + 329 = 447 75 + 374 = 449

Rimnicu
Arad Faragas Oradea Vilcia
280 + 366 = 646 291 + 380 = 671

Sibiu Bucharest Craiova Pitesi Sibiu


338 + 253 = 591 450 + 0 = 450 366 + 160 = 526 300 + 253 = 553

Rimnicu
Bucharest Craiova Vilcia
418 + 0 = 418 455 + 160 = 615 414 + 193 = 607
A* Search
4 intermediate nodes expanded 😄

Oradea Straight Line distance to Bucharest

Start 71 Neamt Arad 366


Node Bucharest 0
Zerind 87 Craiova 160
75 151
Dobreta 242
Arad Iasi
Eforie 161
140 92 Faragas 176
Sibiu Faragas Giurhiu 77
118 99 Hirsova 151
Vaslui Iasi 226
80
Rimnicu Vilcea Lugoj 244
Timisoara
Mehadia 241
End 142 Neamt 234
111 Pitesi 211
Lugoj 97 Node Oradea 380
Pitesi 100
70 98
Hirsova Rimnicu Vilcea 193
Mehadia 146 85
101 Urziceni Sibiu 253
75 138 Bucharest 86 Timisoara 329
Dobreta Urziceni 80
120 90 Vaslui 199
Craiova Eforie
Giurhiu Zerind 374
A* Search


●  When
○ Only Nodes on the shortest path are expanded
○ Optimal solution is found
● When
○ Additional nodes are expanded
○ Optimal solution is found
● When
○ Optimal solution is overlooked
Admissible Heuristic and Dominance


●  A heuristic is admissible if for every node , , where is the true cost to reach the goal state
from .
● An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimistic.
● If is admissible, A* using TREE-SEARCH is optimal
● are both admissible and , then dominates
● If dominates , then is better for A* search
○ Expands less or equal number of nodes
Consistent Heuristic

●   if consistent if for every node and for every successor of :

h(𝑛)
  𝑑 
𝑛 


h(𝑛
  )
𝑐  ( 𝑛 ,𝑛 )
𝑛  ′
Consistent Heuristic


●  If
is consistent then is admissible
● Frequently when is admissible, it is also consistent
● A* generates an optimal solution if is a consistent heuristic and the search space is a
graph
Performance
●  Complete
○ Yes, unless there are infinitely many nodes
● Time
○ Exponential
○ The better the heuristic, the better the time
○ Best case: is perfect,
○ Worst case: , same as BFS
● Space
○ Keeps all nodes in memory and save in case of repetition
○ This is or worse
○ A* usually runs out of space before it runs out of time
● Optimal
○ Yes, cannot expand unless is finished
Thank You !

You might also like