diff --git a/_build/_digests b/_build/_digests index 9514ad4..0f031c4 100644 --- a/_build/_digests +++ b/_build/_digests @@ -1,42 +1,42 @@ -"Rule: ocaml: ml & cmi -> cmx & o (%=src/display )": "\027\"r\253b.\004\234\141\ba\206\238\025\242r" "Rule: ocaml dependencies mli (%=src/gfile )": "7\182\192g\020\238\188\b\211\164{\014\157\135\011\003" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/display )": "\027\"r\253b.\004\234\141\ba\206\238\025\242r" "Resource: /home/alejeune/Documents/4ir/S1/Ocaml/FordFulkersonLeChameau/src/tools.mli": "9\173\222\177]e\245\229\131\151\020fsu\133@" -"Rule: ocaml dependencies ml (%=src/ftest )": "\224h\140`\164\1892\223M>y\242\188\163\157'" "Rule: ocaml: ml & cmi -> cmx & o (%=src/gfile )": "\236O\148Y\157m\028\183\166?\231a\231\187u\132" +"Rule: ocaml dependencies ml (%=src/ftest )": "\252\019/\001\247\140\132b\221\205\237\217\194\139\011\245" "Rule: ocaml dependencies mli (%=src/display )": "B+\230S\204^\178D\253\139t\200\194%5b" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ftest.ml": "\193\219\229\187Q\161x\240|\242FG-\132\1953" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/fordFulkerson.ml": "\146\212\242\180\229\234\254*\132\173\180^\242?v\148" -"Rule: ocaml: mli -> cmi (%=src/graph )": ")2\159\205\136\031\251\145\0263\01878\001\b\134" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ftest.ml": "\185\019Y\252\019n*\004\218s\243\024\173}Zd" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/fordFulkerson.ml": "q\184\138\153\242\011%\207\178\202b\006\1654D\243" "Rule: ocaml: mli -> cmi (%=src/display )": "UAU\224\168o\2429OM\253\194i'\218N" +"Rule: ocaml: mli -> cmi (%=src/graph )": ")2\159\205\136\031\251\145\0263\01878\001\b\134" "Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/graph.mli": "\253S\031\015\162|\210x\252\n \227\001{\133e" -"Rule: ocaml: ml & cmi -> cmx & o (%=src/fordFulkerson )": "'v\231\027\206tFGD\129[\156\177\019\147\128" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/tools.ml": "\195\192\025\161\030\226\027\178\227x\145\250,\014`\012" -"Rule: ocaml: mli -> cmi (%=src/tools )": "*\130\\\221>3X\156\180\205\"\245\255-\230~" -"Rule: ocaml: cmx* & o* -> native (%=src/ftest )": "d\210=\023\185\235\174T4$\157\183\145t)q" -"Rule: ocaml: ml & cmi -> cmx & o (%=src/ftest )": "\211\249\221x\234\164\237\012\189\154\239\246]YK\018" -"Rule: ocaml: mli -> cmi (%=src/fordFulkerson )": "\019]\213\1741`\210\006x(\bcY\143\169\149" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/tools.ml": "\185\244\209\136L\1577;\191J\171\162M\135xa" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/fordFulkerson )": "\128\136\201\143^_\n3V\177lE3\1654\139" +"Rule: ocaml: cmx* & o* -> native (%=src/ftest )": "u8i\1621\017rk\197\200ZA\n;d\b" +"Rule: ocaml: mli -> cmi (%=src/tools )": "\239.\206\1667\139\246~\227$\235l\012\210\208;" +"Rule: ocaml: mli -> cmi (%=src/fordFulkerson )": ";\199h\213Q\200\225\024\160\204\r\225\r\203\155\\" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/ftest )": "\160l\238\232%a\145\130\240\152J#\031_\024\199" "Resource: /home/alejeune/Documents/4ir/S1/Ocaml/FordFulkersonLeChameau/src/graph.ml": "\005\175.\2458\176E\202]\255\235=9\015\000\237" "Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/graph.ml": "\005\175.\2458\176E\202]\255\235=9\015\000\237" "Rule: ocaml: mli -> cmi (%=src/gfile )": "\015\211&r\030l{}\183\187\236\2266\022\129\191" "Resource: /home/alejeune/Documents/4ir/S1/Ocaml/FordFulkersonLeChameau/src/graph.mli": "\031\217\135\022\208\254\154\148\252)\210\130\174\215X\031" "Resource: /home/alejeune/Documents/4ir/S1/Ocaml/FordFulkersonLeChameau/src/gfile.mli": "\203\249\163Ct\234\0067d}\142\011m8T`" -"Rule: ocaml dependencies ml (%=src/tools )": "\238;-\163=t\145N\016@\024\208\158\198-/" "Resource: /home/alejeune/Documents/4ir/S1/Ocaml/FordFulkersonLeChameau/src/tools.ml": "~[\186\208\199\129\006\030\012\196\245\183'\163\211&" +"Rule: ocaml dependencies ml (%=src/tools )": "\228\210\133\187`\193\179>\031\016\197\147\221\006j\017" "Resource: /home/alejeune/Documents/4ir/S1/Ocaml/FordFulkersonLeChameau/src/ftest.ml": "~\190 \235\142\210\r\222\253\136>\194\180\207\183\168" -"Rule: ocaml: ml -> cmo & cmi (%=src/ftest )": "8 D,\027\028\193\161N'\n\184\250\177\237m" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/fordFulkerson.mli": "\\\2004\027\164.\176\217\238\189 cmo & cmi (%=src/ftest )": "\211\163\255\143]\195\185\150\159\224r\005\232\206\148=" +"Rule: ocaml dependencies mli (%=src/fordFulkerson )": "\175u\223\222e6\175\017\025\014\220\011\127\150\218t" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/fordFulkerson.mli": "t\243u\229\130\149\185\161\226\030|\1607\130?+" "Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/display.mli": "j\141\168#\004\174\151?]\022hm\211,\164\147" -"Rule: ocaml: ml & cmi -> cmx & o (%=src/tools )": ";\129\180\230Q\250!\223TK}\193\012D\247\005" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/gfile.ml": "\1966\177\141\185,fpl\1987gT\128b\028" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/tools )": "z\158\235\155v\003\214Q\150\t\224\"\026\246(\158" +"Rule: ocaml dependencies ml (%=src/fordFulkerson )": "\216\216\252\019\234{jF\249\249u\001fe\0241" "Resource: /home/alejeune/Documents/4ir/S1/Ocaml/FordFulkersonLeChameau/src/gfile.ml": "\1966\177\141\185,fpl\1987gT\128b\028" -"Rule: ocaml dependencies ml (%=src/fordFulkerson )": "\187{\021\n?|\014\005\140I\151I\222\135\221i" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/tools.mli": "9\173\222\177]e\245\229\131\151\020fsu\133@" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/gfile.ml": "\1966\177\141\185,fpl\1987gT\128b\028" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/tools.mli": "\025v\144\241\237\241\b\248\197tD\012\171\216\202\148" "Rule: ocaml: ml & cmi -> cmx & o (%=src/graph )": "\190\tV\232\254i\031+\141\154\168\219\155n\156C" "Rule: ocaml dependencies ml (%=src/graph )": "\137kk#\140\236\011\255?\132T\225M\018\169\224" -"Rule: ocaml dependencies ml (%=src/display )": "\162K\\\156\237a\012\132\237\169\243\248\212Sb\221" "Rule: ocaml dependencies mli (%=src/graph )": "\012\213_n\023=\207kZ+\251(^M\2028" +"Rule: ocaml dependencies ml (%=src/display )": "\162K\\\156\237a\012\132\237\169\243\248\212Sb\221" "Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/gfile.mli": "\203\249\163Ct\234\0067d}\142\011m8T`" -"Rule: ocaml dependencies mli (%=src/tools )": "\22566|\026\\\138\197K\020\155\144/$\219\161" "Rule: ocaml dependencies ml (%=src/gfile )": "U4(<\t=rQ\240c\0278\231N\1949" +"Rule: ocaml dependencies mli (%=src/tools )": "\151\181\0055\199\150&\017\021_\215\015\215\018\027+" "Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/display.ml": "y\135\165\238\138M)N\224\237\005 \027+d\t" diff --git a/_build/_log b/_build/_log index c8b7f60..03d7a66 100644 --- a/_build/_log +++ b/_build/_log @@ -1,6 +1,6 @@ ### Starting build. # Target: src/ftest.ml.depends, tags: { extension:ml, file:src/ftest.ml, include, ocaml, ocamldep, quiet, traverse } -/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/ftest.ml > src/ftest.ml.depends +/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/ftest.ml > src/ftest.ml.depends # cached # Target: src/display.mli.depends, tags: { extension:mli, file:src/display.mli, include, ocaml, ocamldep, quiet, traverse } /home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/display.mli > src/display.mli.depends # cached # Target: src/gfile.mli.depends, tags: { extension:mli, file:src/gfile.mli, include, ocaml, ocamldep, quiet, traverse } @@ -22,7 +22,7 @@ # Target: src/fordFulkerson.cmi, tags: { byte, compile, extension:mli, file:src/fordFulkerson.mli, include, interf, ocaml, quiet, traverse } /home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/fordFulkerson.cmi src/fordFulkerson.mli # cached # Target: src/ftest.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:src/ftest.cmo, file:src/ftest.ml, implem, include, ocaml, quiet, traverse } -/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/ftest.cmo src/ftest.ml +/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/ftest.cmo src/ftest.ml # cached # Target: src/display.ml.depends, tags: { extension:ml, file:src/display.ml, include, ocaml, ocamldep, quiet, traverse } /home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/display.ml > src/display.ml.depends # cached # Target: src/gfile.ml.depends, tags: { extension:ml, file:src/gfile.ml, include, ocaml, ocamldep, quiet, traverse } @@ -36,15 +36,15 @@ # Target: src/display.cmx, tags: { compile, extension:cmx, extension:ml, file:src/display.cmx, file:src/display.ml, implem, include, native, ocaml, quiet, traverse } /home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/display.cmx src/display.ml # cached # Target: src/fordFulkerson.ml.depends, tags: { extension:ml, file:src/fordFulkerson.ml, include, ocaml, ocamldep, quiet, traverse } -/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/fordFulkerson.ml > src/fordFulkerson.ml.depends # cached +/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/fordFulkerson.ml > src/fordFulkerson.ml.depends # Target: src/tools.ml.depends, tags: { extension:ml, file:src/tools.ml, include, ocaml, ocamldep, quiet, traverse } /home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/tools.ml > src/tools.ml.depends # cached # Target: src/tools.cmx, tags: { compile, extension:cmx, extension:ml, file:src/tools.cmx, file:src/tools.ml, implem, include, native, ocaml, quiet, traverse } /home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/tools.cmx src/tools.ml # cached # Target: src/fordFulkerson.cmx, tags: { compile, extension:cmx, extension:ml, file:src/fordFulkerson.cmx, file:src/fordFulkerson.ml, implem, include, native, ocaml, quiet, traverse } -/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/fordFulkerson.cmx src/fordFulkerson.ml # cached +/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/fordFulkerson.cmx src/fordFulkerson.ml # Target: src/ftest.cmx, tags: { compile, extension:cmx, extension:ml, file:src/ftest.cmx, file:src/ftest.ml, implem, include, native, ocaml, quiet, traverse } -/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/ftest.cmx src/ftest.ml +/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/ftest.cmx src/ftest.ml # cached # Target: src/ftest.native, tags: { dont_link_with, extension:native, file:src/ftest.native, include, link, native, ocaml, program, quiet, traverse } /home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -I src src/graph.cmx src/gfile.cmx src/display.cmx src/tools.cmx src/fordFulkerson.cmx src/ftest.cmx -o src/ftest.native # Compilation successful. diff --git a/_build/src/ftest.cmi b/_build/src/ftest.cmi index e6da2b7..ff662eb 100644 Binary files a/_build/src/ftest.cmi and b/_build/src/ftest.cmi differ diff --git a/_build/src/ftest.cmo b/_build/src/ftest.cmo index 5ba5d5d..24fa201 100644 Binary files a/_build/src/ftest.cmo and b/_build/src/ftest.cmo differ diff --git a/_build/src/ftest.cmx b/_build/src/ftest.cmx index 263a908..8c4f2e9 100644 Binary files a/_build/src/ftest.cmx and b/_build/src/ftest.cmx differ diff --git a/_build/src/ftest.ml b/_build/src/ftest.ml index 1945637..4eb5246 100644 --- a/_build/src/ftest.ml +++ b/_build/src/ftest.ml @@ -1,54 +1,58 @@ -open Gfile -open Tools -open Display -open FordFulkerson - -let () = + open Gfile + open Tools + open Display + open FordFulkerson - (* Check the number of command-line arguments -*) - if Array.length Sys.argv <> 5 then - begin - 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 ; + let () = - (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *) - - let infile = Sys.argv.(1) - and outfile = Sys.argv.(4) + (* Check the number of command-line arguments + *) + if Array.length Sys.argv <> 5 then + begin + 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 ; - (* 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) - in + (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *) - (* Open file *) - let graph = from_file infile in + let infile = Sys.argv.(1) + and outfile = Sys.argv.(4) - let graphInt = gmap graph int_of_string in + (* 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) + in - let graphBis1 = add_arc graphInt 5 4 10 in - let graphBis2 = add_arc graphBis1 4 1 10 in - let graphBis = add_arc graphBis2 5 1 10 in + (* Open file *) + let graph = from_file infile in - match (way graphBis 5 0) with - | None -> failwith "No way" - | Some (x,y) -> Printf.printf "%d \n" y; + let graphInt = gmap graph int_of_string in - let () = List.iter (Printf.printf "%d, ") x in - (); Printf.printf "\n"; + let pathTest = way graphInt 0 5 in - let graphFinal = gmap graphBis string_of_int in + match pathTest with + | None -> failwith "No way" + | Some (x,y) -> Printf.printf "%d \n" y; - let () = export graphFinal outfile in - () - (*Rewrite the graph that has been read. - let () = write_file outfile graphDot in - () - *) \ No newline at end of file + let () = List.iter (Printf.printf "%d, ") x in + (); Printf.printf "\n"; + + + match pathTest with + | None -> failwith "No way" + | Some (x,y) -> let graphBis = update graphInt (x,y) in + + + let graphFinal = gmap graphBis string_of_int in + + let () = export graphFinal outfile in + () + (* Rewrite the graph that has been read. + let () = write_file outfile graphDot in + () + *) \ No newline at end of file diff --git a/_build/src/ftest.native b/_build/src/ftest.native index 7238118..d253063 100755 Binary files a/_build/src/ftest.native and b/_build/src/ftest.native differ diff --git a/_build/src/ftest.o b/_build/src/ftest.o index 62437f5..8d27fef 100644 Binary files a/_build/src/ftest.o and b/_build/src/ftest.o differ diff --git a/outfile b/outfile index 6fda684..54125d3 100644 --- a/outfile +++ b/outfile @@ -12,17 +12,15 @@ node [shape = circle]; - 0 -> 2 [label = "8"]; - 0 -> 3 [label = "10"]; - 0 -> 1 [label = "7"]; - 2 -> 4 [label = "12"]; - 3 -> 4 [label = "5"]; - 3 -> 2 [label = "2"]; - 3 -> 1 [label = "11"]; + 5 -> 1 [label = "7"]; + 1 -> 5 [label = "14"]; + 1 -> 0 [label = "7"]; 1 -> 4 [label = "1"]; - 1 -> 5 [label = "21"]; + 0 -> 3 [label = "10"]; + 0 -> 2 [label = "8"]; 4 -> 5 [label = "14"]; - 4 -> 1 [label = "10"]; - 5 -> 4 [label = "10"]; - 5 -> 1 [label = "10"]; + 3 -> 1 [label = "11"]; + 3 -> 2 [label = "2"]; + 3 -> 4 [label = "5"]; + 2 -> 4 [label = "12"]; } \ No newline at end of file diff --git a/src/fordFulkerson.ml b/src/fordFulkerson.ml index b96df9b..777d617 100644 --- a/src/fordFulkerson.ml +++ b/src/fordFulkerson.ml @@ -29,6 +29,30 @@ let rec way g n1 n2 = in if n1 == n2 then None - else inner g ([n1], 99999) [] n1 n2 + else inner g ([n1], (maxCapaGraph g)) [] n1 n2 +(*updates the difference graph according to a path, +removes any 0-worth edge and tests for the graph sanity (only positive-valued edges)*) +let update g (nodes,capa) = + let rec updateCapacityAlongPath g (nodes,capa) = + match nodes with + | [] -> g + | x :: [] -> g + | x::y::xs -> + let removedCapcityUsed = sub_arc g x y capa in + let addPossibleUndo = add_arc removedCapcityUsed y x capa in + updateCapacityAlongPath addPossibleUndo (y::xs,capa) + in + testGraphSanity ( + clearNull ( + updateCapacityAlongPath g (nodes,capa) + ) + ) + +(*takes a graph, a start/end node and returns a finished difference graph*) +let rec main g idS idE = + let path = way g idS idE in + match path with + | None -> g + | Same (xs, capa) -> main (update g (xs, capa) idS IdE) diff --git a/src/fordFulkerson.mli b/src/fordFulkerson.mli index 2aee68b..26d371f 100644 --- a/src/fordFulkerson.mli +++ b/src/fordFulkerson.mli @@ -4,6 +4,6 @@ open Display val way: int graph -> id -> id -> (id list * int) option - +val update: int graph -> (id list * int) -> int graph (* *) \ No newline at end of file diff --git a/src/ftest.ml b/src/ftest.ml index 1945637..4eb5246 100644 --- a/src/ftest.ml +++ b/src/ftest.ml @@ -1,54 +1,58 @@ -open Gfile -open Tools -open Display -open FordFulkerson - -let () = + open Gfile + open Tools + open Display + open FordFulkerson - (* Check the number of command-line arguments -*) - if Array.length Sys.argv <> 5 then - begin - 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 ; + let () = - (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *) - - let infile = Sys.argv.(1) - and outfile = Sys.argv.(4) + (* Check the number of command-line arguments + *) + if Array.length Sys.argv <> 5 then + begin + 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 ; - (* 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) - in + (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *) - (* Open file *) - let graph = from_file infile in + let infile = Sys.argv.(1) + and outfile = Sys.argv.(4) - let graphInt = gmap graph int_of_string in + (* 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) + in - let graphBis1 = add_arc graphInt 5 4 10 in - let graphBis2 = add_arc graphBis1 4 1 10 in - let graphBis = add_arc graphBis2 5 1 10 in + (* Open file *) + let graph = from_file infile in - match (way graphBis 5 0) with - | None -> failwith "No way" - | Some (x,y) -> Printf.printf "%d \n" y; + let graphInt = gmap graph int_of_string in - let () = List.iter (Printf.printf "%d, ") x in - (); Printf.printf "\n"; + let pathTest = way graphInt 0 5 in - let graphFinal = gmap graphBis string_of_int in + match pathTest with + | None -> failwith "No way" + | Some (x,y) -> Printf.printf "%d \n" y; - let () = export graphFinal outfile in - () - (*Rewrite the graph that has been read. - let () = write_file outfile graphDot in - () - *) \ No newline at end of file + let () = List.iter (Printf.printf "%d, ") x in + (); Printf.printf "\n"; + + + match pathTest with + | None -> failwith "No way" + | Some (x,y) -> let graphBis = update graphInt (x,y) in + + + let graphFinal = gmap graphBis string_of_int in + + let () = export graphFinal outfile in + () + (* Rewrite the graph that has been read. + let () = write_file outfile graphDot in + () + *) \ No newline at end of file diff --git a/src/tools.ml b/src/tools.ml index d61f89d..9562e6d 100644 --- a/src/tools.ml +++ b/src/tools.ml @@ -11,8 +11,38 @@ let add_arc g id1 id2 n = | None -> new_arc g id1 id2 n | Some a -> new_arc g id1 id2 (n + a) + +let sub_arc g id1 id2 n = + match find_arc g id1 id2 with + | None -> new_arc g id1 id2 (-1 * n) + | Some a -> new_arc g id1 id2 ((-1 * n) + a) + + (* maps all arcs of gr by function f *) let gmap gr f = e_fold gr (fun acc id1 id2 x -> new_arc acc id1 id2 (f x)) (clone_nodes gr) -(*let maxCapaGraph*) \ No newline at end of file +(* removes all empty edges *) +let clearNull g = + let newG = clone_nodes g in + let filterEdge g id1 id2 x = + if x <> 0 then + add_arc g id1 id2 x + else + g + in + e_fold g filterEdge newG + +(*calculates the maximum capacity of the graph +(used as a base value for the min capacity on a eay)*) +let maxCapaGraph g = + e_fold g (fun x id1 id2 a -> (max a x)) 0 + +(*Checks that no null or negative edge exists, +returns the graph unchanged in this case*) +let testGraphSanity g = + if e_fold g (fun x id1 id2 a -> x or a < 1) false + then + failwith "Graph wrongly managed" + else + g diff --git a/src/tools.mli b/src/tools.mli index d2b4af8..136451f 100644 --- a/src/tools.mli +++ b/src/tools.mli @@ -2,4 +2,8 @@ open Graph val clone_nodes: 'a graph -> 'b graph val gmap: 'a graph -> ('a -> 'b) -> 'b graph -val add_arc: int graph -> id -> id -> int -> int graph \ No newline at end of file +val add_arc: int graph -> id -> id -> int -> int graph +val sub_arc: int graph -> id -> id -> int -> int graph +val clearNull: int graph -> int graph +val maxCapaGraph: int graph -> int +val testGraphSanity: int graph -> int graph \ No newline at end of file diff --git a/test.svg b/test.svg index 66cdd84..7e957bf 100644 --- a/test.svg +++ b/test.svg @@ -4,137 +4,123 @@ - - + + finite_state_machine - - + + -0 +5 -0 - - - -2 - -2 - - - -0->2 - - -8 - - - -3 - -3 - - - -0->3 - - -10 +5 - + 1 - -1 - - - -0->1 - - -7 - - - -4 - -4 - - - -2->4 - - -12 - - - -3->2 - - -2 - - - -3->1 - - -11 - - - -3->4 - - -5 - - - -1->4 - - -1 - - - -5 - -5 - - - -1->5 - - -21 - - - -4->1 - - -10 - - - -4->5 - - -14 + +1 - + 5->1 - - -10 + + +7 - - -5->4 - - -10 + + +1->5 + + +14 + + + +0 + +0 + + + +1->0 + + +7 + + + +4 + +4 + + + +1->4 + + +1 + + + +3 + +3 + + + +0->3 + + +10 + + + +2 + +2 + + + +0->2 + + +8 + + + +4->5 + + +14 + + + +3->1 + + +11 + + + +3->4 + + +5 + + + +3->2 + + +2 + + + +2->4 + + +12