From c5fe468b9d5fd87082003101de90e01bbf8c6675 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Fri, 14 Jul 2023 16:46:36 +0200 Subject: [PATCH] Fix a few minor bugs Found by trying to run poor_mans_visualisation :-) --- birdvisu/annotations/analysis.py | 20 ++++++++++++-------- birdvisu/topo_v3.py | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/birdvisu/annotations/analysis.py b/birdvisu/annotations/analysis.py index 134f1a8..3062bd1 100644 --- a/birdvisu/annotations/analysis.py +++ b/birdvisu/annotations/analysis.py @@ -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): diff --git a/birdvisu/topo_v3.py b/birdvisu/topo_v3.py index b25ccc4..e40cf0d 100644 --- a/birdvisu/topo_v3.py +++ b/birdvisu/topo_v3.py @@ -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"