Fix a few minor bugs

Found by trying to run poor_mans_visualisation :-)
topo_v3
LEdoian 1 year ago
parent 5ea2f5548a
commit c5fe468b9d

@ -8,6 +8,7 @@ from ..topo_v3 import MetricType
import heapq
from enum import Enum
from functools import total_ordering
from collections import defaultdict
class TopologyDifference(Annotator):
"""Finds differences between ancestors.
@ -51,16 +52,19 @@ class TopologyDifference(Annotator):
newe = new.edges
only_old = olde - newe
only_new = newe - olde
common = olde & newe
discrepant = set()
for edge in common:
o = old.edges[edge]
n = new.edges[edge]
if o != n: discrepant.add(edge)
# Note: edge can not be discrepant, since it is determined by all its
# details. However, it is useful to highlight edges with changed cost.
changed_cost_old: dict[tuple[VertexID, VertexID], list[Edge]] = defaultdict(lambda: [])
for e in only_old: changed_cost_old[(e.source, e.target)].append(e)
changed_cost_new: dict[tuple[VertexID, VertexID], list[Edge]] = defaultdict(lambda: [])
for e in only_new: changed_cost_new[(e.source, e.target)].append(e)
for e in only_old: result.for_edge[e] = self.Status.Missing
for e in only_new: result.for_edge[e] = self.Status.New
for e in discrepant: result.for_edge[e] = self.Status.Discrepant
for k in changed_cost_old.keys() & changed_cost_new.keys():
# We override the New/Missing status in this case.
for e in changed_cost_old[k]: result.for_edge[e] = self.Status.Discrepant
for e in changed_cost_new[k]: result.for_edge[e] = self.Status.Discrepant
return result
class ShortestPathTree(Annotator):

@ -266,7 +266,7 @@ class VertexFinder:
if not topo.frozen: raise ValueError("Can only add frozen topologies.")
if topo in self.topologies: raise KeyError("This topology is already in the finder")
self.topologies.append(topo)
for v in topo.vertices:
for v in topo.vertices.values():
id = v.id
self.vertices[id].append(topo)
# Add to various "indices"

Loading…
Cancel
Save