use provided base project

This commit is contained in:
Arnaud Vergnet 2020-11-03 16:06:32 +01:00
parent 973184f0a9
commit 9ccd1c005b
16 changed files with 132 additions and 40 deletions

47
.github/workflows/workflow.yml vendored Normal file
View file

@ -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

24
.gitignore vendored
View file

@ -1,22 +1,4 @@
# ---> OCaml
*.annot
*.cmo
*.cma
*.cmi
*.a
*.o
*.cmx
*.cmxs
*.cmxa
# ocamlbuild working directory
_build/ _build/
ftest.native
# ocamlbuild targets outfile
*.byte *~
*.native
# oasis generated files
setup.data
setup.log

4
.merlin Normal file
View file

@ -0,0 +1,4 @@
PRJ maxflow
S src
B _build/src

7
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,7 @@
{
"files.associations": {
"*.ml": "ocaml",
"*.mli": "ocaml"
},
"editor.formatOnSave": true
}

16
.vscode/tasks.json vendored Normal file
View file

@ -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
}
}
]
}

View file

@ -1,5 +0,0 @@
MIT License
Copyright (c) <year> <copyright holders>
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.

20
Makefile Normal file
View file

@ -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

View file

@ -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

3
_tags Normal file
View file

@ -0,0 +1,3 @@
<src/**>: include

View file

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -1,5 +1,5 @@
open Gfile open Gfile
let () = let () =
(* Check the number of command-line arguments *) (* Check the number of command-line arguments *)
@ -11,10 +11,10 @@ let () =
(* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *) (* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *)
let infile = Sys.argv.(1) let infile = Sys.argv.(1)
and outfile = Sys.argv.(4) and outfile = Sys.argv.(4)
(* These command-line arguments are not used for the moment. *) (* These command-line arguments are not used for the moment. *)
and _source = int_of_string Sys.argv.(2) and _source = int_of_string Sys.argv.(2)
and _sink = int_of_string Sys.argv.(3) and _sink = int_of_string Sys.argv.(3)

View file

@ -1,6 +1,6 @@
open Graph open Graph
open Printf open Printf
type path = string type path = string
(* Format of text files: (* Format of text files:
@ -16,7 +16,7 @@ type path = string
e 3 1 11 e 3 1 11
e 0 2 8 e 0 2 8
*) *)
let write_file path graph = let write_file path graph =
@ -32,9 +32,9 @@ let write_file path graph =
(* Write all arcs *) (* Write all arcs *)
e_iter graph (fun id1 id2 lbl -> fprintf ff "e %d %d %s\n" id1 id2 lbl) ; e_iter graph (fun id1 id2 lbl -> fprintf ff "e %d %d %s\n" id1 id2 lbl) ;
fprintf ff "\n%% End of graph\n" ; fprintf ff "\n%% End of graph\n" ;
close_out ff ; close_out ff ;
() ()
@ -95,7 +95,7 @@ let from_file path =
in in
let final_graph = loop 0 empty_graph in let final_graph = loop 0 empty_graph in
close_in infile ; close_in infile ;
final_graph final_graph

View file

@ -32,7 +32,7 @@ let new_arc gr id1 id2 lbl =
(* Update out-arcs. (* Update out-arcs.
* remove_assoc does not fail if id2 is not bound. *) * remove_assoc does not fail if id2 is not bound. *)
let outb = (id2, lbl) :: List.remove_assoc id2 outa in let outb = (id2, lbl) :: List.remove_assoc id2 outa in
(* Replace out-arcs in the graph. *) (* Replace out-arcs in the graph. *)
let gr2 = List.remove_assoc id1 gr in let gr2 = List.remove_assoc id1 gr in
(id1, outb) :: gr2 (id1, outb) :: gr2

View file

@ -38,7 +38,7 @@ type 'a out_arcs = (id * 'a) list
val out_arcs: 'a graph -> id -> 'a out_arcs 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. (* 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 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. *) (* Like n_iter, but the nodes are sorted. *)
val n_iter_sorted: 'a graph -> (id -> unit) -> unit val n_iter_sorted: 'a graph -> (id -> unit) -> unit
(* Fold on all (unsorted) nodes. You must remember what List.fold_left does. *) (* Fold on all (unsorted) nodes. You must remember what List.fold_left does. *)
val n_fold: 'a graph -> ('b -> id -> 'b) -> 'b -> 'b val n_fold: 'a graph -> ('b -> id -> 'b) -> 'b -> 'b