#17: allow multiple outgoing edges with same label

This commit is contained in:
Karl Kroening 2017-07-05 04:52:37 -06:00
parent 11a24d0432
commit aa5156d9c9

View File

@ -104,8 +104,9 @@ def get_incoming_edges(downstream_node, incoming_edge_map):
def get_outgoing_edges(upstream_node, outgoing_edge_map): def get_outgoing_edges(upstream_node, outgoing_edge_map):
edges = [] edges = []
for upstream_label, (downstream_node, downstream_label) in outgoing_edge_map.items(): for upstream_label, downstream_infos in outgoing_edge_map.items():
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label)] for (downstream_node, downstream_label) in downstream_infos:
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label)]
return edges return edges
@ -176,9 +177,11 @@ def topo_sort(downstream_nodes):
raise RuntimeError('Graph is not a DAG') raise RuntimeError('Graph is not a DAG')
if downstream_node is not None: if downstream_node is not None:
if upstream_node not in outgoing_edge_maps: outgoing_edge_map = outgoing_edge_maps.get(upstream_node, {})
outgoing_edge_maps[upstream_node] = {} outgoing_edge_infos = outgoing_edge_map.get(upstream_label, [])
outgoing_edge_maps[upstream_node][upstream_label] = (downstream_node, downstream_label) outgoing_edge_infos += [(downstream_node, downstream_label)]
outgoing_edge_map[upstream_label] = outgoing_edge_infos
outgoing_edge_maps[upstream_node] = outgoing_edge_map
if upstream_node not in sorted_nodes: if upstream_node not in sorted_nodes:
marked_nodes.append(upstream_node) marked_nodes.append(upstream_node)