File: test_johnson.ml

package info (click to toggle)
ocamlgraph 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,624 kB
  • sloc: ml: 19,995; xml: 151; makefile: 14; sh: 1
file content (44 lines) | stat: -rw-r--r-- 931 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

(* Test file for Johnson *)

open Graph

module Int = struct
  type t = int
  let compare = compare
  let hash = Hashtbl.hash
  let equal = (=)
  let default = 0
  end


module G = Imperative.Digraph.ConcreteLabeled(Int)(Int)


module W = struct
  type edge = G.E.t
  type t = int
  let weight e = G.E.label e
  let zero = 0
  let add = (+)
  let sub = (-)
  let compare = compare
  end

module J = Path.Johnson(G)(W)

let g = G.create ()

let () =
  G.add_edge_e g (G.E.create 1 3  2);
  G.add_edge_e g (G.E.create 1 (-4)  5);
  G.add_edge_e g (G.E.create 1 8  3);
  G.add_edge_e g (G.E.create 2 7  5);
  G.add_edge_e g (G.E.create  2 1  4);
  G.add_edge_e g (G.E.create  3 4  2);
  G.add_edge_e g (G.E.create  4 (-5)  3);
  G.add_edge_e g (G.E.create  4 2  1);
  G.add_edge_e g (G.E.create  5 6  4)

let () = let test = J.all_pairs_shortest_paths g in
	 J.HVV.iter (fun (v, u) d -> Printf.printf "[%d -> %d : %d]\n" v u d) test