diff --git a/CHANGES b/CHANGES index 8e019e54..7732613d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ +version 1.8.2, May 12, 2012 +--------------------------- + o new module [Path.BellmanFord] implementing Bellman-Ford algorithm + (contributed by Yuto Takei) o new module Contraction implementing edge contraction (contributed by Markus W. Weissmann) o Gmap: new function [filter_map] (contributed by Markus W. Weissmann) diff --git a/src/path.ml b/src/path.ml index 8870dad5..08b60143 100644 --- a/src/path.ml +++ b/src/path.ml @@ -100,6 +100,7 @@ struct end +(* The following module is a contribution of Yuto Takei (University of Tokyo) *) module BellmanFord (G: G) @@ -116,7 +117,6 @@ struct let dist = H.create 97 in H.add dist vs W.zero; let admissible = H.create 97 in - let build_cycle_from x0 = let rec traverse_parent x ret = let e = H.find admissible x in @@ -138,7 +138,6 @@ struct in visit x0 in - let rec relax i = let update = G.fold_edges_e (fun e x -> diff --git a/src/path.mli b/src/path.mli index 14a01c3e..25e0a841 100644 --- a/src/path.mli +++ b/src/path.mli @@ -69,29 +69,32 @@ sig end +(* The following module is a contribution of Yuto Takei (University of Tokyo) *) module BellmanFord (G: G) (W: WEIGHT with type label = G.E.label) : sig - module H : Hashtbl.S with type key = G.V.t (* and 'a t = W *) + module H : Hashtbl.S with type key = G.V.t exception NegativeCycle of G.E.t list val all_shortest_paths : G.t -> G.V.t -> W.t H.t - (** [shortest_path g vs] computes the distances of shortest paths from - vertex [vs] to all other vertices in graph [g]. They are returned as a - hash table mapping each vertex reachable from [vs] to its distance from [vs]. - If [g] contains a negative-length cycle reachable from [vs], - raises [NegativeCycle l] where [l] is such a cycle. + (** [shortest_path g vs] computes the distances of shortest paths + from vertex [vs] to all other vertices in graph [g]. They are + returned as a hash table mapping each vertex reachable from + [vs] to its distance from [vs]. If [g] contains a + negative-length cycle reachable from [vs], raises + [NegativeCycle l] where [l] is such a cycle. Complexity: at most O(VE) *) val find_negative_cycle_from: G.t -> G.V.t -> G.E.t list - (** [find_negative_cycle_from g vs] looks for a negative-length cycle in graph [g] - that is reachable from vertex [vs] and returns it as a list of edges. - If no such a cycle exists, raises [Not_found]. + (** [find_negative_cycle_from g vs] looks for a negative-length + cycle in graph [g] that is reachable from vertex [vs] and + returns it as a list of edges. If no such a cycle exists, + raises [Not_found]. Complexity: at most O(VE). *)