various refactoring

This commit is contained in:
Raphaël LACROIX 2023-01-14 14:34:40 +01:00
parent b7ae605429
commit ca558bdc4a
13 changed files with 310 additions and 258 deletions

20
INPUT Normal file
View file

@ -0,0 +1,20 @@
Foot 15
Hockey 12
Piscine 15
Poney-aquatique 2
Ocaml 20
Science-de-la-vie-et-de-la-terre 50
Prolog-en-police-windings-sous-microsoft-word 1
Jean 1 2
Jean-Michel 5
Jean-Claude 1
Jean-ti 1 6 2
Jean-Ticipe 3
Jean-Richie 1 2 3
Jean-Peuplu 7
Jean-Rafole 1 2 3
Jean-Sérien 2 3 4 5
Jean-Trouvaisplus 4 5 6

View file

@ -28,6 +28,10 @@ test: build
buildApp:
ocamlbuild appMedium.native
testApp: buildApp
app: buildApp
./appMedium.native
dot -Tsvg outFileApp > outFileApp.svg
appSource: buildApp
./appMedium.native < INPUT
dot -Tsvg outFileApp > outFileApp.svg

View file

@ -1,17 +1,46 @@
*Projet réalisé par Raphaël LACROIX et Aurélia LEJEUNE*
# How to run
- `make test` enables you to test the first step of the project
- ⚠️ But it is needed to roll back in the git history before the changes for the "Medium" part were made like [this one](https://git.etud.insa-toulouse.fr/rlacroix/FordFulkersonLeChameau/src/commit/5ca008700e62474cc17b2845e7d2dd061c319861)
# What is this project about?
Ever needed to organise an day with participants (like children for instance) that can pick a variying number of
activities (like hockey football ...) from a list? Avoid yourself the hassle of filling the table by hand for three
hours just to realize that little jimmy can't go to the swimming pool because there are no remaining spots for him.
- `make testApp` builds the application ("Medium") and runs it. The instructions on how to use the application are thereafter displayed on the screen.
# How to use this software ?
## Installing and running
- clone this repo make sure you have [ocaml](https://ocaml.org/docs/up-and-running) installed
- in the root of the directory run
- `make app` if you want to enter the activities and participants one by one in the terminal (we won't judge you)
- `make appSource` if you prefer to enter those `./INPUT` and let the program do it for you
## inputting data
The format for the file is as follows :
*Nb_... and id_... are numbers. The first represent the number of possible participants. The latter will be used to say
which activities the participant wants. Participant_... and Activity... must be strings of characters without spaces (you
can replace those with `_` or `-`)*
```
Activity_1 Nb_available
Activity_2 Nb_available
...
Activity_n Nb_available
Participant_1 id_1 id_2 id_3 ... id_n
Participant_2 id_1 id_2 id_3 ... id_n
...
Participant_m id_1 id_2 id_3 ... id_n
```
The formatting is the same should you input th information through the terminal. You will be guided along the way.
## NB
- The application seeks to match **students/children** to **activities/courses** as a [bipartite matching](https://www.geeksforgeeks.org/maximum-bipartite-matching/) process.
- The application seeks to match **children/students** to **activities/courses** as a
[bipartite matching](https://www.geeksforgeeks.org/maximum-bipartite-matching/) process.
- The user is asked to provide :
- The `names` and `capacities` of **activities/courses**
- The `names` and `choices` of **children/students**
- The user is **NOT ASKED** (at least at this point in the project)
- The user is **NOT ASKED**
- the order of interest among the choices for a **children/students**
- the answer to the question of life, the universe and everything
- the answer to the question of life, the universe and everything
- `make test` enables you to test the first step of the project
- ⚠️ But it is needed to roll back in the git history before the changes for the "Medium" part were made like
[this one](https://git.etud.insa-toulouse.fr/rlacroix/FordFulkersonLeChameau/src/commit/5ca008700e62474cc17b2845e7d2dd061c319861)

View file

@ -1,49 +1,52 @@
"Rule: ocaml dependencies ml (%=src/appTools )": "\012%\144C\164|\170\156B\169:\0193\177SJ"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/display )": "\239\213\229\211j!\190#\027U\183\135\175^\143<"
"Rule: ocaml dependencies ml (%=src/appTools )": "\251=\168`u\209\146f\001\158_z\160\248?\004"
"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 )": "r\205l\0020\228\241/A\1640\245\127F)-"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appTools.mli": "\155\b\026hx\155\244]\204\252\142\180\149\139\198\233"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appTools.ml": "\213\031\163<\142\00535\157=\207}9|\135\230"
"Rule: ocaml dependencies mli (%=src/ioApp )": "\199}\132Z\031\020^\201\179,\223C\220\169\194\238"
"Rule: ocaml dependencies ml (%=src/ftest )": "\\X\026H\137\163!\027\248i|\012\162k\138\187"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appTools.ml": "\004^\138\189Yz\011d\149\188\227\183\236\162\167\026"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/gfile )": "\236O\148Y\157m\028\183\166?\231a\231\187u\132"
"Rule: ocaml dependencies ml (%=src/ftest )": "\230\175qh\130\015\155\249vP\209\027\168Q\212\153"
"Rule: ocaml: cmx* & o* -> native (%=src/appMedium )": "\206>\142\236!+\211\017\002:\166\189\207\140\227\191"
"Rule: ocaml dependencies mli (%=src/display )": "\231~k=1\249%\182S0\233D\212\252\223\161"
"Rule: ocaml: cmx* & o* -> native (%=src/appMedium )": "\141/)\246;g2kJ3\146r\172^(\012"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ftest.ml": "V \236U\253\130k\1752\249\210>W\027\179\179"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/fordFulkerson.ml": "qra\159@\212u\200\192\132V9-\127\2022"
"Rule: ocaml: mli -> cmi (%=src/display )": "\165\163&C\247\02392\222\141}\166\237\209\226\196"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ftest.ml": "\161\017\169<\253\134ph\188\179@\248\183\026\133'"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/fordFulkerson.ml": "\018\182\220EC\195\028\nc\215W\207\1876\250\179"
"Rule: ocaml: mli -> cmi (%=src/graph )": ")2\159\205\136\031\251\145\0263\01878\001\b\134"
"Rule: ocaml: mli -> cmi (%=src/display )": "\165\163&C\247\02392\222\141}\166\237\209\226\196"
"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 )": "NH\210[_\240)6\144(\177'?\001\2204"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/tools.ml": "\143\\\1796g(\028m\247\209\131_vDeU"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/fordFulkerson )": "\214\1900\020\186\000\135\167\217\223AVA\252\025\025"
"Rule: ocaml: mli -> cmi (%=src/tools )": "\239.\206\1667\139\246~\227$\235l\012\210\208;"
"Rule: ocaml: cmx* & o* -> native (%=src/ftest )": "\190\0032\195\017x\223\240\255\182\150'\181\147\138\218"
"Rule: ocaml: mli -> cmi (%=src/fordFulkerson )": "v\184\208\237V\182T\138\168\207\20258\221\233s"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/ftest )": "\146\202\182\254\187\193y\243ifv\190\182$y\160"
"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/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ioApp.mli": "\178\247\139\175\031\167d)\137\166*\002\145\219/\223"
"Rule: ocaml: mli -> cmi (%=src/appTools )": "0\023\150\158\252\178S\158\b\189\169RA\190\195+"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/appMedium )": "d\031\192\1383\182\210\211sRe\237\024u\152\030"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/appMedium )": "\157Y\149\133\238K\162\023gsd\150\192\208\236X"
"Rule: ocaml dependencies ml (%=src/tools )": ",\255!)\2477ygb7\022\204V\143/$"
"Rule: ocaml: mli -> cmi (%=src/ioApp )": "%\246\167\224\"c>\168\bS,X|ym6"
"Rule: ocaml dependencies ml (%=src/ioApp )": "o[\196\152]\007R\152\141\185\244\004\206\182\243\018"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ioApp.ml": "X\001\188\187\150\143`\138\203\220\200\255\226\147f\210"
"Rule: ocaml dependencies mli (%=src/fordFulkerson )": "\022\200\166Dz0\003\233z\198y\144S\162\2034"
"Rule: ocaml dependencies ml (%=src/ioApp )": "\198\012\135\167\128\222.\135f\145\160\132\003n\179\024"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ioApp.ml": "%\174LQvF\219@\247\171\144\206\023\248\204O"
"Rule: ocaml: ml -> cmo & cmi (%=src/ftest )": "\2035PN<\216\182\028\220+~\028\012{V\007"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/fordFulkerson.mli": "_;(\155\176\"\225\011\230\191\031M\168\250\219\170"
"Rule: ocaml dependencies mli (%=src/fordFulkerson )": "\022\200\166Dz0\003\233z\198y\144S\162\2034"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/display.mli": "\1933\002\200+\198\166\181\251\020[Kl\1395\244"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/tools )": "@\029k\227\011N\245M\025S\161\203\212\156\191F"
"Rule: ocaml dependencies mli (%=src/appTools )": "\190\231\005\208\005\148\218\\\00486\211\183+i?"
"Rule: ocaml: ml -> cmo & cmi (%=src/appMedium )": "\212\238\215\019\142\150\225\1679\224\176`\241)\222g"
"Rule: ocaml dependencies ml (%=src/fordFulkerson )": "P\128\241\162\216\228\240\163<\168\241\235\129v\231\185"
"Rule: ocaml: ml -> cmo & cmi (%=src/appMedium )": "v\154\018A\0148\179V\185_\238\255*\202:\153"
"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/appTools )": "\172]O\222\166\169W\240\018,\242\239\135\204i\030"
"Rule: ocaml dependencies ml (%=src/appMedium )": "\194'6c-A\131\130m&\231 0c\152\170"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/ioApp )": "\224z\001\022x\219H\213k<\209.\247\168\193b"
"Rule: ocaml dependencies ml (%=src/fordFulkerson )": "{V\027D\r\028\012\251;\0033@\020;)P"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/appTools )": "\130\144:A,\158^^\248\134@GT\223Qt"
"Rule: ocaml dependencies ml (%=src/appMedium )": "\148\253\025j\198\175\211\152si\247\179\246DH\237"
"Rule: ocaml: ml & cmi -> cmx & o (%=src/ioApp )": "{\024\188\244z\139\133\157\229I\029\132\136Q\214\246"
"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 )": "\150I\199\147\226\208\148\192\184y\253\190\201\006>\168"
"Rule: ocaml dependencies mli (%=src/graph )": "\012\213_n\023=\207kZ+\251(^M\2028"
"Rule: ocaml dependencies ml (%=src/display )": "\019\144\250c\152\133\228`\149{\127O\bO\247\228"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/gfile.mli": "\203\249\163Ct\234\0067d}\142\011m8T`"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appMedium.ml": "^3NHM\196\012|O\139v\169l\149y\145"
"Rule: ocaml dependencies ml (%=src/gfile )": "U4(<\t=rQ\240c\0278\231N\1949"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appMedium.ml": "\1337\206,5\244\190\164\238?;3\193\130\164h"
"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": "\253\183m\179\227\189\240\189Z\198>\208jt\007#"
"Rule: ocaml dependencies ml (%=src/gfile )": "U4(<\t=rQ\240c\0278\231N\1949"
"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/display.ml": "\224\210\251\012D^\154\134g\244\219\134\016\135\015j"

View file

@ -1,8 +1,8 @@
### 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
# 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/appMedium.ml.depends, tags: { extension:ml, file:src/appMedium.ml, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/appMedium.ml > src/appMedium.ml.depends # cached
# Target: src/appTools.mli.depends, tags: { extension:mli, file:src/appTools.mli, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/appTools.mli > src/appTools.mli.depends # cached
# Target: src/gfile.mli.depends, tags: { extension:mli, file:src/gfile.mli, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/gfile.mli > src/gfile.mli.depends # cached
# Target: src/graph.mli.depends, tags: { extension:mli, file:src/graph.mli, include, ocaml, ocamldep, quiet, traverse }
@ -11,28 +11,56 @@
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/graph.cmi src/graph.mli # cached
# Target: src/gfile.cmi, tags: { byte, compile, extension:mli, file:src/gfile.mli, include, interf, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/gfile.cmi src/gfile.mli # cached
# Target: src/display.cmi, tags: { byte, compile, extension:mli, file:src/display.mli, include, interf, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/display.cmi src/display.mli # cached
# Target: src/fordFulkerson.mli.depends, tags: { extension:mli, file:src/fordFulkerson.mli, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/fordFulkerson.mli > src/fordFulkerson.mli.depends # cached
# Target: src/tools.mli.depends, tags: { extension:mli, file:src/tools.mli, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/tools.mli > src/tools.mli.depends # cached
# Target: src/tools.cmi, tags: { byte, compile, extension:mli, file:src/tools.mli, include, interf, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/tools.cmi src/tools.mli # cached
# Target: src/appTools.cmi, tags: { byte, compile, extension:mli, file:src/appTools.mli, include, interf, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/appTools.cmi src/appTools.mli # 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/display.cmi, tags: { byte, compile, extension:mli, file:src/display.mli, include, interf, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/display.cmi src/display.mli # cached
# Target: src/fordFulkerson.mli.depends, tags: { extension:mli, file:src/fordFulkerson.mli, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/fordFulkerson.mli > src/fordFulkerson.mli.depends # cached
# 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/ioApp.mli.depends, tags: { extension:mli, file:src/ioApp.mli, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/ioApp.mli > src/ioApp.mli.depends # cached
# Target: src/ioApp.cmi, tags: { byte, compile, extension:mli, file:src/ioApp.mli, include, interf, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/ioApp.cmi src/ioApp.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
File "src/ftest.ml", line 32, characters 31-33:
32 | let () = displayAllChoices xs in
^^
Error: This expression has type (string * int * int) list
but an expression was expected of type string list
Type string * int * int is not compatible with type string
Command exited with code 2.
# Compilation unsuccessful.
# Target: src/appMedium.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:src/appMedium.cmo, file:src/appMedium.ml, implem, include, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/appMedium.cmo src/appMedium.ml # cached
# Target: src/appTools.ml.depends, tags: { extension:ml, file:src/appTools.ml, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/appTools.ml > src/appTools.ml.depends # cached
# Target: src/gfile.ml.depends, tags: { extension:ml, file:src/gfile.ml, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/gfile.ml > src/gfile.ml.depends # cached
# Target: src/graph.ml.depends, tags: { extension:ml, file:src/graph.ml, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/graph.ml > src/graph.ml.depends # cached
# Target: src/graph.cmx, tags: { compile, extension:cmx, extension:ml, file:src/graph.cmx, file:src/graph.ml, implem, include, native, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/graph.cmx src/graph.ml # cached
# Target: src/gfile.cmx, tags: { compile, extension:cmx, extension:ml, file:src/gfile.cmx, file:src/gfile.ml, implem, include, native, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/gfile.cmx src/gfile.ml # cached
# 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/appTools.cmx, tags: { compile, extension:cmx, extension:ml, file:src/appTools.cmx, file:src/appTools.ml, implem, include, native, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/appTools.cmx src/appTools.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/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
# 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
# Target: src/ioApp.ml.depends, tags: { extension:ml, file:src/ioApp.ml, include, ocaml, ocamldep, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/ioApp.ml > src/ioApp.ml.depends
# Target: src/ioApp.cmx, tags: { compile, extension:cmx, extension:ml, file:src/ioApp.cmx, file:src/ioApp.ml, implem, include, native, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/ioApp.cmx src/ioApp.ml
# Target: src/appMedium.cmx, tags: { compile, extension:cmx, extension:ml, file:src/appMedium.cmx, file:src/appMedium.ml, implem, include, native, ocaml, quiet, traverse }
/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/appMedium.cmx src/appMedium.ml
# Target: src/appMedium.native, tags: { dont_link_with, extension:native, file:src/appMedium.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/tools.cmx src/appTools.cmx src/display.cmx src/fordFulkerson.cmx src/ioApp.cmx src/appMedium.cmx -o src/appMedium.native
# Compilation successful.

View file

@ -1,30 +1,22 @@
digraph finite_state_machine {
digraph finite_state_machine {
fontname="Helvetica,Arial,sans-serif"
fontname="Helvetica,Arial,sans-serif"
node [fontname="Helvetica,Arial,sans-serif"]
node [fontname="Helvetica,Arial,sans-serif"]
edge [fontname="Helvetica,Arial,sans-serif"]
edge [fontname="Helvetica,Arial,sans-serif"]
rankdir=LR;
rankdir=LR;
node [shape = circle];
node [shape = circle];
5 -> 8 [label = "1"];
3 -> 8 [label = "1"];
4 -> 8 [label = "1"];
7 -> 1 [label = "1"];
7 -> 8 [label = "1"];
2 -> 0 [label = "3"];
4 -> 1 [label = "1"];
3 -> 1 [label = "1"];
5 -> 4 [label = "1"];
5 -> 3 [label = "1"];
2 -> 5 [label = "1"];
2 -> 7 [label = "1"];
6 -> 8 [label = "1"];
6 -> 2 [label = "1"];
1 -> 3 [label = "1"];
1 -> 4 [label = "1"];
1 -> 6 [label = "1"];
0 -> 2 [label = "2"];
0 -> 1 [label = "3"];
1 -> 2 [label = "1"];
0 -> 1 [label = "1"];
}

View file

@ -4,169 +4,95 @@
<!-- Generated by graphviz version 2.50.0 (0)
-->
<!-- Title: finite_state_machine Pages: 1 -->
<svg width="420pt" height="313pt"
viewBox="0.00 0.00 420.00 313.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 309)">
<svg width="364pt" height="113pt"
viewBox="0.00 0.00 364.00 113.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 109)">
<title>finite_state_machine</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-309 416,-309 416,4 -4,4"/>
<!-- 5 -->
<polygon fill="white" stroke="transparent" points="-4,4 -4,-109 360,-109 360,4 -4,4"/>
<!-- 4 -->
<g id="node1" class="node">
<title>5</title>
<ellipse fill="none" stroke="black" cx="314" cy="-78" rx="18" ry="18"/>
<text text-anchor="middle" x="314" y="-74.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">5</text>
<title>4</title>
<ellipse fill="none" stroke="black" cx="18" cy="-87" rx="18" ry="18"/>
<text text-anchor="middle" x="18" y="-83.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">4</text>
</g>
<!-- 8 -->
<!-- 1 -->
<g id="node2" class="node">
<title>8</title>
<ellipse fill="none" stroke="black" cx="394" cy="-178" rx="18" ry="18"/>
<text text-anchor="middle" x="394" y="-174.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">8</text>
<title>1</title>
<ellipse fill="none" stroke="black" cx="98" cy="-37" rx="18" ry="18"/>
<text text-anchor="middle" x="98" y="-33.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 5&#45;&gt;8 -->
<!-- 4&#45;&gt;1 -->
<g id="edge1" class="edge">
<title>5&#45;&gt;8</title>
<path fill="none" stroke="black" d="M327.24,-90.29C336.17,-99.51 348.34,-112.62 358,-125 365.19,-134.23 372.44,-144.91 378.45,-154.25"/>
<polygon fill="black" stroke="black" points="375.5,-156.13 383.8,-162.71 381.42,-152.39 375.5,-156.13"/>
<text text-anchor="middle" x="354" y="-128.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
<title>4&#45;&gt;1</title>
<path fill="none" stroke="black" d="M33.67,-77.6C45,-70.33 60.89,-60.15 73.92,-51.79"/>
<polygon fill="black" stroke="black" points="75.86,-54.71 82.39,-46.36 72.09,-48.81 75.86,-54.71"/>
<text text-anchor="middle" x="58" y="-66.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 2 -->
<g id="node5" class="node">
<title>2</title>
<ellipse fill="none" stroke="black" cx="178" cy="-48" rx="18" ry="18"/>
<text text-anchor="middle" x="178" y="-44.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">2</text>
</g>
<!-- 1&#45;&gt;2 -->
<g id="edge6" class="edge">
<title>1&#45;&gt;2</title>
<path fill="none" stroke="black" d="M115.92,-39.39C125.84,-40.79 138.59,-42.58 149.88,-44.18"/>
<polygon fill="black" stroke="black" points="149.72,-47.69 160.11,-45.62 150.69,-40.76 149.72,-47.69"/>
<text text-anchor="middle" x="138" y="-45.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 3 -->
<g id="node3" class="node">
<title>3</title>
<ellipse fill="none" stroke="black" cx="152" cy="-287" rx="18" ry="18"/>
<text text-anchor="middle" x="152" y="-283.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">3</text>
<ellipse fill="none" stroke="black" cx="338" cy="-18" rx="18" ry="18"/>
<text text-anchor="middle" x="338" y="-14.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">3</text>
</g>
<!-- 3&#45;&gt;8 -->
<!-- 3&#45;&gt;1 -->
<g id="edge2" class="edge">
<title>3&#45;&gt;8</title>
<path fill="none" stroke="black" d="M170.03,-286.66C203.72,-285.23 280.06,-278.15 332,-244 349.49,-232.5 365.4,-214.93 376.59,-200.81"/>
<polygon fill="black" stroke="black" points="379.61,-202.61 382.91,-192.54 374.05,-198.36 379.61,-202.61"/>
<text text-anchor="middle" x="260" y="-280.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
<title>3&#45;&gt;1</title>
<path fill="none" stroke="black" d="M319.81,-16.93C288.06,-15.27 218.15,-13 160,-21 148.33,-22.61 135.69,-25.69 124.96,-28.72"/>
<polygon fill="black" stroke="black" points="123.95,-25.37 115.35,-31.57 125.94,-32.09 123.95,-25.37"/>
<text text-anchor="middle" x="218" y="-20.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 4 -->
<!-- 5 -->
<g id="node4" class="node">
<title>4</title>
<ellipse fill="none" stroke="black" cx="260" cy="-243" rx="18" ry="18"/>
<text text-anchor="middle" x="260" y="-239.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">4</text>
<title>5</title>
<ellipse fill="none" stroke="black" cx="258" cy="-48" rx="18" ry="18"/>
<text text-anchor="middle" x="258" y="-44.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">5</text>
</g>
<!-- 4&#45;&gt;8 -->
<!-- 5&#45;&gt;4 -->
<g id="edge3" class="edge">
<title>4&#45;&gt;8</title>
<path fill="none" stroke="black" d="M276.4,-235.42C298.93,-224.32 341.13,-203.54 368.1,-190.26"/>
<polygon fill="black" stroke="black" points="369.86,-193.29 377.29,-185.74 366.77,-187.01 369.86,-193.29"/>
<text text-anchor="middle" x="314" y="-228.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
<title>5&#45;&gt;4</title>
<path fill="none" stroke="black" d="M241.99,-57C235.92,-60.41 228.76,-64.16 222,-67 210.85,-71.68 207.89,-72.8 196,-75 143.67,-84.69 81.34,-86.77 46.35,-87.09"/>
<polygon fill="black" stroke="black" points="45.98,-83.59 36,-87.14 46.02,-90.59 45.98,-83.59"/>
<text text-anchor="middle" x="138" y="-86.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 7 -->
<g id="node5" class="node">
<title>7</title>
<ellipse fill="none" stroke="black" cx="314" cy="-132" rx="18" ry="18"/>
<text text-anchor="middle" x="314" y="-128.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">7</text>
</g>
<!-- 7&#45;&gt;8 -->
<g id="edge5" class="edge">
<title>7&#45;&gt;8</title>
<path fill="none" stroke="black" d="M331.49,-137.14C339.74,-140.05 349.71,-144.1 358,-149 363.01,-151.96 368.04,-155.63 372.66,-159.34"/>
<polygon fill="black" stroke="black" points="370.55,-162.14 380.44,-165.94 375.08,-156.8 370.55,-162.14"/>
<text text-anchor="middle" x="354" y="-152.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 1 -->
<g id="node6" class="node">
<title>1</title>
<ellipse fill="none" stroke="black" cx="18" cy="-200" rx="18" ry="18"/>
<text text-anchor="middle" x="18" y="-196.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 7&#45;&gt;1 -->
<!-- 5&#45;&gt;3 -->
<g id="edge4" class="edge">
<title>7&#45;&gt;1</title>
<path fill="none" stroke="black" d="M306.99,-148.82C301.51,-161.41 292.12,-177.83 278,-186 239.28,-208.42 104.64,-204.47 46.3,-201.58"/>
<polygon fill="black" stroke="black" points="46.19,-198.07 36.02,-201.04 45.82,-205.06 46.19,-198.07"/>
<text text-anchor="middle" x="152" y="-206.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 1&#45;&gt;3 -->
<g id="edge11" class="edge">
<title>1&#45;&gt;3</title>
<path fill="none" stroke="black" d="M24.78,-216.93C30.25,-230.5 39.77,-249.02 54,-260 74.15,-275.55 102.76,-282.14 123.69,-284.94"/>
<polygon fill="black" stroke="black" points="123.52,-288.44 133.85,-286.09 124.3,-281.49 123.52,-288.44"/>
<text text-anchor="middle" x="58" y="-268.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 1&#45;&gt;4 -->
<g id="edge12" class="edge">
<title>1&#45;&gt;4</title>
<path fill="none" stroke="black" d="M34.76,-207.24C40.68,-209.71 47.55,-212.28 54,-214 116.38,-230.63 192.14,-238.2 231.8,-241.24"/>
<polygon fill="black" stroke="black" points="231.76,-244.74 241.99,-241.98 232.27,-237.76 231.76,-244.74"/>
<text text-anchor="middle" x="98" y="-230.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 6 -->
<g id="node9" class="node">
<title>6</title>
<ellipse fill="none" stroke="black" cx="98" cy="-154" rx="18" ry="18"/>
<text text-anchor="middle" x="98" y="-150.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">6</text>
</g>
<!-- 1&#45;&gt;6 -->
<g id="edge13" class="edge">
<title>1&#45;&gt;6</title>
<path fill="none" stroke="black" d="M31.56,-187.94C37.92,-182.27 45.99,-175.74 54,-171 59.31,-167.86 65.31,-165.07 71.11,-162.71"/>
<polygon fill="black" stroke="black" points="72.4,-165.96 80.51,-159.14 69.92,-159.41 72.4,-165.96"/>
<text text-anchor="middle" x="58" y="-174.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 2 -->
<g id="node7" class="node">
<title>2</title>
<ellipse fill="none" stroke="black" cx="206" cy="-94" rx="18" ry="18"/>
<text text-anchor="middle" x="206" y="-90.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">2</text>
<title>5&#45;&gt;3</title>
<path fill="none" stroke="black" d="M275.16,-41.78C285.62,-37.76 299.46,-32.44 311.4,-27.85"/>
<polygon fill="black" stroke="black" points="312.78,-31.06 320.86,-24.21 310.27,-24.53 312.78,-31.06"/>
<text text-anchor="middle" x="298" y="-36.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 2&#45;&gt;5 -->
<g id="edge7" class="edge">
<g id="edge5" class="edge">
<title>2&#45;&gt;5</title>
<path fill="none" stroke="black" d="M224.03,-91.43C240.72,-88.91 266.42,-85.03 285.92,-82.09"/>
<polygon fill="black" stroke="black" points="286.65,-85.52 296.01,-80.56 285.6,-78.6 286.65,-85.52"/>
<text text-anchor="middle" x="260" y="-92.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 2&#45;&gt;7 -->
<g id="edge8" class="edge">
<title>2&#45;&gt;7</title>
<path fill="none" stroke="black" d="M222.96,-100.6C228.91,-103 235.74,-105.69 242,-108 256.79,-113.45 273.48,-119.12 286.96,-123.57"/>
<polygon fill="black" stroke="black" points="285.96,-126.93 296.55,-126.72 288.14,-120.28 285.96,-126.93"/>
<text text-anchor="middle" x="260" y="-124.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
<path fill="none" stroke="black" d="M196.31,-48C206.11,-48 218.58,-48 229.67,-48"/>
<polygon fill="black" stroke="black" points="229.74,-51.5 239.74,-48 229.74,-44.5 229.74,-51.5"/>
<text text-anchor="middle" x="218" y="-51.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 0 -->
<g id="node8" class="node">
<g id="node6" class="node">
<title>0</title>
<ellipse fill="none" stroke="black" cx="314" cy="-18" rx="18" ry="18"/>
<text text-anchor="middle" x="314" y="-14.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">0</text>
</g>
<!-- 2&#45;&gt;0 -->
<g id="edge6" class="edge">
<title>2&#45;&gt;0</title>
<path fill="none" stroke="black" d="M220.03,-82.64C226.5,-77.14 234.52,-70.55 242,-65 257.48,-53.51 275.62,-41.53 289.69,-32.54"/>
<polygon fill="black" stroke="black" points="291.7,-35.41 298.27,-27.1 287.95,-29.49 291.7,-35.41"/>
<text text-anchor="middle" x="260" y="-68.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">3</text>
<ellipse fill="none" stroke="black" cx="18" cy="-26" rx="18" ry="18"/>
<text text-anchor="middle" x="18" y="-22.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">0</text>
</g>
<!-- 0&#45;&gt;1 -->
<g id="edge15" class="edge">
<g id="edge7" class="edge">
<title>0&#45;&gt;1</title>
<path fill="none" stroke="black" d="M296.82,-12.4C282.18,-8.21 260.18,-4.12 242,-10 148.05,-40.38 68.36,-133.94 35.32,-177.39"/>
<polygon fill="black" stroke="black" points="32.35,-175.52 29.17,-185.62 37.96,-179.71 32.35,-175.52"/>
<text text-anchor="middle" x="152" y="-76.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">3</text>
</g>
<!-- 0&#45;&gt;2 -->
<g id="edge14" class="edge">
<title>0&#45;&gt;2</title>
<path fill="none" stroke="black" d="M296.29,-14.77C280.87,-12.75 258,-12.25 242,-23 227.12,-33 218.32,-51.24 213.26,-66.73"/>
<polygon fill="black" stroke="black" points="209.88,-65.81 210.45,-76.39 216.6,-67.77 209.88,-65.81"/>
<text text-anchor="middle" x="260" y="-26.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">2</text>
</g>
<!-- 6&#45;&gt;8 -->
<g id="edge9" class="edge">
<title>6&#45;&gt;8</title>
<path fill="none" stroke="black" d="M116.08,-155.39C164.99,-159.39 305.95,-170.89 365.7,-175.77"/>
<polygon fill="black" stroke="black" points="365.62,-179.28 375.88,-176.6 366.19,-172.3 365.62,-179.28"/>
<text text-anchor="middle" x="260" y="-171.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
<!-- 6&#45;&gt;2 -->
<g id="edge10" class="edge">
<title>6&#45;&gt;2</title>
<path fill="none" stroke="black" d="M113.91,-144.88C120.1,-141.14 127.36,-136.81 134,-133 149.46,-124.12 167.01,-114.47 180.8,-107"/>
<polygon fill="black" stroke="black" points="182.54,-110.04 189.67,-102.2 179.21,-103.88 182.54,-110.04"/>
<text text-anchor="middle" x="152" y="-136.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
<path fill="none" stroke="black" d="M36.24,-25.4C44.14,-25.38 53.58,-25.72 62,-27 64.93,-27.44 67.96,-28.06 70.95,-28.77"/>
<polygon fill="black" stroke="black" points="70.24,-32.21 80.81,-31.44 72.07,-25.45 70.24,-32.21"/>
<text text-anchor="middle" x="58" y="-30.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 9 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -6,8 +6,10 @@
open AppTools
let () =
(*gets all the choices*)
let xs = List.rev (enterAllChoices ()) in
(*displays the choices*)
let () = displayAllChoices (List.map (
fun x -> match x with
| (a,_,_) -> a
@ -15,17 +17,22 @@
xs) in
();
(*builds the graph of activities*)
let g = buildGraph xs in
(*gets the name and activities of each child*)
let ys = enterChildren (getMaximumNodeId g) xs in
(*completes the graph with this data*)
let gComplete = addChildren ys g in
(*solves the graph optimization problem*)
let gFinal = main gComplete (getMaximumNodeId gComplete) 0 in
(*write the graph to a file / for debug purposes*)
let () = exportBase gFinal "./outFileApp" in
();
(*Displays the final results*)
let () = outputData gFinal ys xs in
(); print_string "\n\n"

View file

@ -2,15 +2,21 @@ open Graph
open Gfile
open Tools
(*same as fst but for 3 elements*)
let fst3 x = match x with
| (a,_,_) -> a
(*same as snd but for 3 elements*)
let snd3 = function
| (_, b, _ ) -> b
(*returns the 3rd value of a 3-elements tuple*)
let thrd3 = function
| (_, _, c ) -> c
(*takes in a list of (String : Name, int Id, int Capacity)
returns the corresponding graph (a sink with a node for each activity and an edge with the corresponding capacity)*)
let buildGraph xs =
let g = new_node empty_graph 0 (*Defines the end*)
in
@ -18,12 +24,13 @@ let buildGraph xs =
| [] -> acc
| (_,id,capa) :: xs -> inner (add_arc (new_node acc id) id 0 capa) xs
in
inner g xs
let getMaximumNodeId g =
n_fold g (fun x id -> max x id) 0
(*Adds all the choices of the children to the grap (i.e. create a node for each and then an edge from the
(*Adds all the choices of the children to the graph (i.e. create a node for each and then an edge from the
node toward the desired node(s). This function also completes the graph by adding a starting node*)
let addChildren xxs g =
(*the id of the start is the maximum id + the number of added nodes + 1 to get the next maximum id *)
@ -37,7 +44,7 @@ let addChildren xxs g =
| x :: xs -> activitiesIterator childNode (add_arc acc childNode x 1) xs
in
(*tool function to create the node for said children and create the edge from th start to this node*)
(*tool function to create the node for said children and create the edge from the start to this node*)
let addChildrenNode g a =
let g1 = (new_node g a) in
add_arc g1 startId a 1

View file

@ -2,38 +2,44 @@ open Graph
open Printf
open Gfile
(*exports an int graph to an output format
and writes it to the the path given as second parameter*)
let exportBase g path =
let str = e_fold
let str = e_fold (*goes over all edges*)
g
(fun x id1 id2 label -> x ^ "\n "
(fun acc id1 id2 label -> acc ^ "\n "
^ (string_of_int id1) ^ " -> "
^ (string_of_int id2) ^ " [label = \""
^ (string_of_int label) ^ "\"];" )
""
in
let startStr =
"
digraph finite_state_machine {\n
fontname=\"Helvetica,Arial,sans-serif\"\n
node [fontname=\"Helvetica,Arial,sans-serif\"]\n
edge [fontname=\"Helvetica,Arial,sans-serif\"]\n
rankdir=LR;\n
node [shape = circle];\n
"
in
(*adds the header for the output file*)
let startStr =
"
digraph finite_state_machine {\n
fontname=\"Helvetica,Arial,sans-serif\"\n
node [fontname=\"Helvetica,Arial,sans-serif\"]\n
edge [fontname=\"Helvetica,Arial,sans-serif\"]\n
rankdir=LR;\n
node [shape = circle];\n
"
in
let finishStr = "\n}" in
let finishStr = "\n}" in
let totalStr = startStr ^ str ^ finishStr in
let ff = open_out path in
fprintf ff "%s%!" totalStr;
close_out ff;
()
(*final string from the 3 parts*)
let totalStr = startStr ^ str ^ finishStr in
(*writes to the file*)
let ff = open_out path in
fprintf ff "%s%!" totalStr;
close_out ff;
()
(*exports an int graph with a source and sink to an output format showing the difference (ex : 5/12)
and writes it to the the path given as second parameter*)
let exportDifference gStart gEnd path =
let findUsedCapacity gEnd id1 id2 capaStart =
let newEdge = find_arc gEnd id1 id2 in

View file

@ -6,41 +6,46 @@ open Printf
(*returns a way (i.e. list of nodes that link s1 to s2, and the maximum capacity that could be added to it) *)
let rec way g n1 n2 =
let rec inner g (xs, capa) visited n1 n2 = match n1, n2 with
| a, b when a = n2 -> Some ((List.rev xs), capa)
| a, b when a = n2 -> Some ((List.rev xs), capa) (*Destination reached --> return the value*)
| a, b ->
let findNext x (arcId, arcCapa) = match x with
| None -> inner g (arcId :: xs, (min capa arcCapa)) (arcId :: visited) arcId n2
| None -> inner g (arcId :: xs, (min capa arcCapa)) (arcId :: visited) arcId n2 (*If we are returned a non then this branch
is empty --> we need to serach in the others*)
| Some a -> Some a
in
let out = List.filter
let out = List.filter (*all the possible outgoing edges from this node that haven't been visited*)
(fun x -> not (List.exists
(fun y -> (fst x) = y) visited))
(out_arcs g a) in
if List.length out > 0
then
fold_left findNext None out
else
None
if List.length out > 0
then
fold_left findNext None out
else
None
in
if n1 == n2
if n1 == n2 (*Same node --> No path*)
then None
else inner g ([n1], (maxCapaGraph g)) [] n1 n2
else inner g ([n1], (maxCapaGraph g)) [] n1 n2 (*We search through the graph using the graph's maximum capacity
as our starting point for the maximum capacity*)
(*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
match nodes with (* goes over all nodes*)
| [] -> g
| x :: [] -> g
| x::y::xs ->
let removedCapcityUsed = sub_arc g x y capa in
let addPossibleUndo = add_arc removedCapcityUsed y x capa in
let removedCapacityUsed = sub_arc g x y capa in (*decrements the value of the edge*)
let addPossibleUndo = add_arc removedCapacityUsed y x capa in (*adds the opposite edge for the difference graph*)
updateCapacityAlongPath addPossibleUndo (y::xs,capa)
in
testGraphSanity (

View file

@ -28,10 +28,6 @@
and _sink = int_of_string Sys.argv.(3)
in
let xs = List.rev (enterAllChoices ()) in
let () = displayAllChoices xs in
();
(* Open file *)
let graph = from_file infile in

View file

@ -5,21 +5,28 @@ open Graph
let enterAllChoices () =
let rec inner xs i =
let str = read_line () in
if str = ""
if str = "" (*means the user hit enter twice --> end of input, we return the list*)
then
xs
else
(*gets a line input, splits it and removes any remaining empty string *)
let inputs = List.filter (fun s -> s <> "") (String.split_on_char ' ' str) in
(*checks for the right number of elements*)
if (List.length inputs) = 2
then
try
(*extracts the name and capacity of said activity*)
let name = List.hd inputs in
let capa = int_of_string (List.nth inputs 1) in
let capa = int_of_string (List.nth inputs 1)
in
(*adds them to the list*)
inner ((name,i,capa) :: xs) (i+1)
with
(*in case of an error : prompts to retry*)
| _ -> let () = (print_string "\nPlease enter a string followed by a number\n") in
(); inner xs i
else
(*in case of a wrong number of arguments : prompts to retry*)
let () = (print_string "\nPlease enter a string followed by a number\n") in
(); inner xs i
@ -28,6 +35,7 @@ let enterAllChoices () =
by new lines and followed by their capacity, hit enter twice to finish \n";
inner [] 1
(* Displays all of the activities alongside their id*)
let displayAllChoices xs =
let rec inner i acc = function
@ -42,36 +50,40 @@ let displayAllChoices xs =
interested in and returns a (id, name, id list) list.
Takes in input the number of the previously assigned nodes' maximum id
and the list of activities) *)
let enterChildren idPrev listActivities =
let rec inner xs i =
let str = read_line ()
in
if str = ""
if str = "" (*means the user hit enter twice --> end of input, we return the list*)
then
xs
xs (*in case of help : prompts to retry*)
else
(*checks if the input is not the keyword for help*)
if str = "HELP"
then
let () = (print_string "\n=========\n"); displayAllChoices (List.map (fun x -> (fst3 x)) listActivities);
(print_string "=========\n") in () ;
inner xs i
else
(*gets a line input, splits it and removes any remaining empty string *)
let inputs = List.filter (fun s -> s <> "") (String.split_on_char ' ' str) in
try
(*get all the choices (i.e. the tail of the input list and the converts them to ints before sorting them)*)
let choices = List.sort_uniq (-) (List.map (fun x -> int_of_string x) (List.tl inputs)) in
(*checks for invalid activities (i.e. ones that do not have a node in the graph)*)
if List.exists (fun x -> x > idPrev) choices
then
let () = (print_string "\n=========\n Please only enter digits that match activities\n");
(print_string "=========\n");
let () = (print_string "\n=========\n Please only enter digits that match activities\n=========\n");
displayAllChoices (List.map (fun x -> (fst3 x)) listActivities); in () ;
(*in case of an error : prompts to retry*)
inner xs i
else
inner ((i, (List.hd inputs), choices) :: xs) (i+1)
with
(*in case of an error : prompts to retry*)
| _ -> (print_string "=========\n");
(print_string "Usage : name id1 id2 id3");
(print_string "\n=========\n");
@ -79,11 +91,27 @@ let enterChildren idPrev listActivities =
in
print_string "Enter the name of the child followed by the ids of the \
activities they are interested in. type \'HELP\' to list the activities\n";
inner [] (idPrev+1)
inner [] (idPrev+1) (*starts at the next available node*)
(*Prints on the screen which children have nothing to do and what the others have*)
let outputData g childrenList choicesList =
(*lists the children that will not have an activity
i.e. the nodes that do have a path from the source to them*)
let listIdleChildren =
let rec inner3 acc = function (*goes over all edges out of the sources's node*)
| [] -> acc
| x :: xs -> inner3 (acc ^
let childNodeId = fst x in
snd3 (List.find (fun a -> fst3 a = childNodeId) childrenList) ^ "/"
) xs
in
inner3 "" (out_arcs g (getMaximumNodeId g))
in
(*lists the children that have an activity
i.e. the nodes that do have a path from said activity to them*)
let findAssignedChildren activity =
let rec inner2 acc = function (*goes over all edges out of the activity's node*)
@ -103,6 +131,7 @@ let outputData g childrenList choicesList =
in
(*goes over all activities and gets the string to print for each activity*)
let rec inner acc g = function
| [] -> print_string acc
| x :: xs ->
@ -114,7 +143,7 @@ let outputData g childrenList choicesList =
in
inner "" g choicesList; print_string("\n the children that did not appear above could \
not be assigned any activity")
inner "" g choicesList;
print_string("\n the children that did not appear above could \
not be assigned any activity : " ^ listIdleChildren)