cleanup + comments

This commit is contained in:
Kevin Cavailles 2020-12-12 19:47:38 +01:00
parent e0f35908b2
commit 6c88eb310c
13 changed files with 46 additions and 366 deletions

View file

@ -11,7 +11,7 @@ edit:
demo: build
@echo "\n==== EXECUTING ====\n"
./ftest.native graphs/graph1 1 2 outfile
./ftest.native graphs/graph1 0 5 outfile
@echo "\n==== RESULT ==== (content of outfile) \n"
@cat outfile

View file

@ -1,21 +0,0 @@
% This is a graph.
n 0.0 1.0
n 1.0 1.0
n 2.0 1.0
n 3.0 1.0
n 4.0 1.0
n 5.0 1.0
e 0 2 8/8
e 0 3 10/10
e 0 1 7/7
e 2 4 9/12
e 3 4 5/5
e 3 2 1/2
e 3 1 4/11
e 1 4 0/1
e 1 5 11/21
e 4 5 14/14
% End of graph

View file

@ -1,14 +0,0 @@
digraph graphique1 {
size="20"
node [shape = circle];
0 -> 2 [ label = "8/8" ];
0 -> 3 [ label = "10/10" ];
0 -> 1 [ label = "7/7" ];
2 -> 4 [ label = "9/12" ];
3 -> 4 [ label = "5/5" ];
3 -> 2 [ label = "1/2" ];
3 -> 1 [ label = "4/11" ];
1 -> 4 [ label = "0/1" ];
1 -> 5 [ label = "11/21" ];
4 -> 5 [ label = "14/14" ];
}

View file

@ -1,119 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: graphique1 Pages: 1 -->
<svg width="188pt" height="392pt"
viewBox="0.00 0.00 188.00 392.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 388)">
<title>graphique1</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-388 184,-388 184,4 -4,4"/>
<!-- 0 -->
<g id="node1" class="node">
<title>0</title>
<ellipse fill="none" stroke="#000000" cx="72" cy="-366" rx="18" ry="18"/>
<text text-anchor="middle" x="72" y="-362.3" font-family="Times,serif" font-size="14.00" fill="#000000">0</text>
</g>
<!-- 2 -->
<g id="node2" class="node">
<title>2</title>
<ellipse fill="none" stroke="#000000" cx="18" cy="-192" rx="18" ry="18"/>
<text text-anchor="middle" x="18" y="-188.3" font-family="Times,serif" font-size="14.00" fill="#000000">2</text>
</g>
<!-- 0&#45;&gt;2 -->
<g id="edge1" class="edge">
<title>0&#45;&gt;2</title>
<path fill="none" stroke="#000000" d="M58.983,-353.1198C46.8886,-340.1986 29.6311,-319.0932 22,-297 13.3896,-272.0714 13.2288,-241.8111 14.72,-220.1919"/>
<polygon fill="#000000" stroke="#000000" points="18.2232,-220.3025 15.5845,-210.0415 11.2484,-219.7084 18.2232,-220.3025"/>
<text text-anchor="middle" x="33.5" y="-275.3" font-family="Times,serif" font-size="14.00" fill="#000000">8/8</text>
</g>
<!-- 3 -->
<g id="node3" class="node">
<title>3</title>
<ellipse fill="none" stroke="#000000" cx="72" cy="-279" rx="18" ry="18"/>
<text text-anchor="middle" x="72" y="-275.3" font-family="Times,serif" font-size="14.00" fill="#000000">3</text>
</g>
<!-- 0&#45;&gt;3 -->
<g id="edge2" class="edge">
<title>0&#45;&gt;3</title>
<path fill="none" stroke="#000000" d="M72,-347.9735C72,-336.1918 72,-320.5607 72,-307.1581"/>
<polygon fill="#000000" stroke="#000000" points="75.5001,-307.0033 72,-297.0034 68.5001,-307.0034 75.5001,-307.0033"/>
<text text-anchor="middle" x="92.5" y="-318.8" font-family="Times,serif" font-size="14.00" fill="#000000">10/10</text>
</g>
<!-- 1 -->
<g id="node4" class="node">
<title>1</title>
<ellipse fill="none" stroke="#000000" cx="137" cy="-192" rx="18" ry="18"/>
<text text-anchor="middle" x="137" y="-188.3" font-family="Times,serif" font-size="14.00" fill="#000000">1</text>
</g>
<!-- 0&#45;&gt;1 -->
<g id="edge3" class="edge">
<title>0&#45;&gt;1</title>
<path fill="none" stroke="#000000" d="M88.0173,-356.9724C97.8133,-350.6458 109.8055,-341.3126 117,-330 138.1739,-296.7064 140.4934,-249.8701 139.3836,-220.2302"/>
<polygon fill="#000000" stroke="#000000" points="142.8735,-219.9456 138.8482,-210.1452 135.8834,-220.3168 142.8735,-219.9456"/>
<text text-anchor="middle" x="148.5" y="-275.3" font-family="Times,serif" font-size="14.00" fill="#000000">7/7</text>
</g>
<!-- 4 -->
<g id="node5" class="node">
<title>4</title>
<ellipse fill="none" stroke="#000000" cx="76" cy="-105" rx="18" ry="18"/>
<text text-anchor="middle" x="76" y="-101.3" font-family="Times,serif" font-size="14.00" fill="#000000">4</text>
</g>
<!-- 2&#45;&gt;4 -->
<g id="edge4" class="edge">
<title>2&#45;&gt;4</title>
<path fill="none" stroke="#000000" d="M17.4941,-173.8297C17.9922,-163.523 19.9922,-150.773 26,-141 31.8818,-131.432 41.3501,-123.6565 50.4733,-117.8128"/>
<polygon fill="#000000" stroke="#000000" points="52.4786,-120.6944 59.336,-112.6181 48.9388,-114.6553 52.4786,-120.6944"/>
<text text-anchor="middle" x="42" y="-144.8" font-family="Times,serif" font-size="14.00" fill="#000000">9/12</text>
</g>
<!-- 3&#45;&gt;2 -->
<g id="edge6" class="edge">
<title>3&#45;&gt;2</title>
<path fill="none" stroke="#000000" d="M57.7101,-267.978C50.0595,-261.4356 41.0026,-252.5652 35,-243 30.5351,-235.8851 27.1085,-227.4695 24.5419,-219.5471"/>
<polygon fill="#000000" stroke="#000000" points="27.8925,-218.5344 21.7375,-209.9108 21.1713,-220.4905 27.8925,-218.5344"/>
<text text-anchor="middle" x="46.5" y="-231.8" font-family="Times,serif" font-size="14.00" fill="#000000">1/2</text>
</g>
<!-- 3&#45;&gt;1 -->
<g id="edge7" class="edge">
<title>3&#45;&gt;1</title>
<path fill="none" stroke="#000000" d="M81.6391,-263.4852C88.1991,-253.1991 97.2478,-239.5259 106,-228 109.7706,-223.0344 114.0174,-217.8624 118.1304,-213.0388"/>
<polygon fill="#000000" stroke="#000000" points="120.8975,-215.1906 124.8183,-205.3479 115.6153,-210.5973 120.8975,-215.1906"/>
<text text-anchor="middle" x="122" y="-231.8" font-family="Times,serif" font-size="14.00" fill="#000000">4/11</text>
</g>
<!-- 3&#45;&gt;4 -->
<g id="edge5" class="edge">
<title>3&#45;&gt;4</title>
<path fill="none" stroke="#000000" d="M72.4205,-260.7078C73.1185,-230.3436 74.5213,-169.3226 75.3484,-133.3464"/>
<polygon fill="#000000" stroke="#000000" points="78.8543,-133.1249 75.5851,-123.0471 71.8561,-132.964 78.8543,-133.1249"/>
<text text-anchor="middle" x="85.5" y="-188.3" font-family="Times,serif" font-size="14.00" fill="#000000">5/5</text>
</g>
<!-- 1&#45;&gt;4 -->
<g id="edge8" class="edge">
<title>1&#45;&gt;4</title>
<path fill="none" stroke="#000000" d="M124.6262,-178.7937C118.6943,-172.1806 111.6654,-163.9136 106,-156 100.1156,-147.7805 94.3223,-138.3442 89.4195,-129.8412"/>
<polygon fill="#000000" stroke="#000000" points="92.4435,-128.0782 84.4867,-121.0825 86.3443,-131.5132 92.4435,-128.0782"/>
<text text-anchor="middle" x="117.5" y="-144.8" font-family="Times,serif" font-size="14.00" fill="#000000">0/1</text>
</g>
<!-- 5 -->
<g id="node6" class="node">
<title>5</title>
<ellipse fill="none" stroke="#000000" cx="108" cy="-18" rx="18" ry="18"/>
<text text-anchor="middle" x="108" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">5</text>
</g>
<!-- 1&#45;&gt;5 -->
<g id="edge9" class="edge">
<title>1&#45;&gt;5</title>
<path fill="none" stroke="#000000" d="M138.6021,-173.6686C140.3628,-146.7805 141.4761,-95.3565 129,-54 127.7305,-49.7917 125.8809,-45.5534 123.798,-41.5363"/>
<polygon fill="#000000" stroke="#000000" points="126.7141,-39.5872 118.6779,-32.6828 120.6544,-43.0917 126.7141,-39.5872"/>
<text text-anchor="middle" x="159.5" y="-101.3" font-family="Times,serif" font-size="14.00" fill="#000000">11/21</text>
</g>
<!-- 4&#45;&gt;5 -->
<g id="edge10" class="edge">
<title>4&#45;&gt;5</title>
<path fill="none" stroke="#000000" d="M78.9419,-87.1717C80.8936,-77.2108 83.8652,-64.6891 88,-54 89.4953,-50.1345 91.3388,-46.1737 93.2963,-42.359"/>
<polygon fill="#000000" stroke="#000000" points="96.5174,-43.7648 98.2634,-33.3148 90.3818,-40.3951 96.5174,-43.7648"/>
<text text-anchor="middle" x="108.5" y="-57.8" font-family="Times,serif" font-size="14.00" fill="#000000">14/14</text>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 6.6 KiB

View file

@ -1,21 +0,0 @@
% This is a graph.
n 0.0 1.0
n 1.0 1.0
n 2.0 1.0
n 3.0 1.0
n 4.0 1.0
n 5.0 1.0
e 4 5 4/4
e 4 3 7/7
e 3 5 19/20
e 3 2 0/9
e 2 4 11/14
e 2 1 2/4
e 1 3 12/12
e 1 2 0/10
e 0 2 13/13
e 0 1 10/16
% End of graph

View file

@ -1,14 +0,0 @@
digraph graphique1 {
size="20"
node [shape = circle];
4 -> 5 [ label = "4/4" ];
4 -> 3 [ label = "7/7" ];
3 -> 5 [ label = "19/20" ];
3 -> 2 [ label = "0/9" ];
2 -> 4 [ label = "11/14" ];
2 -> 1 [ label = "2/4" ];
1 -> 3 [ label = "12/12" ];
1 -> 2 [ label = "0/10" ];
0 -> 2 [ label = "13/13" ];
0 -> 1 [ label = "10/16" ];
}

View file

@ -1,119 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: graphique1 Pages: 1 -->
<svg width="280pt" height="305pt"
viewBox="0.00 0.00 280.00 305.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 301)">
<title>graphique1</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-301 276,-301 276,4 -4,4"/>
<!-- 4 -->
<g id="node1" class="node">
<title>4</title>
<ellipse fill="none" stroke="#000000" cx="90" cy="-279" rx="18" ry="18"/>
<text text-anchor="middle" x="90" y="-275.3" font-family="Times,serif" font-size="14.00" fill="#000000">4</text>
</g>
<!-- 5 -->
<g id="node2" class="node">
<title>5</title>
<ellipse fill="none" stroke="#000000" cx="18" cy="-105" rx="18" ry="18"/>
<text text-anchor="middle" x="18" y="-101.3" font-family="Times,serif" font-size="14.00" fill="#000000">5</text>
</g>
<!-- 4&#45;&gt;5 -->
<g id="edge1" class="edge">
<title>4&#45;&gt;5</title>
<path fill="none" stroke="#000000" d="M77.9541,-265.3725C66.7415,-252.0678 50.2604,-230.8368 40,-210 28.9421,-187.5436 29.0363,-180.5195 24,-156 22.4882,-148.6398 21.3215,-140.5981 20.4366,-133.1214"/>
<polygon fill="#000000" stroke="#000000" points="23.9043,-132.6316 19.3665,-123.0578 16.9436,-133.3718 23.9043,-132.6316"/>
<text text-anchor="middle" x="51.5" y="-188.3" font-family="Times,serif" font-size="14.00" fill="#000000">4/4</text>
</g>
<!-- 3 -->
<g id="node3" class="node">
<title>3</title>
<ellipse fill="none" stroke="#000000" cx="90" cy="-192" rx="18" ry="18"/>
<text text-anchor="middle" x="90" y="-188.3" font-family="Times,serif" font-size="14.00" fill="#000000">3</text>
</g>
<!-- 4&#45;&gt;3 -->
<g id="edge2" class="edge">
<title>4&#45;&gt;3</title>
<path fill="none" stroke="#000000" d="M90,-260.9735C90,-249.1918 90,-233.5607 90,-220.1581"/>
<polygon fill="#000000" stroke="#000000" points="93.5001,-220.0033 90,-210.0034 86.5001,-220.0034 93.5001,-220.0033"/>
<text text-anchor="middle" x="101.5" y="-231.8" font-family="Times,serif" font-size="14.00" fill="#000000">7/7</text>
</g>
<!-- 3&#45;&gt;5 -->
<g id="edge3" class="edge">
<title>3&#45;&gt;5</title>
<path fill="none" stroke="#000000" d="M73.3889,-184.8324C61.1787,-178.7811 45.0301,-169.0177 35,-156 29.7931,-149.2422 26.1373,-140.8083 23.5886,-132.7568"/>
<polygon fill="#000000" stroke="#000000" points="26.9155,-131.6522 20.919,-122.9176 20.1597,-133.4852 26.9155,-131.6522"/>
<text text-anchor="middle" x="55.5" y="-144.8" font-family="Times,serif" font-size="14.00" fill="#000000">19/20</text>
</g>
<!-- 2 -->
<g id="node4" class="node">
<title>2</title>
<ellipse fill="none" stroke="#000000" cx="167" cy="-105" rx="18" ry="18"/>
<text text-anchor="middle" x="167" y="-101.3" font-family="Times,serif" font-size="14.00" fill="#000000">2</text>
</g>
<!-- 3&#45;&gt;2 -->
<g id="edge4" class="edge">
<title>3&#45;&gt;2</title>
<path fill="none" stroke="#000000" d="M99.0402,-175.9907C105.3474,-165.4959 114.3393,-151.7758 124,-141 129.9407,-134.3736 137.1211,-127.8896 143.8985,-122.2911"/>
<polygon fill="#000000" stroke="#000000" points="146.4989,-124.6948 152.1441,-115.7292 142.14,-119.2175 146.4989,-124.6948"/>
<text text-anchor="middle" x="135.5" y="-144.8" font-family="Times,serif" font-size="14.00" fill="#000000">0/9</text>
</g>
<!-- 2&#45;&gt;4 -->
<g id="edge5" class="edge">
<title>2&#45;&gt;4</title>
<path fill="none" stroke="#000000" d="M162.41,-122.6992C155.0214,-149.6635 139.0536,-202.201 117,-243 114.4192,-247.7744 111.2509,-252.6085 108.0039,-257.1185"/>
<polygon fill="#000000" stroke="#000000" points="105.0583,-255.2101 101.7969,-265.2905 110.6326,-259.4441 105.0583,-255.2101"/>
<text text-anchor="middle" x="165.5" y="-188.3" font-family="Times,serif" font-size="14.00" fill="#000000">11/14</text>
</g>
<!-- 1 -->
<g id="node5" class="node">
<title>1</title>
<ellipse fill="none" stroke="#000000" cx="163" cy="-18" rx="18" ry="18"/>
<text text-anchor="middle" x="163" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">1</text>
</g>
<!-- 2&#45;&gt;1 -->
<g id="edge6" class="edge">
<title>2&#45;&gt;1</title>
<path fill="none" stroke="#000000" d="M154.3717,-91.7776C149.1557,-85.4162 143.7041,-77.3626 141,-69 137.9173,-59.4665 140.9614,-49.2702 145.6665,-40.5196"/>
<polygon fill="#000000" stroke="#000000" points="148.6515,-42.3473 150.9839,-32.0124 142.7157,-38.6371 148.6515,-42.3473"/>
<text text-anchor="middle" x="152.5" y="-57.8" font-family="Times,serif" font-size="14.00" fill="#000000">2/4</text>
</g>
<!-- 1&#45;&gt;3 -->
<g id="edge7" class="edge">
<title>1&#45;&gt;3</title>
<path fill="none" stroke="#000000" d="M148.3458,-28.8353C133.0601,-41.0707 109.8445,-62.4968 99,-87 88.2315,-111.3314 86.7934,-141.9038 87.5599,-163.7742"/>
<polygon fill="#000000" stroke="#000000" points="84.0796,-164.2407 88.1029,-174.0419 91.0698,-163.871 84.0796,-164.2407"/>
<text text-anchor="middle" x="119.5" y="-101.3" font-family="Times,serif" font-size="14.00" fill="#000000">12/12</text>
</g>
<!-- 1&#45;&gt;2 -->
<g id="edge8" class="edge">
<title>1&#45;&gt;2</title>
<path fill="none" stroke="#000000" d="M163.8277,-36.0034C164.3692,-47.7801 165.0878,-63.4102 165.7042,-76.8156"/>
<polygon fill="#000000" stroke="#000000" points="162.2155,-77.1449 166.1712,-86.9735 169.2081,-76.8233 162.2155,-77.1449"/>
<text text-anchor="middle" x="181" y="-57.8" font-family="Times,serif" font-size="14.00" fill="#000000">0/10</text>
</g>
<!-- 0 -->
<g id="node6" class="node">
<title>0</title>
<ellipse fill="none" stroke="#000000" cx="244" cy="-192" rx="18" ry="18"/>
<text text-anchor="middle" x="244" y="-188.3" font-family="Times,serif" font-size="14.00" fill="#000000">0</text>
</g>
<!-- 0&#45;&gt;2 -->
<g id="edge9" class="edge">
<title>0&#45;&gt;2</title>
<path fill="none" stroke="#000000" d="M228.0312,-182.8022C217.7,-176.282 204.4623,-166.7966 195,-156 188.5183,-148.6042 182.9169,-139.4574 178.4637,-130.9611"/>
<polygon fill="#000000" stroke="#000000" points="181.4966,-129.1973 173.9381,-121.773 175.217,-132.2903 181.4966,-129.1973"/>
<text text-anchor="middle" x="215.5" y="-144.8" font-family="Times,serif" font-size="14.00" fill="#000000">13/13</text>
</g>
<!-- 0&#45;&gt;1 -->
<g id="edge10" class="edge">
<title>0&#45;&gt;1</title>
<path fill="none" stroke="#000000" d="M242.1687,-173.8503C240.9233,-164.014 238.954,-151.7136 236,-141 224.9216,-100.821 224.4457,-88.4585 201,-54 196.5716,-47.4915 190.7891,-41.2657 185.076,-35.8764"/>
<polygon fill="#000000" stroke="#000000" points="187.2584,-33.1333 177.4621,-29.098 182.6039,-38.3616 187.2584,-33.1333"/>
<text text-anchor="middle" x="251.5" y="-101.3" font-family="Times,serif" font-size="14.00" fill="#000000">10/16</text>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 6.7 KiB

View file

@ -3,48 +3,48 @@ open Graph
type path = id list
(*type record avec id noeud et son cout*)
type t_cost={
type t_cost = {
mutable cout:int;
mutable father:int
}
let blf gr id_src id_dest=
let blf graph idSrc =
(*je compte le nb de noeuds dans le graphe pour instancier mon tableau*)
let nb_n=n_fold gr (fun acu id->acu+1) 0 in
let nb_n = n_fold graph (fun acu id->acu+1) 0 in
let cost ={cout=max_int; father=(-1)} in
let cost = {cout=max_int; father=(-1)} in
let acu =Array.make nb_n cost in
let acu = Array.make nb_n cost in
(*je fais un fold_left pour pouvoir individualiser au niveau de la mémoire les cases de la table*)
let blf_tab=n_fold gr (fun acu id->acu.(id)<-{cout=max_int; father=(-1)}; acu ) acu in
blf_tab.(id_src).cout<-0;
let file_id=[id_src] in
let file_marque =[] in
let blfTab = n_fold graph (fun acu id->acu.(id)<-{cout = max_int; father = (-1) }; acu ) acu in
blfTab.(idSrc).cout <- 0;
let fileId = [idSrc] in
let fileMarquee = [] in
let rec blf_rec gr file_id file_marque= match file_id with
|[]-> blf_tab
let rec blf_rec graph fileId fileMarquee= match fileId with
|[]-> blfTab
|a::b->
let l_out_arc=out_arcs gr a in
let rec loop_suc l_out_arc blf_tab file =
match l_out_arc with
|[]-> blf_rec gr file (a::file_marque)
|(id,label)::d->
if label != 0 && (blf_tab.(a).cout+label)<blf_tab.(id).cout then
let lOutArcs = out_arcs graph a in
let rec loop_suc lOutArcs blfTab file =
match lOutArcs with
|[] -> blf_rec graph file (a::fileMarquee)
|(id,label)::d ->
if label != 0 && (blfTab.(a).cout+label) < blfTab.(id).cout then
begin
blf_tab.(id).cout<-(blf_tab.(a).cout+label);
blf_tab.(id).father<-a;
if not (List.mem id file_marque) then loop_suc d blf_tab (id::file) else loop_suc d blf_tab file
blfTab.(id).cout <- (blfTab.(a).cout+label);
blfTab.(id).father <- a;
if not (List.mem id fileMarquee) then loop_suc d blfTab (id::file) else loop_suc d blfTab file
end
else loop_suc d blf_tab file in
loop_suc l_out_arc blf_tab b in
blf_rec gr file_id file_marque
else loop_suc d blfTab file in
loop_suc lOutArcs blfTab b in
blf_rec graph fileId fileMarquee
(*avec blf_tab, on retrace chemin avec les pères*)
let get_path gr id_src id_dest=
let blf_tab=blf gr id_src id_dest in
let path=[id_dest] in
let rec loop path blf_tab id_src id_dest=
let father_id=blf_tab.(id_dest).father in match father_id with
|(-1)->None
|a->if a == id_src then Some (id_src::path) else loop (a::path) blf_tab id_src a in
loop path blf_tab id_src id_dest
(*avec blfTab, on retrace chemin avec les pères*)
let get_path graph idSrc idDst =
let blfTab = blf graph idSrc in
let path = [idDst] in
let rec loop path blfTab idSrc idDst =
let fatherId = blfTab.(idDst).father in match fatherId with
|(-1) -> None
|a -> if a == idSrc then Some (idSrc::path) else loop (a::path) blfTab idSrc a in
loop path blfTab idSrc idDst

View file

@ -7,6 +7,8 @@ type t_cost={
mutable father:int
}
val blf: int graph -> id -> id -> t_cost array
(* Execute the Bellman-Ford algorithm on a graph from the node with the specified id *)
val blf: int graph -> id -> t_cost array
(* Return a path option from a source node to a destination node *)
val get_path: int graph -> id -> id -> path option

View file

@ -60,17 +60,17 @@ let get_final_graph (initGraph : int graph) (residualGraph : int graph) =
e_fold initGraph
(
fun acu id1 id2 x ->
let label_arc = (match find_arc initGraphString id1 id2 with
let labelArc = (match find_arc initGraphString id1 id2 with
|None -> 0
|Some x -> x) in
let label_rev_arc = match find_arc residualGraphString id2 id1 with
let labelRevArc = match find_arc residualGraphString id2 id1 with
|None -> 0
|Some x -> (match find_arc initGraphString id2 id1 with
|None -> x
|Some y -> x-y) in
let label_arc = string_of_int label_arc in
let label_rev_arc = if (label_rev_arc > 0) then (string_of_int label_rev_arc) else "0" in
new_arc acu id1 id2 (label_rev_arc^"/"^label_arc)
let labelArc = string_of_int labelArc in
let labelRevArc = if (labelRevArc > 0) then (string_of_int labelRevArc) else "0" in
new_arc acu id1 id2 (labelRevArc^"/"^labelArc)
)
finalGraph
@ -87,15 +87,12 @@ let ford_fulk_algorithm (graph : int graph) (origin : id) (sink : id) =
(let path = x in
let arcs = create_arcs_from_nodes path in
(*let () = printf "dans boucle\n" in*)
(* Find the min value of the path *)
let min = get_min_label_from_path graph arcs in
(* Substract the min to every arc of the path *)
let graph = add_value_to_arcs graph arcs (-min) in
(* Get the reverse path *)
let reverse = rev_arcs arcs in
@ -105,6 +102,7 @@ let ford_fulk_algorithm (graph : int graph) (origin : id) (sink : id) =
(* Add the min to the flow *)
let flow = flow + min in
boucle graph origin sink flow) in
let (maxFlow, residualGraph) = boucle graph origin sink flow in
let finalGraph = get_final_graph initGraph residualGraph in
(maxFlow, finalGraph)

View file

@ -2,19 +2,8 @@ open Graph
open Tool
open BLF
(* Return a int graph from a string graph *)
val g_to_int: string graph -> int graph
(* Return a string graph after applying the ford-fulkerson algorithm on an int graph (capacity) *)
val ford_fulk_algorithm : int graph -> id -> id -> (int * string graph)
(* val g_to_string: int graph -> string graph *)
(* val only_one_edge: int graph -> int graph *)
(* for testing purpose *)
(* val rev_arcs: (id * id) list -> (id * id) list
val add_value_to_arcs: int graph -> (id * id) list -> int -> int graph
val get_final_graph: int graph -> int graph -> string graph *)

View file

@ -8,7 +8,7 @@ open Sys
let () =
(*/!\ Format de la commande pour lancer le test :
./ftest.native [nom_fichier_lecture] [id_source] [id_dest] [nom_fichier_ecriture]
./ftest.native [path_input_file] [source] [sink] [path_output_file]
ex : ./ftest.native graphs/graph1 0 5 graphs/graph3 *)
(* Check the number of command-line arguments *)
@ -39,8 +39,6 @@ let () =
let () = printf "max flow = %d\n" flow in
let () = write_file outfile finalGraph in
let () = export outfile finalGraph in
(* let () = export infile graph in *)
(*Uncomment the following line if you have graphviz installed *)
(*let retour = command ("dot -Tsvg "^outfile^".dot > "^outfile^".svg") in*)

View file

@ -6,4 +6,5 @@ val clone_nodes: 'a graph -> 'b graph
(* Apply a function f to every label of the graph's arcs *)
val gmap: 'a graph -> ('a -> 'b) -> 'b graph
(* Add a value to the capacity of the arc id1 id2 in the graph*)
val add_arc: int graph -> id -> id -> int -> int graph