diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..645d1dc --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,47 @@ +name: Basic test workflow + +on: + - pull_request + - push + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: +# - macos-latest +# - ubuntu-latest +# - windows-latest + - ubuntu-18.04 + ocaml-version: + - 4.11.0 +# - 4.10.1 +# - 4.09.1 +# - 4.08.1 + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Try to restore opam cache + if: runner.os != 'Windows' + id: opam-cache + uses: actions/cache@v2 + with: + path: "~/.opam" + key: ${{ matrix.os }}-${{ matrix.ocaml-version }} + + - name: Use OCaml ${{ matrix.ocaml-version }} + uses: avsm/setup-ocaml@v1 + with: + ocaml-version: ${{ matrix.ocaml-version }} + + - run: opam install ocamlbuild + - name: Build project + run: eval $(opam env) && make build + - name: Run demo + run: eval $(opam env) && make demo + diff --git a/.gitignore b/.gitignore index 193bdce..22038d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,4 @@ -# ---> OCaml -*.annot -*.cmo -*.cma -*.cmi -*.a -*.o -*.cmx -*.cmxs -*.cmxa - -# ocamlbuild working directory _build/ - -# ocamlbuild targets -*.byte -*.native - -# oasis generated files -setup.data -setup.log - +ftest.native +outfile +*~ \ No newline at end of file diff --git a/.merlin b/.merlin new file mode 100644 index 0000000..a4d72c7 --- /dev/null +++ b/.merlin @@ -0,0 +1,4 @@ +PRJ maxflow +S src + +B _build/src diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9845603 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "*.ml": "ocaml", + "*.mli": "ocaml" + }, + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..a58e5bf --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "make", + "type": "shell", + "command": "make", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 00d9714..0000000 --- a/LICENSE +++ /dev/null @@ -1,5 +0,0 @@ -MIT License -Copyright (c) -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..876857b --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ + +build: + @echo "\n==== COMPILING ====\n" + ocamlbuild ftest.native + +format: + ocp-indent --inplace src/* + +edit: + code . -n + +demo: build + @echo "\n==== EXECUTING ====\n" + ./ftest.native graphs/graph1 1 2 outfile + @echo "\n==== RESULT ==== (content of outfile) \n" + @cat outfile + +clean: + -rm -rf _build/ + -rm ftest.native diff --git a/README.md b/README.md index 6951aba..2ee1f32 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ -# be_ocaml +Base project for Ocaml project on Ford-Fulkerson. This project contains some simple configuration files to facilitate editing Ocaml in VSCode. + +To use, you should install the *OCaml* extension in VSCode. Other extensions might work as well but make sure there is only one installed. +Then open VSCode in the root directory of this repository (command line: `code path/to/ocaml-maxflow-project`). + +Features : + - full compilation as VSCode build task (Ctrl+Shift+b) + - highlights of compilation errors as you type + - code completion + - automatic indentation on file save + + +A makefile provides some useful commands: + - `make build` to compile. This creates an ftest.native executable + - `make demo` to run the `ftest` program with some arguments + - `make format` to indent the entire project + - `make edit` to open the project in VSCode + - `make clean` to remove build artifacts + +In case of trouble with the VSCode extension (e.g. the project does not build, there are strange mistakes), a common workaround is to (1) close vscode, (2) `make clean`, (3) `make build` and (4) reopen vscode (`make edit`). -Dépôt du be Ocaml 4IR \ No newline at end of file diff --git a/_tags b/_tags new file mode 100644 index 0000000..e8bfe6d --- /dev/null +++ b/_tags @@ -0,0 +1,3 @@ +: include + + diff --git a/graph1 b/graphs/graph1 similarity index 100% rename from graph1 rename to graphs/graph1 diff --git a/graph1.svg b/graphs/graph1.svg similarity index 100% rename from graph1.svg rename to graphs/graph1.svg diff --git a/ftest.ml b/src/ftest.ml similarity index 98% rename from ftest.ml rename to src/ftest.ml index c525a6b..4de8c1f 100644 --- a/ftest.ml +++ b/src/ftest.ml @@ -1,5 +1,5 @@ open Gfile - + let () = (* Check the number of command-line arguments *) @@ -11,10 +11,10 @@ let () = (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *) - + let infile = Sys.argv.(1) and outfile = Sys.argv.(4) - + (* These command-line arguments are not used for the moment. *) and _source = int_of_string Sys.argv.(2) and _sink = int_of_string Sys.argv.(3) diff --git a/gfile.ml b/src/gfile.ml similarity index 99% rename from gfile.ml rename to src/gfile.ml index ccea4c6..9599cc3 100644 --- a/gfile.ml +++ b/src/gfile.ml @@ -1,6 +1,6 @@ open Graph open Printf - + type path = string (* Format of text files: @@ -16,7 +16,7 @@ type path = string e 3 1 11 e 0 2 8 - *) +*) let write_file path graph = @@ -32,9 +32,9 @@ let write_file path graph = (* Write all arcs *) e_iter graph (fun id1 id2 lbl -> fprintf ff "e %d %d %s\n" id1 id2 lbl) ; - + fprintf ff "\n%% End of graph\n" ; - + close_out ff ; () @@ -95,7 +95,7 @@ let from_file path = in let final_graph = loop 0 empty_graph in - + close_in infile ; final_graph - + diff --git a/gfile.mli b/src/gfile.mli similarity index 100% rename from gfile.mli rename to src/gfile.mli diff --git a/graph.ml b/src/graph.ml similarity index 99% rename from graph.ml rename to src/graph.ml index 2bef130..33f7a15 100644 --- a/graph.ml +++ b/src/graph.ml @@ -32,7 +32,7 @@ let new_arc gr id1 id2 lbl = (* Update out-arcs. * remove_assoc does not fail if id2 is not bound. *) let outb = (id2, lbl) :: List.remove_assoc id2 outa in - + (* Replace out-arcs in the graph. *) let gr2 = List.remove_assoc id1 gr in (id1, outb) :: gr2 diff --git a/graph.mli b/src/graph.mli similarity index 97% rename from graph.mli rename to src/graph.mli index dd9c265..416e158 100644 --- a/graph.mli +++ b/src/graph.mli @@ -38,7 +38,7 @@ type 'a out_arcs = (id * 'a) list val out_arcs: 'a graph -> id -> 'a out_arcs (* find_arc gr id1 id2 finds an arc between id1 and id2 and returns its label. Returns None if the arc does not exist. -* @raise Graph_error if id1 is unknown. *) + * @raise Graph_error if id1 is unknown. *) val find_arc: 'a graph -> id -> id -> 'a option @@ -49,7 +49,7 @@ val n_iter: 'a graph -> (id -> unit) -> unit (* Like n_iter, but the nodes are sorted. *) val n_iter_sorted: 'a graph -> (id -> unit) -> unit - + (* Fold on all (unsorted) nodes. You must remember what List.fold_left does. *) val n_fold: 'a graph -> ('b -> id -> 'b) -> 'b -> 'b