UCT Algorithm Circle: Intermediate Class: Shortest Path

UCT Algorithm Circle: Intermediate Class:
Shortest Path
Vaughan Newton
1 September, 2011
Vaughan Newton
Shortest Path
BFS
Breadth First Search
Can find shortest paths for non-weighted graphs
Does not work for weighted graphs
Vaughan Newton
Shortest Path
BFS
Breadth First Search
Can find shortest paths for non-weighted graphs
Does not work for weighted graphs
def bfs(start_node):
queue = [start_node]
while not queue.empty():
node = queue.pop()
# Do something with node
for neighbour in node.neighbours:
if not neighbour.visited:
neighbour.visited = True
queue.push(neighbour)
Vaughan Newton
Shortest Path
Dijkstra’s Shortest Path Algorithm
Like BFS, but uses a priority queue instead of a normal
FIFO queue
Vaughan Newton
Shortest Path
Dijkstra’s Shortest Path Algorithm
Like BFS, but uses a priority queue instead of a normal
FIFO queue
Always chooses the next node which is part of the shortest
path
Vaughan Newton
Shortest Path
Dijkstra’s Shortest Path Algorithm
Like BFS, but uses a priority queue instead of a normal
FIFO queue
Always chooses the next node which is part of the shortest
path
def dijkstra(start_node, end_node):
queue = [(0, start_node)]
while not queue.empty():
# Pops node with shortest distance
node = queue.pop()
for neighbour in node.neighbours:
path = (
node[0] + distance_from(node, neighbour),
neighbour
)
queue.push(path)
Vaughan Newton
Shortest Path