Skip to content

Commit

Permalink
dijkstra longest path
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick James committed Nov 6, 2021
1 parent dc06ef4 commit 69bdfb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 2 additions & 13 deletions ch3.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import grid
import binary
import sidewinder
import pretty
import dijkstra
import sidewinder

dg = dijkstra.DijkstraGrid(6, 7)
b = sidewinder.SideWinder(dg)
dg.build_distances(dg.grid[0][0])
dg.path_to(dg.grid[5][0])

dg.set_longest_path()
print(dg)
#print(d.distances)
#p = pretty.Pretty(g)




12 changes: 12 additions & 0 deletions dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def path_to(self, t):
self.last_path = path
return path

# sets last_path to longest path
def set_longest_path(self):

# a longest path starts at the furtherest cell from (0,0)
self.build_distances(self.grid[0][0])
origin = max(self.distances, key=self.distances.get)

self.build_distances(origin)
dest = max(self.distances, key=self.distances.get)

self.path_to(dest)




0 comments on commit 69bdfb7

Please sign in to comment.