CSE 599 - Walk through of the Dijkstra and A* algorithms in Python Joseph Xu.

Slides:



Advertisements
Similar presentations
AI Pathfinding Representing the Search Space
Advertisements

CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Sociology and CS Philip Chan. How close are people connected? Are people closely connected, not closely connected, isolated into groups, …
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
Graph Algorithms Mathematical Structures for Computer Science Chapter 6 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraph Algorithms.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
1 Dijkstra’s Shortest Path Algorithm Gordon College.
17-Jun-15 Searching in BeeperHunt (Mostly minor variations on old slides)
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Using Search in Problem Solving
Lecture #17, June 5, 2007 Static Single Assignment phi nodes Dominators Dominance Frontiers Dominance Frontiers when inserting phi nodes.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Routing Protocols and the IP Layer CS244A Review Session 2/01/08 Ben Nham Derived from slides by: Paul Tarjan Martin Casado Ari Greenberg.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
Shortest Path. Dijkstra’s Algorithm finds the shortest path from the start vertex to every other vertex in the network. We will find the shortest path.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
OPERATOR PRECEDENCE PARSING
COSC 2007 Data Structures II Chapter 14 Graphs III.
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning.
13 – Routing Algorithms Network Layer.
Graphs. Made up of vertices and arcs Digraph (directed graph) –All arcs have arrows that give direction –You can only traverse the graph in the direction.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Kruskal’s and Dijkstra’s Algorithm.  Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted.
Dijkstra’s Algorithm: single source shortest paths David Kauchak cs62 Spring 2010.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Week 12 - Monday.  What did we talk about last time?  Topological sort and cycle detection in directed graphs  Connectivity  Strong connectivity.
COSC 2007 Data Structures II
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali :
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
CSE 421 Computer Networks. Network Layer 4-2 Chapter 4: Network Layer r 4. 1 Introduction r 4.2 Virtual circuit and datagram networks r 4.3 What’s inside.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Flood fill algorithm Also called seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array, When applied.
Chapter 7 Dynamic Routing
Data Structures Graphs - Terminology
Redraw these graphs so that none of the line intersect except at the vertices B C D E F G H.
Shortest Path from G to C Using Dijkstra’s Algorithm
Solving Equations by Factoring and Problem Solving
Graphs & Graph Algorithms 2
Shortest Path.
Shortest Path.
A* Path Finding Ref: A-star tutorial.
CSE 373: Data Structures and Algorithms
USING GRAPHS TO SOLVE EQUATIONS
2 Understanding Variables and Solving Equations.
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Advanced Computer Networks
CSE 373: Data Structures and Algorithms
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
Shortest Path.
CSE 373 Data Structures and Algorithms
Dijkstra's Shortest Path Algorithm
Implementation of Dijkstra’s Algorithm
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Applications of BFS CSE 2011 Winter /17/2019 7:03 AM.
Graphs: Shortest path and mst
CS203 Lecture 14.
Dijkstra’s Algorithm Ryan Keedy CSE 599 April 4th, 2012.
OPERATOR GRAMMAR No Ɛ-transition. No two adjacent non-terminals. Eg.
Presentation transcript:

CSE Walk through of the Dijkstra and A* algorithms in Python Joseph Xu

Initialization part 1: Construct an empty list for all the nodes (self.visited) and prepare a sorted list for the next node (toVisit) self.visited = [] # (cost_to_reach, parent_node_ID) if self.graph != None: # check the status of the loaded map for i in range(self.graph.getNodeCount()): self.visited.append(None) toVisit = PriorityQueue() # (cost_to_reach, current_node_ID, parent_node_ID)

Initialization part 2:Prepare for the main loop by using the start point # Start of the algorithm self.visited[start] = (0, None) toVisit.put((0, start, None)) # And prepare the drawing: draw = deque([])

Main loop part 1: Use the closet node from toVisit for the next node while not toVisit.empty(): # test condition # temporary tuple for getting the next node nextTuple = toVisit.get() next = nextTuple[1] # Get the “current_node_ID” nextDist = self.visited[next][0] # Get the “cost_to_reach”

Main loop part 2: Draw the progress only for the most recent 50 points. if len(draw) >= 50: draw.popleft() # Throw away the oldest node draw.append(next) # Add ”next” to the right side of the deque self.DrawList(draw, width=2, height=2) # change the size of the symbol

Main loop part 3: Check to see whether the algorithm reaches the goal node if next == goal: #Success! lastPathNode = goal # Construct the path list self.pathCost = self.visited[goal][0] #it's the total cost of the whole path, the value will be used in the GUI self.path = [] # the following loop is for constructing the shortest path to the goal node backward. while self.visited[lastPathNode][1] != None: # Until it reaches the start self.path.append(lastPathNode) lastPathNode = self.visited[lastPathNode][1] # 1 denotes the node we just came from self.path.append(start) # Add the start node to the right side of the path self.path.reverse() return

Main loop part 4: Look for the neighbor node of the “next” node, and based on its visit status, choose to either creat or update the node for adjacency in self.graph.getAdjacencies(next): # For each neightbor, see if have a path to nextNbr, cost = adjacency[0], adjacency[1] #the cost is the distannce from "next" to "nextNbr" totalTravel = nextDist + cost if self.visited[nextNbr] == None: # The neighbor is unvisited self.visited[nextNbr] = ( totalTravel, next ) # Mark the node as visited toVisit.put( (totalTravel, nextNbr, next) ) # Add node to priority queue elif totalTravel < self.visited[nextNbr][0]: # The neighbor has been visited, but that is shorter # if we've found a shorter route to nextNbr self.visited[nextNbr] = (totalTravel, next) # then replace old route to nextNbr with new toVisit.put( (totalTravel, nextNbr, next)) #else: Node has been visited, but current path is equal or longer

Main loop part 4 (A* case): Look for the neighbor node of the “next” node, and based on its visit status, choose to either creat or update the node for adjacency in self.graph.getAdjacencies(next): # For each neightbor, see if have a path to nextNbr, cost = adjacency[0], adjacency[1] #the cost is the distannce from "next" to "nextNbr" totalTravel = nextDist + cost if self.visited[nextNbr] == None: # The neighbor is unvisited self.visited[nextNbr] = ( totalTravel, next ) # Mark the node as visited goalDist = euclidDist(nextNbr, goal, self.graph) toVisit.put( (totalTravel + goalDist, nextNbr, next) ) # Add node to priority queue elif totalTravel < self.visited[nextNbr][0]: # The neighbor has been visited, but that is shorter # if we've found a shorter route to nextNbr self.visited[nextNbr] = (totalTravel, next) # then replace old route to nextNbr with new goalDist = euclidDist(nextNbr, goal, self.graph) toVisit.put( (totalTravel + goalDist, nextNbr, next)) #else: Node has been visited, but current path is equal or longer

Path finding using Laplace’s equations Step 1.Define the V(start, goal) Step 2. Assign values to the state of the node: Start. state = +1, goal.state = -1 for all the nodes in graph G if Num(node. adjacency) >= 8 node. state = ??? “10000” else node.state = Step 3. Solve laplace’s equations using while (error > threshold) for all the nodes in graph G v(i,j)=(v(i+1,j)+v(i-1,j)+v(i,j+1)+v(i,j-1))/4

Path finding using Laplace’s equations Step 4.Finding the Gradients, and normalize the values in both x and y direction. Step 5. Follow the streamlines of the gradient. Try separate list for the node’s state.

CSE 599 – Arm Planning and Forward Kinematics Joseph Xu

Denavit-Hartenberg (DH) notation Y2Y2 X2X2 Y3Y3 X3X3 Y2Y2 (X 0 ) X1X1 (Y 0 ) l1l1 l2l2 l3l3 l 1 = 1.0 l 2 = 1.0 l 3 = 0.5

Denavit-Hartenberg (DH) notation Link 1000 Link 200 Link 300

Denavit-Hartenberg (DH) notation