// Copyright 2003, Trustees of Indiana University // Please see the license in the file ../LICENSE using GCollections; public class bellman_ford_shortest_paths { public static bool go (Graph g, int size, WeightMap w, PredecessorMap predecessor, DistanceMap distance, DistanceCombine combine, DistanceCompare compare) where Graph: EdgeListGraph, Edge: GraphEdge, EdgeIterator: IEnumerable, WeightMap: ReadablePropertyMap, PredecessorMap: ReadWritePropertyMap, DistanceMap: ReadWritePropertyMap, DistanceCombine: BinaryFunction, DistanceCompare: StrictWeakOrdering { bool any_relaxed; for (int i = 0; i < size; ++i) { any_relaxed = false; // Optimization from BGL for (IEnumerator e_iter = g.edges().GetEnumerator(); e_iter.MoveNext();) { Edge e = e_iter.Current; if(relax.go(e, w, distance, predecessor, combine, compare)) { any_relaxed = true; } } if (!any_relaxed) break; } for (IEnumerator e_iter = g.edges().GetEnumerator(); e_iter.MoveNext();) { Edge e = e_iter.Current; if (compare.less(combine.op(((ReadablePropertyMap)w)[e], ((ReadWritePropertyMap)distance)[e.source]), ((ReadWritePropertyMap)distance)[e.target])) { return false; } } return true; } }