Last active
September 4, 2019 13:37
-
-
Save alexgolec/12fd2a37f197511c251b7551ec122c9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def bfs(rate_graph, start, end): | |
to_visit = deque() | |
to_visit.appendleft( (start, 1.0) ) | |
visited = set() | |
while to_visit: | |
node, rate_from_origin = to_visit.pop() | |
if node == end: | |
return rate_from_origin | |
visited.add(node) | |
for unit, rate in rate_graph.get_neighbors(node): | |
if unit not in visited: | |
to_visit.appendleft((unit, rate_from_origin * rate)) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good eye, corrected.