├── .gitignore ├── .ocp-indent ├── CHANGES.md ├── COPYING ├── CREDITS ├── FAQ ├── INSTALL.md ├── LICENSE ├── Makefile ├── README.md ├── TODO.md ├── ThreatDragonModels └── New Threat Model │ └── New Threat Model.json ├── dgraph ├── dGraphContainer.ml ├── dGraphContainer.mli ├── dGraphMake.ml ├── dGraphView.ml ├── dGraphView.mli ├── dGraphViewItem.ml ├── dGraphViewItem.mli ├── dGraphViewer.ml ├── doc │ └── style.css ├── dune ├── examples │ ├── awilliams.gv │ ├── clusters.dot │ ├── clusters.svg │ ├── clusters_with_edges.dot │ ├── crazy.dot │ ├── crazy2.dot │ ├── dep.dot │ ├── dfa.gv │ ├── fancy.dot │ ├── fsm.dot │ ├── gzip.dot │ ├── gzip_annot.dot │ ├── jsort.dot │ ├── pmpipe.gv │ ├── polygonal.dot │ ├── polypoly.gv │ ├── services.dot │ ├── siblings.dot │ ├── switch.gv │ ├── unix2.gv │ └── viewfile.gv ├── headers │ ├── CEA_LGPL │ ├── headache_config.txt │ └── headers.sh ├── pangoMeasure.ml └── pangoMeasure.mli ├── dune-project ├── editor ├── dirTree.ml ├── dirTree.mli ├── dune ├── ed_display.ml ├── ed_draw.ml ├── ed_graph.ml ├── ed_hyper.ml ├── ed_icon.xpm ├── ed_main.ml ├── editor.ml ├── graphEd.ml ├── graphEdGTK.ml ├── gtree.ml ├── gtree.mli ├── htree.ml ├── htree.mli ├── outils_math.ml ├── outils_tort.ml └── tests │ ├── de_bruijn4.gml │ ├── dep_ed.dot │ ├── dep_why.dot │ ├── divisors12.gml │ ├── fsm.dot │ ├── full10.gml │ ├── full20.gml │ ├── full30.gml │ ├── full50.gml │ ├── parcours.dot │ ├── rand_100_10.gml │ ├── rand_100_300.gml │ ├── rand_10_10.gml │ ├── rand_10_40.gml │ ├── rand_50_300.gml │ ├── ring_100.gml │ ├── softmaint.dot │ ├── test.gml │ ├── test2,1_2.gml │ ├── test2,1_3.gml │ ├── test2,1_3tot.gml │ ├── test2_2.gml │ ├── transparency.dot │ ├── twopi2.dot │ ├── unix.dot │ └── world.dot ├── examples ├── color.ml ├── compare_prim_kruskal.ml ├── demo.ml ├── demo_planar.ml ├── demo_prim.ml ├── depend2dot.ml ├── dune ├── sudoku.ml └── words.ml ├── ocamlgraph.opam ├── ocamlgraph_gtk.opam ├── src ├── blocks.ml ├── builder.ml ├── builder.mli ├── chaoticIteration.ml ├── chaoticIteration.mli ├── classic.ml ├── classic.mli ├── clique.ml ├── clique.mli ├── cliquetree.ml ├── cliquetree.mli ├── coloring.ml ├── coloring.mli ├── components.ml ├── components.mli ├── contraction.ml ├── contraction.mli ├── cycles.ml ├── cycles.mli ├── dGraphModel.ml ├── dGraphModel.mli ├── dGraphRandModel.ml ├── dGraphRandModel.mli ├── dGraphSubTree.ml ├── dGraphSubTree.mli ├── dGraphTreeLayout.ml ├── dGraphTreeLayout.mli ├── dGraphTreeModel.ml ├── dGraphTreeModel.mli ├── delaunay.ml ├── delaunay.mli ├── dominator.ml ├── dominator.mli ├── dot.ml ├── dot.mli ├── dot_ast.mli ├── dot_lexer.mll ├── dot_parser.mly ├── dune ├── eulerian.ml ├── eulerian.mli ├── fixpoint.ml ├── fixpoint.mli ├── flow.ml ├── flow.mli ├── gmap.ml ├── gmap.mli ├── gml.mli ├── gml.mll ├── graph.ml ├── graphml.ml ├── graphml.mli ├── graphviz.ml ├── graphviz.mli ├── imperative.ml ├── imperative.mli ├── kruskal.ml ├── kruskal.mli ├── leaderlist.ml ├── leaderlist.mli ├── lib │ ├── bitv.ml │ ├── bitv.mli │ ├── deque.ml │ ├── deque.mli │ ├── heap.ml │ ├── heap.mli │ ├── persistentQueue.ml │ ├── persistentQueue.mli │ ├── unionfind.ml │ └── unionfind.mli ├── mcs_m.ml ├── mcs_m.mli ├── md.ml ├── md.mli ├── merge.ml ├── merge.mli ├── mincut.ml ├── mincut.mli ├── minsep.ml ├── minsep.mli ├── nonnegative.ml ├── nonnegative.mli ├── oper.ml ├── oper.mli ├── pack.ml ├── pack.mli ├── path.ml ├── path.mli ├── persistent.ml ├── persistent.mli ├── prim.ml ├── prim.mli ├── rand.ml ├── rand.mli ├── sig.mli ├── sig_pack.mli ├── strat.ml ├── strat.mli ├── topological.ml ├── topological.mli ├── traverse.ml ├── traverse.mli ├── util.ml ├── util.mli ├── weakTopological.ml ├── weakTopological.mli ├── xDot.ml ├── xDot.mli ├── xDotDraw.ml └── xDotDraw.mli ├── tests ├── basic.expected ├── basic.ml ├── bench.ml ├── check.ml ├── dot.dot ├── dot.expected ├── dot.ml ├── dune ├── nonneg.ml ├── strat.expected ├── strat.ml ├── test_149.ml ├── test_31.ml ├── test_bf.expected ├── test_bf.ml ├── test_bfs.ml ├── test_bfs01.ml ├── test_chaotic.expected ├── test_chaotic.ml ├── test_check_path.ml ├── test_classic.ml ├── test_components.expected ├── test_components.ml ├── test_contraction.expected ├── test_contraction.ml ├── test_cycles.expected ├── test_cycles.ml ├── test_dfs.ml ├── test_eulerian.ml ├── test_fixpoint.expected ├── test_fixpoint.ml ├── test_johnson.expected ├── test_johnson.ml ├── test_map_vertex.ml ├── test_nontrivial_dom.expected ├── test_nontrivial_dom.ml ├── test_saps.expected ├── test_saps.ml ├── test_topsort.ml ├── test_wto.expected ├── test_wto.ml └── testgraphml.ml └── view_graph ├── README ├── doc ├── intro.txt └── style.css ├── dune ├── viewGraph.ml ├── viewGraph_core.ml ├── viewGraph_core.mli ├── viewGraph_select.ml ├── viewGraph_select.mli ├── viewGraph_test.ml ├── viewGraph_utils.ml └── viewGraph_utils.mli /.gitignore: -------------------------------------------------------------------------------- 1 | .merlin 2 | /META 3 | /www/index.en.html 4 | /www/index.fr.html 5 | /www/version.prehtml 6 | _build 7 | 8 | _opam -------------------------------------------------------------------------------- /.ocp-indent: -------------------------------------------------------------------------------- 1 | normal 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/COPYING -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | 2 | Contributors, in alphabetic order 3 | 4 | Sylvain Conchon 5 | Jean-Christophe Filliâtre 6 | François Pottier 7 | Julien Signoles 8 | Vincent Simonet 9 | Matthieu Sozeau 10 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | 2 | The simplest way to install OCamlGraph is via opam. 3 | 4 | If instead you choose to compile OCamlGraph from sources, 5 | the simplest way is to use `dune`. 6 | 7 | Otherwise, you can still use the old way: 8 | - Configure with 9 | ``` 10 | autoconf 11 | ./configure 12 | ``` 13 | - Compile with 14 | ``` 15 | make 16 | ``` 17 | - Install (as root if needed) with 18 | ``` 19 | make install 20 | ``` 21 | To install somewhere else, with a different path prefix, use instead 22 | ``` 23 | make DESTDIR=/another/place install 24 | ``` 25 | findlib users may also do 26 | ``` 27 | make install-findlib 28 | ``` 29 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | dune build 4 | 5 | test: 6 | dune runtest 7 | 8 | doc: 9 | dune build @doc 10 | 11 | clean: 12 | dune clean 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OCamlgraph 2 | 3 | OCamlgraph is a graph library for OCaml. Its contribution is three-fold: 4 | 5 | 1. It provides an easy-to-use graph implementation together with several 6 | operations and algorithms over graphs, in [`Graph.Pack.Digraph`](https://backtracking.github.io/ocamlgraph/ocamlgraph/Graph/Pack/Digraph/index.html). 7 | It is a reasonably efficient imperative data structure for directed graphs 8 | with vertices and edges labeled with integers. 9 | 10 | Have a look at this module first in order to get an overview of what 11 | this library provides. See also [`demo.ml`](https://github.com/backtracking/ocamlgraph/blob/master/examples/demo.ml). 12 | 13 | 2. Then OCamlgraph provides several other graph implementations for those 14 | not satisfied with the one above. Some are persistent (immutable) and other 15 | imperative (mutable). Some are directed and other are not. 16 | Some have labels for vertices, or labels for edges, or both. 17 | Some have abstract types for vertices. etc. 18 | 19 | See interface [`Sig`](https://backtracking.github.io/ocamlgraph/ocamlgraph/Graph/Sig/index.html) 20 | for the graph signatures and modules [`Persistent`](https://backtracking.github.io/ocamlgraph/ocamlgraph/Graph/Persistent/index.html) and 21 | [`Imperative`](https://backtracking.github.io/ocamlgraph/ocamlgraph/Graph/Imperative/index.html) for the implementations. 22 | 23 | These implementations are written as functors: you give the types of 24 | vertices labels, edge labels, etc. and you get the data structure as a 25 | result. 26 | 27 | 4. Finally, OCamlgraph provides several classic operations and algorithms 28 | over graphs. They are also written as functors i.e. independently of the 29 | data structure for graphs. One consequence is that you can define your own 30 | data structure for graphs and yet re-use all the algorithms from this 31 | library -- you only need to provide a few operations such as iterating over 32 | all vertices, over the successors of a vertex, etc. 33 | 34 | 35 | ## Documentation 36 | 37 | https://backtracking.github.io/ocamlgraph/ 38 | 39 | 40 | ## Examples 41 | 42 | You'll find examples of OCamlgraph use in subdirectory examples/ 43 | (demo.ml, demo_planar.ml, color.ml, etc.). 44 | 45 | 46 | ## Bug reports 47 | 48 | https://github.com/backtracking/ocamlgraph/issues 49 | 50 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/TODO.md -------------------------------------------------------------------------------- /dgraph/dGraphContainer.mli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/dgraph/dGraphContainer.mli -------------------------------------------------------------------------------- /dgraph/dGraphMake.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/dgraph/dGraphMake.ml -------------------------------------------------------------------------------- /dgraph/dGraphView.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/dgraph/dGraphView.ml -------------------------------------------------------------------------------- /dgraph/dGraphView.mli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/dgraph/dGraphView.mli -------------------------------------------------------------------------------- /dgraph/dGraphViewItem.mli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/dgraph/dGraphViewItem.mli -------------------------------------------------------------------------------- /dgraph/doc/style.css: -------------------------------------------------------------------------------- 1 | a:visited {color : #416DFF; text-decoration : none; } 2 | a:link {color : #416DFF; text-decoration : none;} 3 | a:hover {color : Red; text-decoration : none; background-color: #5FFF88} 4 | a:active {color : Red; text-decoration : underline; } 5 | .keyword { font-weight : bold ; color : Red } 6 | .keywordsign { color : #C04600 } 7 | .superscript { font-size : 4 } 8 | .subscript { font-size : 4 } 9 | .comment { color : Green } 10 | .constructor { color : Blue } 11 | .type { color : #5C6585 } 12 | .string { color : Maroon } 13 | .warning { color : Red ; font-weight : bold } 14 | .info { margin-left : 3em; margin-right : 3em } 15 | .param_info { margin-top: 4px; margin-left : 3em; margin-right : 3em } 16 | .code { color : #465F91 ; } 17 | h1 { font-size : 20pt ; text-align: center; } 18 | h2 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #90BDFF ;padding: 2px; } 19 | h3 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #90DDFF ;padding: 2px; } 20 | h4 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #90EDFF ;padding: 2px; } 21 | h5 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #90FDFF ;padding: 2px; } 22 | h6 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #C0FFFF ; padding: 2px; } 23 | div.h7 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #E0FFFF ; padding: 2px; } 24 | div.h8 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #F0FFFF ; padding: 2px; } 25 | div.h9 { font-size : 20pt ; border: 1px solid #000000; margin-top: 5px; margin-bottom: 2px;text-align: center; background-color: #FFFFFF ; padding: 2px; } 26 | .typetable { border-style : hidden } 27 | .indextable { border-style : hidden } 28 | .paramstable { border-style : hidden ; padding: 5pt 5pt} 29 | body { background-color : White } 30 | tr { background-color : White } 31 | td.typefieldcomment { background-color : #FFFFFF ; font-size: smaller ;} 32 | pre { margin-bottom: 4px } 33 | div.sig_block {margin-left: 2em} -------------------------------------------------------------------------------- /dgraph/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name graph_gtk) 3 | (public_name ocamlgraph_gtk) 4 | (modules :standard \ dGraphViewer) 5 | (libraries ocamlgraph lablgtk2.gnomecanvas lablgtk2) 6 | (flags -open Graph)) 7 | 8 | (executable 9 | (name dGraphViewer) 10 | (modules dGraphViewer) 11 | (libraries graph_gtk lablgtk2.gnomecanvas lablgtk2)) 12 | -------------------------------------------------------------------------------- /dgraph/examples/clusters.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | 3 | subgraph cluster_0 { 4 | style=filled; 5 | color=lightgrey; 6 | node [style=filled,color=white]; 7 | a0 -> a1 -> a2 -> a3; 8 | label = "process #1"; 9 | } 10 | 11 | subgraph cluster_1 { 12 | node [style=filled]; 13 | b0 -> b1 -> b2 -> b3; 14 | label = "process #2"; 15 | color=blue 16 | } 17 | start -> a0; 18 | start -> b0; 19 | a1 -> b3; 20 | b2 -> a3; 21 | a3 -> a0; 22 | a3 -> end; 23 | b3 -> end; 24 | 25 | start [shape=Mdiamond]; 26 | end [shape=Msquare]; 27 | } 28 | -------------------------------------------------------------------------------- /dgraph/examples/clusters_with_edges.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | compound=true; 3 | subgraph cluster0 { 4 | a -> b; 5 | a -> c; 6 | b -> d; 7 | c -> d; 8 | } 9 | subgraph cluster1 { 10 | e -> g; 11 | e -> f; 12 | } 13 | b -> f [lhead=cluster1]; 14 | d -> e; 15 | c -> g [ltail=cluster0, 16 | lhead=cluster1]; 17 | c -> e [ltail=cluster0]; 18 | d -> h; 19 | } 20 | -------------------------------------------------------------------------------- /dgraph/examples/crazy2.dot: -------------------------------------------------------------------------------- 1 | digraph "unix" { 2 | graph [ fontname = "Helvetica-Oblique", 3 | fontsize = 36, 4 | label = "\n\n\n\nObject Oriented Graphs\nStephen North, 3/19/93", 5 | size = "6,6" ]; 6 | node [ shape = polygon, 7 | sides = 4, 8 | distortion = "0.0", 9 | orientation = "0.0", 10 | skew = "0.0", 11 | color = blue, 12 | style = filled, 13 | fontname = "Helvetica-Outline" ]; 14 | "CB Unix 2" [sides=10, distortion="0.851818", orientation=32, skew="-0.020120", color=greenyellow]; 15 | } 16 | -------------------------------------------------------------------------------- /dgraph/examples/dfa.gv: -------------------------------------------------------------------------------- 1 | digraph g { 2 | "start" [ label = "MWGC-" ]; 3 | "n1" [ label = "WC-MG" ]; 4 | "n2" [ label = "MWC-G" ]; 5 | "n3" [ label = "C-MWG" ]; 6 | "n4" [ label = "W-MGC" ]; 7 | "n5" [ label = "MGC-W" ]; 8 | "n6" [ label = "MWG-C" ]; 9 | "n7" [ label = "G-MWC" ]; 10 | "n8" [ label = "MG-WC" ]; 11 | "n9" [ label = "-MWGC" ]; 12 | "start" -> "n1" [ label = "g" ]; 13 | "n1" -> "start" [ label = "g" ]; 14 | subgraph l { rank = same; "n3" "n4" } 15 | subgraph r { rank = same; "n5" "n6" } 16 | "n1" -> "n2" [ label = "m" ]; 17 | "n2" -> "n1" [ label = "m" ]; 18 | "n2" -> "n3" [ label = "w" ]; 19 | "n3" -> "n2" [ label = "w" ]; 20 | "n2" -> "n4" [ label = "c" ]; 21 | "n4" -> "n2" [ label = "c" ]; 22 | "n3" -> "n5" [ label = "g" ]; 23 | "n5" -> "n3" [ label = "g" ]; 24 | "n4" -> "n6" [ label = "g" ]; 25 | "n6" -> "n4" [ label = "g" ]; 26 | "n5" -> "n7" [ label = "c" ]; 27 | "n7" -> "n5" [ label = "c" ]; 28 | "n6" -> "n7" [ label = "w" ]; 29 | "n7" -> "n6" [ label = "w" ]; 30 | "n7" -> "n8" [ label = "m" ]; 31 | "n8" -> "n7" [ label = "m" ]; 32 | "n8" -> "n9" [ label = "g" ]; 33 | "n9" -> "n8" [ label = "g" ]; 34 | } 35 | -------------------------------------------------------------------------------- /dgraph/examples/fancy.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | size ="4,4"; 3 | main [shape=box]; /* this is a comment */ 4 | main -> parse [weight=8]; 5 | parse -> execute; 6 | main -> init [style=dotted, comment="youhou"]; 7 | main -> cleanup; 8 | execute -> { make_string; printf} 9 | init -> make_string; 10 | edge [color=red]; // so is this 11 | main -> printf [style=bold,label="100 times"]; 12 | make_string [label="make a\nstring"]; 13 | node [shape=box,style=filled,color=".7 .3 1.0"]; 14 | execute -> compare; 15 | } 16 | -------------------------------------------------------------------------------- /dgraph/examples/fsm.dot: -------------------------------------------------------------------------------- 1 | digraph finite_state_machine { 2 | rankdir=LR; 3 | size="8,5" 4 | node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8; 5 | node [shape = circle]; 6 | LR_0 -> LR_2 [ label = "SS(B)" ]; 7 | LR_0 -> LR_1 [ label = "SS(S)" ]; 8 | LR_1 -> LR_3 [ label = "S($end)" ]; 9 | LR_2 -> LR_6 [ label = "SS(b)" ]; 10 | LR_2 -> LR_5 [ label = "SS(a)" ]; 11 | LR_2 -> LR_4 [ label = "S(A)" ]; 12 | LR_5 -> LR_7 [ label = "S(b)" ]; 13 | LR_5 -> LR_5 [ label = "S(a)" ]; 14 | LR_6 -> LR_6 [ label = "S(b)" ]; 15 | LR_6 -> LR_5 [ label = "S(a)" ]; 16 | LR_7 -> LR_8 [ label = "S(b)" ]; 17 | LR_7 -> LR_5 [ label = "S(a)" ]; 18 | LR_8 -> LR_6 [ label = "S(b)" ]; 19 | LR_8 -> LR_5 [ label = "S(a)" ]; 20 | } 21 | -------------------------------------------------------------------------------- /dgraph/examples/polygonal.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | a -> b -> c; 3 | b -> d; 4 | a [shape=polygon,sides=5,peripheries=3,color=lightblue,style=filled]; 5 | c [shape=polygon,sides=4,skew=.4,label="hello world"] 6 | d [shape=invtriangle]; 7 | e [shape=polygon,sides=4,distortion=.7]; 8 | } 9 | -------------------------------------------------------------------------------- /dgraph/examples/switch.gv: -------------------------------------------------------------------------------- 1 | digraph G { 2 | graph [center=true rankdir=LR bgcolor="#808080"] 3 | edge [dir=none] 4 | node [width=0.3 height=0.3 label=""] 5 | { node [shape=circle style=invis] 6 | 1 2 3 4 5 6 7 8 10 20 30 40 50 60 70 80 7 | } 8 | { node [shape=circle] 9 | a b c d e f g h i j k l m n o p q r s t u v w x 10 | } 11 | { node [shape=diamond] 12 | A B C D E F G H I J K L M N O P Q R S T U V W X 13 | } 14 | 1 -> a -> {A B} [color="#0000ff"] 15 | 2 -> b -> {B A} [color="#ff0000"] 16 | 3 -> c -> {C D} [color="#ffff00"] 17 | 4 -> d -> {D C} [color="#00ff00"] 18 | 5 -> e -> {E F} [color="#000000"] 19 | 6 -> f -> {F E} [color="#00ffff"] 20 | 7 -> g -> {G H} [color="#ffffff"] 21 | 8 -> h -> {H G} [color="#ff00ff"] 22 | { edge [color="#ff0000:#0000ff"] 23 | A -> i -> {I K} 24 | B -> j -> {J L} 25 | } 26 | { edge [color="#00ff00:#ffff00"] 27 | C -> k -> {K I} 28 | D -> l -> {L J} 29 | } 30 | { edge [color="#00ffff:#000000"] 31 | E -> m -> {M O} 32 | F -> n -> {N P} 33 | } 34 | { edge [color="#ff00ff:#ffffff"] 35 | G -> o -> {O M} 36 | H -> p -> {P N} 37 | } 38 | { edge [color="#00ff00:#ffff00:#ff0000:#0000ff"] 39 | I -> q -> {Q U} 40 | J -> r -> {R V} 41 | K -> s -> {S W} 42 | L -> t -> {T X} 43 | } 44 | { edge [color="#ff00ff:#ffffff:#00ffff:#000000"] 45 | M -> u -> {U Q} 46 | N -> v -> {V R} 47 | O -> w -> {W S} 48 | P -> x -> {X T} 49 | } 50 | { edge [color="#ff00ff:#ffffff:#00ffff:#000000:#00ff00:#ffff00:#ff0000:#0000ff"] 51 | Q -> 10 52 | R -> 20 53 | S -> 30 54 | T -> 40 55 | U -> 50 56 | V -> 60 57 | W -> 70 58 | X -> 80 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /dgraph/examples/unix2.gv: -------------------------------------------------------------------------------- 1 | /* Courtesy of Ian Darwin 2 | * and Geoff Collyer 3 | * Mildly updated by Ian Darwin in 2000. 4 | */ 5 | digraph unix { 6 | size="6,6"; 7 | node [color=lightblue2, style=filled]; 8 | "5th Edition" -> "6th Edition"; 9 | "5th Edition" -> "PWB 1.0"; 10 | "6th Edition" -> "LSX"; 11 | "6th Edition" -> "1 BSD"; 12 | "6th Edition" -> "Mini Unix"; 13 | "6th Edition" -> "Wollongong"; 14 | "6th Edition" -> "Interdata"; 15 | "Interdata" -> "Unix/TS 3.0"; 16 | "Interdata" -> "PWB 2.0"; 17 | "Interdata" -> "7th Edition"; 18 | "7th Edition" -> "8th Edition"; 19 | "7th Edition" -> "32V"; 20 | "7th Edition" -> "V7M"; 21 | "7th Edition" -> "Ultrix-11"; 22 | "7th Edition" -> "Xenix"; 23 | "7th Edition" -> "UniPlus+"; 24 | "V7M" -> "Ultrix-11"; 25 | "8th Edition" -> "9th Edition"; 26 | "9th Edition" -> "10th Edition"; 27 | "1 BSD" -> "2 BSD"; 28 | "2 BSD" -> "2.8 BSD"; 29 | "2.8 BSD" -> "Ultrix-11"; 30 | "2.8 BSD" -> "2.9 BSD"; 31 | "32V" -> "3 BSD"; 32 | "3 BSD" -> "4 BSD"; 33 | "4 BSD" -> "4.1 BSD"; 34 | "4.1 BSD" -> "4.2 BSD"; 35 | "4.1 BSD" -> "2.8 BSD"; 36 | "4.1 BSD" -> "8th Edition"; 37 | "4.2 BSD" -> "4.3 BSD"; 38 | "4.2 BSD" -> "Ultrix-32"; 39 | "4.3 BSD" -> "4.4 BSD"; 40 | "4.4 BSD" -> "FreeBSD"; 41 | "4.4 BSD" -> "NetBSD"; 42 | "4.4 BSD" -> "OpenBSD"; 43 | "PWB 1.0" -> "PWB 1.2"; 44 | "PWB 1.0" -> "USG 1.0"; 45 | "PWB 1.2" -> "PWB 2.0"; 46 | "USG 1.0" -> "CB Unix 1"; 47 | "USG 1.0" -> "USG 2.0"; 48 | "CB Unix 1" -> "CB Unix 2"; 49 | "CB Unix 2" -> "CB Unix 3"; 50 | "CB Unix 3" -> "Unix/TS++"; 51 | "CB Unix 3" -> "PDP-11 Sys V"; 52 | "USG 2.0" -> "USG 3.0"; 53 | "USG 3.0" -> "Unix/TS 3.0"; 54 | "PWB 2.0" -> "Unix/TS 3.0"; 55 | "Unix/TS 1.0" -> "Unix/TS 3.0"; 56 | "Unix/TS 3.0" -> "TS 4.0"; 57 | "Unix/TS++" -> "TS 4.0"; 58 | "CB Unix 3" -> "TS 4.0"; 59 | "TS 4.0" -> "System V.0"; 60 | "System V.0" -> "System V.2"; 61 | "System V.2" -> "System V.3"; 62 | "System V.3" -> "System V.4"; 63 | } 64 | -------------------------------------------------------------------------------- /dgraph/examples/viewfile.gv: -------------------------------------------------------------------------------- 1 | digraph Viewfile { 2 | node [ style = filled ]; 3 | atoi [color=green]; 4 | chkmalloc [color=green]; 5 | close [color=green]; 6 | error [color=blue]; 7 | exit [color=blue]; 8 | fclose [color=green]; 9 | fgets [color=red]; 10 | fopen [color=green]; 11 | fprintf [color=blue]; 12 | free [color=blue]; 13 | free_list [color=blue]; 14 | fstat [color=green]; 15 | getopt [color=green]; 16 | init_list [color=green]; 17 | insert_list [color=green]; 18 | main [color=green]; 19 | makeargs [color=blue]; 20 | makepairs [color=green]; 21 | malloc [color=green]; 22 | open [color=green]; 23 | printf [color=red]; 24 | read [color=green]; 25 | rewind [color=green]; 26 | viewline [color=green]; 27 | viewlines [color=green]; 28 | walk_list [color=green]; 29 | write [color=green]; 30 | fclose -> close [color=green]; 31 | fgets -> fstat [color=green]; 32 | fgets -> read [color=green]; 33 | fopen -> open [color=green]; 34 | printf -> write [color=green]; 35 | main -> fgets [color=blue]; 36 | main -> getopt [color=green]; 37 | main -> makeargs [color=blue]; 38 | main -> makepairs [color=green]; 39 | main -> chkmalloc [color=green]; 40 | main -> error [color=blue]; 41 | main -> viewlines [color=green]; 42 | makeargs -> chkmalloc [color=blue]; 43 | makepairs -> atoi [color=green]; 44 | makepairs -> init_list [color=green]; 45 | makepairs -> insert_list [color=green]; 46 | makepairs -> chkmalloc [color=green]; 47 | free_list -> free [color=blue]; 48 | init_list -> chkmalloc [color=green]; 49 | insert_list -> chkmalloc [color=green]; 50 | walk_list -> error [color=blue]; 51 | walk_list -> viewline [color=green]; 52 | chkmalloc -> malloc [color=green]; 53 | chkmalloc -> error [color=blue]; 54 | error -> exit [color=blue]; 55 | error -> fprintf [color=blue]; 56 | error -> error [color=blue]; 57 | viewline -> fgets [color=red]; 58 | viewline -> printf [color=red]; 59 | viewline -> rewind [color=green]; 60 | viewlines -> fclose [color=green]; 61 | viewlines -> fopen [color=green]; 62 | viewlines -> walk_list [color=green]; 63 | viewlines -> viewline [color=blue]; 64 | } 65 | -------------------------------------------------------------------------------- /dgraph/headers/CEA_LGPL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/dgraph/headers/CEA_LGPL -------------------------------------------------------------------------------- /dgraph/headers/headache_config.txt: -------------------------------------------------------------------------------- 1 | # Objective Caml source 2 | | ".*\\.mly" -> frame open:"/*" line:"*" close:"*/" 3 | | ".*\\.ml[il4]?.*" -> frame open:"(*" line:"*" close:"*)" 4 | # C source 5 | | ".*\\.c" -> frame open:"/*" line:"*" close:"*/" 6 | | ".*\\.ast" -> frame open:"//" line:" " close:" " 7 | | ".*\\.cc" -> frame open:"/*" line:"*" close:"*/" 8 | # Asm source 9 | | ".*\\.S" -> frame open:"/*" line:"*" close:"*/" 10 | # Configure 11 | | "config\\.h\\.in" -> frame open:"/*" line:"*" close:"*/" 12 | | "configure\\.in" -> frame open:"#" line:"#" close:"#" 13 | # Makefile 14 | | "Makefile" -> frame open:"#" line:"#" close:"#" 15 | # Sh 16 | | ".*\\.sh" -> frame open:"#" line:"#" close:"#" 17 | # Misc 18 | | "make_release" -> frame open:"#" line:"#" close:"#" 19 | | "FAQ" -> frame open:"#" line:"#" close:"#" 20 | | ".*\\.el" -> frame open: ";" line: ";" close:";" 21 | -------------------------------------------------------------------------------- /dgraph/headers/headers.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | headache -c headers/headache_config.txt -h headers/CEA_LGPL *.ml* *Makefile* 3 | -------------------------------------------------------------------------------- /dgraph/pangoMeasure.ml: -------------------------------------------------------------------------------- 1 | let withContext ~context ~fontName ~fontSize text = 2 | let font_description = Pango.Font.from_string fontName in 3 | Pango.Font.modify font_description 4 | ~size:(fontSize * Pango.scale) 5 | (); 6 | Pango.Context.set_font_description context font_description; 7 | let layout = Pango.Layout.create context in 8 | Pango.Layout.set_text layout text; 9 | Pango.Layout.get_pixel_size layout 10 | -------------------------------------------------------------------------------- /dgraph/pangoMeasure.mli: -------------------------------------------------------------------------------- 1 | val withContext : context:Pango.context -> fontName:string -> fontSize:int -> string -> int * int -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.0) 2 | 3 | (name ocamlgraph) 4 | 5 | (formatting (enabled_for dune)) 6 | -------------------------------------------------------------------------------- /editor/dirTree.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | open Unix ;; 19 | 20 | type t = { 21 | id : int; 22 | name : string ; 23 | children : t list Lazy.t 24 | } ;; 25 | let id t = t.id 26 | 27 | let newid = let r = ref 0 in fun () -> incr r; !r 28 | 29 | type label = string ;; 30 | 31 | let children t = Lazy.force t.children ;; 32 | let label t = t.name ;; 33 | let string_of_label s = s ;; 34 | 35 | let is_dir path = 36 | try (lstat path).st_kind = S_DIR 37 | with Unix_error _ -> false ;; 38 | 39 | let less t1 t2 = t1.name <= t2.name ;; 40 | 41 | let rec tree_list_from_path path = 42 | let opt_handle = 43 | try Some(opendir path) 44 | with Unix_error _ -> None in 45 | match opt_handle with 46 | | None -> [] 47 | | Some handle -> 48 | let list = Sort.list less (tree_list_from_handle path handle) in 49 | closedir handle ; list 50 | 51 | and tree_list_from_handle path handle = 52 | let opt_name = 53 | try Some(readdir handle) 54 | with End_of_file -> None in 55 | match opt_name with 56 | | None -> [] 57 | | Some name -> 58 | let path' = path ^ "/" ^ name in 59 | if name <> "." && name <> ".." && is_dir path' then 60 | { id = newid(); name = name ; children = lazy (tree_list_from_path path') } :: 61 | tree_list_from_handle path handle 62 | else 63 | tree_list_from_handle path handle ;; 64 | 65 | let from_dir path name = 66 | try 67 | let path' = path ^ "/" ^ name in 68 | if is_dir path' then 69 | { id = newid(); name = name ; 70 | children = lazy (tree_list_from_path path') } 71 | else invalid_arg "DirTree.from_dir" 72 | with _ -> failwith "DirTree.from_dir" ;; 73 | -------------------------------------------------------------------------------- /editor/dirTree.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | type t 19 | val id : t -> int 20 | 21 | type label 22 | 23 | val children : t -> t list ;; 24 | val label : t -> label ;; 25 | val string_of_label : label -> string ;; 26 | 27 | val from_dir : string -> string -> t ;; 28 | -------------------------------------------------------------------------------- /editor/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name ed_main) 3 | (modules ed_main ed_display ed_graph ed_hyper ed_draw) 4 | (libraries graph lablgtk2 lablgtk2.gnomecanvas)) 5 | 6 | (executable 7 | (name editor) 8 | (modules editor gtree htree) 9 | (libraries graph lablgtk2 lablgtk2.gnomecanvas) 10 | (flags -w -32)) 11 | 12 | (executable 13 | (name graphEdGTK) 14 | (modules graphEdGTK outils_tort outils_math) 15 | (libraries graph lablgtk2 lablgtk2.gnomecanvas) 16 | (flags -w -32)) 17 | 18 | ;; FIXME: graphEd cannot be built because tmoveto / tlineto don't exist (anymore ?) 19 | 20 | ; (executable 21 | ; (name graphEd) 22 | ; (modules graphEd outils_math outils_tort) 23 | ; (libraries graph lablgtk2 lablgtk2.gnomecanvas)) 24 | 25 | ;; This was commented in the old makefile that was here before : 26 | 27 | ; # tortuegpoint: tortue.ml 28 | ; # ocamlopt outils_math.ml 29 | ; # ocamlopt -o $@ graphics.cmxa outils_math.cmx $^ 30 | 31 | ; # graphEd.opt : outils_math.ml outils_tort.ml graphEd.ml 32 | ; # ocamlopt -o $@ graphics.cmxa -I .. ../graph.cmxa $^ 33 | 34 | ; # graphEdGTK : outils_math.ml outils_tort.ml graphEdGTK.ml 35 | ; # ocamlopt.opt -o $@ -I +lablgtk2 lablgtk.cmxa lablgnomecanvas.cmxa unix.cmxa -I .. ../graph.cmxa $^ 36 | 37 | ; # graphEdGTK.byte : outils_math.ml outils_tort.ml graphEdGTK.ml 38 | ; # ocamlc.opt -g -o $@ -I +lablgtk2 lablgtk.cma lablgnomecanvas.cma unix.cma -I .. ../graph.cma $^ 39 | 40 | ; # editor.opt: 41 | ; # make -C .. 42 | -------------------------------------------------------------------------------- /editor/gtree.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/editor/gtree.ml -------------------------------------------------------------------------------- /editor/gtree.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* 19 | module T : sig 20 | type t = DirTree.t 21 | val root : t 22 | end 23 | *) 24 | 25 | module T : sig 26 | type t 27 | val root : t 28 | end 29 | 30 | 31 | val show_tree : #GnoCanvas.group -> T.t -> int -> int -> unit 32 | -------------------------------------------------------------------------------- /editor/htree.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | module type TREE = sig 19 | type t 20 | type label 21 | val children : t -> t list 22 | val label : t -> label 23 | end ;; 24 | 25 | module type HTREE = sig 26 | type t 27 | type label 28 | val children : t -> t list 29 | val label : t -> label 30 | 31 | type coord = float * float 32 | 33 | type driver = { 34 | rlimit : float ; 35 | moveto : coord -> unit ; 36 | lineto : coord -> unit ; 37 | curveto : coord -> coord -> coord -> unit ; 38 | draw_label : label -> coord -> float -> unit ; 39 | init_edge_pass : unit -> unit ; 40 | init_label_pass : unit -> unit ; 41 | finalize : unit -> unit ; 42 | } 43 | 44 | val shrink_factor : coord -> float 45 | val drag_origin : coord -> coord -> coord -> coord 46 | 47 | val draw_linear_tree : driver -> t -> coord -> float -> unit 48 | val draw_curved_tree : driver -> t -> coord -> float -> unit 49 | end ;; 50 | 51 | module Make(T : TREE) : 52 | HTREE with type t = T.t and type label = T.label ;; 53 | -------------------------------------------------------------------------------- /editor/outils_math.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (*** Operateurs Complex ***) 19 | 20 | let ( ~-& ) (x, y) = (-.x, -.y) 21 | let ( ~& ) (x, y) = (x, -.y) 22 | 23 | let ( +& ) (x1, y1) (x2, y2) = 24 | (x1 +. x2, y1 +. y2) 25 | 26 | let ( -& ) (x1, y1) (x2, y2) = 27 | (x1 +. x2, y1 +. y2) 28 | 29 | let ( *& ) (x1, y1) (x2, y2) = 30 | (x1*.x2 -. y1*.y2, x1*.y2 +. y1*.x2) 31 | 32 | let ( /& ) (x1, y1) (x2, y2) = 33 | let n2 = x2*.x2 +. y2*.y2 in 34 | ((x1*.x2 +. y1*.y2)/.n2, (-.x1*.y2 +. y1*.x2)/.n2) 35 | 36 | let ( *.& ) f (x, y) = 37 | (f*.x, f*.y) 38 | 39 | let norm_sqr (x, y) = 40 | x*.x +. y*.y 41 | 42 | let norm (x, y) = 43 | sqrt(x*.x +. y*.y) 44 | 45 | let normalize (x, y) = 46 | let n = sqrt(x*.x +. y*.y) in 47 | (x/.n, y/.n) 48 | 49 | let expi t = 50 | (cos t, sin t) 51 | 52 | (*** Fonctions Hyperboliques ***) 53 | 54 | let th t = 55 | let ept = exp t 56 | and emt = exp (-.t) in 57 | (ept -. emt)/.(ept +. emt) 58 | 59 | let ath x = 60 | 0.5*.log((1.0 +. x)/.(1.0 -. x)) 61 | 62 | let pi = 3.14159265358979323846 63 | let pi_over_2 = pi/.2.0 64 | let pi_over_4 = pi/.4.0 65 | 66 | let one = (1.0, 0.0) 67 | 68 | let translate a z = 69 | (a +& z)/&(one +& (~&a) *& z) 70 | 71 | let gamma a u t = 72 | let utht = th t *.& u in 73 | (a +& utht) /& (one +& (~&a) *& utht) 74 | 75 | let delta a u t = 76 | let atht = th t *.& a 77 | and utht = th t *.& u in 78 | normalize ((u +& atht) /& (one +& (~&a) *& utht)) 79 | 80 | (* solving a Cramer system *) 81 | let cramer a1 a2 b1 b2 c1 c2 = 82 | let cdet = a1*.b2 -. a2*.b1 83 | and xdet = c1*.b2 -. c2*.b1 84 | and ydet = a1*.c2 -. a2*.c1 in 85 | (xdet/.cdet, ydet/.cdet) ;; 86 | 87 | let drag_origin (x0, y0) (x1, y1) (x2, y2) = 88 | let (x1, y1) = translate (-.x0, -.y0) (x1, y1) in 89 | let x3 = x1*.x2 -. y1*.y2 in 90 | let y3 = x1*.y2 +. y1*.x2 in 91 | cramer (1.0 -. x3) (-.y3) (-.y3) (1.0 +. x3) (x2 -. x1) (y2 -. y1) 92 | 93 | -------------------------------------------------------------------------------- /editor/tests/de_bruijn4.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | node [ 3 | id 1 4 | label 0 5 | ] 6 | node [ 7 | id 2 8 | label 1 9 | ] 10 | node [ 11 | id 3 12 | label 2 13 | ] 14 | node [ 15 | id 4 16 | label 3 17 | ] 18 | node [ 19 | id 5 20 | label 4 21 | ] 22 | node [ 23 | id 6 24 | label 5 25 | ] 26 | node [ 27 | id 7 28 | label 6 29 | ] 30 | node [ 31 | id 8 32 | label 7 33 | ] 34 | node [ 35 | id 9 36 | label 8 37 | ] 38 | node [ 39 | id 10 40 | label 9 41 | ] 42 | node [ 43 | id 11 44 | label 10 45 | ] 46 | node [ 47 | id 12 48 | label 11 49 | ] 50 | node [ 51 | id 13 52 | label 12 53 | ] 54 | node [ 55 | id 14 56 | label 13 57 | ] 58 | node [ 59 | id 15 60 | label 14 61 | ] 62 | node [ 63 | id 16 64 | label 15 65 | ] 66 | edge [ 67 | source 1 68 | target 1 69 | label 0 70 | ] 71 | edge [ 72 | source 2 73 | target 1 74 | label 0 75 | ] 76 | edge [ 77 | source 3 78 | target 2 79 | label 0 80 | ] 81 | edge [ 82 | source 4 83 | target 2 84 | label 0 85 | ] 86 | edge [ 87 | source 5 88 | target 3 89 | label 0 90 | ] 91 | edge [ 92 | source 6 93 | target 3 94 | label 0 95 | ] 96 | edge [ 97 | source 7 98 | target 4 99 | label 0 100 | ] 101 | edge [ 102 | source 8 103 | target 4 104 | label 0 105 | ] 106 | edge [ 107 | source 9 108 | target 1 109 | label 0 110 | ] 111 | edge [ 112 | source 9 113 | target 2 114 | label 0 115 | ] 116 | edge [ 117 | source 9 118 | target 5 119 | label 0 120 | ] 121 | edge [ 122 | source 10 123 | target 3 124 | label 0 125 | ] 126 | edge [ 127 | source 10 128 | target 4 129 | label 0 130 | ] 131 | edge [ 132 | source 10 133 | target 5 134 | label 0 135 | ] 136 | edge [ 137 | source 11 138 | target 5 139 | label 0 140 | ] 141 | edge [ 142 | source 11 143 | target 6 144 | label 0 145 | ] 146 | edge [ 147 | source 12 148 | target 6 149 | label 0 150 | ] 151 | edge [ 152 | source 12 153 | target 7 154 | label 0 155 | ] 156 | edge [ 157 | source 12 158 | target 8 159 | label 0 160 | ] 161 | edge [ 162 | source 13 163 | target 7 164 | label 0 165 | ] 166 | edge [ 167 | source 13 168 | target 9 169 | label 0 170 | ] 171 | edge [ 172 | source 13 173 | target 10 174 | label 0 175 | ] 176 | edge [ 177 | source 14 178 | target 7 179 | label 0 180 | ] 181 | edge [ 182 | source 14 183 | target 11 184 | label 0 185 | ] 186 | edge [ 187 | source 14 188 | target 12 189 | label 0 190 | ] 191 | edge [ 192 | source 15 193 | target 8 194 | label 0 195 | ] 196 | edge [ 197 | source 15 198 | target 13 199 | label 0 200 | ] 201 | edge [ 202 | source 15 203 | target 14 204 | label 0 205 | ] 206 | edge [ 207 | source 16 208 | target 8 209 | label 0 210 | ] 211 | edge [ 212 | source 16 213 | target 15 214 | label 0 215 | ] 216 | edge [ 217 | source 16 218 | target 16 219 | label 0 220 | ] 221 | ] 222 | 223 | -------------------------------------------------------------------------------- /editor/tests/dep_ed.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | size="7.5,10" ; 3 | rankdir = TB ; 4 | "Ed_main" -> "Ed_display" ; 5 | "Ed_main" -> "Ed_draw" ; 6 | "Ed_graph" -> "Ed_hyper" ; 7 | "Ed_draw" -> "Ed_graph" ; 8 | "Ed_display" -> "Ed_graph" ; 9 | } 10 | -------------------------------------------------------------------------------- /editor/tests/dep_why.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | size="7.5,10" ; 3 | rankdir = TB ; 4 | "Why" -> "Main" ; 5 | "Theoryreducer" -> "Logic_decl" ; 6 | "Theoryreducer" -> "Pp" ; 7 | "Theoryreducer" -> "Unionfind" ; 8 | "Theory_filtering" -> "Logic_decl" ; 9 | "Theory_filtering" -> "Pp" ; 10 | "Theory_filtering" -> "Unionfind" ; 11 | "Options" -> "Lib" ; 12 | "Options" -> "Version" ; 13 | "Main" -> "Coq" ; 14 | "Main" -> "Dispatcher" ; 15 | "Main" -> "Fastwp" ; 16 | "Main" -> "Gappa" ; 17 | "Main" -> "Hol4" ; 18 | "Main" -> "Holl" ; 19 | "Main" -> "Hypotheses_filtering" ; 20 | "Main" -> "Isabelle" ; 21 | "Main" -> "Mizar" ; 22 | "Main" -> "Monad" ; 23 | "Main" -> "Ocaml" ; 24 | "Main" -> "PredDefExpansor" ; 25 | "Main" -> "Pvs" ; 26 | "Main" -> "Wp" ; 27 | "Hypotheses_filtering" -> "Util" ; 28 | "Encoding_mono" -> "Util" ; 29 | "Zenon" -> "Encoding" ; 30 | "Zenon" -> "Ltyping" ; 31 | "Wp" -> "Typing" ; 32 | "Vcg" -> "Log" ; 33 | "Vcg" -> "Util" ; 34 | "Util" -> "Logic_decl" ; 35 | "Util" -> "Rename" ; 36 | "Typing" -> "Ltyping" ; 37 | "Types" -> "Effect" ; 38 | "Smtlib" -> "Encoding" ; 39 | "Simplify" -> "Encoding" ; 40 | "Report" -> "Lexer" ; 41 | "Report" -> "Misc" ; 42 | "Rename" -> "Pp" ; 43 | "Rename" -> "Report" ; 44 | "Regen" -> "Vcg" ; 45 | "Red" -> "Util" ; 46 | "Pvs" -> "Vcg" ; 47 | "Purify" -> "Env" ; 48 | "Ptree" -> "Loc" ; 49 | "Ptree" -> "Types" ; 50 | "Pretty" -> "Logic_decl" ; 51 | "Pretty" -> "Pp" ; 52 | "PredDefExpansor" -> "Util" ; 53 | "Parser" -> "Error" ; 54 | "Parser" -> "Float_lexer" ; 55 | "Parser" -> "Ptree" ; 56 | "Ocaml" -> "Util" ; 57 | "Monomorph" -> "Vcg" ; 58 | "Monad" -> "Typing" ; 59 | "Mlize" -> "Monad" ; 60 | "Mizar" -> "Regen" ; 61 | "Misc" -> "Ast" ; 62 | "Misc" -> "Option_misc" ; 63 | "Misc" -> "Options" ; 64 | "Ltyping" -> "Util" ; 65 | "Logic" -> "Ident" ; 66 | "Logic_decl" -> "Env" ; 67 | "Lexer" -> "Parser" ; 68 | "Isabelle" -> "Regen" ; 69 | "Holl" -> "Vcg" ; 70 | "Hol4" -> "Vcg" ; 71 | "Harvey" -> "Encoding" ; 72 | "Gappa" -> "Logic_decl" ; 73 | "Gappa" -> "Pp" ; 74 | "Fpi" -> "Misc" ; 75 | "Fpi" -> "Pp" ; 76 | "Fastwp" -> "Util" ; 77 | "Error" -> "Effect" ; 78 | "Env" -> "Report" ; 79 | "Encoding_strat" -> "Util" ; 80 | "Encoding_rec" -> "Logic_decl" ; 81 | "Encoding_pred" -> "Logic_decl" ; 82 | "Encoding" -> "Encoding_mono" ; 83 | "Encoding" -> "Encoding_pred" ; 84 | "Encoding" -> "Encoding_rec" ; 85 | "Encoding" -> "Encoding_strat" ; 86 | "Encoding" -> "Monomorph" ; 87 | "Effect" -> "Logic" ; 88 | "Dispatcher" -> "Cvcl" ; 89 | "Dispatcher" -> "Harvey" ; 90 | "Dispatcher" -> "Pretty" ; 91 | "Dispatcher" -> "Simplify" ; 92 | "Dispatcher" -> "Smtlib" ; 93 | "Dispatcher" -> "Theory_filtering" ; 94 | "Dispatcher" -> "Zenon" ; 95 | "Cvcl" -> "Encoding" ; 96 | "Cvcl" -> "Ltyping" ; 97 | "Coq" -> "Regen" ; 98 | "Cc" -> "Loc" ; 99 | "Cc" -> "Logic" ; 100 | "Ast" -> "Cc" ; 101 | "Ast" -> "Ptree" ; 102 | "Annot" -> "Util" ; 103 | } 104 | -------------------------------------------------------------------------------- /editor/tests/divisors12.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | node [ 3 | id 1 4 | label 1 5 | ] 6 | node [ 7 | id 2 8 | label 2 9 | ] 10 | node [ 11 | id 3 12 | label 3 13 | ] 14 | node [ 15 | id 4 16 | label 4 17 | ] 18 | node [ 19 | id 5 20 | label 5 21 | ] 22 | node [ 23 | id 6 24 | label 6 25 | ] 26 | node [ 27 | id 7 28 | label 7 29 | ] 30 | node [ 31 | id 8 32 | label 8 33 | ] 34 | node [ 35 | id 9 36 | label 9 37 | ] 38 | node [ 39 | id 10 40 | label 10 41 | ] 42 | node [ 43 | id 11 44 | label 11 45 | ] 46 | edge [ 47 | source 3 48 | target 1 49 | 50 | ] 51 | edge [ 52 | source 5 53 | target 1 54 | 55 | ] 56 | edge [ 57 | source 5 58 | target 2 59 | 60 | ] 61 | edge [ 62 | source 7 63 | target 1 64 | 65 | ] 66 | edge [ 67 | source 7 68 | target 3 69 | 70 | ] 71 | edge [ 72 | source 8 73 | target 2 74 | 75 | ] 76 | edge [ 77 | source 9 78 | target 1 79 | 80 | ] 81 | edge [ 82 | source 9 83 | target 4 84 | 85 | ] 86 | edge [ 87 | source 11 88 | target 1 89 | 90 | ] 91 | edge [ 92 | source 11 93 | target 2 94 | 95 | ] 96 | edge [ 97 | source 11 98 | target 3 99 | 100 | ] 101 | edge [ 102 | source 11 103 | target 5 104 | 105 | ] 106 | ] 107 | 108 | -------------------------------------------------------------------------------- /editor/tests/fsm.dot: -------------------------------------------------------------------------------- 1 | digraph finite_state_machine { 2 | LR_0 -> LR_2 [ label = "SS(B)" ]; 3 | LR_0 -> LR_1 [ label = "SS(S)" ]; 4 | LR_1 -> LR_3 [ label = "S($end)" ]; 5 | LR_2 -> LR_6 [ label = "SS(b)" ]; 6 | LR_2 -> LR_5 [ label = "SS(a)" ]; 7 | LR_2 -> LR_4 [ label = "S(A)" ]; 8 | LR_5 -> LR_7 [ label = "S(b)" ]; 9 | LR_5 -> LR_5 [ label = "S(a)" ]; 10 | LR_6 -> LR_6 [ label = "S(b)" ]; 11 | LR_6 -> LR_5 [ label = "S(a)" ]; 12 | LR_7 -> LR_8 [ label = "S(b)" ]; 13 | LR_7 -> LR_5 [ label = "S(a)" ]; 14 | LR_8 -> LR_6 [ label = "S(b)" ]; 15 | LR_8 -> LR_5 [ label = "S(a)" ]; 16 | } 17 | -------------------------------------------------------------------------------- /editor/tests/parcours.dot: -------------------------------------------------------------------------------- 1 | digraph g { 2 | 3 | r -> U; 4 | r -> D; 5 | r -> T; 6 | 7 | U -> Ua; 8 | U -> Ub; 9 | Ua -> Uaa; 10 | Ub -> Ubb; 11 | Ua -> Ubb; 12 | Ub -> Uaa; 13 | 14 | D -> Da; 15 | D -> Db; 16 | Da -> Daa; 17 | Db -> Dbb; 18 | Da -> Dbb; 19 | Db -> Daa; 20 | 21 | T -> Ta; 22 | T -> Tb; 23 | Ta -> Taa; 24 | Tb -> Tbb; 25 | Ta -> Tbb; 26 | Tb -> Taa; 27 | 28 | Ua -> Da; 29 | Db -> Ta; 30 | Tb -> Ub; 31 | 32 | } -------------------------------------------------------------------------------- /editor/tests/rand_10_10.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | node [ 3 | id 1 4 | label 0 5 | ] 6 | node [ 7 | id 2 8 | label 1 9 | ] 10 | node [ 11 | id 3 12 | label 2 13 | ] 14 | node [ 15 | id 4 16 | label 3 17 | ] 18 | node [ 19 | id 5 20 | label 4 21 | ] 22 | node [ 23 | id 6 24 | label 5 25 | ] 26 | node [ 27 | id 7 28 | label 6 29 | ] 30 | node [ 31 | id 8 32 | label 7 33 | ] 34 | node [ 35 | id 9 36 | label 8 37 | ] 38 | node [ 39 | id 10 40 | label 9 41 | ] 42 | edge [ 43 | source 3 44 | target 1 45 | label 0 46 | ] 47 | edge [ 48 | source 5 49 | target 2 50 | label 0 51 | ] 52 | edge [ 53 | source 5 54 | target 3 55 | label 0 56 | ] 57 | edge [ 58 | source 6 59 | target 3 60 | label 0 61 | ] 62 | edge [ 63 | source 7 64 | target 3 65 | label 0 66 | ] 67 | edge [ 68 | source 9 69 | target 5 70 | label 0 71 | ] 72 | edge [ 73 | source 9 74 | target 6 75 | label 0 76 | ] 77 | edge [ 78 | source 10 79 | target 6 80 | label 0 81 | ] 82 | edge [ 83 | source 10 84 | target 7 85 | label 0 86 | ] 87 | edge [ 88 | source 10 89 | target 9 90 | label 0 91 | ] 92 | ] 93 | 94 | -------------------------------------------------------------------------------- /editor/tests/test.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | comment "This is a sample graph" 3 | directed 1 4 | id 42 5 | label "Hello, I am a graph" 6 | node [ id 1 label "Node 1" ] 7 | node [ id 2 label "node 2" ] 8 | node [ id 3 label "node 3" ] 9 | node [ id 4 label "node 3" ] 10 | node [ id 5 label "node 3" ] 11 | node [ id 6 label "node 3" ] 12 | node [ id 7 label "node 3" ] 13 | node [ id 8 label "node 3" ] 14 | node [ id 9 label "node 3" ] 15 | node [ id 10 label "node 3" ] 16 | node [ id 11 label "node 3" ] 17 | node [ id 12 label "node 3" ] 18 | edge [ source 1 target 2 ] 19 | edge [ source 1 target 4 ] 20 | edge [ source 1 target 5 ] 21 | edge [ source 1 target 6 ] 22 | edge [ source 1 target 7 ] 23 | edge [ source 2 target 7 ] 24 | edge [ source 3 target 7 ] 25 | edge [ source 1 target 8 ] 26 | edge [ source 2 target 3 ] 27 | edge [ source 3 target 1 ] 28 | edge [ source 8 target 9 ] 29 | edge [ source 8 target 10 ] 30 | edge [ source 8 target 11 ] 31 | edge [ source 8 target 12 ] 32 | ] -------------------------------------------------------------------------------- /editor/tests/test2,1_2.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | comment "This is a sample graph" 3 | directed 1 4 | id 42 5 | label "Hello, I am a graph" 6 | node [ id 1 label "Node 1" ] 7 | node [ id 2 label "node 2" ] 8 | node [ id 3 label "node 3" ] 9 | node [ id 4 label "node 4" ] 10 | node [ id 5 label "node 5" ] 11 | node [ id 6 label "node 6" ] 12 | edge [ source 1 target 2 ] 13 | edge [ source 1 target 3 ] 14 | edge [ source 1 target 4 ] 15 | edge [ source 1 target 5 ] 16 | edge [ source 1 target 6 ] 17 | edge [ source 2 target 4 ] 18 | edge [ source 5 target 6] 19 | 20 | ] -------------------------------------------------------------------------------- /editor/tests/test2,1_3.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | comment "This is a sample graph" 3 | directed 1 4 | id 42 5 | label "Hello, I am a graph" 6 | node [ id 1 label "Node 1" ] 7 | node [ id 2 label "node 2" ] 8 | node [ id 3 label "node 3" ] 9 | node [ id 4 label "node 4" ] 10 | node [ id 5 label "node 5" ] 11 | node [ id 6 label "node 6" ] 12 | node [ id 7 label "node 7" ] 13 | edge [ source 1 target 2 ] 14 | edge [ source 1 target 3 ] 15 | edge [ source 1 target 4 ] 16 | edge [ source 1 target 6 ] 17 | edge [ source 1 target 5 ] 18 | edge [ source 1 target 7 ] 19 | edge [ source 2 target 4 ] 20 | edge [ source 6 target 5 ] 21 | edge [ source 5 target 7 ] 22 | 23 | ] -------------------------------------------------------------------------------- /editor/tests/test2,1_3tot.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | comment "This is a sample graph" 3 | directed 1 4 | id 42 5 | label "Hello, I am a graph" 6 | node [ id 1 label "Node 1" ] 7 | node [ id 2 label "node 2" ] 8 | node [ id 3 label "node 3" ] 9 | node [ id 4 label "node 4" ] 10 | node [ id 5 label "node 5" ] 11 | node [ id 6 label "node 6" ] 12 | node [ id 7 label "node 7" ] 13 | edge [ source 1 target 2 ] 14 | edge [ source 1 target 3 ] 15 | edge [ source 1 target 4 ] 16 | edge [ source 1 target 5 ] 17 | edge [ source 1 target 6 ] 18 | edge [ source 1 target 7 ] 19 | edge [ source 2 target 4 ] 20 | edge [ source 5 target 6 ] 21 | edge [ source 6 target 7 ] 22 | edge [ source 5 target 7 ] 23 | 24 | ] -------------------------------------------------------------------------------- /editor/tests/test2_2.gml: -------------------------------------------------------------------------------- 1 | graph [ 2 | comment "This is a sample graph" 3 | directed 1 4 | id 42 5 | label "Hello, I am a graph" 6 | node [ id 1 label "Node 1" ] 7 | node [ id 2 label "node 2" ] 8 | node [ id 3 label "node 3" ] 9 | node [ id 4 label "node 4" ] 10 | node [ id 5 label "node 5" ] 11 | edge [ source 1 target 2 ] 12 | edge [ source 1 target 3 ] 13 | edge [ source 1 target 4 ] 14 | edge [ source 1 target 5 ] 15 | edge [ source 2 target 3 ] 16 | edge [ source 4 target 5 ] 17 | 18 | ] -------------------------------------------------------------------------------- /editor/tests/transparency.dot: -------------------------------------------------------------------------------- 1 | graph G { 2 | graph [splines=true overlap=false] 3 | graph [truecolor bgcolor="#ff00005f"] 4 | node [style=filled fillcolor="#00ff005f"] 5 | 1 -- 30 [f=1]; 6 | 1 -- 40 [f=14]; 7 | 8 -- 46 [f=1]; 8 | 8 -- 16 [f=18]; 9 | 10 -- 25 [f=1]; 10 | 10 -- 19 [f=5]; 11 | 10 -- 33 [f=1]; 12 | 12 -- 8 [f=1]; 13 | 12 -- 36 [f=5]; 14 | 12 -- 17 [f=16]; 15 | 13 -- 38 [f=1]; 16 | 13 -- 24 [f=19]; 17 | 24 -- 49 [f=1]; 18 | 24 -- 13 [f=1]; 19 | 24 -- 47 [f=12]; 20 | 24 -- 12 [f=19]; 21 | 25 -- 27 [f=1]; 22 | 25 -- 12 [f=1]; 23 | 27 -- 12 [f=1]; 24 | 27 -- 14 [f=8]; 25 | 29 -- 10 [f=1]; 26 | 29 -- 8 [f=17]; 27 | 30 -- 24 [f=1]; 28 | 30 -- 44 [f=15]; 29 | 38 -- 29 [f=1]; 30 | 38 -- 35 [f=15]; 31 | 2 -- 42 [f=2]; 32 | 2 -- 35 [f=3]; 33 | 2 -- 11 [f=19]; 34 | 14 -- 18 [f=2]; 35 | 14 -- 24 [f=15]; 36 | 14 -- 38 [f=18]; 37 | 18 -- 49 [f=2]; 38 | 18 -- 47 [f=20]; 39 | 26 -- 41 [f=2]; 40 | 26 -- 42 [f=15]; 41 | 31 -- 39 [f=2]; 42 | 31 -- 47 [f=17]; 43 | 31 -- 25 [f=14]; 44 | 37 -- 26 [f=2]; 45 | 37 -- 16 [f=14]; 46 | 39 -- 50 [f=2]; 47 | 39 -- 14 [f=2]; 48 | 39 -- 18 [f=17]; 49 | 39 -- 47 [f=10]; 50 | 41 -- 31 [f=2]; 51 | 41 -- 8 [f=16]; 52 | 42 -- 44 [f=2]; 53 | 42 -- 29 [f=12]; 54 | 44 -- 37 [f=2]; 55 | 44 -- 32 [f=15]; 56 | 3 -- 20 [f=2]; 57 | 3 -- 28 [f=19]; 58 | 6 -- 45 [f=2]; 59 | 6 -- 28 [f=10]; 60 | 9 -- 6 [f=2]; 61 | 9 -- 16 [f=1]; 62 | 15 -- 16 [f=2]; 63 | 15 -- 48 [f=2]; 64 | 16 -- 50 [f=2]; 65 | 16 -- 32 [f=14]; 66 | 16 -- 39 [f=8]; 67 | 20 -- 33 [f=2]; 68 | 33 -- 9 [f=2]; 69 | 33 -- 46 [f=3]; 70 | 33 -- 48 [f=17]; 71 | 45 -- 15 [f=2]; 72 | 4 -- 17 [f=4]; 73 | 4 -- 15 [f=6]; 74 | 4 -- 12 [f=16]; 75 | 17 -- 21 [f=4]; 76 | 19 -- 35 [f=4]; 77 | 19 -- 15 [f=9]; 78 | 19 -- 43 [f=4]; 79 | 21 -- 19 [f=4]; 80 | 21 -- 50 [f=4]; 81 | 23 -- 36 [f=4]; 82 | 34 -- 23 [f=4]; 83 | 34 -- 24 [f=11]; 84 | 35 -- 34 [f=4]; 85 | 35 -- 16 [f=6]; 86 | 35 -- 18 [f=16]; 87 | 36 -- 46 [f=4]; 88 | 5 -- 7 [f=1]; 89 | 5 -- 36 [f=6]; 90 | 7 -- 32 [f=1]; 91 | 7 -- 11 [f=2]; 92 | 7 -- 14 [f=17]; 93 | 11 -- 40 [f=1]; 94 | 11 -- 50 [f=1]; 95 | 22 -- 46 [f=1]; 96 | 28 -- 43 [f=1]; 97 | 28 -- 8 [f=18]; 98 | 32 -- 28 [f=1]; 99 | 32 -- 39 [f=13]; 100 | 32 -- 42 [f=15]; 101 | 40 -- 22 [f=1]; 102 | 40 -- 47 [f=1]; 103 | 43 -- 11 [f=1]; 104 | 43 -- 17 [f=19]; 105 | } 106 | -------------------------------------------------------------------------------- /editor/tests/unix.dot: -------------------------------------------------------------------------------- 1 | /* courtesy Ian Darwin and Geoff Collyer, Softquad Inc. */ 2 | digraph unix { 3 | "5th Edition" -> "6th Edition"; 4 | "5th Edition" -> "PWB 1.0"; 5 | "6th Edition" -> "LSX"; 6 | "6th Edition" -> "1 BSD"; 7 | "6th Edition" -> "Mini Unix"; 8 | "6th Edition" -> "Wollongong"; 9 | "6th Edition" -> "Interdata"; 10 | "Interdata" -> "Unix/TS 3.0"; 11 | "Interdata" -> "PWB 2.0"; 12 | "Interdata" -> "7th Edition"; 13 | "7th Edition" -> "8th Edition"; 14 | "7th Edition" -> "32V"; 15 | "7th Edition" -> "V7M"; 16 | "7th Edition" -> "Ultrix-11"; 17 | "7th Edition" -> "Xenix"; 18 | "7th Edition" -> "UniPlus+"; 19 | "V7M" -> "Ultrix-11"; 20 | "8th Edition" -> "9th Edition"; 21 | "1 BSD" -> "2 BSD"; 22 | "2 BSD" -> "2.8 BSD"; 23 | "2.8 BSD" -> "Ultrix-11"; 24 | "2.8 BSD" -> "2.9 BSD"; 25 | "32V" -> "3 BSD"; 26 | "3 BSD" -> "4 BSD"; 27 | "4 BSD" -> "4.1 BSD"; 28 | "4.1 BSD" -> "4.2 BSD"; 29 | "4.1 BSD" -> "2.8 BSD"; 30 | "4.1 BSD" -> "8th Edition"; 31 | "4.2 BSD" -> "4.3 BSD"; 32 | "4.2 BSD" -> "Ultrix-32"; 33 | "PWB 1.0" -> "PWB 1.2"; 34 | "PWB 1.0" -> "USG 1.0"; 35 | "PWB 1.2" -> "PWB 2.0"; 36 | "USG 1.0" -> "CB Unix 1"; 37 | "USG 1.0" -> "USG 2.0"; 38 | "CB Unix 1" -> "CB Unix 2"; 39 | "CB Unix 2" -> "CB Unix 3"; 40 | "CB Unix 3" -> "Unix/TS++"; 41 | "CB Unix 3" -> "PDP-11 Sys V"; 42 | "USG 2.0" -> "USG 3.0"; 43 | "USG 3.0" -> "Unix/TS 3.0"; 44 | "PWB 2.0" -> "Unix/TS 3.0"; 45 | "Unix/TS 1.0" -> "Unix/TS 3.0"; 46 | "Unix/TS 3.0" -> "TS 4.0"; 47 | "Unix/TS++" -> "TS 4.0"; 48 | "CB Unix 3" -> "TS 4.0"; 49 | "TS 4.0" -> "System V.0"; 50 | "System V.0" -> "System V.2"; 51 | "System V.2" -> "System V.3"; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /editor/tests/world.dot: -------------------------------------------------------------------------------- 1 | digraph world { 2 | size="7,7"; 3 | {rank=same; S8 S24 S1 S35 S30;} 4 | {rank=same; T8 T24 T1 T35 T30;} 5 | {rank=same; 43 37 36 10 2;} 6 | {rank=same; 25 9 38 40 13 17 12 18;} 7 | {rank=same; 26 42 11 3 33 19 39 14 16;} 8 | {rank=same; 4 31 34 21 41 28 20;} 9 | {rank=same; 27 5 22 32 29 15;} 10 | {rank=same; 6 23;} 11 | {rank=same; 7;} 12 | 13 | S8 -> 9; 14 | S24 -> 25; 15 | S24 -> 27; 16 | S1 -> 2; 17 | S1 -> 10; 18 | S35 -> 43; 19 | S35 -> 36; 20 | S30 -> 31; 21 | S30 -> 33; 22 | 9 -> 42; 23 | 9 -> T1; 24 | 25 -> T1; 25 | 25 -> 26; 26 | 27 -> T24; 27 | 2 -> {3 ; 16 ; 17 ; T1 ; 18} 28 | 10 -> { 11 ; 14 ; T1 ; 13; 12;} 29 | 31 -> T1; 30 | 31 -> 32; 31 | 33 -> T30; 32 | 33 -> 34; 33 | 42 -> 4; 34 | 26 -> 4; 35 | 3 -> 4; 36 | 16 -> 15; 37 | 17 -> 19; 38 | 18 -> 29; 39 | 11 -> 4; 40 | 14 -> 15; 41 | 37 -> {39 ; 41 ; 38 ; 40;} 42 | 13 -> 19; 43 | 12 -> 29; 44 | 43 -> 38; 45 | 43 -> 40; 46 | 36 -> 19; 47 | 32 -> 23; 48 | 34 -> 29; 49 | 39 -> 15; 50 | 41 -> 29; 51 | 38 -> 4; 52 | 40 -> 19; 53 | 4 -> 5; 54 | 19 -> {21 ; 20 ; 28;} 55 | 5 -> {6 ; T35 ; 23;} 56 | 21 -> 22; 57 | 20 -> 15; 58 | 28 -> 29; 59 | 6 -> 7; 60 | 15 -> T1; 61 | 22 -> T35; 62 | 22 -> 23; 63 | 29 -> T30; 64 | 7 -> T8; 65 | 23 -> T24; 66 | 23 -> T1; 67 | } 68 | -------------------------------------------------------------------------------- /examples/depend2dot.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2007 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | open Graph 19 | 20 | let usage () = 21 | Format.eprintf "usage: depend2dot@."; 22 | Format.eprintf "reads a dependency graph on the standard input, in format@."; 23 | Format.eprintf " a: b c d@."; 24 | Format.eprintf " b: c e@."; 25 | Format.eprintf " etc.@."; 26 | Format.eprintf "and prints a reduced graph in DOT format on the standard output.@."; 27 | exit 1 28 | 29 | module G = Imperative.Digraph.Abstract(String) 30 | module O = Oper.Make(Builder.I(G)) 31 | module H = Hashtbl 32 | 33 | let graph = G.create () 34 | 35 | let () = 36 | let nodes = H.create 16 in 37 | let node s = try H.find nodes s 38 | with Not_found -> let v = G.V.create s in H.add nodes s v; v in 39 | let node s = node (String.trim s) in 40 | let add v w = if w <> "" then G.add_edge graph (node v) (node w) in 41 | let add v w = add v w in 42 | let parse_line s = match String.split_on_char ':' s with 43 | | [v; deps] -> List.iter (add v) (String.split_on_char ' ' deps) 44 | | [_] -> () 45 | | _ -> usage () in 46 | let rec read () = match read_line () with 47 | | s -> parse_line s; read () 48 | | exception End_of_file -> () in 49 | read () 50 | 51 | let graph = O.replace_by_transitive_reduction graph 52 | 53 | module Display = struct 54 | include G 55 | let vertex_name = V.label 56 | let graph_attributes _ = [] 57 | let default_vertex_attributes _ = [] 58 | let vertex_attributes _ = [] 59 | let default_edge_attributes _ = [] 60 | let edge_attributes _ = [] 61 | let get_subgraph _ = None 62 | end 63 | module Dot = Graphviz.Dot(Display) 64 | 65 | let () = Dot.output_graph stdout graph 66 | -------------------------------------------------------------------------------- /examples/dune: -------------------------------------------------------------------------------- 1 | (executables 2 | (names color compare_prim_kruskal demo_planar demo_prim demo sudoku 3 | depend2dot words) 4 | (libraries graph unix graphics threads)) 5 | 6 | (alias 7 | (name runtest) 8 | (deps color.exe compare_prim_kruskal.exe demo_planar.exe demo_prim.exe 9 | demo.exe sudoku.exe)) 10 | -------------------------------------------------------------------------------- /examples/sudoku.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2007 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* Ocamlgraph demo program: solving the Sudoku puzzle using graph coloring *) 19 | 20 | open Format 21 | open Graph 22 | 23 | (* We use undirected graphs with nodes containing a pair of integers 24 | (the cell coordinates in 0..8 x 0..8). 25 | The integer marks of the nodes will store the colors. *) 26 | module G = Imperative.Graph.Abstract(struct type t = int * int end) 27 | 28 | (* The Sudoku grid = a graph with 9x9 nodes *) 29 | let g = G.create () 30 | 31 | (* We create the 9x9 nodes, add them to the graph and keep them in a matrix 32 | for later access *) 33 | let nodes = 34 | let new_node i j = let v = G.V.create (i, j) in G.add_vertex g v; v in 35 | Array.init 9 (fun i -> Array.init 9 (new_node i)) 36 | 37 | let node i j = nodes.(i).(j) (* shortcut for easier access *) 38 | 39 | (* We add the edges: 40 | two nodes are connected whenever they can't have the same value, 41 | i.e. they belong to the same line, the same column or the same 3x3 group *) 42 | let () = 43 | for i = 0 to 8 do for j = 0 to 8 do 44 | for k = 0 to 8 do 45 | if k <> i then G.add_edge g (node i j) (node k j); 46 | if k <> j then G.add_edge g (node i j) (node i k); 47 | done; 48 | let gi = 3 * (i / 3) and gj = 3 * (j / 3) in 49 | for di = 0 to 2 do for dj = 0 to 2 do 50 | let i' = gi + di and j' = gj + dj in 51 | if i' <> i || j' <> j then G.add_edge g (node i j) (node i' j') 52 | done done 53 | done done 54 | 55 | (* Displaying the current state of the graph *) 56 | let display () = 57 | for i = 0 to 8 do 58 | for j = 0 to 8 do printf "%d" (G.Mark.get (node i j)) done; 59 | printf "\n"; 60 | done; 61 | printf "@?" 62 | 63 | (* We read the initial constraints from standard input and we display g *) 64 | let () = 65 | for i = 0 to 8 do 66 | let s = read_line () in 67 | for j = 0 to 8 do match s.[j] with 68 | | '1'..'9' as ch -> G.Mark.set (node i j) (Char.code ch - Char.code '0') 69 | | _ -> () 70 | done 71 | done; 72 | display (); 73 | printf "---------@." 74 | 75 | (* We solve the Sudoku by 9-coloring the graph g and we display the solution *) 76 | module C = Coloring.Mark(G) 77 | 78 | let () = 79 | C.coloring g 9; display () 80 | -------------------------------------------------------------------------------- /examples/words.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Word Graph 3 | (example taken from The Stanford GraphBase) 4 | 5 | Given a number of letters n and a file containing words (one per line), 6 | this program builds the undirected graph where 7 | - vertices are words of length n; 8 | - two words are connected with an edge if they differ by exactly one letter. 9 | 10 | Then the program computes and prints the components. 11 | 12 | Finally, it repeatedly queries a word from the user and displays 13 | its component. 14 | *) 15 | 16 | open Format 17 | open Graph 18 | 19 | module S = struct 20 | type t = string 21 | let compare = compare 22 | let hash = Hashtbl.hash 23 | let equal = (=) 24 | end 25 | module H = Hashtbl.Make(S) 26 | 27 | module G = Imperative.Graph.Abstract(S) 28 | let g = G.create () 29 | 30 | let words : G.V.t H.t = H.create 16 31 | 32 | let add_word w = 33 | let v = G.V.create w in H.add words w v; G.add_vertex g v 34 | 35 | let rec read_words n c = 36 | match input_line c with 37 | | s -> if String.length s = n then add_word s; read_words n c 38 | | exception End_of_file -> () 39 | 40 | let () = 41 | try match Sys.argv with [| _; n; f |] -> 42 | let n = int_of_string n in 43 | let c = open_in f in 44 | read_words n c; 45 | close_in c; 46 | | _ -> raise Exit 47 | with _ -> eprintf "%s @." Sys.argv.(0); exit 1 48 | 49 | let () = printf "%d words@." (G.nb_vertex g) 50 | 51 | let diff1 s1 s2 = 52 | let n = String.length s1 in 53 | assert (String.length s2 = n); 54 | let rec scan d i = 55 | i = n && d = 1 || 56 | i < n && if s1.[i] = s2.[i] then scan d (i+1) else d = 0 && scan 1 (i+1) in 57 | scan 0 0 58 | 59 | let () = 60 | G.iter_vertex (fun v1 -> 61 | G.iter_vertex (fun v2 -> 62 | if diff1 (G.V.label v1) (G.V.label v2) then G.add_edge g v1 v2 63 | ) g) g 64 | 65 | let () = printf "%d edges@." (G.nb_edges g) 66 | 67 | module C = Components.Undirected(G) 68 | let comp = C.components_array g 69 | 70 | let histogram a = 71 | let h = Hashtbl.create (Array.length a) in 72 | let incr v = 73 | Hashtbl.replace h v (1 + try Hashtbl.find h v with Not_found -> 0) in 74 | Array.iter incr a; 75 | let l = Hashtbl.fold (fun v n acc -> (v, n) :: acc) h [] in 76 | List.sort (fun (v1, _) (v2, _) -> compare v1 v2) l 77 | 78 | let () = 79 | printf "%d components@." (Array.length comp); 80 | Array.sort (fun l1 l2 -> Stdlib.compare (List.length l1) (List.length l2)) 81 | comp; 82 | let print1 v = printf "@ %s" (G.V.label v) in 83 | let print c = 84 | printf "@[%d:" (List.length c); List.iter print1 c; printf "@]@." in 85 | Array.iter print comp; 86 | let hist = histogram (Array.map List.length comp) in 87 | List.iter (fun (v, n) -> printf "%d component(s) of size %d@." n v) hist 88 | 89 | module D = Traverse.Dfs(G) 90 | 91 | let () = 92 | while true do 93 | printf "start: @?"; 94 | let s = read_line () in 95 | try 96 | let v = H.find words s in 97 | printf "@[component:"; 98 | let m = ref 0 in 99 | let visit v = printf "@ %s" (G.V.label v); incr m in 100 | D.prefix_component visit g v; 101 | printf "@]@."; 102 | printf "%d word(s)@." !m 103 | with Not_found -> 104 | printf "not a vertex@." 105 | done 106 | -------------------------------------------------------------------------------- /ocamlgraph.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "A generic graph library for OCaml" 3 | description: "Provides both graph data structures and graph algorithms" 4 | maintainer: ["jean-christophe.filliatre@cnrs.fr"] 5 | authors: ["Sylvain Conchon" "Jean-Christophe Filliâtre" "Julien Signoles"] 6 | license: "LGPL-2.1-only" 7 | tags: [ 8 | "graph" 9 | "library" 10 | "algorithms" 11 | "directed graph" 12 | "vertice" 13 | "edge" 14 | "persistent" 15 | "imperative" 16 | ] 17 | homepage: "https://github.com/backtracking/ocamlgraph/" 18 | doc: "https://backtracking.github.io/ocamlgraph" 19 | bug-reports: "https://github.com/backtracking/ocamlgraph/issues/new" 20 | depends: [ 21 | "ocaml" {>= "4.08.0"} 22 | "dune" {>= "2.0"} 23 | "graphics" {with-test} 24 | ] 25 | build: [ 26 | ["dune" "subst"] {dev} 27 | [ 28 | "dune" 29 | "build" 30 | "-p" 31 | name 32 | "-j" 33 | jobs 34 | "@install" 35 | "@runtest" {with-test} 36 | "@doc" {with-doc} 37 | ] 38 | ] 39 | dev-repo: "git+https://github.com/backtracking/ocamlgraph.git" 40 | -------------------------------------------------------------------------------- /ocamlgraph_gtk.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Displaying graphs using OCamlGraph and GTK" 3 | description: "Displaying graphs using OCamlGraph and GTK" 4 | maintainer: ["jean-christophe.filliatre@cnrs.fr"] 5 | authors: ["Sylvain Conchon" "Jean-Christophe Filliâtre" "Julien Signoles"] 6 | license: "LGPL-2.1-only" 7 | tags: [ 8 | "graph" 9 | "library" 10 | "algorithms" 11 | "directed graph" 12 | "vertice" 13 | "edge" 14 | "persistent" 15 | "imperative" 16 | ] 17 | homepage: "https://github.com/backtracking/ocamlgraph/" 18 | doc: "https://backtracking.github.io/ocamlgraph" 19 | bug-reports: "https://github.com/backtracking/ocamlgraph/issues/new" 20 | depends: [ 21 | "ocaml" {>= "4.08.0"} 22 | "lablgtk" 23 | "conf-gnomecanvas" 24 | "ocamlgraph" {>= "2.0.0"} 25 | "dune" {>= "2.0"} 26 | "graphics" {with-test} 27 | ] 28 | build: [ 29 | ["dune" "subst"] {dev} 30 | [ 31 | "dune" 32 | "build" 33 | "-p" 34 | name 35 | "-j" 36 | jobs 37 | "@install" 38 | "@runtest" {with-test} 39 | "@doc" {with-doc} 40 | ] 41 | ] 42 | dev-repo: "git+https://github.com/backtracking/ocamlgraph.git" 43 | -------------------------------------------------------------------------------- /src/builder.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | module type S = sig 19 | module G : Sig.G 20 | val empty : unit -> G.t 21 | val copy : G.t -> G.t 22 | val add_vertex : G.t -> G.V.t -> G.t 23 | val add_edge : G.t -> G.V.t -> G.V.t -> G.t 24 | val add_edge_e : G.t -> G.E.t -> G.t 25 | val remove_vertex : G.t -> G.V.t -> G.t 26 | val remove_edge : G.t -> G.V.t -> G.V.t -> G.t 27 | val remove_edge_e : G.t -> G.E.t -> G.t 28 | end 29 | 30 | module type INT = S with type G.V.label = int 31 | 32 | module P(G : Sig.P) = struct 33 | module G = G 34 | let empty () = G.empty 35 | let copy g = g 36 | let add_vertex = G.add_vertex 37 | let add_edge = G.add_edge 38 | let add_edge_e = G.add_edge_e 39 | let remove_vertex = G.remove_vertex 40 | let remove_edge = G.remove_edge 41 | let remove_edge_e = G.remove_edge_e 42 | end 43 | 44 | module I(G : Sig.I) = struct 45 | module G = G 46 | let empty () = G.create ~size:97 () 47 | let copy = G.copy 48 | let add_vertex g v = G.add_vertex g v; g 49 | let add_edge g v1 v2 = G.add_edge g v1 v2; g 50 | let add_edge_e g e = G.add_edge_e g e; g 51 | let remove_vertex g v = G.remove_vertex g v; g 52 | let remove_edge g v1 v2 = G.remove_edge g v1 v2; g 53 | let remove_edge_e g e = G.remove_edge_e g e; g 54 | end 55 | 56 | (* 57 | Local Variables: 58 | compile-command: "make -C .." 59 | End: 60 | *) 61 | -------------------------------------------------------------------------------- /src/builder.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Graph builders in order to persistent/imperative graphs sharing a same 19 | signature. *) 20 | 21 | (** {2 Common interface for graph builders}. 22 | 23 | Note: the following functions always return graphs but this is meaningless 24 | for imperative implementations (the graph is modified in-place). 25 | This is just to provide a common interface. *) 26 | 27 | module type S = sig 28 | module G : Sig.G 29 | val empty : unit -> G.t 30 | val copy : G.t -> G.t 31 | val add_vertex : G.t -> G.V.t -> G.t 32 | val add_edge : G.t -> G.V.t -> G.V.t -> G.t 33 | val add_edge_e : G.t -> G.E.t -> G.t 34 | val remove_vertex : G.t -> G.V.t -> G.t 35 | val remove_edge : G.t -> G.V.t -> G.V.t -> G.t 36 | val remove_edge_e : G.t -> G.E.t -> G.t 37 | end 38 | 39 | module type INT = S with type G.V.label = int 40 | 41 | (** {1 Builders for the various graph implementations} *) 42 | 43 | module P(G : Sig.P) : S with module G = G 44 | (** Persistent Graphs Builders. *) 45 | 46 | module I(G : Sig.I) : S with module G = G 47 | (** Imperative Graphs Builders. *) 48 | 49 | (* 50 | Local Variables: 51 | compile-command: "make -C .." 52 | End: 53 | *) 54 | -------------------------------------------------------------------------------- /src/clique.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2014-2015 *) 5 | (* Giselle Reis *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | module type G = sig 19 | type t 20 | module V : Sig.COMPARABLE 21 | val succ : t -> V.t -> V.t list 22 | val fold_vertex : (V.t -> 'a -> 'a) -> t -> 'a -> 'a 23 | end 24 | 25 | module Bron_Kerbosch(G : G) = struct 26 | 27 | let rec bron_kerbosch cliquelst graph clique candidates used = match (candidates, used) with 28 | | ([], []) -> clique :: cliquelst 29 | | ([], _) -> cliquelst 30 | | (c, u) -> 31 | let (_, _, cliques) = List.fold_left ( fun (c, u, acc) v -> 32 | (* Get the neighbors ignoring self-loops *) 33 | let n = List.filter (fun nb -> not (G.V.equal nb v)) (G.succ graph v) in 34 | let c' = List.filter (fun cv -> List.exists (fun v -> G.V.equal v cv) n) c in 35 | let u' = List.filter (fun cv -> List.exists (fun v -> G.V.equal v cv) n) u in 36 | let c_minus_v = List.filter (fun cv -> not (G.V.equal cv v)) c in 37 | 38 | ( c_minus_v, (v :: u), bron_kerbosch acc graph (v :: clique) c' u') 39 | ) (c, u, []) c in 40 | cliques @ cliquelst 41 | 42 | let maximalcliques g = 43 | let vertices = G.fold_vertex (fun v acc -> v :: acc) g [] in 44 | bron_kerbosch [] g [] vertices [] 45 | 46 | end 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/clique.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2014-2015 *) 5 | (* Giselle Reis *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Graph cliques *) 19 | 20 | (** {1 Clique algorithms} *) 21 | 22 | (** {2 Bron-Kerbosch Algorithm} 23 | 24 | This algorithm will find and return all maximal cliques in an undirected graph. *) 25 | 26 | (** Minimal graph signature for Bron-Kerbosch. 27 | Sub-signature of {!Sig.G}. *) 28 | module type G = sig 29 | type t 30 | module V : Sig.COMPARABLE 31 | val succ : t -> V.t -> V.t list 32 | val fold_vertex : (V.t -> 'a -> 'a) -> t -> 'a -> 'a 33 | end 34 | 35 | module Bron_Kerbosch(G : G) : sig 36 | val maximalcliques : G.t -> G.V.t list list 37 | (** [maximalcliques g] computes all the maximal cliques of [g] using the 38 | Bron-Kerbosch algorithm. It returns the sets of vertices belonging to the 39 | same maximal clique. *) 40 | end 41 | -------------------------------------------------------------------------------- /src/cliquetree.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Construction of the clique tree of a graph and recognition 19 | of chordal graphs. 20 | 21 | Based on the article: 22 | Chordal graphs and their clique graph 23 | by P. Galinier, M. Habib and C. Paul. 24 | 25 | @author Matthieu Sozeau *) 26 | 27 | module CliqueTree(G : Sig.G) : sig 28 | 29 | (** Original graph vertex *) 30 | module CliqueV : 31 | sig 32 | type t 33 | val compare : t -> t -> int 34 | val hash : t -> int 35 | val equal : t -> t -> bool 36 | val label : t -> t 37 | val create : G.V.t -> t 38 | val vertex : t -> G.V.t 39 | end 40 | 41 | (** Set of original vertices *) 42 | module CVS : Set.S with type elt = CliqueV.t 43 | 44 | (** Clique tree vertex type *) 45 | module CliqueTreeV : sig 46 | (** Trace of the algorithm as a list of markers Clique vertices *) 47 | type data = CliqueV.t list * CVS.t 48 | type label 49 | type t 50 | 51 | val compare : t -> t -> int 52 | val hash : t -> int 53 | val equal : t -> t -> bool 54 | 55 | val create : data -> label -> t 56 | val label : t -> label 57 | val data : t -> data 58 | end 59 | 60 | module CliqueTreeE : sig 61 | type t = int * CVS.t 62 | val compare : t -> t -> int 63 | val default : t 64 | val create : int -> CVS.t -> t 65 | 66 | (** Vertices in the clique tree edge 67 | (intersection of the two clique extremities). *) 68 | val vertices : t -> CVS.t 69 | end 70 | 71 | (** The clique tree graph type *) 72 | module CliqueTree : Sig.G with type V.t = CliqueTreeV.t 73 | and type E.label = CliqueTreeE.t 74 | 75 | (** [mcs_clique g] return an perfect elimination order of [g] 76 | (if it is chordal), the clique tree of [g] and its root. *) 77 | val mcs_clique : G.t -> G.V.t list * CliqueTree.t * CliqueTree.V.t 78 | 79 | (** [is_chordal g] uses the clique tree construction to test if a graph is 80 | chordal or not. *) 81 | val is_chordal : G.t -> bool 82 | 83 | (** [maxwidth g tri tree] returns the maxwidth characteristic of the 84 | triangulation [tri] of graph [g] given the clique tree [tree] of [tri]. *) 85 | val maxwidth : G.t -> G.t -> CliqueTree.t -> int 86 | end 87 | -------------------------------------------------------------------------------- /src/contraction.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* Copyright (c) 2012 Technische Universitaet Muenchen 19 | * Markus W. Weissmann 20 | * All rights reserved. *) 21 | 22 | (* Edge contraction for directed, edge-labeled graphs *) 23 | 24 | module type G = sig 25 | type t 26 | module V : Sig.COMPARABLE 27 | type vertex = V.t 28 | module E : Sig.EDGE with type vertex = vertex 29 | type edge = E.t 30 | 31 | val empty : t 32 | val add_edge_e : t -> edge -> t 33 | val fold_edges_e : (edge -> 'a -> 'a) -> t -> 'a -> 'a 34 | val fold_vertex : (vertex -> 'a -> 'a) -> t -> 'a -> 'a 35 | end 36 | 37 | module Make 38 | (G : G) = 39 | struct 40 | module M = Map.Make(G.V) 41 | module S = Set.Make(G.V) 42 | 43 | let contract' prop g = 44 | (* if the edge is to be removed (property = true): 45 | * make a union of the two union-sets of start and end node; 46 | * put this set in the map for all nodes in this set *) 47 | let f edge m = 48 | if prop edge then 49 | let s_src, s_dst = M.find (G.E.src edge) m, M.find (G.E.dst edge) m in 50 | let s = S.union s_src s_dst in 51 | S.fold (fun vertex m -> M.add vertex s m) s m 52 | else 53 | m 54 | in 55 | (* if the edge is to be kept, add it to the new graph, exchanging 56 | * the start and end node with the minimum element from the set of 57 | * to-be-unified nodes; 'minimum is an arbitrary choice: any 58 | * deterministic choice will do *) 59 | let add m edge g = 60 | if prop edge then 61 | g 62 | else 63 | let lookup n = S.min_elt (M.find n m) in 64 | G.add_edge_e g 65 | (G.E.create (lookup (G.E.src edge)) (G.E.label edge) 66 | (lookup (G.E.dst edge))) 67 | in 68 | (* initialize map with singleton-sets for every node (of itself) *) 69 | let m = 70 | G.fold_vertex (fun vertex m -> M.add vertex (S.singleton vertex) m) 71 | g M.empty 72 | in 73 | (* find all closures *) 74 | let m = G.fold_edges_e f g m in 75 | (* rewrite the node numbers to close the gaps *) 76 | G.fold_edges_e (add m) g G.empty, m 77 | 78 | let contract prop g = fst (contract' prop g) 79 | 80 | end 81 | 82 | -------------------------------------------------------------------------------- /src/contraction.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* Copyright (c) 2012 Technische Universitaet Muenchen 19 | * Markus W. Weissmann 20 | * All rights reserved. *) 21 | 22 | (** Edge contraction for directed, edge-labeled graphs *) 23 | 24 | (* This algorithm should be extensible to undirected, unlabeled graphs! *) 25 | 26 | (** Minimal graph signature for edge contraction algorithm *) 27 | module type G = sig 28 | type t 29 | module V : Sig.COMPARABLE 30 | type vertex = V.t 31 | module E : Sig.EDGE with type vertex = vertex 32 | type edge = E.t 33 | 34 | val empty : t 35 | val add_edge_e : t -> edge -> t 36 | val fold_edges_e : (edge -> 'a -> 'a) -> t -> 'a -> 'a 37 | val fold_vertex : (vertex -> 'a -> 'a) -> t -> 'a -> 'a 38 | end 39 | 40 | module Make 41 | (G : G) : 42 | sig 43 | module S : Set.S with type elt = G.vertex 44 | module M : Map.S with type key = G.vertex 45 | 46 | val contract : (G.E.t -> bool) -> G.t -> G.t 47 | (** [contract p g] will perform edge contraction on the graph [g]. 48 | The edges for which the property [p] holds/is true will get contracted: 49 | The resulting graph will not have these edges; the start- and end-node 50 | of these edges will get united. The result graph does not include nodes 51 | with no incoming or outgoing edges. *) 52 | 53 | (** As for {!contract} but additionally returns a mapping that associates 54 | each node in the original graph to the set of nodes with which it is 55 | contracted in the result graph. The minimum element of each such set 56 | is used as the representative of the set in the result graph. Nodes 57 | with no incoming or outgoing edges are present in the mapping even if 58 | they are omitted from the result graph. *) 59 | val contract' : (G.E.t -> bool) -> G.t -> G.t * S.t M.t 60 | end 61 | 62 | -------------------------------------------------------------------------------- /src/dGraphRandModel.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* This file is part of OcamlGraph. *) 4 | (* *) 5 | (* Copyright (C) 2009-2010 *) 6 | (* CEA (Commissariat � l'�nergie Atomique) *) 7 | (* *) 8 | (* you can redistribute it and/or modify it under the terms of the GNU *) 9 | (* Lesser General Public License as published by the Free Software *) 10 | (* Foundation, version 2.1, with a linking exception. *) 11 | (* *) 12 | (* It is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) 15 | (* GNU Lesser General Public License for more details. *) 16 | (* *) 17 | (* See the file ../LICENSE for more details. *) 18 | (* *) 19 | (* Authors: *) 20 | (* - Julien Signoles (Julien.Signoles@cea.fr) *) 21 | (* - Jean-Denis Koeck (jdkoeck@gmail.com) *) 22 | (* - Benoit Bataille (benoit.bataille@gmail.com) *) 23 | (* *) 24 | (**************************************************************************) 25 | 26 | let element = function 27 | | [] -> invalid_arg "empty list in element" 28 | | l -> 29 | Random.self_init (); 30 | List.nth l (Random.int (List.length l)) 31 | 32 | let black = 0x000000 33 | and white = 0xFFFFFF 34 | and red = 0xFF0000 35 | and green = 0x00FF00 36 | and blue = 0x0000FF 37 | and yellow = 0xFFFF00 38 | and cyan = 0x00FFFF 39 | and magenta = 0xFF00FF 40 | 41 | module Vertex = struct 42 | type t = int 43 | end 44 | 45 | module Edge = struct 46 | type t = int 47 | let compare : int -> int -> int = Stdlib.compare 48 | let default = 0 49 | end 50 | 51 | module G = Imperative.Digraph.AbstractLabeled(Vertex)(Edge) 52 | module R = Rand.I(G) 53 | 54 | module GraphAttrs = struct 55 | include G 56 | let graph_attributes _ = [] 57 | let default_vertex_attributes _ = [] 58 | let vertex_name v = string_of_int (G.V.label v) 59 | let vertex_attributes _ = 60 | let shape = element [`Ellipse; `Box; `Circle; `Doublecircle; `Diamond] in 61 | let color = element [black; white; red; green; blue; yellow; cyan; magenta] in 62 | [`Shape shape; `Color color] 63 | let default_edge_attributes _ = [] 64 | let edge_attributes _ = [] 65 | let get_subgraph _ = None 66 | end 67 | 68 | module Model = DGraphModel.Make(GraphAttrs) 69 | 70 | let create () = 71 | (* State *) 72 | Random.self_init (); 73 | let v = 100 in 74 | let e = Random.int (v*2) in 75 | let g = R.graph ~loops:true ~v ~e () in 76 | Model.from_graph g 77 | -------------------------------------------------------------------------------- /src/dGraphRandModel.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* This file is part of OcamlGraph. *) 4 | (* *) 5 | (* Copyright (C) 2009-2010 *) 6 | (* CEA (Commissariat � l'�nergie Atomique) *) 7 | (* *) 8 | (* you can redistribute it and/or modify it under the terms of the GNU *) 9 | (* Lesser General Public License as published by the Free Software *) 10 | (* Foundation, version 2.1, with a linking exception. *) 11 | (* *) 12 | (* It is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) 15 | (* GNU Lesser General Public License for more details. *) 16 | (* *) 17 | (* See the file ../LICENSE for more details. *) 18 | (* *) 19 | (* Authors: *) 20 | (* - Julien Signoles (Julien.Signoles@cea.fr) *) 21 | (* - Jean-Denis Koeck (jdkoeck@gmail.com) *) 22 | (* - Benoit Bataille (benoit.bataille@gmail.com) *) 23 | (* *) 24 | (**************************************************************************) 25 | 26 | module G: Sig.G 27 | 28 | module GraphAttrs: 29 | Graphviz.GraphWithDotAttrs with type t = G.t 30 | and type V.t = G.V.t 31 | and type E.t = G.E.t 32 | 33 | val create: unit -> DGraphModel.Make(GraphAttrs).model 34 | -------------------------------------------------------------------------------- /src/dGraphTreeLayout.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* This file is part of OcamlGraph. *) 4 | (* *) 5 | (* Copyright (C) 2009-2010 *) 6 | (* CEA (Commissariat � l'�nergie Atomique) *) 7 | (* *) 8 | (* you can redistribute it and/or modify it under the terms of the GNU *) 9 | (* Lesser General Public License as published by the Free Software *) 10 | (* Foundation, version 2.1, with a linking exception. *) 11 | (* *) 12 | (* It is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) 15 | (* GNU Lesser General Public License for more details. *) 16 | (* *) 17 | (* See the file ../LICENSE for more details. *) 18 | (* *) 19 | (* Authors: *) 20 | (* - Julien Signoles (Julien.Signoles@cea.fr) *) 21 | (* - Jean-Denis Koeck (jdkoeck@gmail.com) *) 22 | (* - Benoit Bataille (benoit.bataille@gmail.com) *) 23 | (* *) 24 | (**************************************************************************) 25 | 26 | type cluster = string 27 | 28 | module Make 29 | (Tree: Graphviz.GraphWithDotAttrs) 30 | (TreeManipulation: sig val is_ghost_node: Tree.V.t -> bool end): 31 | sig 32 | 33 | val from_tree: 34 | fontMeasure:( 35 | fontName:string -> fontSize:int -> string -> int * int 36 | ) -> Tree.t -> Tree.V.t -> XDot.Make(Tree).graph_layout 37 | 38 | end 39 | 40 | module MakeFromDotModel 41 | (Tree : Sig.G with type V.label = DGraphModel.DotG.V.t 42 | and type E.label = unit) 43 | (TreeManipulation: sig val is_ghost_node: Tree.V.t -> bool end): 44 | sig 45 | 46 | module Tree: Graphviz.GraphWithDotAttrs with module V = Tree.V 47 | and module E = Tree.E 48 | and type t = Tree.t 49 | 50 | val from_model: 51 | Tree.t -> Tree.V.t -> DGraphModel.dotg_model -> XDot.Make(Tree).graph_layout 52 | 53 | end 54 | -------------------------------------------------------------------------------- /src/dGraphTreeModel.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* This file is part of OcamlGraph. *) 4 | (* *) 5 | (* Copyright (C) 2009-2010 *) 6 | (* CEA (Commissariat � l'�nergie Atomique) *) 7 | (* *) 8 | (* you can redistribute it and/or modify it under the terms of the GNU *) 9 | (* Lesser General Public License as published by the Free Software *) 10 | (* Foundation, version 2.1, with a linking exception. *) 11 | (* *) 12 | (* It is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) 15 | (* GNU Lesser General Public License for more details. *) 16 | (* *) 17 | (* See the file ../LICENSE for more details. *) 18 | (* *) 19 | (* Authors: *) 20 | (* - Julien Signoles (Julien.Signoles@cea.fr) *) 21 | (* - Jean-Denis Koeck (jdkoeck@gmail.com) *) 22 | (* - Benoit Bataille (benoit.bataille@gmail.com) *) 23 | (* *) 24 | (**************************************************************************) 25 | 26 | module type S = sig 27 | 28 | module Tree: Graphviz.GraphWithDotAttrs 29 | 30 | module TreeManipulation : sig 31 | type t 32 | val get_structure : t -> Tree.t 33 | val get_tree_vertices : Tree.V.label -> t -> Tree.V.t list 34 | val get_graph_vertex : Tree.V.t -> t -> Tree.V.label 35 | val is_ghost_node : Tree.V.t -> t -> bool 36 | val is_ghost_edge : Tree.E.t -> t -> bool 37 | end 38 | 39 | type cluster = string 40 | type graph_layout 41 | 42 | class tree_model : 43 | graph_layout -> 44 | TreeManipulation.t -> 45 | [ Tree.V.t, Tree.E.t, cluster ] DGraphModel.abstract_model 46 | 47 | val tree : unit -> TreeManipulation.t 48 | 49 | end 50 | 51 | (** This functor creates a model centered on a vertex from a graph *) 52 | module SubTreeMake(G : Graphviz.GraphWithDotAttrs) : sig 53 | 54 | include S with type Tree.V.label = G.V.t 55 | 56 | val from_graph : 57 | ?depth_forward:int -> ?depth_backward:int -> 58 | fontMeasure:( 59 | fontName:string -> fontSize:int -> string -> int * int 60 | ) -> G.t -> G.V.t -> tree_model 61 | 62 | end 63 | 64 | (** Creates a model centered on a vertex from a dot model *) 65 | module SubTreeDotModelMake : sig 66 | 67 | include S with type Tree.V.label = DGraphModel.DotG.V.t 68 | 69 | val from_model : 70 | ?depth_forward:int -> ?depth_backward:int 71 | -> DGraphModel.dotg_model 72 | -> DGraphModel.DotG.V.t 73 | -> tree_model 74 | 75 | end 76 | -------------------------------------------------------------------------------- /src/dot.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Parser for DOT file format. *) 19 | 20 | open Dot_ast 21 | 22 | val parse_dot_ast : string -> Dot_ast.file 23 | 24 | type clusters_hash = (string, attr list) Hashtbl.t 25 | 26 | (** Provide a parser for DOT file format. *) 27 | module Parse 28 | (B : Builder.S) 29 | (L : sig 30 | val node : node_id -> attr list -> B.G.V.label 31 | (** How to build the node label out of the set of attributes *) 32 | 33 | val edge : attr list -> B.G.E.label 34 | (** How to build the edge label out of the set of attributes *) 35 | 36 | end) : 37 | sig 38 | 39 | (** Parses a dot file *) 40 | val parse : string -> B.G.t 41 | 42 | (** Parses a dot file and returns the graph, its bounding box and 43 | a hash table from clusters to dot attributes *) 44 | val parse_bounding_box_and_clusters : 45 | string -> B.G.t * string * clusters_hash 46 | 47 | end 48 | -------------------------------------------------------------------------------- /src/dot_ast.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* $Id:$ *) 19 | 20 | (** AST for DOT file format. *) 21 | 22 | type id = 23 | | Ident of string 24 | | Number of string 25 | | String of string 26 | | Html of string 27 | 28 | type attr = (id * id option) list 29 | 30 | type compass_pt = N | Ne | E | Se | S | Sw | W | Nw 31 | 32 | type port = 33 | | PortId of id * compass_pt option 34 | | PortC of compass_pt 35 | 36 | type node_id = id * port option 37 | 38 | type subgraph = 39 | | SubgraphId of id 40 | | SubgraphDef of id option * stmt list 41 | 42 | and node = 43 | | NodeId of node_id 44 | | NodeSub of subgraph 45 | 46 | and stmt = 47 | | Node_stmt of node_id * attr list 48 | | Edge_stmt of node * node list * attr list 49 | | Attr_graph of attr list 50 | | Attr_node of attr list 51 | | Attr_edge of attr list 52 | | Equal of id * id 53 | | Subgraph of subgraph 54 | 55 | type file = 56 | { strict : bool; 57 | digraph : bool; 58 | id : id option; 59 | stmts : stmt list } 60 | -------------------------------------------------------------------------------- /src/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs unqualified) 2 | 3 | (library 4 | (name graph) 5 | (public_name ocamlgraph) 6 | (modules_without_implementation dot_ast sig sig_pack)) 7 | 8 | (ocamlyacc dot_parser) 9 | 10 | (ocamllex gml dot_lexer) 11 | -------------------------------------------------------------------------------- /src/eulerian.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Eulerian path 19 | 20 | This module implements Hierholzer's algorithm, with O(E) complexity 21 | where E is the number of edges. 22 | 23 | Limitations: 24 | - multigraphs are not supported 25 | *) 26 | 27 | module type G = sig 28 | type t 29 | val is_directed : bool 30 | module V : Sig.COMPARABLE 31 | module E : Sig.EDGE with type vertex = V.t 32 | val iter_edges_e : (E.t -> unit) -> t -> unit 33 | end 34 | 35 | module Make(G: G) : sig 36 | 37 | val path: G.t -> G.E.t list * bool 38 | (** [path g] returns an Eulerian path of [g]. The Boolean indicates 39 | whether the path is a cycle. Raises [Invalid_argument] if there 40 | is no Eulerian path. *) 41 | 42 | val cycle: G.t -> G.E.t list 43 | (** [cycle g] returns an Eulerian cycle of [g]. 44 | Raises [Invalid_argument] if there is no Eulerian cycle. *) 45 | 46 | end 47 | -------------------------------------------------------------------------------- /src/gmap.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Graph mapping. Map a graph to another one. *) 19 | 20 | (** {2 Mapping of vertices} *) 21 | 22 | (** Signature for the source graph. *) 23 | module type V_SRC = sig 24 | type t 25 | module V : Sig.HASHABLE 26 | val fold_vertex : (V.t -> 'a -> 'a) -> t -> 'a -> 'a 27 | end 28 | 29 | (** Signature for the destination graph. *) 30 | module type V_DST = sig 31 | type t 32 | type vertex 33 | val empty : unit -> t 34 | val add_vertex : t -> vertex -> t 35 | end 36 | 37 | (** Provide a mapping function from a mapping of vertices. *) 38 | module Vertex(G_Src : V_SRC)(G_Dst : V_DST) : sig 39 | 40 | val map : (G_Src.V.t -> G_Dst.vertex) -> G_Src.t -> G_Dst.t 41 | (** [map f g] applies [f] to each vertex of [g] and so builds a new graph 42 | based on [g] *) 43 | 44 | val filter_map : (G_Src.V.t -> G_Dst.vertex option) -> G_Src.t -> G_Dst.t 45 | (** [filter_map f g] applies [f] to each vertex of [g] and so 46 | builds a new graph based on [g]; if [None] is returned by [f] 47 | the vertex is omitted in the new graph. *) 48 | 49 | end 50 | 51 | (** {2 Mapping of edges} *) 52 | 53 | (** Signature for the source graph. *) 54 | module type E_SRC = sig 55 | type t 56 | module E : Sig.ORDERED_TYPE 57 | val fold_edges_e : (E.t -> 'a -> 'a) -> t -> 'a -> 'a 58 | end 59 | 60 | (** Signature for the destination graph. *) 61 | module type E_DST = sig 62 | type t 63 | type edge 64 | val empty : unit -> t 65 | val add_edge_e : t -> edge -> t 66 | end 67 | 68 | (** Provide a mapping function from a mapping of edges. *) 69 | module Edge(G_Src: E_SRC)(G_Dst: E_DST) : sig 70 | 71 | val map : (G_Src.E.t -> G_Dst.edge) -> G_Src.t -> G_Dst.t 72 | (** [map f g] applies [f] to each edge of [g] and so builds a new graph 73 | based on [g] *) 74 | 75 | val filter_map : (G_Src.E.t -> G_Dst.edge option) -> G_Src.t -> G_Dst.t 76 | (** [filter_map f g] applies [f] to each edge of [g] and so builds 77 | a new graph based on [g]; if [None] is returned by [f] the 78 | edge is omitted in the new graph. *) 79 | 80 | end 81 | -------------------------------------------------------------------------------- /src/gml.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* $Id: gml.mli,v 1.3 2005-07-06 13:20:31 conchon Exp $ *) 19 | 20 | (** Parser and pretty-printer for GML file format. *) 21 | 22 | type value = 23 | | Int of int 24 | | Float of float 25 | | String of string 26 | | List of value_list 27 | 28 | and value_list = (string * value) list 29 | 30 | (** {2 Parser} *) 31 | 32 | (** Provide a parser for GML file format. *) 33 | module Parse 34 | (B : Builder.S) 35 | (L : sig 36 | val node : value_list -> B.G.V.label 37 | (** How to build the node label out of the set of GML attributes. 38 | For example {v node [ id 12 label "foo" ] v} will call this 39 | function with [["id", Int 12; "label", String "foo"]] *) 40 | 41 | val edge : value_list -> B.G.E.label 42 | (** How to build the edge label out of the set of GML attributes *) 43 | end) : 44 | sig 45 | val parse : string -> B.G.t 46 | end 47 | 48 | (** {2 Pretty-printer} *) 49 | 50 | (** Signature for graph required by {!Print}. 51 | Sub-signature of {!Sig.G}. *) 52 | module type G = sig 53 | module V : sig 54 | type t 55 | val hash : t -> int 56 | val equal : t -> t -> bool 57 | type label 58 | val label : t -> label 59 | end 60 | module E : sig 61 | type t 62 | type label 63 | val src : t -> V.t 64 | val dst : t -> V.t 65 | val label : t -> label 66 | end 67 | type t 68 | val iter_vertex : (V.t -> unit) -> t -> unit 69 | val iter_edges_e : (E.t -> unit) -> t -> unit 70 | end 71 | 72 | (** Provide a pretty-printer for GML file format. *) 73 | module Print 74 | (G: G) 75 | (L: sig 76 | val node : G.V.label -> value_list 77 | val edge : G.E.label -> value_list 78 | end) : 79 | sig 80 | val print : Format.formatter -> G.t -> unit 81 | end 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/graph.ml: -------------------------------------------------------------------------------- 1 | module Sig = Sig 2 | module Sig_pack = Sig_pack 3 | module Dot_ast = Dot_ast 4 | module Util = Util 5 | module Blocks = Blocks 6 | module Persistent = Persistent 7 | module Imperative = Imperative 8 | module Delaunay = Delaunay 9 | module Builder = Builder 10 | module Classic = Classic 11 | module Rand = Rand 12 | module Oper = Oper 13 | module Components = Components 14 | module Path = Path 15 | module Cycles = Cycles 16 | module Nonnegative = Nonnegative 17 | module Traverse = Traverse 18 | module Coloring = Coloring 19 | module Topological = Topological 20 | module Kruskal = Kruskal 21 | module Flow = Flow 22 | module Prim = Prim 23 | module Dominator = Dominator 24 | module Graphviz = Graphviz 25 | module Gml = Gml 26 | module Dot = Dot 27 | module Pack = Pack 28 | module Gmap = Gmap 29 | module Minsep = Minsep 30 | module Cliquetree = Cliquetree 31 | module Mcs_m = Mcs_m 32 | module Md = Md 33 | module Strat = Strat 34 | module Fixpoint = Fixpoint 35 | module Leaderlist = Leaderlist 36 | module Contraction = Contraction 37 | module Graphml = Graphml 38 | module Merge = Merge 39 | module Mincut = Mincut 40 | module Clique = Clique 41 | module WeakTopological = WeakTopological 42 | module ChaoticIteration = ChaoticIteration 43 | module XDotDraw = XDotDraw 44 | module XDot = XDot 45 | module DGraphModel = DGraphModel 46 | module DGraphTreeLayout = DGraphTreeLayout 47 | module DGraphSubTree = DGraphSubTree 48 | module DGraphTreeModel = DGraphTreeModel 49 | module DGraphRandModel = DGraphRandModel 50 | -------------------------------------------------------------------------------- /src/graphml.mli: -------------------------------------------------------------------------------- 1 | (******************************************************************************) 2 | (* *) 3 | (* Copyright (C) 2012 Pietro Abate *) 4 | (* *) 5 | (* This library is free software: you can redistribute it and/or modify *) 6 | (* it under the terms of the GNU Lesser General Public License as *) 7 | (* published by the Free Software Foundation, either version 3 of the *) 8 | (* License, or (at your option) any later version. A special linking *) 9 | (* exception to the GNU Lesser General Public License applies to this *) 10 | (* library, see the COPYING file for more information. *) 11 | (* *) 12 | (******************************************************************************) 13 | 14 | (** Generic GraphMl Printer *) 15 | 16 | (** Graph information required by Graphml *) 17 | module type G = sig 18 | 19 | type t 20 | type vertex 21 | module E : sig 22 | type t 23 | val src: t -> vertex 24 | val dst : t -> vertex 25 | end 26 | val is_directed : bool 27 | val iter_vertex : (vertex -> unit) -> t -> unit 28 | val iter_edges_e : (E.t -> unit) -> t -> unit 29 | 30 | end 31 | 32 | (** Graphml Printer given a graph and required info *) 33 | module Print 34 | (G: G) 35 | (L : sig 36 | val vertex_properties : (string * string * string option) list 37 | (** List of the type of the vertex proprierties. 38 | The format is (id,type,default). *) 39 | 40 | val edge_properties : (string * string * string option) list 41 | (** List of the type of the edge proprierties. *) 42 | 43 | val map_vertex : G.vertex -> (string * string) list 44 | (** Associates to each vertex a key/value list where 45 | the key is the id of a vertex attribute and the value is the value 46 | associated to this vertex *) 47 | 48 | val map_edge : G.E.t -> (string * string) list 49 | (** Associates to each edge a key/value list *) 50 | 51 | val vertex_uid : G.vertex -> int 52 | (** @return a unique integer identifier for the vertex *) 53 | 54 | val edge_uid : G.E.t -> int 55 | (** @return a unique integer identifier for the edge *) 56 | end) : 57 | sig 58 | val print : Format.formatter -> G.t -> unit 59 | (** [print fmt graph] print the GraphMl representation of the given graph 60 | on the given formatter *) 61 | end 62 | 63 | 64 | (* 65 | Local Variables: 66 | compile-command: "make -C .." 67 | End: 68 | *) 69 | -------------------------------------------------------------------------------- /src/kruskal.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* $Id: kruskal.ml,v 1.5 2005-06-30 10:48:55 filliatr Exp $ *) 19 | 20 | module type UNIONFIND = sig 21 | type elt 22 | type t 23 | val init : elt list -> t 24 | val find : elt -> t -> elt 25 | val union : elt -> elt -> t -> unit 26 | end 27 | 28 | module type G = sig 29 | type t 30 | module V : Sig.COMPARABLE 31 | module E : sig 32 | type t 33 | type label 34 | val label : t -> label 35 | val dst : t -> V.t 36 | val src : t -> V.t 37 | end 38 | val fold_vertex : (V.t -> 'a -> 'a) -> t -> 'a -> 'a 39 | val iter_edges_e : (E.t -> unit) -> t -> unit 40 | end 41 | 42 | module Generic 43 | (G: G) 44 | (W : Sig.ORDERED_TYPE with type t = G.E.label) 45 | (UF: UNIONFIND with type elt = G.V.t) = 46 | struct 47 | 48 | let spanningtree g = 49 | let vertices = G.fold_vertex (fun v a -> v :: a) g [] in 50 | let uf = UF.init vertices in 51 | let edges = 52 | let l = ref [] in 53 | G.iter_edges_e (fun e -> l := e :: !l) g; 54 | List.sort (fun e e'-> W.compare (G.E.label e) (G.E.label e')) !l 55 | in 56 | let s = ref [] in 57 | let cover e = 58 | let u, v = G.E.src e, G.E.dst e in 59 | if G.V.compare (UF.find u uf) (UF.find v uf) <> 0 then begin 60 | UF.union u v uf; 61 | s := e :: !s 62 | end 63 | in 64 | List.iter cover edges; 65 | !s 66 | 67 | end 68 | 69 | module Make(G: G)(W : Sig.ORDERED_TYPE with type t=G.E.label) = 70 | Generic(G)(W)(Unionfind.Make(G.V)) 71 | 72 | -------------------------------------------------------------------------------- /src/kruskal.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* $Id: kruskal.mli,v 1.5 2005-06-30 10:48:55 filliatr Exp $ *) 19 | 20 | (** Kruskal's minimum-spanning-tree algorithm. *) 21 | 22 | (** Minimal graph signature for Kruskal. 23 | Sub-signature of {!Sig.G}. *) 24 | module type G = sig 25 | type t 26 | module V : Sig.COMPARABLE 27 | module E : sig 28 | type t 29 | type label 30 | val label : t -> label 31 | val dst : t -> V.t 32 | val src : t -> V.t 33 | end 34 | val fold_vertex : (V.t -> 'a -> 'a) -> t -> 'a -> 'a 35 | val iter_edges_e : (E.t -> unit) -> t -> unit 36 | end 37 | 38 | (** Functor providing an implementation of Kruskal's minimum-spanning-tree 39 | algorithm. 40 | Parameter [W] ensures that label on edges are comparable. *) 41 | module Make(G: G)(W: Sig.ORDERED_TYPE with type t = G.E.label) : sig 42 | val spanningtree : G.t -> G.E.t list 43 | end 44 | 45 | (** {2 Generic version where union-find implementation is provided} *) 46 | 47 | (** Signature of union-find. *) 48 | module type UNIONFIND = sig 49 | type elt 50 | type t 51 | val init : elt list -> t 52 | val find : elt -> t -> elt 53 | val union : elt -> elt -> t -> unit 54 | end 55 | 56 | (** Functor providing an implementation of Kruskal's minimum-spanning-tree 57 | algorithm using a user-defined union-find algorithm. 58 | Parameter [W] ensures that label on edges are comparable. *) 59 | module Generic 60 | (G: G) 61 | (W: Sig.ORDERED_TYPE with type t = G.E.label) 62 | (UF: UNIONFIND with type elt = G.V.t) : 63 | sig 64 | val spanningtree : G.t -> G.E.t list 65 | end 66 | -------------------------------------------------------------------------------- /src/leaderlist.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* Copyright (c) 2010 - 2011 Technische Universitaet Muenchen 19 | * Markus W. Weissmann 20 | * Florian Pichlmeier 21 | * All rights reserved. *) 22 | 23 | (** The leader list algorithm; it generates a list of basic blocks from 24 | a directed graph. A basic block is a forward path of nodes that requires 25 | neither branching from nor into. 26 | *) 27 | 28 | (** Minimal graph signature for leader list algorithm *) 29 | module type G = sig 30 | type t 31 | module V : Sig.COMPARABLE 32 | val fold_vertex : (V.t -> 'a -> 'a) -> t -> 'a -> 'a 33 | val succ : t -> V.t -> V.t list 34 | val pred : t -> V.t -> V.t list 35 | end 36 | 37 | module Make 38 | (G : G) : 39 | sig 40 | val leader_lists : G.t -> G.V.t -> G.V.t list list 41 | (** [leader_lists graph root] computes the leader lists or basic blocks 42 | of the given graph. The node [root] is always a leader of a basic block. *) 43 | end 44 | -------------------------------------------------------------------------------- /src/lib/deque.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Double-ended queue *) 19 | 20 | type 'a t 21 | 22 | val create: unit -> 'a t 23 | val length: 'a t -> int 24 | 25 | val clear: 'a t -> unit 26 | 27 | val push_front: 'a t -> 'a -> unit 28 | val peek_front: 'a t -> 'a 29 | val pop_front: 'a t -> 'a 30 | 31 | val push_back: 'a t -> 'a -> unit 32 | val peek_back: 'a t -> 'a 33 | val pop_back: 'a t -> 'a 34 | -------------------------------------------------------------------------------- /src/lib/heap.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Priority queues *) 19 | 20 | module type Ordered = sig 21 | type t 22 | val compare : t -> t -> int 23 | end 24 | 25 | exception EmptyHeap 26 | 27 | module Imperative(X: Ordered) : sig 28 | 29 | (* Type of imperative heaps. 30 | (In the following [n] refers to the number of elements in the heap) *) 31 | 32 | type t 33 | 34 | (* [create c] creates a new heap, with initial capacity of [c] *) 35 | val create : int -> t 36 | 37 | (* [is_empty h] checks the emptiness of [h] *) 38 | val is_empty : t -> bool 39 | 40 | (* [add x h] adds a new element [x] in heap [h]; size of [h] is doubled 41 | when maximum capacity is reached; complexity $O(log(n))$ *) 42 | val add : t -> X.t -> unit 43 | 44 | (* [maximum h] returns the maximum element of [h]; raises [EmptyHeap] 45 | when [h] is empty; complexity $O(1)$ *) 46 | val maximum : t -> X.t 47 | 48 | (* [remove h] removes the maximum element of [h]; raises [EmptyHeap] 49 | when [h] is empty; complexity $O(log(n))$ *) 50 | val remove : t -> unit 51 | 52 | (* [pop_maximum h] removes the maximum element of [h] and returns it; 53 | raises [EmptyHeap] when [h] is empty; complexity $O(log(n))$ *) 54 | val pop_maximum : t -> X.t 55 | 56 | (* usual iterators and combinators; elements are presented in 57 | arbitrary order *) 58 | val iter : (X.t -> unit) -> t -> unit 59 | 60 | val fold : (X.t -> 'a -> 'a) -> t -> 'a -> 'a 61 | 62 | end 63 | 64 | -------------------------------------------------------------------------------- /src/lib/persistentQueue.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Purely applicative queues implemented in a standard way 19 | using a pair of lists (Hood & Melville 1981) *) 20 | 21 | type 'a t = 'a list * 'a list 22 | (** a queue is a pair (prefix, xiffus), with elements popped from prefix 23 | and inserted into xiffus 24 | invariant: prefix=[] -> xiffus=[] *) 25 | 26 | let empty = [], [] 27 | 28 | let is_empty (prefix, _) = 29 | prefix = [] 30 | 31 | let add queue elt = match queue with 32 | | [], [] -> [elt], [] 33 | | prefix, xiffus -> prefix, elt :: xiffus 34 | 35 | let head = function 36 | | head :: _, _-> head 37 | | [], _ -> raise Not_found 38 | 39 | let tail = function 40 | | [_], xiffus -> List.rev xiffus, [] 41 | | _ :: prefix, xiffus -> prefix, xiffus 42 | | [], _ -> raise Not_found 43 | -------------------------------------------------------------------------------- /src/lib/persistentQueue.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Purely applicative queues *) 19 | 20 | type 'a t 21 | val empty : 'a t 22 | val is_empty : 'a t -> bool 23 | val add : 'a t -> 'a -> 'a t 24 | val head : 'a t -> 'a 25 | val tail : 'a t -> 'a t 26 | -------------------------------------------------------------------------------- /src/lib/unionfind.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | 19 | 20 | (* Unionfind structure over hash-ordered types. 21 | 22 | This module implements a unionfind data structure, given a total ordering 23 | function and a hash function over the elements. 24 | 25 | *) 26 | 27 | 28 | module type HashedOrderedType = sig 29 | (* The type of the elements*) 30 | type t 31 | val equal : t -> t -> bool 32 | val hash : t -> int 33 | val compare : t -> t -> int 34 | end 35 | 36 | (* Input signature of the functor Unionfind.Make *) 37 | 38 | module type S = sig 39 | type elt 40 | type t 41 | 42 | val init : elt list -> t 43 | val find : elt -> t -> elt 44 | val union : elt -> elt -> t -> unit 45 | end 46 | 47 | module Make (X : HashedOrderedType) : S with type elt = X.t 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/mcs_m.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* $Id: mcs_m.mli,v 1.2 2004-10-19 15:21:44 signoles Exp $ *) 19 | 20 | (** Maximal Cardinality Search (MCS-M) algorithm 21 | 22 | Based on the article: 23 | Maximal Cardinality Search for Computing Minimal Triangulations of Graphs. 24 | by A. Berry, Jean R. S. Blair, Pinar Heggernes & Barry W. Peyton. 25 | 26 | @author Matthieu Sozeau 27 | @author Pierre-Loic Garoche *) 28 | 29 | module MaximalCardinalitySearch : sig 30 | module P(G : Sig.P) : sig 31 | type edgelist = (G.V.t * G.V.t) list 32 | 33 | (** [mcsm g] returns a tuple [(o, e)] where [o] is a perfect elimination 34 | order of [g'] where [g'] is the triangulation [e] applied to [g]. *) 35 | val mcsm : G.t -> (int * G.V.t) list * edgelist 36 | 37 | (** [triangulate g] computes a triangulation of [g] 38 | using the MCS-M algorithm *) 39 | val triangulate : G.t -> G.t 40 | end 41 | module I(Gr : Sig.I) : sig 42 | type edgelist = (Gr.V.t * Gr.V.t) list 43 | 44 | (** [mcsm g] return a tuple [(o, e)] where o is a perfect elimination order 45 | of [g'] where [g'] is the triangulation [e] applied to [g]. *) 46 | val mcsm : Gr.t -> (int * Gr.V.t) list * edgelist 47 | 48 | (** [triangulate g] triangulates [g] using the MCS-M algorithm *) 49 | val triangulate : Gr.t -> unit 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /src/md.mli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backtracking/ocamlgraph/89ab6d98c551a99f17fb6062c9a4c13a2b3f6ebc/src/md.mli -------------------------------------------------------------------------------- /src/mincut.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2013-2014 *) 5 | (* David Monniaux, Gabriel Radanne *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Minimal cutset of a graph 19 | 20 | Compute a minimal vertex cutset of a reducible oriented graph. 21 | The set [S] of vertices is a cutset of [G] if [G \ S] doesn't 22 | contain any cycle. 23 | 24 | Based on the article: A linear time algorithm for finding minimum 25 | cutsets in reducible graphs by A. Shamir (1979). 26 | *) 27 | 28 | (** Minimal signature for computing the minimal separators *) 29 | module type G = sig 30 | type t 31 | module V : Sig.VERTEX 32 | val succ : t -> V.t -> V.t list 33 | end 34 | 35 | module Make (G : G) : sig 36 | 37 | (** Find a minimal cutset. 38 | @raise Invalid_argument if the graph is not reducible. 39 | *) 40 | val min_cutset : G.t -> G.V.t -> G.V.t list 41 | 42 | end 43 | -------------------------------------------------------------------------------- /src/minsep.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** 19 | Minimal separators of a graph 20 | 21 | Based on the article: 22 | Generating all the minimal separators of a graph. 23 | by A. Berry, J.-P. Bordat and O.Cogis 24 | http://www.isima.fr/berry/generating.html 25 | 26 | A set [S] of vertices is a minimal separator if it exists 2 distinct 27 | connected components [C] and [D] in [G \ S] such that each vertex of [S] has 28 | a successor in [C] and [D]. *) 29 | 30 | (** Minimal signature for computing the minimal separators *) 31 | module type G = sig 32 | type t 33 | module V : Sig.COMPARABLE 34 | val succ: t -> V.t -> V.t list 35 | val iter_succ: (V.t -> unit) -> t -> V.t -> unit 36 | val fold_succ: (V.t -> 'a -> 'a) -> t -> V.t -> 'a -> 'a 37 | val iter_vertex: (V.t -> unit) -> t -> unit 38 | val fold_vertex: (V.t -> 'a -> 'a) -> t -> 'a -> 'a 39 | end 40 | 41 | module type MINSEP = sig 42 | module G : G 43 | (** Implementation of a graph *) 44 | 45 | module Vertex_Set : Set.S with type elt = G.V.t 46 | (** Implementation of a set of vertex *) 47 | 48 | module VSetset : Set.S with type elt = Vertex_Set.t 49 | (** Implementation of a set of [Vertex_Set] *) 50 | 51 | val allminsep : G.t -> Vertex_Set.t list 52 | (** [allminsep g] computes the list of all minimal separators of g. *) 53 | 54 | val list_of_allminsep : G.t -> G.V.t list list 55 | (** Less efficient that [allminsep] *) 56 | 57 | val set_of_allminsep : G.t -> VSetset.t 58 | (** Less efficient that [allminsep] *) 59 | end 60 | 61 | (** Implementation for a persistent graph *) 62 | module P(G : sig include G val remove_vertex : t -> V.t -> t end) : 63 | MINSEP with module G = G 64 | 65 | (** Implementation for an imperative graph. 66 | Less efficient that the implementation for a persistent graph *) 67 | module I(G : sig 68 | include G 69 | module Mark : Sig.MARK with type graph = t and type vertex = V.t 70 | end) : 71 | MINSEP with module G = G 72 | 73 | -------------------------------------------------------------------------------- /src/nonnegative.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* This module is a contribution of Yuto Takei *) 19 | 20 | (** Weighted graphs without negative-cycles. *) 21 | 22 | (** This graph maintains the invariant that it is free of such cycles that 23 | the total length of edges involving is negative. With introduction of 24 | those negative-cycles causes an inability to compute the shortest paths 25 | from arbitrary vertex. By using the graph modules defined here, 26 | introduction of such a cycle is automatically prevented. *) 27 | 28 | module Imperative 29 | (G: Sig.IM) 30 | (W: Sig.WEIGHT with type edge = G.E.t) : sig 31 | 32 | include Sig.IM with module V = G.V and module E = G.E 33 | 34 | exception Negative_cycle of G.E.t list 35 | 36 | end 37 | 38 | 39 | (** Persistent graphs with negative-cycle prevention *) 40 | module Persistent 41 | (G: Sig.P) 42 | (W: Sig.WEIGHT with type edge = G.E.t) : sig 43 | 44 | include Sig.P with module V = G.V and module E = G.E 45 | 46 | exception Negative_cycle of G.E.t list 47 | (** Exception [NegativeCycle] is raised whenever a negative cycle 48 | is introduced for the first time (either with [add_edge] 49 | or [add_edge_e]) *) 50 | 51 | end 52 | -------------------------------------------------------------------------------- /src/pack.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* $Id: pack.mli,v 1.1 2004-02-04 11:52:02 filliatr Exp $ *) 19 | 20 | (** {b Immediate access to the library}: provides implementation of imperative 21 | graphs labeled with integer as well as algorithms on such graphs. 22 | 23 | So if you bother functors, you can use this module. *) 24 | 25 | (** Directed imperative graphs with edges and vertices labeled with integer. *) 26 | module Digraph : Sig_pack.S 27 | 28 | (** Undirected imperative graphs with edges and vertices labeled with 29 | integer. *) 30 | module Graph : Sig_pack.S 31 | 32 | -------------------------------------------------------------------------------- /src/prim.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | module type G = sig 19 | type t 20 | module V : Sig.COMPARABLE 21 | module E : sig 22 | type t 23 | type label 24 | val label : t -> label 25 | val dst : t -> V.t 26 | val src : t -> V.t 27 | val compare : t -> t -> int 28 | end 29 | val iter_vertex : (V.t -> unit) -> t -> unit 30 | val iter_edges_e : (E.t -> unit) -> t -> unit 31 | val iter_succ_e : (E.t -> unit) -> t -> V.t -> unit 32 | end 33 | 34 | module Make 35 | (G: G) 36 | (W: Sig.WEIGHT with type edge = G.E.t) = 37 | struct 38 | open G.E 39 | module H = Hashtbl.Make(G.V) 40 | 41 | module Elt = struct 42 | type t = W.t * G.V.t 43 | 44 | (* weights are compared first, and minimal weights come first in the 45 | queue *) 46 | let compare (w1,v1) (w2,v2) = 47 | let cw = W.compare w2 w1 in 48 | if cw != 0 then cw else G.V.compare v1 v2 49 | end 50 | 51 | module Q = Heap.Imperative(Elt) 52 | 53 | let spanningtree_from g r = 54 | let visited = H.create 97 in 55 | let key = H.create 97 in 56 | let q = Q.create 17 in 57 | Q.add q (W.zero, r); 58 | while not (Q.is_empty q) do 59 | let (_,u) = Q.pop_maximum q in 60 | if not (H.mem visited u) then begin 61 | H.add visited u (); 62 | G.iter_succ_e (fun e -> 63 | let v = dst e in 64 | if not (H.mem visited v) then begin 65 | let wuv = W.weight e in 66 | let improvement = 67 | try W.compare wuv (fst (H.find key v)) < 0 with Not_found -> true 68 | in 69 | if improvement then begin 70 | H.replace key v (wuv, e); 71 | Q.add q (wuv, v) 72 | end; 73 | end) g u 74 | end 75 | done; 76 | H.fold (fun _ (_, e) acc -> e :: acc) key [] 77 | 78 | let spanningtree g = 79 | let r = ref None in 80 | try 81 | G.iter_vertex (fun v -> r := Some v; raise Exit) g; 82 | invalid_arg "spanningtree" 83 | with Exit -> 84 | match !r with 85 | | None -> assert false 86 | | Some r -> spanningtree_from g r 87 | 88 | end 89 | -------------------------------------------------------------------------------- /src/prim.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | module type G = sig 19 | type t 20 | module V : Sig.COMPARABLE 21 | module E : sig 22 | type t 23 | type label 24 | val label : t -> label 25 | val dst : t -> V.t 26 | val src : t -> V.t 27 | val compare : t -> t -> int 28 | end 29 | val iter_vertex : (V.t -> unit) -> t -> unit 30 | val iter_edges_e : (E.t -> unit) -> t -> unit 31 | val iter_succ_e : (E.t -> unit) -> t -> V.t -> unit 32 | end 33 | 34 | (** Functor providing an implementation of Prim's minimum-spanning-tree 35 | algorithm. 36 | Parameter [W] ensures that label on edges are comparable. *) 37 | module Make(G: G)(W: Sig.WEIGHT with type edge = G.E.t) : sig 38 | val spanningtree : G.t -> G.E.t list 39 | val spanningtree_from : G.t -> G.V.t -> G.E.t list 40 | end 41 | 42 | -------------------------------------------------------------------------------- /src/util.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | open Sig 19 | 20 | module OTProduct(X: ORDERED_TYPE)(Y: ORDERED_TYPE) = struct 21 | type t = X.t * Y.t 22 | let compare (x1, y1) (x2, y2) = 23 | let cv = X.compare x1 x2 in 24 | if cv != 0 then cv else Y.compare y1 y2 25 | end 26 | 27 | module HTProduct(X: HASHABLE)(Y: HASHABLE) = struct 28 | type t = X.t * Y.t 29 | let equal (x1, y1) (x2, y2) = X.equal x1 x2 && Y.equal y1 y2 30 | let hash (x, y) = Hashtbl.hash (X.hash x, Y.hash y) 31 | end 32 | 33 | module CMPProduct(X: COMPARABLE)(Y: COMPARABLE) = struct 34 | include HTProduct(X)(Y) 35 | include (OTProduct(X)(Y): sig val compare : t -> t -> int end) 36 | end 37 | 38 | module DataV(L : sig type t end)(V : Sig.COMPARABLE) = struct 39 | type data = L.t 40 | type label = V.t 41 | type t = data ref * V.t 42 | let compare (_, x) (_, x') = V.compare x x' 43 | let hash (_, x) = V.hash x 44 | let equal (_, x) (_, x') = V.equal x x' 45 | let create y lbl = (ref y, lbl) 46 | let label (_, z) = z 47 | let data (y, _) = !y 48 | let set_data (y, _) = (:=) y 49 | end 50 | 51 | module Memo(X: HASHABLE) = struct 52 | module H = Hashtbl.Make(X) 53 | let memo ?(size=128) f = 54 | let h = H.create size in 55 | fun x -> try H.find h x with Not_found -> let y = f x in H.add h x y; y 56 | end 57 | -------------------------------------------------------------------------------- /src/util.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2010 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2.1, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** Some useful operations. *) 19 | 20 | open Sig 21 | 22 | (** Cartesian product of two ordered types. *) 23 | module OTProduct(X: ORDERED_TYPE)(Y: ORDERED_TYPE) : 24 | ORDERED_TYPE with type t = X.t * Y.t 25 | 26 | (** Cartesian product of two hashable types. *) 27 | module HTProduct(X: HASHABLE)(Y: HASHABLE) : 28 | HASHABLE with type t = X.t * Y.t 29 | 30 | (** Cartesian product of two comparable types. *) 31 | module CMPProduct(X: COMPARABLE)(Y: COMPARABLE) : 32 | COMPARABLE with type t = X.t * Y.t 33 | 34 | (** Create a vertex type with some data attached to it *) 35 | module DataV(L : sig type t end)(V : Sig.COMPARABLE) : sig 36 | type data = L.t 37 | and label = V.t 38 | and t = data ref * V.t 39 | val compare : t -> t -> int 40 | val hash : t -> int 41 | val equal : t -> t -> bool 42 | val create : data -> V.t -> t 43 | val label : t -> V.t 44 | val data : t -> data 45 | val set_data : t -> data -> unit 46 | end 47 | 48 | module Memo(X: HASHABLE) : sig 49 | val memo: ?size:int -> (X.t -> 'a) -> X.t -> 'a 50 | end 51 | -------------------------------------------------------------------------------- /tests/basic.expected: -------------------------------------------------------------------------------- 1 | [1 -> 2][2 -> 3][3 -> 5] 2 | 1 -> 2 3 | 1 -> 5 4 | 2 -> 3 5 | 3 -> 2 6 | 3 -> 5 7 | 3 components 8 | 1 -> 2 9 | 2 -> 1 10 | 3 -> 1 11 | 5 -> 0 12 | -------------------------------------------------------------------------------- /tests/basic.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2007 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | open Format 19 | open Graph 20 | 21 | module Int = struct 22 | type t = int 23 | let compare = compare 24 | let hash = Hashtbl.hash 25 | let equal = (=) 26 | let default = 0 27 | end 28 | 29 | module G = Persistent.Digraph.ConcreteLabeled(Int)(Int) 30 | 31 | let g = G.empty 32 | let g = G.add_vertex g 1 33 | let g = G.add_edge_e g (G.E.create 1 10 2) 34 | let g = G.add_edge_e g (G.E.create 2 50 3) 35 | let g = G.add_edge_e g (G.E.create 1 30 4) 36 | let g = G.add_edge_e g (G.E.create 1 100 5) 37 | let g = G.add_edge_e g (G.E.create 3 10 5) 38 | let g = G.add_edge_e g (G.E.create 4 20 3) 39 | let g = G.add_edge_e g (G.E.create 4 60 5) 40 | 41 | let g = G.remove_vertex g 4 42 | 43 | let gc = G.add_edge_e g (G.E.create 5 10 1) 44 | let gc = G.add_vertex gc 6 45 | 46 | module W = struct 47 | type edge = G.E.t 48 | type t = int 49 | let weight e = G.E.label e 50 | let zero = 0 51 | let add = (+) 52 | let sub = (-) 53 | let compare = compare 54 | end 55 | 56 | module Dij = Path.Dijkstra(G)(W) 57 | 58 | let p,w = Dij.shortest_path gc 1 5 59 | 60 | open G.E 61 | 62 | let () = List.iter (fun e -> printf "[%d -> %d]" (src e) (dst e)) p; printf "@." 63 | 64 | module Comp = Components.Make(G) 65 | let g = G.add_edge g 3 2 66 | let n, f = Comp.scc g 67 | let () = G.iter_edges (fun u v -> printf "%d -> %d@." u v) g 68 | let () = printf "%d components@." n 69 | let () = G.iter_vertex (fun v -> printf " %d -> %d@." v (f v)) g 70 | -------------------------------------------------------------------------------- /tests/dot.dot: -------------------------------------------------------------------------------- 1 | digraph D { 2 | 3 | node [shape=plaintext fontname="Sans serif" fontsize="8"]; 4 | 5 | task_menu [ label=< 6 | 7 | 8 | 9 | 10 |
Task 1
Choose Menu
done
>]; 11 | 12 | task_ingredients [ label=< 13 | 14 | 15 | 16 | 17 |
Task 2
Buy ingredients
done
>]; 18 | 19 | task_invitation [ label=< 20 | 21 | 22 | 23 | 24 |
Task 4
Send invitation
done
>]; 25 | 26 | task_cook [ label=< 27 | 28 | 29 | 30 | 31 |
Task 5
Cook
todo
>]; 32 | 33 | task_table[ label=< 34 | 35 | 36 | 37 | 38 |
Task 3
Lay table
todo
>]; 39 | 40 | task_eat[ label=< 41 | 42 | 43 | 44 | 45 |
Task 6
Eat
todo
>]; 46 | 47 | 48 | task_menu -> task_ingredients; 49 | task_ingredients -> task_cook; 50 | task_invitation -> task_cook; 51 | task_table -> task_eat; 52 | task_cook -> task_eat; 53 | 54 | } -------------------------------------------------------------------------------- /tests/dot.expected: -------------------------------------------------------------------------------- 1 | ========= BEGIN output graph ========= 2 | digraph G { 3 | "task_menu"; 4 | "task_ingredients"; 5 | "task_invitation"; 6 | "task_cook"; 7 | "task_table"; 8 | "task_eat"; 9 | 10 | 11 | "task_menu" -> "task_ingredients" [label=, ]; 12 | "task_ingredients" -> "task_cook" [label=, ]; 13 | "task_invitation" -> "task_cook" [label=, ]; 14 | "task_cook" -> "task_eat" [label=, ]; 15 | "task_table" -> "task_eat" [label=, ]; 16 | 17 | } 18 | ========= END output graph ========= -------------------------------------------------------------------------------- /tests/dot.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2007 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (* $Id:$ *) 19 | 20 | open Graph 21 | module G = Imperative.Digraph.Abstract(String) 22 | module B = Builder.I(G) 23 | module DotInput = 24 | Dot.Parse 25 | (B) 26 | (struct 27 | let node (id,_) _ = match id with 28 | | Dot_ast.Ident s 29 | | Dot_ast.Number s 30 | | Dot_ast.String s 31 | | Dot_ast.Html s -> s 32 | let edge _ = () 33 | end) 34 | module Display = struct 35 | include G 36 | let vertex_name v = "\"" ^ String.escaped (V.label v) ^ "\"" 37 | let graph_attributes _ = [] 38 | let default_vertex_attributes _ = [] 39 | let vertex_attributes _ = [] 40 | let default_edge_attributes _ = [] 41 | let edge_attributes _ = [ `HtmlLabel "f$oo" ] 42 | let get_subgraph _ = None 43 | end 44 | module DotOutput = Graphviz.Dot(Display) 45 | 46 | let g = DotInput.parse Sys.argv.(1) 47 | 48 | let () = 49 | Printf.printf "========= BEGIN output graph =========\n"; 50 | DotOutput.output_graph stdout g; 51 | Printf.printf "========= END output graph =========" -------------------------------------------------------------------------------- /tests/nonneg.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for module [Nonnegative] *) 3 | 4 | open Printf 5 | open Graph 6 | open Pack.NonnegDigraph 7 | open Nonnegative 8 | 9 | let test () = 10 | let v = Array.init 10 V.create in 11 | let g = create () in 12 | 13 | let test result op = 14 | begin 15 | try 16 | op g; 17 | with 18 | | Assert_failure _ -> print_string "bug bug bug?"; assert false 19 | | exc -> 20 | let exc_name = Printexc.to_string exc in 21 | if exc_name = "Nonnegative.Imperative(G)(W).Negative_cycle(_)" then 22 | assert (not result) 23 | else begin 24 | print_endline exc_name; 25 | Printexc.print_backtrace stdout; 26 | assert false 27 | end 28 | end; 29 | flush_all (); 30 | display_with_gv g 31 | in 32 | 33 | let add s t g = add_edge g v.(s) v.(t) in 34 | let add_e s w t g = add_edge_e g (E.create v.(s) w v.(t)) in 35 | let rem s t g = remove_edge g v.(s) v.(t) in 36 | let rem_v s g = remove_vertex g v.(s) in 37 | let rem_e s w t g = remove_edge_e g (E.create v.(s) w v.(t)) in 38 | 39 | test true (add 0 1); 40 | test true (rem 0 1); 41 | clear g; 42 | 43 | test true (add_e 0 1 1); 44 | test true (add_e 0 1 1); 45 | test true (rem 0 1); 46 | clear g; 47 | 48 | test true (add 0 1); 49 | test true (add_e 0 1 1); 50 | test true (rem 0 1); 51 | test true (rem_v 0 ); 52 | test true (rem_v 1 ); 53 | clear g; 54 | 55 | test true (add_e 2 1 3); 56 | test true (add_e 3 2 4); 57 | test true (add_e 0 (-1) 2); 58 | test true (add_e 3 1 4); 59 | test false (add_e 4 (-4) 2); 60 | test false (add_e 4 (-3) 2); 61 | test true (add_e 4 (-2) 2); 62 | test true (add_e 1 3 2); 63 | test true (add_e 5 (-2) 4); 64 | test false (add 2 5); 65 | test true (add_e 2 4 5); 66 | test true (rem 2 3); 67 | test true (rem_v 2 ); 68 | clear g; 69 | 70 | test false (add_e 1 (-1) 1); 71 | test true (add 1 1); 72 | test true (add_e 1 1 1); 73 | test true (add_e 1 1 2); 74 | test false (add_e 2 (-2) 1); 75 | test true (rem_v 1 ); 76 | clear g; 77 | 78 | test true (add 1 2); 79 | test true (add_e 2 1 3); 80 | test true (add_e 3 2 4); 81 | test true (add_e 4 3 1); 82 | test true (add 5 6); 83 | test true (add_e 6 1 7); 84 | test true (add_e 7 2 8); 85 | test true (add_e 8 3 5); 86 | test true (add_e 1 (-3) 5); 87 | test false (add_e 8 (-4) 4); 88 | test true (add_e 8 (-3) 4); 89 | test true (rem 1 5); 90 | assert false; (* FIXME: Bug in choosing new source *) 91 | clear g; 92 | 93 | printf "All test succeeded.\n"; 94 | () 95 | 96 | let _ = test () 97 | -------------------------------------------------------------------------------- /tests/strat.expected: -------------------------------------------------------------------------------- 1 | 2 | For 15 matches, is there a winning strategy for the first player ? 3 | true --- (15, 13) (14, 13) (12, 9) (11, 9) (10, 9) (8, 5) (7, 5) (6, 5) (4, 1) (3, 1) (2, 1) 4 | 5 | For 13 matches, is there a winning strategy for the first player ? 6 | false 7 | 8 | -------------------------------------------------------------------------------- /tests/test_149.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Issue #149 *) 3 | 4 | module G = Graph.Persistent.Digraph.Concrete( 5 | struct 6 | type t = string 7 | let compare = compare 8 | let hash = Hashtbl.hash 9 | let equal = (=) 10 | end) 11 | 12 | let g0 = G.empty 13 | let g1 = G.add_edge g0 "a" "b" 14 | let g2 = G.add_edge g1 "a" "c" 15 | let g = G.add_edge g2 "c" "a" 16 | 17 | module Topo = Graph.Topological.Make_stable(G) 18 | 19 | let l = Topo.fold (fun v l -> v :: l) g [] 20 | let () = assert (l = ["b"; "c"; "a"]) 21 | -------------------------------------------------------------------------------- /tests/test_31.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Issue #31 3 | 4 | This would fail in the current state of OCamlGraph, 5 | as map_vertex requires a supplied function that is injective. 6 | *) 7 | 8 | module String = struct include String let hash = Hashtbl.hash end 9 | module G = Graph.Persistent.Digraph.ConcreteBidirectional(String) 10 | 11 | (* Make a persistent graph where: 12 | A -> B 13 | B -> C 14 | C -> B *) 15 | let g = List.fold_left (fun g (x, y) -> 16 | G.add_edge g x y) G.empty [("A", "B"); ("B", "C"); ("C", "B")] 17 | 18 | (* Contract the SCC *) 19 | module C = Graph.Components.Make(G) 20 | 21 | let contract g = 22 | let names = Array.map (String.concat ",") (C.scc_array g) in 23 | let (_, numbering) = C.scc g in 24 | Array.fold_left (fun g x -> G.remove_edge g x x) 25 | (G.map_vertex (fun x -> names.(numbering x)) g) 26 | names 27 | 28 | let g' = contract g 29 | (* this is now "A" -> "C,B" *) 30 | 31 | let () = 32 | assert (G.in_degree g' "C,B" = 1) 33 | -------------------------------------------------------------------------------- /tests/test_bf.expected: -------------------------------------------------------------------------------- 1 | Running test with name: cycle_1 2 | 1 --(1)--> 2 3 | 2 --(1)--> 0 4 | 0 --(-3)--> 1 5 | 6 | Running test with name: cycle_2 7 | 1 --(1)--> 2 8 | 2 --(1)--> 0 9 | 0 --(-10)--> 1 10 | 11 | Running test with name: cycle_3 12 | 0 --(-10)--> 1 13 | 1 --(1)--> 3 14 | 3 --(1)--> 4 15 | 4 --(1)--> 0 16 | 17 | Running test with name: cycle_4 18 | 0 --(-10)--> 1 19 | 1 --(1)--> 3 20 | 3 --(1)--> 4 21 | 4 --(1)--> 0 22 | 23 | Running test with name: cycle_5 24 | 0 --(-10)--> 1 25 | 1 --(1)--> 2 26 | 2 --(1)--> 0 27 | 28 | Running test with name: cycle_6 29 | 0 --(-10)--> 1 30 | 1 --(1)--> 2 31 | 2 --(1)--> 0 32 | 33 | Running test with name: nocycle_1 34 | No cycle found 35 | 36 | Running test with name: nocycle_2 37 | No cycle found 38 | 39 | All tests succeeded. 40 | -------------------------------------------------------------------------------- /tests/test_bf.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for Bellman-Ford *) 3 | 4 | open Printf 5 | open Graph 6 | open Pack.Digraph 7 | 8 | (* TODO: This could be done a tiny bit better, 9 | no need for printing, this could use alcotest or equivalent *) 10 | 11 | let test ~name has_cycle spec = 12 | printf "Running test with name: %s\n" name; 13 | let v = Array.init 5 V.create in 14 | let g = create () in 15 | let () = Array.iter (add_vertex g) v in 16 | 17 | let build (s,w,t) = add_edge_e g (E.create v.(s) w v.(t)) in 18 | List.iter build spec; 19 | begin try 20 | let cycle = bellman_ford g v.(1) in 21 | let print_edge e = 22 | printf "%d --(%d)--> %d\n" (V.label (E.src e)) (E.label e) (V.label (E.dst e)) 23 | in 24 | List.iter print_edge cycle; 25 | assert has_cycle 26 | with Not_found -> 27 | printf "No cycle found\n"; 28 | assert (not has_cycle) 29 | end; 30 | print_newline (); 31 | flush stdout 32 | 33 | let () = 34 | test ~name:"cycle_1" true [ 0, (-3), 1; 1, 1, 2; 2, 1, 0; 1, 1, 3; 3, 1, 4; 4, 1, 0 ]; 35 | test ~name:"cycle_2" true [ 0, (-10), 1; 1, 1, 2; 2, 1, 0; 1, 1, 3; 3, 1, 4; 4, 1, 0 ]; 36 | test ~name:"cycle_3" true [ 0, (-10), 1; 2, 1, 0; 1, 1, 3; 3, 1, 4; 4, 1, 0 ]; 37 | test ~name:"cycle_4" true [ 0, (-10), 1; 1, 1, 2; 1, 1, 3; 3, 1, 4; 4, 1, 0 ]; 38 | test ~name:"cycle_5" true [ 0, (-10), 1; 1, 1, 2; 2, 1, 0; 3, 1, 4; 4, 1, 0 ]; 39 | test ~name:"cycle_6" true [ 0, (-10), 1; 1, 1, 2; 2, 1, 0; 1, 1, 3; 4, 1, 0 ]; 40 | test ~name:"nocycle_1" false [ 1, 1, 2; 2, 1, 0; 1, 1, 3; 3, 1, 4; 4, 1, 0 ]; 41 | test ~name:"nocycle_2" false [ 0, (-10), 1; 1, 1, 2; 1, 1, 3; 3, 1, 4; ]; 42 | 43 | printf "All tests succeeded.\n" 44 | -------------------------------------------------------------------------------- /tests/test_bfs.ml: -------------------------------------------------------------------------------- 1 | 2 | (* 0 3 | / \ 4 | / \ 5 | v v 6 | 1---2---3 (All edges are undirected, 7 | |\ /| apart from 0->1 0->3 1->5 and 3->6.) 8 | | \ / | 9 | | 4 | 10 | | / \ | 11 | v / \ v 12 | 5 6 13 | *) 14 | 15 | open Format 16 | open Graph 17 | open Pack.Digraph 18 | 19 | let debug = false 20 | 21 | let g = create () 22 | let v = Array.init 7 V.create 23 | let () = Array.iter (add_vertex g) v 24 | let adde x y = add_edge g v.(x) v.(y) 25 | let addu x y = adde x y; adde y x 26 | let () = adde 0 1; adde 0 3 27 | let () = addu 1 2; addu 2 3 28 | let () = adde 1 5; adde 3 6 29 | let () = addu 1 4; addu 4 3; addu 5 4; addu 4 6 30 | 31 | module B = Traverse.Bfs(Pack.Digraph) 32 | 33 | let dist = Array.make 7 (-1) 34 | let reset () = Array.fill dist 0 7 (-1) 35 | let mark v d = 36 | let i = V.label v in 37 | (* eprintf "visit %d at distance %d@." i d; *) 38 | assert (dist.(i) = -1); (* visit at most once *) 39 | dist.(i) <- d 40 | 41 | let test s dl = 42 | reset (); 43 | B.iter_component_dist mark g v.(s); 44 | List.iter (fun (d, vl) -> 45 | List.iter (fun v -> assert (dist.(v) = d)) vl) dl 46 | 47 | let () = test 0 [0, [0]; 48 | 1, [1;3]; 49 | 2, [2;4;5;6]; ] 50 | let () = test 2 [-1, [0]; 51 | 0, [2]; 52 | 1, [1;3]; 53 | 2, [4;5;6]; ] 54 | let () = test 5 [-1, [0]; 55 | 0, [5]; 56 | 1, [4]; 57 | 2, [1;3;6]; 58 | 3, [2]; ] 59 | 60 | let () = printf "All tests succeeded.@." 61 | -------------------------------------------------------------------------------- /tests/test_bfs01.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for Path.Bfs01 *) 3 | 4 | open Graph 5 | open Pack.Digraph 6 | 7 | let zero e = 8 | E.label e = 0 9 | 10 | let test n = 11 | let g = create () in 12 | let nv = 2*n+2 in 13 | let v = Array.init nv V.create in 14 | Array.iter (add_vertex g) v; 15 | let edge i d j = add_edge_e g (E.create v.(i) d v.(j)) in 16 | for i = 1 to n do let i = 2*i in edge (i-2) 0 i done; edge (2*n) 1 (2*n+1); 17 | edge 0 1 1; for i = 0 to n-1 do let i = 2*i+1 in edge i 1 (i+2) done; 18 | let check v d = 19 | let i = V.label v in 20 | assert (d = if i mod 2 = 0 then 0 21 | else if i = 2*n+1 then 1 22 | else (i+1) / 2) in 23 | bfs_0_1 check g ~zero v.(0) 24 | 25 | let () = 26 | for n = 0 to 10 do test n done 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/test_chaotic.expected: -------------------------------------------------------------------------------- 1 | W = WTO, delay=40: 2 | 1 -> [-∞; +∞] 3 | 2 -> [0; +∞] 4 | 3 -> [0; 39] 5 | 4 -> [40; +∞] 6 | 7 | W = {3}, delay=39: 8 | 1 -> [-∞; +∞] 9 | 2 -> [0; +∞] 10 | 3 -> [0; +∞] 11 | 4 -> [40; +∞] 12 | 13 | W = WTO, delay=41: 14 | 1 -> [-∞; +∞] 15 | 2 -> [0; 40] 16 | 3 -> [0; 39] 17 | 4 -> [40; 40] 18 | 19 | -------------------------------------------------------------------------------- /tests/test_check_path.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for Path.Check *) 3 | 4 | open Format 5 | open Graph 6 | open Pack.Digraph 7 | 8 | let test n edges = 9 | let v = Array.init n V.create in 10 | let g = create () in 11 | let () = Array.iter (add_vertex g) v in 12 | let build (s,t) = add_edge g v.(s) v.(t) in 13 | List.iter build edges; 14 | let path = PathCheck.check_path (PathCheck.create g) in 15 | for i = 0 to n - 1 do 16 | let seen = Array.make n false in 17 | let pre v = seen.(V.label v) <- true in 18 | Dfs.prefix_component pre g v.(i); 19 | for j = 0 to n - 1 do 20 | assert (seen.(j) = path v.(i) v.(j)) 21 | done 22 | done 23 | 24 | let () = 25 | test 3 [0,1; 1,2]; 26 | test 3 []; 27 | (* 1-cycle *) 28 | test 1 [0,0]; 29 | (* 2-cycle *) 30 | test 2 [0,1; 1,0]; 31 | test 3 [0,1; 1,0]; 32 | (* 2-cycle with out edge *) 33 | test 3 [0,1; 1,0; 1,2]; 34 | test 3 [2,0; 0,2; 0,1]; 35 | test 3 [1,2; 2,1; 2,0]; 36 | (* 2 loops *) 37 | test 5 [1,2; 2,1; 2,0; 3,4; 4,3]; 38 | test 5 [1,2; 2,1; 2,0; 2,3; 3,4; 4,3]; 39 | (* 2-cycle with in edge *) 40 | test 3 [1,2; 2,1; 0,2]; 41 | test 3 [1,2; 2,1; 0,1]; 42 | (* 2 cycles connected *) 43 | test 4 [0,1; 1,0; 2,3; 3,2; 2,1]; 44 | test 4 [0,1; 1,0; 2,3; 3,2; 1,2]; 45 | test 4 [0,1; 1,0; 2,3; 3,2; 1,2; 2,1]; 46 | (* 3-cycle with in and out edges *) 47 | test 5 [0,1; 1,2; 2,0; 3,0; 2,4]; 48 | (* 3 cycles in a row *) 49 | test 7 [0,1; 1,0; 1,2; 2,3; 3,2; 3,4; 4,5; 5,6; 6,4]; 50 | (* 3 cycles with 2 cycles in a cycle *) 51 | test 7 [0,1; 1,0; 1,2; 2,3; 3,2; 3,4; 4,5; 5,6; 6,4; 5,2]; 52 | printf "test check_path: all tests succeeded.@." 53 | -------------------------------------------------------------------------------- /tests/test_classic.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2007 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | open Graph.Pack.Graph (* undirected graphs *) 19 | 20 | let g = Classic.petersen () 21 | let () = assert (nb_vertex g = 10) 22 | let () = assert (nb_edges g = 15) 23 | let () = dot_output g "petersen.dot" 24 | 25 | let g = Classic.kneser ~n:7 ~k:3 26 | let () = dot_output g "k_7_3.dot" 27 | 28 | let g = Classic.kneser ~n:0 ~k:0 29 | let () = assert (nb_vertex g = 1) 30 | let () = assert (nb_edges g = 0) 31 | 32 | let g = Classic.kneser ~n:1 ~k:0 33 | let () = assert (nb_vertex g = 1) 34 | let () = assert (nb_edges g = 0) 35 | 36 | let g = Classic.kneser ~n:1 ~k:1 37 | let () = assert (nb_vertex g = 1) 38 | let () = assert (nb_edges g = 0) 39 | 40 | let g = Classic.kneser ~n:2 ~k:1 41 | let () = assert (nb_vertex g = 2) 42 | let () = assert (nb_edges g = 1) 43 | -------------------------------------------------------------------------------- /tests/test_components.expected: -------------------------------------------------------------------------------- 1 | 4 components 2 | 0 -> 0 3 | 1 -> 1 4 | 2 -> 0 5 | 3 -> 2 6 | 4 -> 2 7 | 5 -> 3 8 | 6 -> 2 9 | 7 -> 0 10 | -------------------------------------------------------------------------------- /tests/test_components.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* Ocamlgraph: a generic graph library for OCaml *) 4 | (* Copyright (C) 2004-2007 *) 5 | (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | open Format 19 | open Graph 20 | 21 | module C = Components.Undirected(Pack.Graph) 22 | 23 | open Pack.Graph 24 | 25 | (* 0 -- 2 -- 7 1 3 -- 4 5 26 | \ / 27 | 6 28 | 29 | component: 0 1 2 3 30 | *) 31 | 32 | let () = 33 | let g = create () in 34 | let v = Array.init 8 V.create in 35 | Array.iter (add_vertex g) v; 36 | let add i j = add_edge g v.(i) v.(j) in 37 | add 0 2; add 7 2; add 3 4; add 4 6; add 3 6; 38 | let n, f = C.components g in 39 | printf "%d components@." n; 40 | iter_vertex (fun v -> printf "%d -> %d@." (V.label v) (f v)) g 41 | 42 | -------------------------------------------------------------------------------- /tests/test_contraction.expected: -------------------------------------------------------------------------------- 1 | digraph G { 2 | 0; 3 | 1; 4 | 2; 5 | 3; 6 | 4; 7 | 5; 8 | 6; 9 | 7; 10 | 8; 11 | 9; 12 | 10; 13 | 11; 14 | 12; 15 | 13; 16 | 17 | 18 | 0 -> 1 [taillabel="0-1", ]; 19 | 0 -> 2 [taillabel="0-2", ]; 20 | 1 -> 6 [taillabel="1-6", ]; 21 | 2 -> 3 [taillabel="2-3", ]; 22 | 2 -> 4 [taillabel="2-4", ]; 23 | 2 -> 5 [taillabel="2-5", ]; 24 | 3 -> 7 [taillabel="3-7", ]; 25 | 4 -> 5 [taillabel="4-5", ]; 26 | 5 -> 9 [taillabel="5-9", ]; 27 | 6 -> 8 [taillabel="6-8", ]; 28 | 7 -> 8 [taillabel="7-8", ]; 29 | 9 -> 10 [taillabel="9-10", ]; 30 | 10 -> 12 [taillabel="10-12", ]; 31 | 12 -> 11 [taillabel="12-11", ]; 32 | 33 | } 34 | digraph G { 35 | 0; 36 | 1; 37 | 3; 38 | 5; 39 | 6; 40 | 7; 41 | 9; 42 | 10; 43 | 11; 44 | 45 | 46 | 0 -> 1 [taillabel="0-1", ]; 47 | 0 -> 3 [taillabel="2-3", ]; 48 | 0 -> 5 [taillabel="2-5", ]; 49 | 0 -> 5 [taillabel="4-5", ]; 50 | 1 -> 6 [taillabel="1-6", ]; 51 | 3 -> 7 [taillabel="3-7", ]; 52 | 5 -> 9 [taillabel="5-9", ]; 53 | 7 -> 6 [taillabel="7-8", ]; 54 | 9 -> 10 [taillabel="9-10", ]; 55 | 10 -> 11 [taillabel="12-11", ]; 56 | 57 | } 58 | 59 | # union-find sets 60 | 0 -> {0, 2, 4} 61 | 1 -> {1} 62 | 2 -> {0, 2, 4} 63 | 3 -> {3} 64 | 4 -> {0, 2, 4} 65 | 5 -> {5} 66 | 6 -> {6, 8} 67 | 7 -> {7} 68 | 8 -> {6, 8} 69 | 9 -> {9} 70 | 10 -> {10, 12} 71 | 11 -> {11} 72 | 12 -> {10, 12} 73 | 13 -> {13} 74 | 75 | # g -> g' 76 | 0 -> 0 77 | 1 -> 1 78 | 2 -> 0 79 | 3 -> 3 80 | 4 -> 0 81 | 5 -> 5 82 | 6 -> 6 83 | 7 -> 7 84 | 8 -> 6 85 | 9 -> 9 86 | 10 -> 10 87 | 11 -> 11 88 | 12 -> 10 89 | 13 -> 13 90 | 91 | -------------------------------------------------------------------------------- /tests/test_contraction.ml: -------------------------------------------------------------------------------- 1 | (* Test file for Contraction *) 2 | 3 | open Graph 4 | 5 | module Int = struct 6 | type t = int 7 | let compare = compare 8 | let hash = Hashtbl.hash 9 | let equal = (=) 10 | let default = 0 11 | end 12 | 13 | module String = struct 14 | type t = string 15 | let compare = compare 16 | let default = "" 17 | end 18 | 19 | module G = Persistent.Digraph.ConcreteLabeled(Int)(String) 20 | 21 | (* Make a persistent graph where: 22 | 23 | 0---1---6 24 | / \ 25 | 2---3---7---8 26 | / \ 27 | 4---5---9---10---12---11 13 28 | 29 | and contract edges linking even numbers. 30 | 31 | 1---6,8 32 | / / 33 | 4,2,0---3---7 34 | \\ 35 | 5---9---10,12---11 36 | 37 | *) 38 | let g = List.fold_left (fun g -> G.add_edge_e g) (G.add_vertex G.empty 13) [ 39 | (0, "0-1", 1); (1, "1-6", 6); 40 | (0, "0-2", 2); (6, "6-8", 8); 41 | (2, "2-3", 3); (3, "3-7", 7); (7, "7-8", 8); 42 | (2, "2-4", 4); (2, "2-5", 5); 43 | (4, "4-5", 5); (5, "5-9", 9); (9, "9-10", 10); 44 | (10, "10-12", 12); (12, "12-11", 11) 45 | ] 46 | 47 | module C = Contraction.Make(G) 48 | 49 | let connects_even (src, _, dst) = (src mod 2 = 0) && (dst mod 2 = 0) 50 | let g', m = C.contract' connects_even g 51 | 52 | module Dot = Graphviz.Dot ( 53 | struct 54 | include G 55 | let vertex_name = string_of_int 56 | let graph_attributes _ = [] 57 | let default_vertex_attributes _ = [] 58 | let vertex_attributes _ = [] 59 | let default_edge_attributes _ = [] 60 | let edge_attributes (_, l, _) = [`Taillabel l] 61 | let get_subgraph _ = None 62 | end) 63 | 64 | let _ = Dot.output_graph stdout g 65 | let _ = Dot.output_graph stdout g' 66 | 67 | let pp_comma fmt () = Format.fprintf fmt ",@ " 68 | let pp_map pp_value fmt = 69 | C.M.iter (fun x v -> Format.(fprintf fmt "%d -> %a@\n" x pp_value v)) 70 | let pp_set fmt s = 71 | Format.fprintf fmt "@[{%a}@]" 72 | Format.(pp_print_list ~pp_sep:pp_comma pp_print_int) 73 | (C.S.elements s) 74 | 75 | let make_map_to_contracted = C.M.map C.S.min_elt 76 | 77 | let _ = 78 | Format.open_vbox 0; 79 | Format.(printf "@\n# union-find sets@\n%a@\n" (pp_map pp_set) m); 80 | Format.(printf "# g -> g'@\n%a@\n" (pp_map pp_print_int) (make_map_to_contracted m)); 81 | Format.close_box () 82 | 83 | -------------------------------------------------------------------------------- /tests/test_cycles.expected: -------------------------------------------------------------------------------- 1 | 2 | g1 cycles = 3 | cycle 0: 1, 3, 2 4 | cycle 1: 2, 4, 3 5 | cycles1 = { 3 -> 2 } (cycles to no cycles) 6 | 7 | g1' cycles = 8 | 9 | g2 cycles = 10 | cycle 0: 1, 2, 3 11 | cycle 1: 1, 2, 4, 8, 6, 7, 5, 3 12 | cycle 2: 1, 2, 4, 8, 7, 5, 3 13 | cycle 3: 5, 6, 7 14 | cycles2 = { 7 -> 5, 3 -> 1 } (cycles to no cycles) 15 | 16 | g2' cycles = 17 | 18 | g3 cycles = 19 | cycle 0: 1, 2, 6, 4, 3 20 | cycle 1: 1, 5, 3 21 | cycle 2: 1, 5, 6, 4, 3 22 | cycle 3: 2, 6, 4 23 | cycles3 = { 4 -> 2, 3 -> 1 } (cycles to no cycles) 24 | 25 | g3' cycles = 26 | 27 | cycle_5 cycles = 28 | cycle 0: 0, 1, 2, 3, 4 29 | 30 | cycle_10 cycles = 31 | cycle 0: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 32 | |full_5| = 84 33 | |full_5 (with self loops)| = 89 34 | |full_6| = 409 35 | |grid_5,5| = 0 36 | -------------------------------------------------------------------------------- /tests/test_dfs.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Stack-based DFS is tricky to get right. See 3 | https://11011110.github.io/blog/2013/12/17/stack-based-graph-traversal.html 4 | 5 | On this graph, 6 | 7 | 0 8 | / \ 9 | / \ 10 | v v 11 | 1---2---3 (All edges are undirected, 12 | |\ /| apart from 0->1 0->3 1->5 and 3->6.) 13 | | \ / | 14 | | 4 | 15 | | / \ | 16 | v / \ v 17 | 5 6 18 | 19 | an incorrect stack-based DFS starting from 0 would first mark 1 and 3, 20 | and then would not go as deep as possible in the traversal. 21 | 22 | In the following, we check that, whenever 2 and 4 are visited, 23 | then necessarily both 1 and 3 are already visited. 24 | *) 25 | 26 | open Format 27 | open Graph 28 | open Pack.Digraph 29 | 30 | let debug = false 31 | 32 | let g = create () 33 | let v = Array.init 7 V.create 34 | let () = Array.iter (add_vertex g) v 35 | let adde x y = add_edge g v.(x) v.(y) 36 | let addu x y = adde x y; adde y x 37 | let () = adde 0 1; adde 0 3 38 | let () = addu 1 2; addu 2 3 39 | let () = adde 1 5; adde 3 6 40 | let () = addu 1 4; addu 4 3; addu 5 4; addu 4 6 41 | 42 | let () = assert (Dfs.has_cycle g) 43 | 44 | let marked = Array.make 7 false 45 | let reset () = Array.fill marked 0 7 false 46 | let mark v = 47 | let i = V.label v in 48 | marked.(i) <- true; 49 | if marked.(2) && marked.(4) then assert (marked.(1) && marked.(3)) 50 | 51 | let pre v = if debug then printf "pre %d@." (V.label v); mark v 52 | let post v = if debug then printf "post %d@." (V.label v) 53 | let f v () = if debug then printf "fold %d@." (V.label v); mark v 54 | 55 | let () = reset (); Dfs.iter ~pre ~post g 56 | let () = reset (); Dfs.prefix pre g 57 | let () = reset (); Dfs.postfix post g 58 | let () = reset (); Dfs.iter_component ~pre ~post g v.(0) 59 | let () = reset (); Dfs.prefix_component pre g v.(0) 60 | let () = reset (); Dfs.postfix_component post g v.(0) 61 | let () = reset (); Dfs.fold f () g 62 | let () = reset (); Dfs.fold_component f () g v.(0) 63 | 64 | module D = Traverse.Dfs(Pack.Digraph) 65 | 66 | let rec visit it = 67 | let v = D.get it in 68 | mark v; 69 | visit (D.step it) 70 | 71 | let () = try visit (D.start g) with Exit -> () 72 | 73 | let () = printf "All tests succeeded.@." 74 | -------------------------------------------------------------------------------- /tests/test_fixpoint.expected: -------------------------------------------------------------------------------- 1 | Labels for 2: 2, 4, 6, 8, 10, 12, 14 2 | Labels for 3: 3, 6, 9, 12, 15 3 | Labels for 4: 4, 8, 12 4 | Labels for 5: 5, 10, 15 5 | Labels for 6: 6, 12 6 | Labels for 7: 7, 14 7 | Labels for 8: 8 8 | Labels for 9: 9 9 | Labels for 10: 10 10 | Labels for 11: 11 11 | Labels for 12: 12 12 | Labels for 13: 13 13 | Labels for 14: 14 14 | Labels for 15: 15 15 | -------------------------------------------------------------------------------- /tests/test_fixpoint.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for Fixpoint *) 3 | 4 | let id x = x 5 | module IntOrdered = struct 6 | type t = int 7 | let compare: int -> int -> int = compare 8 | let hash: int -> int = id 9 | let equal: int -> int -> bool = (=) 10 | end 11 | module IntSet = Set.Make(IntOrdered) 12 | module G = Graph.Persistent.Digraph.Concrete(IntOrdered) 13 | module Divisors = Graph.Classic.P(G) 14 | module Analysis = struct 15 | type data = IntSet.t 16 | type edge = G.edge 17 | type vertex = G.vertex 18 | type g = G.t 19 | let direction = Graph.Fixpoint.Backward 20 | let join = IntSet.union 21 | let equal = IntSet.equal 22 | let analyze (_: edge): data -> data = id 23 | end 24 | module Fixpoint = Graph.Fixpoint.Make(G)(Analysis) 25 | 26 | let pp_int_set pp set = 27 | let first = ref true in 28 | Format.fprintf pp "@["; 29 | IntSet.iter (fun x -> 30 | if !first then 31 | first := false 32 | else 33 | Format.fprintf pp ",@ "; 34 | Format.pp_print_int pp x) 35 | set; 36 | Format.fprintf pp "@]" 37 | 38 | let () = 39 | let n = 15 in 40 | let labels = Fixpoint.analyze IntSet.singleton (Divisors.divisors n) in 41 | Format.open_vbox 0; 42 | for i = 2 to n do 43 | Format.printf "Labels for %d: %a@," i pp_int_set (labels i) 44 | done; 45 | Format.close_box (); 46 | Format.print_flush () 47 | 48 | -------------------------------------------------------------------------------- /tests/test_johnson.expected: -------------------------------------------------------------------------------- 1 | [2 -> 5 : -1] 2 | [5 -> 1 : 8] 3 | [2 -> 4 : 1] 4 | [2 -> 1 : 3] 5 | [3 -> 2 : 4] 6 | [3 -> 5 : 3] 7 | [5 -> 2 : 5] 8 | [1 -> 1 : 0] 9 | [2 -> 3 : -4] 10 | [1 -> 4 : 2] 11 | [5 -> 5 : 0] 12 | [4 -> 4 : 0] 13 | [5 -> 3 : 1] 14 | [1 -> 5 : -4] 15 | [4 -> 5 : -2] 16 | [1 -> 2 : 1] 17 | [2 -> 2 : 0] 18 | [4 -> 3 : -5] 19 | [3 -> 1 : 7] 20 | [3 -> 4 : 5] 21 | [4 -> 2 : -1] 22 | [4 -> 1 : 2] 23 | [1 -> 3 : -3] 24 | [5 -> 4 : 6] 25 | [3 -> 3 : 0] 26 | -------------------------------------------------------------------------------- /tests/test_johnson.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for Johnson *) 3 | 4 | open Graph 5 | 6 | module Int = struct 7 | type t = int 8 | let compare = compare 9 | let hash = Hashtbl.hash 10 | let equal = (=) 11 | let default = 0 12 | end 13 | 14 | 15 | module G = Imperative.Digraph.ConcreteLabeled(Int)(Int) 16 | 17 | 18 | module W = struct 19 | type edge = G.E.t 20 | type t = int 21 | let weight e = G.E.label e 22 | let zero = 0 23 | let add = (+) 24 | let sub = (-) 25 | let compare = compare 26 | end 27 | 28 | module J = Path.Johnson(G)(W) 29 | 30 | let g = G.create () 31 | 32 | let () = 33 | G.add_edge_e g (G.E.create 1 3 2); 34 | G.add_edge_e g (G.E.create 1 (-4) 5); 35 | G.add_edge_e g (G.E.create 1 8 3); 36 | G.add_edge_e g (G.E.create 2 7 5); 37 | G.add_edge_e g (G.E.create 2 1 4); 38 | G.add_edge_e g (G.E.create 3 4 2); 39 | G.add_edge_e g (G.E.create 4 (-5) 3); 40 | G.add_edge_e g (G.E.create 4 2 1); 41 | G.add_edge_e g (G.E.create 5 6 4) 42 | 43 | let () = let test = J.all_pairs_shortest_paths g in 44 | J.HVV.iter (fun (v, u) d -> Printf.printf "[%d -> %d : %d]\n" v u d) test 45 | -------------------------------------------------------------------------------- /tests/test_map_vertex.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Check that map_vertex applies the function exactly once per vertex *) 3 | 4 | open Graph 5 | 6 | let () = Random.init 1597 7 | 8 | module TestB(B: Builder.S with type G.V.label = int) = struct 9 | let test n = 10 | let v = Array.init n B.G.V.create in 11 | let rec make g i = 12 | if i = n then g else make (B.add_vertex g v.(i)) (i + 1) in 13 | let g = ref (make (B.empty ()) 0) in 14 | for i = 0 to n - 1 do 15 | for j = 0 to n - 1 do 16 | if Random.bool () then g := B.add_edge !g v.(i) v.(j) 17 | done 18 | done; 19 | let counter = ref 0 in 20 | let f x = incr counter; x in 21 | let g' = B.G.map_vertex f !g in 22 | assert (!counter = n); 23 | assert (B.G.nb_vertex g' = n) 24 | 25 | let () = 26 | for n = 0 to 10 do test n done 27 | end 28 | module TestI(G: Sig.I with type V.label = int) = TestB(Builder.I(G)) 29 | module TestP(G: Sig.P with type V.label = int) = TestB(Builder.P(G)) 30 | 31 | module Int = struct 32 | type t = int let compare = Stdlib.compare let equal = (=) 33 | let hash x = x let default = 42 34 | end 35 | 36 | include TestI(Pack.Digraph) 37 | include TestI(Pack.Graph) 38 | 39 | (* imperative, directed *) 40 | include TestI(Imperative.Digraph.Concrete(Int)) 41 | include TestI(Imperative.Digraph.Abstract(Int)) 42 | include TestI(Imperative.Digraph.ConcreteBidirectional(Int)) 43 | include TestI(Imperative.Digraph.ConcreteLabeled(Int)(Int)) 44 | include TestI(Imperative.Digraph.AbstractLabeled(Int)(Int)) 45 | include TestI(Imperative.Digraph.ConcreteBidirectionalLabeled(Int)(Int)) 46 | (* imperative, undirected *) 47 | include TestI(Imperative.Graph.Concrete(Int)) 48 | include TestI(Imperative.Graph.Abstract(Int)) 49 | include TestI(Imperative.Graph.ConcreteLabeled(Int)(Int)) 50 | include TestI(Imperative.Graph.AbstractLabeled(Int)(Int)) 51 | 52 | module TestM(G: Imperative.Matrix.S) = struct 53 | let test n = 54 | let g = G.make n in 55 | for i = 0 to n - 1 do 56 | for j = 0 to n - 1 do 57 | if Random.bool () then G.add_edge g i j 58 | done 59 | done; 60 | let counter = ref 0 in 61 | let f x = incr counter; x in 62 | let g' = G.map_vertex f g in 63 | assert (!counter = n); 64 | assert (G.nb_vertex g' = n) 65 | 66 | let () = 67 | for n = 0 to 10 do test n done 68 | end 69 | include TestM(Imperative.Matrix.Digraph) 70 | include TestM(Imperative.Matrix.Graph) 71 | 72 | (* persistent, directed *) 73 | include TestP(Persistent.Digraph.Concrete(Int)) 74 | include TestP(Persistent.Digraph.Abstract(Int)) 75 | include TestP(Persistent.Digraph.ConcreteBidirectional(Int)) 76 | include TestP(Persistent.Digraph.ConcreteLabeled(Int)(Int)) 77 | include TestP(Persistent.Digraph.AbstractLabeled(Int)(Int)) 78 | include TestP(Persistent.Digraph.ConcreteBidirectionalLabeled(Int)(Int)) 79 | (* persistent, undirected *) 80 | include TestP(Persistent.Graph.Concrete(Int)) 81 | include TestP(Persistent.Graph.Abstract(Int)) 82 | include TestP(Persistent.Graph.ConcreteLabeled(Int)(Int)) 83 | include TestP(Persistent.Graph.AbstractLabeled(Int)(Int)) 84 | -------------------------------------------------------------------------------- /tests/test_nontrivial_dom.expected: -------------------------------------------------------------------------------- 1 | {3, 6, 9} 2 | {3, 6, 9} 3 | -------------------------------------------------------------------------------- /tests/test_nontrivial_dom.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for Dominators.dom_tree_to_(s)nontrivial_dom *) 3 | 4 | open Graph 5 | 6 | module Int = struct 7 | type t = int 8 | let compare = compare 9 | let hash = Hashtbl.hash 10 | let equal = (=) 11 | let default = 0 12 | end 13 | 14 | module G = Imperative.Digraph.ConcreteLabeled(Int)(Int) 15 | 16 | module Dominator = Dominator.Make (G) 17 | 18 | let g = G.create () 19 | 20 | let () = 21 | G.add_edge g 1 11; 22 | G.add_edge g 1 2; 23 | G.add_edge g 1 9; 24 | G.add_edge g 2 3; 25 | G.add_edge g 2 9; 26 | G.add_edge g 2 10; 27 | G.add_edge g 3 4; 28 | G.add_edge g 3 5; 29 | G.add_edge g 4 5; 30 | G.add_edge g 5 6; 31 | G.add_edge g 6 8; 32 | G.add_edge g 7 6; 33 | G.add_edge g 8 1; 34 | G.add_edge g 8 10; 35 | G.add_edge g 9 1; 36 | G.add_edge g 9 7; 37 | G.add_edge g 9 10; 38 | G.add_edge g 10 1; 39 | G.add_edge g 10 2; 40 | G.add_edge g 11 1; 41 | G.add_edge g 11 3 42 | 43 | let pp_comma p () = Format.(pp_print_char p ','; pp_print_space p ()) 44 | let pp_set pf s = 45 | Format.(fprintf pf "@[{%a}@]" 46 | (pp_print_list ~pp_sep:pp_comma pp_print_int) 47 | (Dominator.S.elements s)) 48 | 49 | let () = 50 | let idom = Dominator.compute_idom g 1 in 51 | let domtree = Dominator.idom_to_dom_tree g idom in 52 | let s1 = Dominator.S.of_list 53 | (Dominator.dom_tree_to_nontrivial_dom 1 domtree) 54 | in 55 | let s2 = Dominator.dom_tree_to_snontrivial_dom 1 domtree in 56 | Format.(printf "@[%a@]@." (pp_print_list pp_set) [s1; s2]) 57 | 58 | -------------------------------------------------------------------------------- /tests/test_saps.expected: -------------------------------------------------------------------------------- 1 | {3, 5} 2 | {1, 2, 3, 4, 5, 6} 3 | {B, C, E, I} 4 | {1, 2, 3, 4, 6, 7, 9, 12, 13, 14} 5 | {2, 4, 7, 12, 13} 6 | -------------------------------------------------------------------------------- /tests/test_topsort.ml: -------------------------------------------------------------------------------- 1 | 2 | (* Test file for topological sort *) 3 | 4 | open Format 5 | open Graph 6 | open Pack.Digraph 7 | 8 | let test ?(check=true) iter n edges = 9 | let v = Array.init n V.create in 10 | let g = create () in 11 | let () = Array.iter (add_vertex g) v in 12 | let build (s,t) = add_edge g v.(s) v.(t) in 13 | List.iter build edges; 14 | (* run top sort *) 15 | let num = Array.make n 0 in 16 | let i = ref 0 in 17 | iter (fun v -> incr i; num.(V.label v) <- !i) g; 18 | let r = Array.init n (fun i -> i) in 19 | Array.sort (fun i j -> num.(i) - num.(j)) r; 20 | (* if check then for v = 0 to n-1 do printf "%d " r.(v) done; printf "@."; *) 21 | (* check *) 22 | let path = PathCheck.check_path (PathCheck.create g) in 23 | let check_edge (x,y) = 24 | let vx = v.(x) and vy = v.(y) in 25 | (* printf "x=%d y=%d num(x)=%d num(y)=%d@." x y num.(x) num.(y); 26 | * printf "x-->y=%b y-->x=%b@." (path vx vy) (path vy vx); *) 27 | assert (num.(x) > 0 && num.(y) > 0); 28 | assert (num.(x) >= num.(y) || path vx vy || not (path vy vx)) in 29 | if check then 30 | for x = 0 to n-1 do for y = 0 to n-1 do check_edge (x,y) done done; 31 | (* display_with_gv g; *) 32 | () 33 | 34 | let tests iter = 35 | let test = test iter in 36 | test 3 [0,1; 1,2]; 37 | test 3 []; 38 | (* 1-cycle *) 39 | test 1 [0,0]; 40 | (* 2-cycle *) 41 | test 2 [0,1; 1,0]; 42 | (* 2-cycle with out edge *) 43 | test 3 [0,1; 1,0; 1,2]; 44 | test 3 [2,0; 0,2; 0,1]; 45 | test 3 [1,2; 2,1; 2,0]; 46 | (* 2 loops *) 47 | test 5 [1,2; 2,1; 2,0; 3,4; 4,3]; 48 | (* 2-cycle with in edge *) 49 | test 3 [1,2; 2,1; 0,2]; 50 | test 3 [1,2; 2,1; 0,1]; 51 | (* 2 cycles connected *) 52 | test 4 [0,1; 1,0; 2,3; 3,2; 2,1]; 53 | test 4 [0,1; 1,0; 2,3; 3,2; 1,2]; 54 | test 4 [0,1; 1,0; 2,3; 3,2; 1,2; 2,1]; 55 | (* 3-cycle with in and out edges *) 56 | test 5 [0,1; 1,2; 2,0; 3,0; 2,4]; 57 | (* 3 cycles in a row *) 58 | test 7 [0,1; 1,0; 1,2; 2,3; 3,2; 3,4; 4,5; 5,6; 6,4]; 59 | (* 3 cycles with 2 cycles in a cycle *) 60 | test 7 [0,1; 1,0; 1,2; 2,3; 3,2; 3,4; 4,5; 5,6; 6,4; 5,2]; 61 | printf "test topsort: all tests succeeded.@." 62 | 63 | let () = tests Topological.iter 64 | let () = tests Topological.iter_stable 65 | 66 | let rec pow a = function 67 | | 0 -> 1 68 | | 1 -> a 69 | | n -> 70 | let b = pow a (n / 2) in 71 | b * b * (if n mod 2 = 0 then 1 else a) 72 | 73 | let () = 74 | for n_iter = 0 to 5 do 75 | let n = pow 10 n_iter in 76 | let el = ref [] in 77 | (* linear graph *) 78 | (* for i = 0 to n-2 do el := (i,i+1) :: !el done; *) 79 | (* for i = 0 to n-2 do el := (i+1,i) :: !el done; *) 80 | el := [n-1,0]; for i = 0 to n-2 do el := (i,i+1) :: !el done; 81 | test ~check:false Topological.iter n !el 82 | done 83 | -------------------------------------------------------------------------------- /tests/test_wto.expected: -------------------------------------------------------------------------------- 1 | (1 4 1' 4' ) 2' 3' 2 3 (6 5' 6' 5 ) -------------------------------------------------------------------------------- /tests/test_wto.ml: -------------------------------------------------------------------------------- 1 | open Graph 2 | 3 | (* 4 | The non-reducible example from Bourdoncle paper 5 | Reference is in WeakTopological source 6 | *) 7 | 8 | (* Execution should print something like (i and i' can be switched) : 9 | (1 4 1' 4') 2' 3' 2 3 (6 5' 6' 5) *) 10 | 11 | module Vertex = struct 12 | type t = string 13 | let compare = Stdlib.compare 14 | let hash = Hashtbl.hash 15 | let equal = ( = ) 16 | end 17 | 18 | module G = Persistent.Digraph.Concrete (Vertex) 19 | module Wto = WeakTopological.Make (G) 20 | 21 | let rec print_element = function 22 | | WeakTopological.Vertex v -> print_string v 23 | | WeakTopological.Component (head, components) -> 24 | (* Printf is for the weak *) 25 | print_string "("; 26 | print_string head; 27 | print_string " "; 28 | print_components components; 29 | print_string ")" 30 | 31 | and print_components components = 32 | WeakTopological.fold_left 33 | (fun () elem -> print_element elem; print_string " ") 34 | () 35 | components 36 | 37 | let edges = [ 38 | "1", "4"; 39 | "1", "2"; 40 | "2", "3"; 41 | "3", "6"; 42 | "4", "1'"; 43 | "5", "6"; 44 | "6", "5'"; 45 | "1'", "2'"; 46 | "1'", "4'"; 47 | "2'", "3'"; 48 | "3'", "6'"; 49 | "4'", "1"; 50 | "5'", "6'"; 51 | "6'", "5"; 52 | ] 53 | 54 | let g = 55 | List.fold_left 56 | (fun acc (v, w) -> G.add_edge acc v w) 57 | G.empty edges 58 | 59 | let result = Wto.recursive_scc g "1" 60 | 61 | let () = 62 | print_components result 63 | -------------------------------------------------------------------------------- /tests/testgraphml.ml: -------------------------------------------------------------------------------- 1 | (******************************************************************************) 2 | (* *) 3 | (* Copyright (C) 2012 Pietro Abate *) 4 | (* *) 5 | (* This library is free software: you can redistribute it and/or modify *) 6 | (* it under the terms of the GNU Lesser General Public License as *) 7 | (* published by the Free Software Foundation, either version 3 of the *) 8 | (* License, or (at your option) any later version. A special linking *) 9 | (* exception to the GNU Lesser General Public License applies to this *) 10 | (* library, see the COPYING file for more information. *) 11 | (* *) 12 | (******************************************************************************) 13 | 14 | module V = struct 15 | type t = int 16 | let compare = compare 17 | let hash i = i 18 | let equal = (=) 19 | end 20 | 21 | module G = Graph.Imperative.Digraph.ConcreteBidirectional(V) 22 | 23 | module Gr = struct 24 | include G 25 | let vertex_properties = ["id1","string",None; "id2","string",Some "2"] 26 | let edge_properties = ["ed", "string",Some "3"] 27 | let map_edge e = ["ed", string_of_int (E.dst e)] 28 | let map_vertex v = [ "id1", string_of_int v ; "id2", string_of_int v] 29 | let vertex_uid = G.V.hash 30 | let edge_uid e = 31 | Hashtbl.hash (vertex_uid (G.E.src e), G.E.label e, vertex_uid (G.E.dst e)) 32 | end 33 | 34 | module GraphPrinter = Graph.Graphml.Print(G)(Gr) 35 | 36 | let print g = GraphPrinter.print Format.std_formatter g 37 | 38 | let () = 39 | let g = G.create () in 40 | G.add_vertex g 1; 41 | G.add_vertex g 2; 42 | G.add_vertex g 3; 43 | G.add_edge g 1 2; 44 | G.add_edge g 1 3; 45 | print g;; 46 | -------------------------------------------------------------------------------- /view_graph/README: -------------------------------------------------------------------------------- 1 | ====================================================== 2 | ViewGraph is now deprecated. Prefer to use dgraph now. 3 | ====================================================== 4 | 5 | ViewGraph is a small ocaml library that helps to view a graph from a dot file 6 | in a Lablgtk canvas, and interact with it. 7 | 8 | To have more information : 9 | make doc 10 | and browse the documentation starting from doc/index.html 11 | 12 | You can also compile the test file, and try to use it : 13 | make; ./viewgraph file.dot 14 | 15 | -------------------------------------------------------------------------------- /view_graph/doc/intro.txt: -------------------------------------------------------------------------------- 1 | {1 ViewGraph} 2 | 3 | {2 Presentation} 4 | 5 | ViewGraph is a small {{:http://caml.inria.fr/ocaml/}ocaml} library 6 | that helps to view a graph from a dot file 7 | in a Lablgtk canvas, and interact with it. 8 | 9 | It reads dot files and uses the dot tool for the layout of the nodes. 10 | You can have a look to {{:http://www.graphviz.org/}Graphviz} 11 | to know more about the dot tool and file format. 12 | 13 | It also uses the {{:http://caml.inria.fr/ocaml/}ocaml} 14 | graph library {{:http://ocamlgraph.lri.fr/}ocamlgraph}. 15 | 16 | It is composed of the {{:index_modules.html}modules}: 17 | - {!module:ViewGraph} : which is the main part and that can be used alone 18 | to parse a file, generate an image of the graph 19 | and add some user defined callbacks to interact with it, 20 | - {!module:ViewGraph_select} : which can be used to add selection features 21 | in addition to user callbacks, 22 | - {!module:ViewGraph_test} : which is not really part of the library 23 | but that creates a small gui to show how to use the 2 other modules. 24 | 25 | To know more about it, the best thing to do is to compile 26 | and test : 27 | - [make] 28 | - [./viewgraph file.dot] 29 | 30 | If you don't have any dot file, you can for instance use some examples from 31 | {{:http://www.graphviz.org/Gallery.php}graphviz gallery} 32 | but please remove the size attibutes (they are not handdled yet : see below) 33 | 34 | Notice also that if you are already using 35 | {{:http://ocamlgraph.lri.fr/}ocamlgraph} to build some graphs, 36 | it is quite easy to generate dot files by using 37 | {{:http://ocamlgraph.lri.fr/doc/Graphviz.html}Graph.Graphviz.Dot}. 38 | 39 | {2 Some more things TODO} 40 | 41 | - some of the dot format attributes are not handled 42 | (size and ratio for instance) 43 | - the zoom feature is very ugly at the moment ! 44 | - as we call 'dot' once for the image and another time for annotations, 45 | the layout is computed twice. That can be a problem for big graphs. 46 | - instead of using PNG images from dot, we could generate the GTK objects, 47 | and the zoom problem would be solved. This requires a lot of work, 48 | but we hope to do it soon ! 49 | - add something to find a node by its name 50 | - ... and more... 51 | 52 | {2 More links} 53 | 54 | - GTK : 55 | {ul {- all the {{:http://library.gnome.org/devel/gtk/stable/}widgets} 56 | Reference Manual} 57 | {- the 58 | {{:http://library.gnome.org/devel/libgnomecanvas/stable/}GnomeCanvas} 59 | Library Reference Manual} 60 | } 61 | - Lablgtk : 62 | {ul{- ocamldoc 63 | {{:http://plus.kaist.ac.kr/~shoh/ocaml/lablgtk2/lablgtk-2.4.0/doc/html/index.html} 64 | reference} with links on GTK reference,} 65 | {- an excellent 66 | {{:http://plus.kaist.ac.kr/~shoh/english/ocaml/lablgtk2/lablgtk2-tutorial/index.html}tutorial} fo those (like me) who don't know GTK.} 67 | } 68 | - Author : {{:http://www-sop.inria.fr/everest/personnel/Anne.Pacalet/}Anne 69 | Pacalet} 70 | -------------------------------------------------------------------------------- /view_graph/doc/style.css: -------------------------------------------------------------------------------- 1 | .typetable { 2 | border-style : hidden 3 | } 4 | .indextable { 5 | border-style : hidden 6 | } 7 | .paramstable { 8 | border-style : hidden ; 9 | padding: 5pt 5pt 10 | } 11 | body { 12 | background-color : white 13 | font-family: Lucida,Times,serif; 14 | margin-left: 2em; 15 | margin-right: 1em; 16 | } 17 | td.typefieldcomment { 18 | background-color : white 19 | font-size: smaller ; 20 | } 21 | pre { 22 | margin-bottom: 2px; 23 | } 24 | pre, code { 25 | font-family: terminal,"courier new",monospace; 26 | font-size: 10pt; 27 | } 28 | div.sig_block { 29 | margin-left: 2em 30 | } 31 | .keyword { 32 | font-weight : bold ; 33 | color : fuchsia; 34 | } 35 | .keywordsign { 36 | color : #C04600 37 | } 38 | .superscript { 39 | font-size : 4 40 | } 41 | .subscript { 42 | font-size : 4 43 | } 44 | .comment { 45 | color : Green 46 | } 47 | .constructor { 48 | color : Blue 49 | } 50 | .type { 51 | color : #5C6585 52 | } 53 | .string { 54 | color : Maroon 55 | } 56 | .warning { 57 | color : Red ; 58 | font-weight : bold 59 | } 60 | .info { 61 | margin-left : 3em; 62 | margin-right : 3em 63 | } 64 | .param_info { 65 | margin-top: 4px; 66 | margin-left : 3em; 67 | margin-right : 3em 68 | } 69 | .code { 70 | color : #465F91 ; 71 | } 72 | a .code { 73 | color : #416DFF; 74 | } 75 | a:link { 76 | color : #416DFF; 77 | text-decoration : none; 78 | } 79 | a:visited { 80 | color : #416DFF; 81 | text-decoration : none; 82 | } 83 | a:hover { 84 | color : fuchsia; 85 | text-decoration : none; 86 | background-color: #CCE8FE; 87 | } 88 | a:active { 89 | color : fuchsia; 90 | text-decoration : underline; 91 | } 92 | h1 { 93 | font-size : 30 ; 94 | text-align: center; 95 | } 96 | h2 { 97 | background-color: #1E90FF ; 98 | font-size : 25 ; 99 | border: 1px solid #000000; 100 | margin-top: 2ex; 101 | margin-bottom: 1ex; 102 | margin-left: -1ex; 103 | margin-right: -1ex; 104 | text-align: center; 105 | padding: 2px; 106 | } 107 | h3 { 108 | background-color: #00CFFF ; 109 | font-size : 18 ; 110 | border: 1px solid #000000; 111 | margin-top: 5px; 112 | margin-bottom: 2px; 113 | margin-left: 0; 114 | margin-right: 0; 115 | text-align: center; 116 | padding: 2px; 117 | } 118 | h4 { 119 | font-size : 18 ; 120 | margin-top: 1ex; 121 | margin-bottom: 1ex; 122 | } 123 | ul { 124 | margin:0; 125 | list-style-type: square; 126 | } 127 | ul ul { 128 | list-style-type: disc; 129 | } 130 | -------------------------------------------------------------------------------- /view_graph/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name viewGraph) 3 | (wrapped false) 4 | (modules :standard \ viewGraph_test) 5 | (libraries ocamlgraph lablgtk2 lablgtk2.gnomecanvas)) 6 | 7 | (executable 8 | (name viewGraph_test) 9 | (modules viewGraph_test) 10 | (libraries viewGraph) 11 | (flags -open ViewGraph)) 12 | -------------------------------------------------------------------------------- /view_graph/viewGraph.ml: -------------------------------------------------------------------------------- 1 | module ViewGraph = ViewGraph_core 2 | 3 | module ViewGraph_select = ViewGraph_select 4 | module ViewGraph_utils = ViewGraph_utils -------------------------------------------------------------------------------- /view_graph/viewGraph_core.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* ViewGraph: a library to interact with graphs in ocaml and lablgtk2 *) 4 | (* *) 5 | (* Copyright (C) 2008 - Anne Pacalet *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** ViewGraph : a library to view .dot graphs and interact with the GUI. 19 | * To use it you have : 20 | * - first to define callbacks (see {!modtype:ViewGraph.SigCb}) 21 | * - then instanciate the module {!module:ViewGraph.M} with your callbacks, 22 | * - then use {!ViewGraph.M.open_dot_file} 23 | * - don't forget to call {!ViewGraph.M.clear} when changing the file. 24 | *) 25 | 26 | (** raised when the call to a dot command fails. 27 | * The string gives the command that failed *) 28 | exception DotError of string 29 | 30 | type t_point = float * float 31 | type t_coord = t_point * t_point 32 | 33 | type t_graph 34 | type t_node 35 | 36 | type t_gtk_obj = GnomeCanvas.re_p GnoCanvas.item 37 | 38 | (*val get_canvas : t_graph -> GnoCanvas.canvas *) 39 | 40 | val get_id : t_node -> string 41 | val get_coord : t_node -> t_coord option 42 | val get_obj : t_node -> t_gtk_obj option 43 | 44 | (** @return 2 lists : the predecessors and successors of the node*) 45 | val get_neighbours : t_graph -> t_node -> t_node list * t_node list 46 | 47 | module type SigCb = sig 48 | type t_env 49 | 50 | val button_one_press_on_graph : t_env -> unit 51 | val button_two_press_on_graph : t_env -> unit 52 | val button_three_press_on_graph : t_env -> unit 53 | val button_one_press_on_node : t_env -> t_node -> unit 54 | val button_two_press_on_node : t_env -> t_node -> unit 55 | val button_three_press_on_node : t_env -> t_node -> unit 56 | val enter_node : t_env -> t_node -> unit 57 | val leave_node : t_env -> t_node -> unit 58 | end 59 | 60 | (** usefull when we don't want to have callbacks on the nodes *) 61 | module EmptyCb : SigCb with type t_env=unit 62 | 63 | module M (Cb : SigCb) : sig 64 | 65 | (** Open the dot file in the canvas. 66 | * @raise Error if either the image or the graph fail to build *) 67 | val open_dot_file : Cb.t_env -> GnoCanvas.canvas -> 68 | ?dot_cmd:string -> string -> t_graph 69 | 70 | (** it is very important to not using the graph anymore after calling [clear] *) 71 | val clear : GnoCanvas.canvas -> t_graph -> unit 72 | end 73 | -------------------------------------------------------------------------------- /view_graph/viewGraph_select.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* ViewGraph: a library to interact with graphs in ocaml and lablgtk2 *) 4 | (* *) 5 | (* Copyright (C) 2008 - Anne Pacalet *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** This module can be used to add some selection feature to {!ViewGraph}. 19 | * See {!ViewGraph_test} to see how to use it. 20 | * *) 21 | 22 | (** object returned by [init] and used by [open_dot_file] *) 23 | type t_env 24 | 25 | type t_options = { 26 | sel_1_color : string; (** color of the selected node (default "red") *) 27 | sel_2_color : string; (** color of the selected neighbour (default "green") *) 28 | center_node_when_selected :bool; 29 | (** automatically center a node when it is selected (default true) *) 30 | } 31 | 32 | (** some default values for the options. 33 | * It is a good idea to use it and overwrite the one that have to be changed, 34 | * just in case some more options appear *) 35 | val default_options : t_options 36 | 37 | (** should be called only once because it creates widgets. 38 | * The packing function is the place to put the messages about selection. 39 | *) 40 | val init : t_options -> GnoCanvas.canvas -> (GObj.widget -> unit) -> t_env 41 | 42 | (** functor to instanciate with your callbacks *) 43 | module VG (UserCb : ViewGraph_core.SigCb) : sig 44 | val open_dot_file : UserCb.t_env -> t_env -> 45 | ?dot_cmd:string -> string -> ViewGraph_core.t_graph 46 | end 47 | 48 | (** Popup a message window with some help. *) 49 | val show_help : unit -> unit 50 | -------------------------------------------------------------------------------- /view_graph/viewGraph_utils.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* ViewGraph: a library to interact with graphs in ocaml and lablgtk2 *) 4 | (* *) 5 | (* Copyright (C) 2008 - Anne Pacalet *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** This file provide useful function to build windows to put the graph *) 19 | 20 | let create_scrolled_canvas packing = 21 | let frame = GBin.frame ~shadow_type:`IN () in 22 | let canvas = 23 | let aa = false (* anti-aliasing *) in 24 | GnoCanvas.canvas ~aa ~width:600 ~height:400 ~packing:frame#add () 25 | in 26 | let _ = canvas#set_center_scroll_region true in 27 | (* if the graph is too big, show its center *) 28 | let table = GPack.table ~packing 29 | ~rows:2 ~columns:2 ~row_spacings:4 ~col_spacings:4 () in 30 | let _ = table#attach ~left:0 ~right:1 ~top:0 ~bottom:1 31 | ~expand:`BOTH ~fill:`BOTH ~shrink:`BOTH ~xpadding:0 ~ypadding:0 32 | frame#coerce in 33 | let w = GRange.scrollbar `HORIZONTAL ~adjustment:canvas#hadjustment () in 34 | let _ = table#attach ~left:0 ~right:1 ~top:1 ~bottom:2 35 | ~expand:`X ~fill:`BOTH ~shrink:`X ~xpadding:0 ~ypadding:0 36 | w#coerce in 37 | let w = GRange.scrollbar `VERTICAL ~adjustment:canvas#vadjustment () in 38 | let _ = table#attach ~left:1 ~right:2 ~top:0 ~bottom:1 39 | ~expand:`Y ~fill:`BOTH ~shrink:`Y ~xpadding:0 ~ypadding:0 40 | w#coerce in 41 | canvas 42 | 43 | let create_graph_win title = 44 | let window = GWindow.window ~title 45 | ~allow_shrink:true ~allow_grow:true () in 46 | let vbox = GPack.vbox ~border_width:4 ~spacing:4 ~packing:window#add () in 47 | let help_but = GButton.button ~label:"Help" 48 | ~packing:(vbox#pack ~expand:false ~fill:true) () in 49 | let _ = help_but#connect#clicked ~callback:ViewGraph_select.show_help in 50 | let canvas = create_scrolled_canvas (vbox#pack ~expand:true ~fill:true) in 51 | let hbox = GPack.hbox ~spacing:4 ~packing:vbox#pack () in 52 | let select_init_env = 53 | ViewGraph_select.init ViewGraph_select.default_options 54 | canvas (hbox#pack ~expand:true ~fill:true) in 55 | window#show (); 56 | select_init_env 57 | 58 | -------------------------------------------------------------------------------- /view_graph/viewGraph_utils.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* ViewGraph: a library to interact with graphs in ocaml and lablgtk2 *) 4 | (* *) 5 | (* Copyright (C) 2008 - Anne Pacalet *) 6 | (* *) 7 | (* This software is free software; you can redistribute it and/or *) 8 | (* modify it under the terms of the GNU Library General Public *) 9 | (* License version 2, with the special exception on linking *) 10 | (* described in file LICENSE. *) 11 | (* *) 12 | (* This software is distributed in the hope that it will be useful, *) 13 | (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14 | (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *) 15 | (* *) 16 | (**************************************************************************) 17 | 18 | (** This file provide useful function to build windows to put the graph *) 19 | 20 | val create_scrolled_canvas : (GObj.widget -> unit) -> GnoCanvas.canvas 21 | 22 | val create_graph_win : string -> ViewGraph_select.t_env 23 | 24 | --------------------------------------------------------------------------------