transitiveWeightedEdges property

Map<T, Map<T, W>> transitiveWeightedEdges

Returns the weighted edges representing the transitive closure of this.

Implementation

Map<T, Map<T, W>> get transitiveWeightedEdges {
  final tcEdges = <T, Map<T, W>>{};
  final maxWeight = summation(weight, weight);
  for (final vertex in sortedVertices) {
    // Weighted edges connected to vertex:
    final weightedEdges = <T, W>{};
    final mappedTree = crawler.mappedTree(vertex);
    for (final connectedVertex in mappedTree.keys) {
      // Calculate min. weight.
      var minWeight = maxWeight;
      for (final path in mappedTree[connectedVertex]!) {
        final currentWeight = weightAlong([vertex, ...path]);
        if (currentWeight.compareTo(minWeight) < 0) {
          minWeight = currentWeight;
        }
      }

      weightedEdges[connectedVertex] = minWeight;
    }
    tcEdges[vertex] = weightedEdges;
  }
  return tcEdges;
}