2022 update

This commit is contained in:
Arthur Bit-Monnot 2022-11-18 14:12:55 +01:00
parent 1ec2eed82f
commit 336ab07955
6 changed files with 71 additions and 9 deletions

21
graphs/graph1.txt Normal file
View file

@ -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

37
graphs/graph2.txt Normal file
View file

@ -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

View file

@ -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)

View file

@ -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
*)

View file

@ -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

View file

@ -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