Debian Codegraph @

lib/mlrisc-lib/MLRISC/graphs/test2.sml

raw
1 CM.make "../cm/Graphs.cm";
2 (* See page 249 of Aho Hopcroft Ullman *)
3 structure TestMatching =
4 struct
5 val G as Graph.GRAPH g = DirectedGraph.graph("foo",(),10) :
6 (string,int,unit) Graph.graph
7 val _ = app (#add_node g)
8 [(1,"1"),
9 (2,"2"),
10 (3,"3"),
11 (4,"4"),
12 (5,"5"),
13 (6,"6"),
14 (7,"7"),
15 (8,"8"),
16 (9,"9"),
17 (10,"10")
18 ]
19 val _ = app (#add_edge g)
20 (rev[(1,6,1),
21 (1,7,1),
22 (1,8,1),
23 (2,6,1),
24 (2,9,1),
25 (2,10,1),
26 (3,6,1),
27 (3,7,1),
28 (4,8,1),
29 (4,9,1),
30 (4,10,1),
31 (5,6,1)
32 ])
33 fun matching((i,j,c),_) =
34 print(Int.toString i ^ " -> " ^ Int.toString j ^ "\n")
35
36 fun test() =
37 let val (_,card) = BipartiteMatching.matching G matching ()
38 in if card <> 5 then raise Match else card
39 end
40
41 end