Browse Source

Version Fonctionnelle : EmploiCost OK (TAF : maj ReadMe, check all tested)

Paul Faure 3 years ago
parent
commit
0ef00507b5
8 changed files with 391 additions and 4 deletions
  1. 1
    0
      .gitignore
  2. 20
    0
      Makefile
  3. 198
    0
      emplois/emploi1_priorised_affected.svg
  4. 3
    3
      src/emploifile.ml
  5. 0
    1
      src/emploifile.mli
  6. 132
    0
      src/emploifilecost.ml
  7. 9
    0
      src/emploifilecost.mli
  8. 28
    0
      src/emploifilecosttest.ml

+ 1
- 0
.gitignore View File

@@ -2,3 +2,4 @@ _build/
2 2
 *.native
3 3
 outfile
4 4
 *~
5
+graphs/*.dot

+ 20
- 0
Makefile View File

@@ -31,6 +31,13 @@ man:
31 31
 	@echo "   - demo_Emploi EMPLOI=\"chemin\""
32 32
 	@echo "        Pour compiler le programme l'executer sur le fichier d'emplois donné (ex ./emplois/emploi1)"
33 33
 	@echo "        Cela charge le fichier, le transforme en graphe, applique FordFulkerson pour affecter les emplois, exporte le résultat au format svg, et l'affiche dans Firefox\n"
34
+	@echo "En ce qui concerne l'affectation d'emploi avec priorisation, elle a été codée dans le module emploifilecost, et, peut être lancé grace au fichier emploifilecosttest.ml"
35
+	@echo "Pour simplifier son utilisation, la aussi, des cibles ont été créées : "
36
+	@echo "   - build_EmploiCost : pour compiler le programme et créér emploifilecosttest.native"
37
+	@echo "   - demo_EmploiCost EMPLOI=\"chemin\""
38
+	@echo "        Pour compiler le programme l'executer sur le fichier d'emplois donné (ex ./emplois/emploi1)"
39
+	@echo "        Cela charge le fichier, le transforme en graphe, applique FordFulkersonCost pour affecter les emplois, exporte le résultat au format svg, et l'affiche dans Firefox\n"
40
+	@echo " NB : Emploi et EmploiCost utilisent les mêmes fichers en entier, pour la priorisation des voeux, l'ordre d'écriture compte\n"
34 41
 	@echo "Autres cibles : "
35 42
 	@echo "   - format : Pour indenter le code"
36 43
 	@echo "   - edit  : Pour ouvrir le code dans VsCode"
@@ -100,6 +107,19 @@ else
100 107
 	firefox $(EMPLOI)_affected.svg
101 108
 endif
102 109
 
110
+build_EmploiCost: 
111
+	@echo "\n==== COMPILING EmploiCost ====\n"
112
+	ocamlbuild emploifilecosttest.native
113
+
114
+demo_EmploiCost: build_EmploiCost
115
+ifeq ($(EMPLOI),null)
116
+	@echo "USAGE : make demo_EmploiCost EMPLOI=\"chemin\""
117
+else
118
+	./emploifilecosttest.native $(EMPLOI) $(EMPLOI)_priorised_affected.dot
119
+	dot -Tsvg $(EMPLOI)_priorised_affected.dot > $(EMPLOI)_priorised_affected.svg
120
+	firefox $(EMPLOI)_priorised_affected.svg
121
+endif
122
+
103 123
 format:
104 124
 	ocp-indent --inplace src/*
105 125
 

+ 198
- 0
emplois/emploi1_priorised_affected.svg View File

@@ -0,0 +1,198 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+<!-- Generated by graphviz version 2.40.1 (20161225.0304)
5
+ -->
6
+<!-- Title: finite_state_machine Pages: 1 -->
7
+<svg width="576pt" height="480pt"
8
+ viewBox="0.00 0.00 576.00 479.83" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
+<g id="graph0" class="graph" transform="scale(.9496 .9496) rotate(0) translate(4 501.2884)">
10
+<title>finite_state_machine</title>
11
+<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-501.2884 602.5663,-501.2884 602.5663,4 -4,4"/>
12
+<!-- Source -->
13
+<g id="node1" class="node">
14
+<title>Source</title>
15
+<ellipse fill="none" stroke="#000000" cx="35.0969" cy="-232.1926" rx="35.194" ry="35.194"/>
16
+<text text-anchor="middle" x="35.0969" y="-228.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Source</text>
17
+</g>
18
+<!-- Gerard -->
19
+<g id="node6" class="node">
20
+<title>Gerard</title>
21
+<ellipse fill="none" stroke="#000000" cx="186.09" cy="-69.1926" rx="35.194" ry="35.194"/>
22
+<text text-anchor="middle" x="186.09" y="-65.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Gerard</text>
23
+</g>
24
+<!-- Source&#45;&gt;Gerard -->
25
+<g id="edge10" class="edge">
26
+<title>Source&#45;&gt;Gerard</title>
27
+<path fill="none" stroke="#000000" d="M55.2801,-203.4339C64.8002,-190.449 76.5978,-175.1505 88.1938,-162.1926 108.067,-139.9853 132.3435,-116.9003 151.7494,-99.2854"/>
28
+<polygon fill="#000000" stroke="#000000" points="154.1113,-101.8685 159.1982,-92.5747 149.4259,-96.6677 154.1113,-101.8685"/>
29
+<text text-anchor="middle" x="106.6938" y="-165.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
30
+</g>
31
+<!-- Sandrine -->
32
+<g id="node7" class="node">
33
+<title>Sandrine</title>
34
+<ellipse fill="none" stroke="#000000" cx="186.09" cy="-232.1926" rx="42.4939" ry="42.4939"/>
35
+<text text-anchor="middle" x="186.09" y="-228.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Sandrine</text>
36
+</g>
37
+<!-- Source&#45;&gt;Sandrine -->
38
+<g id="edge11" class="edge">
39
+<title>Source&#45;&gt;Sandrine</title>
40
+<path fill="none" stroke="#000000" d="M70.4981,-232.1926C89.3,-232.1926 112.776,-232.1926 133.6506,-232.1926"/>
41
+<polygon fill="#000000" stroke="#000000" points="133.6573,-235.6927 143.6572,-232.1926 133.6572,-228.6927 133.6573,-235.6927"/>
42
+<text text-anchor="middle" x="106.6938" y="-235.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
43
+</g>
44
+<!-- Patrice -->
45
+<g id="node8" class="node">
46
+<title>Patrice</title>
47
+<ellipse fill="none" stroke="#000000" cx="186.09" cy="-431.1926" rx="35.194" ry="35.194"/>
48
+<text text-anchor="middle" x="186.09" y="-427.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Patrice</text>
49
+</g>
50
+<!-- Source&#45;&gt;Patrice -->
51
+<g id="edge9" class="edge">
52
+<title>Source&#45;&gt;Patrice</title>
53
+<path fill="none" stroke="#000000" d="M53.7091,-262.2033C74.1415,-294.3093 108.6555,-346.1516 143.1938,-387.1926 146.5425,-391.1719 150.1715,-395.2312 153.8524,-399.1958"/>
54
+<polygon fill="#000000" stroke="#000000" points="151.512,-401.8141 160.9351,-406.6571 156.5889,-396.9948 151.512,-401.8141"/>
55
+<text text-anchor="middle" x="106.6938" y="-365.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
56
+</g>
57
+<!-- Christine -->
58
+<g id="node9" class="node">
59
+<title>Christine</title>
60
+<ellipse fill="none" stroke="#000000" cx="186.09" cy="-335.1926" rx="42.7926" ry="42.7926"/>
61
+<text text-anchor="middle" x="186.09" y="-331.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Christine</text>
62
+</g>
63
+<!-- Source&#45;&gt;Christine -->
64
+<g id="edge13" class="edge">
65
+<title>Source&#45;&gt;Christine</title>
66
+<path fill="none" stroke="#000000" d="M64.2099,-252.0521C86.307,-267.1256 117.0595,-288.1035 142.145,-305.2155"/>
67
+<polygon fill="#000000" stroke="#000000" points="140.1809,-308.1125 150.4143,-310.8564 144.1256,-302.3298 140.1809,-308.1125"/>
68
+<text text-anchor="middle" x="106.6938" y="-295.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(2/2):0</text>
69
+</g>
70
+<!-- Leo -->
71
+<g id="node10" class="node">
72
+<title>Leo</title>
73
+<ellipse fill="none" stroke="#000000" cx="186.09" cy="-147.1926" rx="24.8972" ry="24.8972"/>
74
+<text text-anchor="middle" x="186.09" y="-143.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Leo</text>
75
+</g>
76
+<!-- Source&#45;&gt;Leo -->
77
+<g id="edge12" class="edge">
78
+<title>Source&#45;&gt;Leo</title>
79
+<path fill="none" stroke="#000000" d="M66.0169,-214.7865C92.1434,-200.0789 129.3663,-179.1246 155.4212,-164.4573"/>
80
+<polygon fill="#000000" stroke="#000000" points="157.4767,-167.3167 164.4739,-159.3612 154.0428,-161.2168 157.4767,-167.3167"/>
81
+<text text-anchor="middle" x="106.6938" y="-205.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
82
+</g>
83
+<!-- Professeur -->
84
+<g id="node2" class="node">
85
+<title>Professeur</title>
86
+<ellipse fill="none" stroke="#000000" cx="385.1788" cy="-449.1926" rx="48.1917" ry="48.1917"/>
87
+<text text-anchor="middle" x="385.1788" y="-445.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Professeur</text>
88
+</g>
89
+<!-- Puits -->
90
+<g id="node11" class="node">
91
+<title>Puits</title>
92
+<ellipse fill="none" stroke="#000000" cx="569.9689" cy="-268.1926" rx="28.6953" ry="28.6953"/>
93
+<text text-anchor="middle" x="569.9689" y="-264.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Puits</text>
94
+</g>
95
+<!-- Professeur&#45;&gt;Puits -->
96
+<g id="edge6" class="edge">
97
+<title>Professeur&#45;&gt;Puits</title>
98
+<path fill="none" stroke="#000000" d="M426.6851,-424.1142C440.5759,-414.8663 455.7302,-403.7941 468.3714,-392.1926 499.0851,-364.0052 528.6394,-326.3511 547.8761,-299.9586"/>
99
+<polygon fill="#000000" stroke="#000000" points="550.7402,-301.9707 553.7476,-291.8116 545.0614,-297.8779 550.7402,-301.9707"/>
100
+<text text-anchor="middle" x="504.8714" y="-376.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(2/2):0</text>
101
+</g>
102
+<!-- Laveur_de_carreaux -->
103
+<g id="node3" class="node">
104
+<title>Laveur_de_carreaux</title>
105
+<ellipse fill="none" stroke="#000000" cx="385.1788" cy="-83.1926" rx="83.3857" ry="83.3857"/>
106
+<text text-anchor="middle" x="385.1788" y="-79.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Laveur_de_carreaux</text>
107
+</g>
108
+<!-- Laveur_de_carreaux&#45;&gt;Puits -->
109
+<g id="edge8" class="edge">
110
+<title>Laveur_de_carreaux&#45;&gt;Puits</title>
111
+<path fill="none" stroke="#000000" d="M444.1556,-142.2364C477.0339,-175.1521 516.437,-214.5999 542.2791,-240.4714"/>
112
+<polygon fill="#000000" stroke="#000000" points="539.9728,-243.1151 549.5162,-247.7167 544.9254,-238.1681 539.9728,-243.1151"/>
113
+<text text-anchor="middle" x="504.8714" y="-221.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(2/2):0</text>
114
+</g>
115
+<!-- Cuisinier -->
116
+<g id="node4" class="node">
117
+<title>Cuisinier</title>
118
+<ellipse fill="none" stroke="#000000" cx="385.1788" cy="-340.1926" rx="42.7926" ry="42.7926"/>
119
+<text text-anchor="middle" x="385.1788" y="-336.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Cuisinier</text>
120
+</g>
121
+<!-- Cuisinier&#45;&gt;Puits -->
122
+<g id="edge17" class="edge">
123
+<title>Cuisinier&#45;&gt;Puits</title>
124
+<path fill="none" stroke="#000000" d="M425.2755,-324.5697C457.4585,-312.0302 502.2641,-294.5725 533.4578,-282.4185"/>
125
+<polygon fill="#000000" stroke="#000000" points="535.0271,-285.5634 543.0741,-278.6717 532.4857,-279.041 535.0271,-285.5634"/>
126
+<text text-anchor="middle" x="504.8714" y="-302.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
127
+</g>
128
+<!-- Poissonier -->
129
+<g id="node5" class="node">
130
+<title>Poissonier</title>
131
+<ellipse fill="none" stroke="#000000" cx="385.1788" cy="-232.1926" rx="47.3916" ry="47.3916"/>
132
+<text text-anchor="middle" x="385.1788" y="-228.4926" font-family="Times,serif" font-size="14.00" fill="#000000">Poissonier</text>
133
+</g>
134
+<!-- Poissonier&#45;&gt;Puits -->
135
+<g id="edge5" class="edge">
136
+<title>Poissonier&#45;&gt;Puits</title>
137
+<path fill="none" stroke="#000000" d="M431.8091,-241.2769C462.6619,-247.2876 502.6231,-255.0726 531.6255,-260.7227"/>
138
+<polygon fill="#000000" stroke="#000000" points="531.2928,-264.2236 541.7776,-262.7005 532.6314,-257.3528 531.2928,-264.2236"/>
139
+<text text-anchor="middle" x="504.8714" y="-261.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/3):0</text>
140
+</g>
141
+<!-- Gerard&#45;&gt;Laveur_de_carreaux -->
142
+<g id="edge3" class="edge">
143
+<title>Gerard&#45;&gt;Laveur_de_carreaux</title>
144
+<path fill="none" stroke="#000000" d="M221.2248,-71.6633C241.0329,-73.0562 266.8041,-74.8685 292.0259,-76.6421"/>
145
+<polygon fill="#000000" stroke="#000000" points="291.8048,-80.1351 302.0257,-77.3453 292.2959,-73.1523 291.8048,-80.1351"/>
146
+<text text-anchor="middle" x="265.4862" y="-79.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
147
+</g>
148
+<!-- Sandrine&#45;&gt;Poissonier -->
149
+<g id="edge4" class="edge">
150
+<title>Sandrine&#45;&gt;Poissonier</title>
151
+<path fill="none" stroke="#000000" d="M228.7995,-232.1926C257.5419,-232.1926 295.7914,-232.1926 327.267,-232.1926"/>
152
+<polygon fill="#000000" stroke="#000000" points="327.6581,-235.6927 337.6581,-232.1926 327.6581,-228.6927 327.6581,-235.6927"/>
153
+<text text-anchor="middle" x="265.4862" y="-235.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
154
+</g>
155
+<!-- Patrice&#45;&gt;Professeur -->
156
+<g id="edge2" class="edge">
157
+<title>Patrice&#45;&gt;Professeur</title>
158
+<path fill="none" stroke="#000000" d="M221.2248,-434.3692C250.3601,-437.0034 292.3963,-440.804 326.6094,-443.8973"/>
159
+<polygon fill="#000000" stroke="#000000" points="326.6786,-447.4177 336.9532,-444.8324 327.309,-440.4461 326.6786,-447.4177"/>
160
+<text text-anchor="middle" x="265.4862" y="-442.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
161
+</g>
162
+<!-- Patrice&#45;&gt;Cuisinier -->
163
+<g id="edge1" class="edge">
164
+<title>Patrice&#45;&gt;Cuisinier</title>
165
+<path fill="none" stroke="#000000" d="M218.8861,-417.5634C237.9762,-409.5203 262.4502,-399.0203 283.9862,-389.1926 301.5165,-381.1929 320.5743,-372.0764 337.3748,-363.8941"/>
166
+<polygon fill="#000000" stroke="#000000" points="339.0048,-366.9932 346.4522,-359.4575 335.9309,-360.7042 339.0048,-366.9932"/>
167
+<text text-anchor="middle" x="265.4862" y="-407.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(0/1):1</text>
168
+</g>
169
+<!-- Christine&#45;&gt;Professeur -->
170
+<g id="edge15" class="edge">
171
+<title>Christine&#45;&gt;Professeur</title>
172
+<path fill="none" stroke="#000000" d="M228.0002,-344.7516C246.2908,-350.2413 267.3181,-358.4382 283.9862,-370.1926 294.3106,-377.4735 292.6813,-383.6472 301.9862,-392.1926 312.0564,-401.441 323.7245,-410.3512 335.0783,-418.2688"/>
173
+<polygon fill="#000000" stroke="#000000" points="333.4325,-421.3826 343.6678,-424.1192 337.3731,-415.5971 333.4325,-421.3826"/>
174
+<text text-anchor="middle" x="265.4862" y="-373.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
175
+</g>
176
+<!-- Christine&#45;&gt;Cuisinier -->
177
+<g id="edge16" class="edge">
178
+<title>Christine&#45;&gt;Cuisinier</title>
179
+<path fill="none" stroke="#000000" d="M229.4675,-335.3629C246.4704,-335.501 266.1451,-335.749 283.9862,-336.1926 299.4095,-336.5761 316.1489,-337.1667 331.49,-337.7773"/>
180
+<polygon fill="#000000" stroke="#000000" points="331.7194,-341.2895 341.854,-338.201 332.0053,-334.2954 331.7194,-341.2895"/>
181
+<text text-anchor="middle" x="265.4862" y="-339.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):1</text>
182
+</g>
183
+<!-- Christine&#45;&gt;Poissonier -->
184
+<g id="edge14" class="edge">
185
+<title>Christine&#45;&gt;Poissonier</title>
186
+<path fill="none" stroke="#000000" d="M224.4763,-315.3332C255.5938,-299.2343 299.7291,-276.4006 333.8759,-258.7345"/>
187
+<polygon fill="#000000" stroke="#000000" points="335.5009,-261.8345 342.7744,-254.1308 332.2844,-255.6173 335.5009,-261.8345"/>
188
+<text text-anchor="middle" x="265.4862" y="-304.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(0/1):2</text>
189
+</g>
190
+<!-- Leo&#45;&gt;Laveur_de_carreaux -->
191
+<g id="edge7" class="edge">
192
+<title>Leo&#45;&gt;Laveur_de_carreaux</title>
193
+<path fill="none" stroke="#000000" d="M209.7099,-139.5997C231.1792,-132.698 264.2491,-122.0672 295.9162,-111.8874"/>
194
+<polygon fill="#000000" stroke="#000000" points="297.2355,-115.1397 305.6845,-108.7472 295.0932,-108.4756 297.2355,-115.1397"/>
195
+<text text-anchor="middle" x="265.4862" y="-130.9926" font-family="Times,serif" font-size="14.00" fill="#000000">(1/1):0</text>
196
+</g>
197
+</g>
198
+</svg>

+ 3
- 3
src/emploifile.ml View File

@@ -38,7 +38,7 @@ let construc_graph_from_lists (n,listeJobs,listeApplicants) =
38 38
   let rec loopJobs listeJ graph =
39 39
     match listeJ with
40 40
     | [] -> graph
41
-    | x :: rest -> loopJobs rest (new_arc (new_node graph x.id) x.id n (string_of_int x.nbPersonnesMax))
41
+    | x :: rest -> loopJobs rest (new_arc (new_node graph x.id) x.id n ("(0/" ^ (string_of_int x.nbPersonnesMax) ^ ")"))
42 42
   in
43 43
 
44 44
   let graph_with_jobs = loopJobs listeJobs graph_base in
@@ -46,13 +46,13 @@ let construc_graph_from_lists (n,listeJobs,listeApplicants) =
46 46
   let rec processApplicant listeJobs id graph =
47 47
     match listeJobs with
48 48
     | [] -> graph
49
-    | x :: rest -> processApplicant rest id (new_arc graph id x (string_of_int 1))
49
+    | x :: rest -> processApplicant rest id (new_arc graph id x "(0/1)")
50 50
   in
51 51
 
52 52
   let rec loopApplicants listeA graph =
53 53
     match listeA with
54 54
     | [] -> graph
55
-    | x :: rest -> loopApplicants rest (processApplicant x.jobs x.id (new_arc (new_node graph x.id) 0 x.id (string_of_int x.nbJobsPossible)))
55
+    | x :: rest -> loopApplicants rest (processApplicant x.jobs x.id (new_arc (new_node graph x.id) 0 x.id ("(0/" ^ (string_of_int x.nbJobsPossible) ^ ")")))
56 56
   in
57 57
 
58 58
   loopApplicants listeApplicants graph_with_jobs

+ 0
- 1
src/emploifile.mli View File

@@ -1,6 +1,5 @@
1 1
 open Graph
2 2
 open Gfile
3
-open Flot
4 3
 
5 4
 type traducteur
6 5
 

+ 132
- 0
src/emploifilecost.ml View File

@@ -0,0 +1,132 @@
1
+open Graph
2
+open Printf
3
+open Gfile
4
+
5
+(*Faire un type record à retourner à chaque ligne du fichier et quand on a tout lu, on créé le graphe à partir de la liste obtenue*)
6
+type voeu = {job : int; priorite : int}
7
+type applicantIdentifier = {name : string;nbJobsPossible:int; id:int; jobs : voeu list}
8
+type jobIdentifier = {name : string; id: int; nbPersonnesMax : int}
9
+
10
+type traducteur = (int * jobIdentifier list * applicantIdentifier list)
11
+
12
+let get_puit_id (n, listeJobs, listeApplicants) = n
13
+
14
+(* Reads a line with a node. *)
15
+let read_jobs line listJobs listeApplicants =
16
+  try Scanf.sscanf line "j %d %s %d" (fun n nom nbPersonnes -> (n+1,{name = nom; id = n; nbPersonnesMax  = nbPersonnes}::listJobs, listeApplicants))
17
+  with e ->
18
+    Printf.printf "Cannot read node in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
19
+    failwith "from_file"
20
+
21
+let rec map_voeu_list n = function 
22
+  |[] -> []
23
+  |x :: next -> {job = x ; priorite = n} :: (map_voeu_list (n+1) next)
24
+
25
+let map_voeu l = map_voeu_list 0 l
26
+
27
+(* Reads a line with a node. *)
28
+let read_applicants n line listeJobs listApplicants =
29
+  try Scanf.sscanf line "a %d %s %s@:" (fun nbJobs nom listJobsIds -> let listJobsIdsFormated = String.split_on_char ' ' listJobsIds in
30
+                                         (n+1,listeJobs,{name = nom; nbJobsPossible = nbJobs; id = n; jobs = map_voeu (List.map (fun a -> int_of_string a) listJobsIdsFormated)}::listApplicants))
31
+  with e ->
32
+    Printf.printf "Cannot read node in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
33
+    failwith "from_file"
34
+
35
+(* Reads a comment or fail. *)
36
+let read_comment n line listeJobs listeApplicants =
37
+  try Scanf.sscanf line " %%" (n,listeJobs,listeApplicants)
38
+  with _ -> 
39
+    Printf.printf "Unknown line:\n%s\n%!" line ;
40
+    failwith "from_file"
41
+
42
+
43
+let construc_graph_from_lists (n,listeJobs,listeApplicants) =
44
+  let graph_base =  (new_node (new_node empty_graph 0) n) in (*On créé le source et le puit en 1er*)
45
+  let rec loopJobs listeJ graph =
46
+    match listeJ with
47
+    | [] -> graph
48
+    | x :: rest -> loopJobs rest (new_arc (new_node graph x.id) x.id n ("(0/" ^ (string_of_int x.nbPersonnesMax) ^ "):0"))
49
+  in
50
+
51
+  let graph_with_jobs = loopJobs listeJobs graph_base in
52
+
53
+  let rec processApplicant listeJobs id graph =
54
+    match listeJobs with
55
+    | [] -> graph
56
+    | x :: rest -> processApplicant rest id (new_arc graph id x.job ("(0/1):" ^ (string_of_int x.priorite)))
57
+  in
58
+
59
+  let rec loopApplicants listeA graph =
60
+    match listeA with
61
+    | [] -> graph
62
+    | x :: rest -> loopApplicants rest (processApplicant x.jobs x.id (new_arc (new_node graph x.id) 0 x.id ("(0/" ^ (string_of_int x.nbJobsPossible) ^ "):0")))
63
+  in
64
+
65
+  loopApplicants listeApplicants graph_with_jobs
66
+
67
+
68
+let from_file_emploi path =
69
+  let infile = open_in path in
70
+
71
+  (* Read all lines until end of file. 
72
+   * n is the current node counter. *)
73
+  let rec loop n listeJobs listeApplicants =
74
+    try
75
+      let line = input_line infile in
76
+
77
+      (* Remove leading and trailing spaces. *)
78
+      let line = String.trim line in
79
+
80
+      let (n2, lJ, lA) =
81
+        (* Ignore empty lines *)
82
+        if line = "" then (n, listeJobs, listeApplicants)
83
+
84
+        (* The first character of a line determines its content : n or e. *)
85
+        else match line.[0] with
86
+          | 'a' -> read_applicants n line listeJobs listeApplicants 
87
+          | 'j' -> read_jobs line listeJobs listeApplicants
88
+
89
+          (* It should be a comment, otherwise we complain. *)
90
+          | _ -> read_comment n line listeJobs listeApplicants
91
+      in      
92
+      loop n2 lJ lA
93
+
94
+    with End_of_file -> (n,listeJobs,listeApplicants) (* Done *)
95
+  in
96
+  let (n, listeJobs, listeApplicants) = loop 1 [] [] in 
97
+  let final_graph = construc_graph_from_lists (n, listeJobs, listeApplicants) in
98
+
99
+  close_in infile ;
100
+  (final_graph, (n, List.rev listeJobs, List.rev listeApplicants))
101
+
102
+
103
+let string_from_id id ((listeJobs : jobIdentifier list), (listeApplicants : applicantIdentifier list)) = 
104
+  if id = 0 then
105
+    "Source"
106
+  else if id <= (List.length listeJobs) then
107
+    (List.nth listeJobs (id - 1)).name
108
+  else if id <= ((List.length listeJobs) + (List.length listeApplicants)) then
109
+    (List.nth listeApplicants (id - ((List.length listeJobs) + 1))).name 
110
+  else
111
+    "Puits"
112
+
113
+let export_emploi path graph ((n : id), (listeJobs : jobIdentifier list), (listeApplicants : applicantIdentifier list)) = 
114
+  (* Open a write-file. *)
115
+  let ff = open_out path in
116
+
117
+  (* Write in this file. *)
118
+  fprintf ff "digraph finite_state_machine {\n" ;
119
+
120
+  fprintf ff "\trankdir=LR;\n" ;
121
+  fprintf ff "\tsize=\"8\";\n" ;
122
+  fprintf ff "\tnode [shape = circle];" ;
123
+
124
+  (* Write all nodes (with fake coordinates) *)
125
+  n_iter_sorted graph (fun id -> fprintf ff " %s" (string_from_id id (listeJobs, listeApplicants))) ;
126
+  fprintf ff ";\n" ;
127
+
128
+  e_iter graph (fun id1 id2 lbl -> fprintf ff "\t%s -> %s [ label = \"%s\" ];\n" (string_from_id id1 (listeJobs, listeApplicants)) (string_from_id id2 (listeJobs, listeApplicants)) lbl) ;
129
+  fprintf ff "}\n" ;
130
+
131
+  close_out ff ;
132
+  ()

+ 9
- 0
src/emploifilecost.mli View File

@@ -0,0 +1,9 @@
1
+open Graph
2
+open Gfile
3
+
4
+type traducteur
5
+
6
+val get_puit_id: traducteur -> id
7
+
8
+val from_file_emploi: path -> (string graph * traducteur)
9
+val export_emploi: path -> string graph -> traducteur -> unit

+ 28
- 0
src/emploifilecosttest.ml View File

@@ -0,0 +1,28 @@
1
+open Flotcost
2
+open Emploifilecost
3
+
4
+let () = (* Check the number of command-line arguments *)
5
+  if Array.length Sys.argv <> 3 then
6
+    begin
7
+      Printf.printf "\nUsage: %s infile outfile\n\n%!" Sys.argv.(0) ;
8
+      exit 0
9
+    end ;
10
+
11
+
12
+  (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *)
13
+
14
+  let infile = Sys.argv.(1)
15
+  and outfile = Sys.argv.(2)
16
+
17
+  (* These command-line arguments are not used for the moment. *)
18
+  and source = 0
19
+  in
20
+
21
+  (* Open file *)
22
+  let (string_graph, traductor) = from_file_emploi infile in
23
+  let graph = read_flot_graph_from_string_graph string_graph in
24
+
25
+  let sink = get_puit_id traductor in
26
+
27
+  (* NB : Constructeurs, Setteurs, et Getteurs ne seront pas testés *)
28
+  export_emploi outfile (export_string_graph_from_flot_graph (ford_fulkerson graph source sink)) traductor

Loading…
Cancel
Save