From a85a66c9a7d0151870f2c5f280bac2ba4e98960b Mon Sep 17 00:00:00 2001 From: rlacroix Date: Fri, 9 Dec 2022 21:12:37 +0100 Subject: [PATCH] added inputs support. The application can read its input. Missing the output part. --- _build/_digests | 45 +++++++++--------- _build/_log | 39 ++++++++------- appMedium.native | 1 + outFileApp | 12 +++-- outFileApp.svg | 120 +++++++++++++++++++++++++++++++++++------------ src/appMedium.ml | 16 ++++++- src/appTools.ml | 37 +++++++++++++-- src/appTools.mli | 9 +++- src/ioApp.ml | 63 ++++++++++++++++++------- src/ioApp.mli | 29 ++---------- 10 files changed, 247 insertions(+), 124 deletions(-) create mode 120000 appMedium.native diff --git a/_build/_digests b/_build/_digests index f1561c9..0320f1e 100644 --- a/_build/_digests +++ b/_build/_digests @@ -1,44 +1,47 @@ -"Rule: ocaml dependencies ml (%=src/appTools )": "\003~\021L\228\004\183\150J\023\129k$\243.y" -"Rule: ocaml: ml & cmi -> cmx & o (%=src/display )": "\239\213\229\211j!\190#\027U\183\135\175^\143<" +"Rule: ocaml dependencies ml (%=src/appTools )": "\183\148#t\166\132\168\206#\210\238[Q2\b[" "Rule: ocaml dependencies mli (%=src/gfile )": "7\182\192g\020\238\188\b\211\164{\014\157\135\011\003" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appTools.mli": "\132\r\001\182e@\193\228{\201\001T\028\193Z." -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appTools.ml": "\237\194\004\240\234x)\235\141\229\133A#\210{X" -"Rule: ocaml dependencies mli (%=src/ioApp )": ",\249\026Y\003\016\207\2482j!Z\228\189e\166" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/display )": "\239\213\229\211j!\190#\027U\183\135\175^\143<" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appTools.mli": "\150\255\014\015\006\217\135\239\138\221\031\024D\175\187\240" +"Rule: ocaml dependencies mli (%=src/ioApp )": "\015p\211\144\234B\152\220\232~\227\1799o\140:" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/appTools.ml": "^\251~s!\164;8\176\224\157\152K\214\135\223" "Rule: ocaml: ml & cmi -> cmx & o (%=src/gfile )": "\236O\148Y\157m\028\183\166?\231a\231\187u\132" +"Rule: ocaml: cmx* & o* -> native (%=src/appMedium )": "\007g\183Z\031\194]+_\241X\200\rD\023\246" "Rule: ocaml dependencies mli (%=src/display )": "\231~k=1\249%\182S0\233D\212\252\223\161" "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" "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 )": "NH\210[_\240)6\144(\177'?\001\2204" "Rule: ocaml: mli -> cmi (%=src/tools )": "\239.\206\1667\139\246~\227$\235l\012\210\208;" "Rule: ocaml: mli -> cmi (%=src/fordFulkerson )": "v\184\208\237V\182T\138\168\207\20258\221\233s" "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": "*\027\197C\000\030}\147\219Kx\159\153\2463\245" -"Rule: ocaml: mli -> cmi (%=src/appTools )": "\006a$\191W\146\176aU0w_\197\181d-" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ioApp.mli": "\151\003\019\151\016\160\201G\158\215\195\0282\192\193\179" +"Rule: ocaml: mli -> cmi (%=src/appTools )": "\254\007-\022GJ\148\228/\220\"#%3\186\024" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/appMedium )": "PM(\023e6\192\145\205\140Xf\241\184\028#" "Rule: ocaml dependencies ml (%=src/tools )": ",\255!)\2477ygb7\022\204V\143/$" -"Rule: ocaml: mli -> cmi (%=src/ioApp )": "\202\189io\239\154Dl\130Z\150\029\238\212\163\249" -"Rule: ocaml dependencies ml (%=src/ioApp )": "\179o\011\147\170\140\133:*\005P\152O\014K\232" -"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ioApp.ml": "\170\147\162w\171\210QN\189\137\137-\227\184\222j" -"Rule: ocaml dependencies mli (%=src/fordFulkerson )": "\022\200\166Dz0\003\233z\198y\144S\162\2034" +"Rule: ocaml: mli -> cmi (%=src/ioApp )": "\157\160\238I\0164\025\190\144\018\016\222\162B\006i" +"Rule: ocaml dependencies ml (%=src/ioApp )": "*\222\b4~[\166S\002\239\253\162\252\227\250\130" +"Resource: /home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/src/ioApp.ml": "\241W\154\212\017'L|v.pw\243\253\206/" "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 )": "\131\213\134\023\170\184\227\194y\196[v\172=A\210" -"Rule: ocaml: ml -> cmo & cmi (%=src/appMedium )": "0Z<\189\021\232\163\188bE\025E\129:\011\179" -"Rule: ocaml dependencies ml (%=src/fordFulkerson )": "P\128\241\162\216\228\240\163<\168\241\235\129v\231\185" +"Rule: ocaml dependencies mli (%=src/appTools )": "\144I\155\245\193\219\140\169\228\151\003d\023\029\176\247" +"Rule: ocaml: ml -> cmo & cmi (%=src/appMedium )": "\196\219\130\186p\144\141Q\228\142\217\015\133{\154\168" "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 )": "Z>\162l4\144\001\029D\tv\210\237\202b+" -"Rule: ocaml dependencies ml (%=src/appMedium )": "\rk\244M\254v'3T489m\239\247\217" +"Rule: ocaml dependencies ml (%=src/fordFulkerson )": "P\128\241\162\216\228\240\163<\168\241\235\129v\231\185" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/appTools )": ")\214w`^\253B\200\150,\219\173\0174\006d" +"Rule: ocaml dependencies ml (%=src/appMedium )": "\142\163\229\252\003U{\202!:\138\184$\247ZN" +"Rule: ocaml: ml & cmi -> cmx & o (%=src/ioApp )": "\193\015X--\018\239\025\016\241\025\225\172jI\206" "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 )": "\150I\199\147\226\208\148\192\184y\253\190\201\006>\168" "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": "\174H\007\251\150\248u\185\140\197\1745 c\204\213" -"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": "\216\2227\174z\bw\1511b\183\194j\156\201s" "Rule: ocaml dependencies mli (%=src/tools )": "\151\181\0055\199\150&\017\021_\215\015\215\018\027+" +"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": "\253\183m\179\227\189\240\189Z\198>\208jt\007#" diff --git a/_build/_log b/_build/_log index ff08f89..b062229 100644 --- a/_build/_log +++ b/_build/_log @@ -1,6 +1,6 @@ ### Starting build. # 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 +/home/chepycou/.opam/4.14.0/bin/ocamldep.opt -modules src/appMedium.ml > src/appMedium.ml.depends # 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 } @@ -26,11 +26,16 @@ # 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 +/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 +/home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/ioApp.cmi src/ioApp.mli # cached # 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 ++ /home/chepycou/.opam/4.14.0/bin/ocamlc.opt -c -I src -o src/appMedium.cmo src/appMedium.ml +File "src/appMedium.ml", line 25, characters 12-18: +25 | let gFinal = main gComplete (getMaximumNodeId gComplete) 0 in + ^^^^^^ +Warning 26 [unused-var]: unused variable gFinal. # 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 } @@ -58,20 +63,14 @@ # 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 # cached # 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 -+ /home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/ioApp.cmx src/ioApp.ml -File "src/ioApp.ml", line 1: -Error: The implementation src/ioApp.ml - does not match the interface src/ioApp.cmi: - Values do not match: - val enterChildren : int -> 'a -> (int * string * string list) list - is not included in - val enterChildren : int -> int -> (int * string * int list) list - The type int -> int -> (int * string * string list) list - is not compatible with the type - int -> int -> (int * string * int list) list - Type string is not compatible with type int - File "src/ioApp.mli", line 6, characters 0-63: Expected declaration - File "src/ioApp.ml", line 32, characters 4-17: Actual declaration -Command exited with code 2. -# Compilation unsuccessful. +/home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/ioApp.cmx src/ioApp.ml # cached +# 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 ++ /home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/appMedium.cmx src/appMedium.ml +File "src/appMedium.ml", line 25, characters 12-18: +25 | let gFinal = main gComplete (getMaximumNodeId gComplete) 0 in + ^^^^^^ +Warning 26 [unused-var]: unused variable gFinal. +# 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. diff --git a/appMedium.native b/appMedium.native new file mode 120000 index 0000000..9ab5bb5 --- /dev/null +++ b/appMedium.native @@ -0,0 +1 @@ +/home/chepycou/Documents/cours/4-IR/functionalProgramming/Projet/repoGit/ocaml-maxflow-project/_build/src/appMedium.native \ No newline at end of file diff --git a/outFileApp b/outFileApp index 429e6af..f8d8f6d 100644 --- a/outFileApp +++ b/outFileApp @@ -12,7 +12,13 @@ node [shape = circle]; - 3 -> 0 [label = "1"]; - 2 -> 0 [label = "1"]; - 1 -> 0 [label = "1"]; + 4 -> 3 [label = "1"]; + 4 -> 2 [label = "1"]; + 4 -> 1 [label = "1"]; + 6 -> 4 [label = "1"]; + 6 -> 5 [label = "1"]; + 5 -> 2 [label = "1"]; + 3 -> 0 [label = "4"]; + 2 -> 0 [label = "3"]; + 1 -> 0 [label = "2"]; } \ No newline at end of file diff --git a/outFileApp.svg b/outFileApp.svg index 55706fb..66e1bfc 100644 --- a/outFileApp.svg +++ b/outFileApp.svg @@ -4,55 +4,115 @@ - - + + finite_state_machine - - + + -3 - -3 +4 + +4 - + -0 - -0 +3 + +3 - + -3->0 - - -1 +4->3 + + +1 2 - -2 + +2 - + -2->0 - - -1 +4->2 + + +1 1 - -1 + +1 + + + +4->1 + + +1 + + + +0 + +0 + + + +3->0 + + +4 + + + +2->0 + + +3 - + 1->0 - - -1 + + +2 + + + +6 + +6 + + + +6->4 + + +1 + + + +5 + +5 + + + +6->5 + + +1 + + + +5->2 + + +1 diff --git a/src/appMedium.ml b/src/appMedium.ml index addd96e..1fc8aba 100644 --- a/src/appMedium.ml +++ b/src/appMedium.ml @@ -8,9 +8,21 @@ let () = let xs = List.rev (enterAllChoices ()) in - let () = displayAllChoices xs in + let () = displayAllChoices (List.map ( + fun x -> match x with + | (a,_,_) -> a + ) + xs) in (); + let g = buildGraph xs in - let () = exportBase g "./outFileApp" in + + let ys = enterChildren (getMaximumNodeId g) xs in + + let gComplete = addChildren ys g in + + let gFinal = main gComplete (getMaximumNodeId gComplete) 0 in + + let () = exportBase gComplete "./outFileApp" in () \ No newline at end of file diff --git a/src/appTools.ml b/src/appTools.ml index 39d973a..764abaa 100644 --- a/src/appTools.ml +++ b/src/appTools.ml @@ -2,17 +2,48 @@ open Graph open Gfile open Tools +let fst3 x = match x with + | (a,_,_) -> a + +let thrd3 = function + | (_, _, a ) -> a + let buildGraph xs = let g = new_node empty_graph 0 (*Defines the end*) in let rec inner acc = function | [] -> acc - | (_,id) :: xs -> inner (add_arc (new_node acc id) id 0 1) xs + | (_,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 -let thrd = function - | (_, _, a ) -> a \ No newline at end of file +(*Adds all the choices of the children to the grap (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 *) + let startId = (getMaximumNodeId g) + (List.length xxs) + 1 in + (*We create the node*) + let g2 = new_node g startId in + + (*goes over all the activities of a children*) + let rec activitiesIterator childNode acc = function + | [] -> acc + | 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*) + let addChildrenNode g a = + let g1 = (new_node g a) in + add_arc g1 startId a 1 + in + + (*goes over all the children of the list*) + let rec childrenIterator acc = function + | [] -> acc + | (a,b,c) :: xs -> childrenIterator (activitiesIterator a (addChildrenNode acc a) c) xs + in + childrenIterator g2 xxs + diff --git a/src/appTools.mli b/src/appTools.mli index 92debb4..2324052 100644 --- a/src/appTools.mli +++ b/src/appTools.mli @@ -2,8 +2,13 @@ open Graph open Gfile open Tools -val buildGraph : (string * int) list -> int graph +val fst3 : ('a * 'b * 'c) -> 'a + +val thrd3 : ('a * 'b * 'c) -> 'c + +val buildGraph : (string * int * int) list -> int graph val getMaximumNodeId : 'a graph -> int -val thrd : ('a * 'b * 'c) -> 'c \ No newline at end of file + +val addChildren : (id * string * int list) list -> int graph -> int graph \ No newline at end of file diff --git a/src/ioApp.ml b/src/ioApp.ml index 0bba279..997db92 100644 --- a/src/ioApp.ml +++ b/src/ioApp.ml @@ -1,3 +1,5 @@ +open AppTools + (* Prompts the user to enter all activities and stores them in a (id, name) list*) let enterAllChoices () = let rec inner xs i = @@ -6,10 +8,23 @@ let enterAllChoices () = then xs else - inner ((str,i) :: xs) (i+1) + let inputs = List.filter (fun s -> s <> "") (String.split_on_char ' ' str) in + if (List.length inputs) = 2 + then + try + let name = List.hd inputs in + let capa = int_of_string (List.nth inputs 1) in + inner ((name,i,capa) :: xs) (i+1) + with + | _ -> let () = (print_string "\nPlease enter a string followed by a number\n") in + (); inner xs i + else + let () = (print_string "\nPlease enter a string followed by a number\n") in + (); inner xs i + in - print_string "Enter the next possible choices for the children separated \ - by new lines, hit enter to finish \n"; + print_string "Enter the possible choices for the children separated \ + by new lines and followed by their capacity, hit enter twice to finish \n"; inner [] 1 (* Displays all of the activities alongside their id*) @@ -19,12 +34,12 @@ let displayAllChoices xs = | x :: xs -> inner (i+1) ( acc ^ (string_of_int i) ^ " : " ^ x ^ "\n") xs in - print_string (inner 1 "" (List.map (fun x -> fst x) xs)) + print_string (inner 1 "" xs) (* Prompts the user to enter all children's names the activities they are interested in and returns a (id, name, id list) list. - Takes in input the number of the previously assigned nodes' maximum id* + Takes in input the number of the previously assigned nodes' maximum id and the list of activities) *) @@ -37,22 +52,34 @@ let enterChildren idPrev listActivities = then xs else - (*if str = "1" + if str = "HELP" then - displayAllChoices listActivities - else*) - let inputs = List.filter (fun s -> s <> "") (String.split_on_char ' ' str) - in - inner ((i, (List.hd inputs), (List.tl inputs)) :: xs) (i+1) + let () = (print_string "\n=========\n"); displayAllChoices (List.map (fun x -> (fst3 x)) listActivities); + (print_string "=========\n") in () ; + inner xs i + else + let inputs = List.filter (fun s -> s <> "") (String.split_on_char ' ' str) in + + try + let choices = List.sort_uniq (-) (List.map (fun x -> int_of_string x) (List.tl inputs)) in + + 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"); + displayAllChoices (List.map (fun x -> (fst3 x)) listActivities); in () ; + inner xs i + else + inner ((i, (List.hd inputs), choices) :: xs) (i+1) + + with + | _ -> (print_string "=========\n"); + (print_string "Usage : name id1 id2 id3"); + (print_string "\n=========\n"); + inner xs i in print_string "Enter the name of the child followed by the ids of the \ - activities they are interested in. type \'1\' to list the activities\n"; + activities they are interested in. type \'HELP\' to list the activities\n"; inner [] (idPrev+1) - - - -(* Takes an already built graph and adds it capacities -(i.e. : the number of people that can register for a said activity *) -(*let setCapcities g = TODO Complete *) \ No newline at end of file diff --git a/src/ioApp.mli b/src/ioApp.mli index 71bcd1e..41fccda 100644 --- a/src/ioApp.mli +++ b/src/ioApp.mli @@ -1,28 +1,7 @@ -val enterAllChoices: unit -> (string * int) list +open Graph -val displayAllChoices: (string * int) list -> unit +val enterAllChoices: unit -> (string * int * int) list -(*TODO : figure out error message : -ocamlbuild appMedium.native -+ /home/chepycou/.opam/4.14.0/bin/ocamlopt.opt -c -I src -o src/ioApp.cmx src/ioApp.ml -File "src/ioApp.ml", line 1: -Error: The implementation src/ioApp.ml - does not match the interface src/ioApp.cmi: - Values do not match: - val enterChildren : int -> 'a -> (int * string * string list) list - is not included in - val enterChildren : int -> int -> (int * string * int list) list - The type int -> int -> (int * string * string list) list - is not compatible with the type - int -> int -> (int * string * int list) list - Type string is not compatible with type int - File "src/ioApp.mli", line 6, characters 0-63: Expected declaration - File "src/ioApp.ml", line 32, characters 4-17: Actual declaration -Command exited with code 2. -Compilation unsuccessful after building 30 targets (26 cached) in 00:00:00. -make: *** [Makefile:29: buildApp] Error 10*) +val displayAllChoices: string list -> unit -val enterChildren: int -> (string * int) list -> (int * string * int list) list - - -(*TODO val setCapcities : int graph -> int graph *) \ No newline at end of file +val enterChildren: int -> (string * int * int) list -> (int * string * (int list)) list \ No newline at end of file