2020 version update

This commit is contained in:
Arthur Bit-Monnot 2020-11-02 12:39:47 +01:00
parent 0b7ef0ba2b
commit 6410eaba37
2 changed files with 10 additions and 4 deletions

View file

@ -45,9 +45,14 @@ let read_node id graph line =
Printf.printf "Cannot read node in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
failwith "from_file"
(* Ensure that the given node exists in the graph. If not, create it.
* (Necessary because the website we use to create online graphs does not generate correct files when some nodes have been deleted.) *)
let ensure graph id = if node_exists graph id then graph else new_node graph id
(* Reads a line with an arc. *)
let read_arc graph line =
try Scanf.sscanf line "e %d %d %s" (fun id1 id2 label -> new_arc graph id1 id2 label)
try Scanf.sscanf line "e %d %d %s"
(fun id1 id2 label -> new_arc (ensure (ensure graph id1) id2) id1 id2 label)
with e ->
Printf.printf "Cannot read arc in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
failwith "from_file"

View file

@ -17,9 +17,10 @@ val empty_graph: 'a graph
* @raise Graph_error if the id already exists. *)
val new_node: 'a graph -> id -> 'a graph
(* add_arc gr id1 id2 lbl : adds an arc from node id1 to node id2 with label lbl
* If an arc already exists between id1 and id2, its label is replaced by lbl.
* @raise Graph_error if id1 or id2 does not exist in the graph. *)
(* new_arc gr id1 id2 lbl : adds an arc from node id1 to node id2 with label lbl
* Both nodes must already exist in the graph.
* If the arc already exists, its label is replaced by lbl.
* @raise Graph_error if node id1 or id2 does not exist in the graph. *)
val new_arc: 'a graph -> id -> id -> 'a -> 'a graph