From 336ab07955121a1f18ce18c32a31f6eebfff89fc Mon Sep 17 00:00:00 2001 From: Arthur Bit-Monnot Date: Fri, 18 Nov 2022 14:12:55 +0100 Subject: [PATCH] 2022 update --- graphs/graph1.txt | 21 +++++++++++++++++++++ graphs/graph2.txt | 37 +++++++++++++++++++++++++++++++++++++ src/ftest.ml | 13 +++++++++---- src/gfile.mli | 3 +-- src/graph.ml | 2 +- src/graph.mli | 4 ++-- 6 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 graphs/graph1.txt create mode 100644 graphs/graph2.txt diff --git a/graphs/graph1.txt b/graphs/graph1.txt new file mode 100644 index 0000000..e1cb393 --- /dev/null +++ b/graphs/graph1.txt @@ -0,0 +1,21 @@ +% This is a graph. + +n 20 300 0 +n 200 300 1 +n 200 200 2 +n 200 400 3 +n 380 300 4 +n 380 200 5 + +e 0 2 0 8 +e 0 3 1 10 +e 0 1 2 7 +e 2 4 3 12 +e 3 4 4 5 +e 3 2 5 2 +e 3 1 6 11 +e 1 4 7 1 +e 1 5 8 21 +e 4 5 9 14 + +% End of graph diff --git a/graphs/graph2.txt b/graphs/graph2.txt new file mode 100644 index 0000000..b772ff0 --- /dev/null +++ b/graphs/graph2.txt @@ -0,0 +1,37 @@ +% This is a graph. + +n 20 300 0 +n 200 300 1 +n 200 200 2 +n 200 400 3 +n 380 300 4 +n 380 200 5 +n 380 400 6 +n 380 100 7 +n 380 500 8 +n 560 300 9 +n 560 200 10 +n 560 400 11 +n 560 100 12 + +e 0 3 0 2 +e 0 2 1 2 +e 0 1 2 4 +e 1 4 3 2 +e 1 6 4 2 +e 1 5 5 2 +e 4 10 6 2 +e 2 5 7 2 +e 10 12 8 6 +e 3 6 9 2 +e 3 8 10 2 +e 6 9 11 2 +e 8 11 12 2 +e 11 9 13 2 +e 9 10 14 4 +e 5 10 15 1 +e 5 7 16 1 +e 7 12 17 2 +e 7 10 18 1 + +% End of graph diff --git a/src/ftest.ml b/src/ftest.ml index 4de8c1f..80489df 100644 --- a/src/ftest.ml +++ b/src/ftest.ml @@ -1,20 +1,25 @@ open Gfile - + let () = (* Check the number of command-line arguments *) if Array.length Sys.argv <> 5 then begin - Printf.printf "\nUsage: %s infile source sink outfile\n\n%!" Sys.argv.(0) ; + Printf.printf + "\n ✻ Usage: %s infile source sink outfile\n\n%s%!" Sys.argv.(0) + (" 🟄 infile : input file containing a graph\n" ^ + " 🟄 source : identifier of the source vertex (used by the ford-fulkerson algorithm)\n" ^ + " 🟄 sink : identifier of the sink vertex (ditto)\n" ^ + " 🟄 outfile : output file in which the result should be written.\n\n") ; exit 0 end ; (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *) - + let infile = Sys.argv.(1) and outfile = Sys.argv.(4) - + (* These command-line arguments are not used for the moment. *) and _source = int_of_string Sys.argv.(2) and _sink = int_of_string Sys.argv.(3) diff --git a/src/gfile.mli b/src/gfile.mli index 81a2c14..465e693 100644 --- a/src/gfile.mli +++ b/src/gfile.mli @@ -13,7 +13,6 @@ val from_file: path -> string graph val write_file: path -> string graph -> unit - (* The format of files is compatible with the files generated by: - https://www-m9.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html + https://algorithms.discrete.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html *) diff --git a/src/graph.ml b/src/graph.ml index 33f7a15..2bef130 100644 --- a/src/graph.ml +++ b/src/graph.ml @@ -32,7 +32,7 @@ let new_arc gr id1 id2 lbl = (* Update out-arcs. * remove_assoc does not fail if id2 is not bound. *) let outb = (id2, lbl) :: List.remove_assoc id2 outa in - + (* Replace out-arcs in the graph. *) let gr2 = List.remove_assoc id1 gr in (id1, outb) :: gr2 diff --git a/src/graph.mli b/src/graph.mli index 416e158..dd9c265 100644 --- a/src/graph.mli +++ b/src/graph.mli @@ -38,7 +38,7 @@ type 'a out_arcs = (id * 'a) list val out_arcs: 'a graph -> id -> 'a out_arcs (* find_arc gr id1 id2 finds an arc between id1 and id2 and returns its label. Returns None if the arc does not exist. - * @raise Graph_error if id1 is unknown. *) +* @raise Graph_error if id1 is unknown. *) val find_arc: 'a graph -> id -> id -> 'a option @@ -49,7 +49,7 @@ val n_iter: 'a graph -> (id -> unit) -> unit (* Like n_iter, but the nodes are sorted. *) val n_iter_sorted: 'a graph -> (id -> unit) -> unit - + (* Fold on all (unsorted) nodes. You must remember what List.fold_left does. *) val n_fold: 'a graph -> ('b -> id -> 'b) -> 'b -> 'b