Created
September 2, 2019 02:52
-
-
Save alexgolec/e572da2ba27e616fa135aaa7b9422bda to your computer and use it in GitHub Desktop.
This file contains hidden or 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 make_conversions(graph): | |
def conversions_bfs(rate_graph, start, conversions): | |
to_visit = deque() | |
to_visit.appendleft( (start, 1.0) ) | |
while to_visit: | |
node, rate_from_origin = to_visit.pop() | |
conversions[node] = (start, rate_from_origin) | |
for unit, rate in rate_graph.get_neighbors(node): | |
if unit not in conversions: | |
to_visit.append((unit, rate_from_origin * rate)) | |
return conversions | |
conversions = {} | |
for node in graph.get_nodes(): | |
if node not in conversions: | |
conversions_bfs(graph, node, conversions) | |
return conversions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment