added visualisation
This commit is contained in:
parent
1daa4beaf7
commit
052d75604e
6 changed files with 181 additions and 22 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
|||
/_build/
|
||||
_build/
|
||||
.gitignore
|
||||
ftest.native
|
||||
ftest.byte
|
||||
|
|
40
outfile
40
outfile
|
@ -1,21 +1,25 @@
|
|||
% This is a graph.
|
||||
|
||||
n 0.0 1.0
|
||||
n 1.0 1.0
|
||||
n 2.0 1.0
|
||||
n 3.0 1.0
|
||||
n 4.0 1.0
|
||||
n 5.0 1.0
|
||||
digraph finite_state_machine {
|
||||
|
||||
e 2 4 12
|
||||
e 3 4 5
|
||||
e 3 2 2
|
||||
e 3 1 11
|
||||
e 1 4 1
|
||||
e 1 5 21
|
||||
e 4 5 14
|
||||
e 0 2 8
|
||||
e 0 1 7
|
||||
e 0 3 15
|
||||
fontname="Helvetica,Arial,sans-serif"
|
||||
|
||||
% End of graph
|
||||
node [fontname="Helvetica,Arial,sans-serif"]
|
||||
|
||||
edge [fontname="Helvetica,Arial,sans-serif"]
|
||||
|
||||
rankdir=LR;
|
||||
|
||||
node [shape = circle];
|
||||
|
||||
|
||||
2 -> 4 [label = "12"];
|
||||
3 -> 4 [label = "5"];
|
||||
3 -> 2 [label = "2"];
|
||||
3 -> 1 [label = "11"];
|
||||
1 -> 4 [label = "1"];
|
||||
1 -> 5 [label = "21"];
|
||||
4 -> 5 [label = "14"];
|
||||
0 -> 2 [label = "8"];
|
||||
0 -> 1 [label = "7"];
|
||||
0 -> 3 [label = "15"];
|
||||
}
|
30
src/display.ml
Normal file
30
src/display.ml
Normal file
|
@ -0,0 +1,30 @@
|
|||
open Graph
|
||||
open Printf
|
||||
open Gfile
|
||||
|
||||
let export g path =
|
||||
let str = e_fold
|
||||
g
|
||||
(fun x id1 id2 label -> x ^ "\n " ^ (string_of_int id1) ^ " -> " ^ (string_of_int id2) ^ " [label = \"" ^ label ^"\"];" )
|
||||
""
|
||||
in
|
||||
|
||||
let startStr =
|
||||
"
|
||||
digraph finite_state_machine {\n
|
||||
fontname=\"Helvetica,Arial,sans-serif\"\n
|
||||
node [fontname=\"Helvetica,Arial,sans-serif\"]\n
|
||||
edge [fontname=\"Helvetica,Arial,sans-serif\"]\n
|
||||
rankdir=LR;\n
|
||||
node [shape = circle];\n
|
||||
"
|
||||
in
|
||||
|
||||
let finishStr = "\n}" in
|
||||
|
||||
let totalStr = startStr ^ str ^ finishStr in
|
||||
|
||||
let ff = open_out path in
|
||||
fprintf ff "%s%!" totalStr;
|
||||
close_out ff;
|
||||
()
|
3
src/display.mli
Normal file
3
src/display.mli
Normal file
|
@ -0,0 +1,3 @@
|
|||
open Graph
|
||||
open Gfile
|
||||
val export: string graph -> path -> unit
|
|
@ -1,5 +1,6 @@
|
|||
open Gfile
|
||||
open Tools
|
||||
open Display
|
||||
|
||||
let () =
|
||||
|
||||
|
@ -35,8 +36,10 @@ let () =
|
|||
|
||||
let graphFinal = gmap graphBis string_of_int in
|
||||
|
||||
(* Rewrite the graph that has been read. *)
|
||||
let () = write_file outfile graphFinal in
|
||||
let () = export graphFinal outfile in
|
||||
()
|
||||
(* Rewrite the graph that has been read.
|
||||
let () = write_file outfile graphDot in
|
||||
|
||||
()
|
||||
() *)
|
||||
|
||||
|
|
119
test.svg
Normal file
119
test.svg
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 2.50.0 (0)
|
||||
-->
|
||||
<!-- Title: finite_state_machine Pages: 1 -->
|
||||
<svg width="396pt" height="154pt"
|
||||
viewBox="0.00 0.00 396.00 154.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 150)">
|
||||
<title>finite_state_machine</title>
|
||||
<polygon fill="white" stroke="transparent" points="-4,4 -4,-150 392,-150 392,4 -4,4"/>
|
||||
<!-- 2 -->
|
||||
<g id="node1" class="node">
|
||||
<title>2</title>
|
||||
<ellipse fill="none" stroke="black" cx="194" cy="-128" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="194" y="-124.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">2</text>
|
||||
</g>
|
||||
<!-- 4 -->
|
||||
<g id="node2" class="node">
|
||||
<title>4</title>
|
||||
<ellipse fill="none" stroke="black" cx="282" cy="-71" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="282" y="-67.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">4</text>
|
||||
</g>
|
||||
<!-- 2->4 -->
|
||||
<g id="edge1" class="edge">
|
||||
<title>2->4</title>
|
||||
<path fill="none" stroke="black" d="M209.59,-118.33C222.89,-109.52 242.75,-96.35 258.16,-86.14"/>
|
||||
<polygon fill="black" stroke="black" points="260.22,-88.97 266.63,-80.53 256.36,-83.13 260.22,-88.97"/>
|
||||
<text text-anchor="middle" x="238" y="-107.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">12</text>
|
||||
</g>
|
||||
<!-- 5 -->
|
||||
<g id="node5" class="node">
|
||||
<title>5</title>
|
||||
<ellipse fill="none" stroke="black" cx="370" cy="-30" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="370" y="-26.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">5</text>
|
||||
</g>
|
||||
<!-- 4->5 -->
|
||||
<g id="edge7" class="edge">
|
||||
<title>4->5</title>
|
||||
<path fill="none" stroke="black" d="M298.77,-63.48C311.5,-57.41 329.64,-48.77 344.29,-41.78"/>
|
||||
<polygon fill="black" stroke="black" points="345.81,-44.94 353.33,-37.47 342.79,-38.62 345.81,-44.94"/>
|
||||
<text text-anchor="middle" x="326" y="-57.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">14</text>
|
||||
</g>
|
||||
<!-- 3 -->
|
||||
<g id="node3" class="node">
|
||||
<title>3</title>
|
||||
<ellipse fill="none" stroke="black" cx="106" cy="-77" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="106" y="-73.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">3</text>
|
||||
</g>
|
||||
<!-- 3->2 -->
|
||||
<g id="edge3" class="edge">
|
||||
<title>3->2</title>
|
||||
<path fill="none" stroke="black" d="M121.98,-85.88C135.05,-93.64 154.24,-105.02 169.38,-113.99"/>
|
||||
<polygon fill="black" stroke="black" points="167.81,-117.13 178.19,-119.22 171.38,-111.11 167.81,-117.13"/>
|
||||
<text text-anchor="middle" x="150" y="-110.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">2</text>
|
||||
</g>
|
||||
<!-- 3->4 -->
|
||||
<g id="edge2" class="edge">
|
||||
<title>3->4</title>
|
||||
<path fill="none" stroke="black" d="M124,-76.41C154.15,-75.37 217.21,-73.2 253.57,-71.95"/>
|
||||
<polygon fill="black" stroke="black" points="254.06,-75.43 263.93,-71.59 253.82,-68.44 254.06,-75.43"/>
|
||||
<text text-anchor="middle" x="194" y="-77.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">5</text>
|
||||
</g>
|
||||
<!-- 1 -->
|
||||
<g id="node4" class="node">
|
||||
<title>1</title>
|
||||
<ellipse fill="none" stroke="black" cx="194" cy="-18" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="194" y="-14.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
|
||||
</g>
|
||||
<!-- 3->1 -->
|
||||
<g id="edge4" class="edge">
|
||||
<title>3->1</title>
|
||||
<path fill="none" stroke="black" d="M119.9,-65.47C126.35,-59.93 134.38,-53.35 142,-48 150.52,-42.02 160.29,-36.07 168.98,-31.07"/>
|
||||
<polygon fill="black" stroke="black" points="170.89,-34.02 177.88,-26.06 167.45,-27.92 170.89,-34.02"/>
|
||||
<text text-anchor="middle" x="150" y="-51.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">11</text>
|
||||
</g>
|
||||
<!-- 1->4 -->
|
||||
<g id="edge5" class="edge">
|
||||
<title>1->4</title>
|
||||
<path fill="none" stroke="black" d="M210.29,-26.73C220.49,-32.61 234.14,-40.62 246,-48 249.93,-50.44 254.06,-53.09 258.06,-55.69"/>
|
||||
<polygon fill="black" stroke="black" points="256.18,-58.65 266.46,-61.21 260.03,-52.8 256.18,-58.65"/>
|
||||
<text text-anchor="middle" x="238" y="-51.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
|
||||
</g>
|
||||
<!-- 1->5 -->
|
||||
<g id="edge6" class="edge">
|
||||
<title>1->5</title>
|
||||
<path fill="none" stroke="black" d="M212,-19.17C242.15,-21.25 305.21,-25.6 341.57,-28.11"/>
|
||||
<polygon fill="black" stroke="black" points="341.71,-31.63 351.93,-28.82 342.19,-24.64 341.71,-31.63"/>
|
||||
<text text-anchor="middle" x="282" y="-28.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">21</text>
|
||||
</g>
|
||||
<!-- 0 -->
|
||||
<g id="node6" class="node">
|
||||
<title>0</title>
|
||||
<ellipse fill="none" stroke="black" cx="18" cy="-77" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="18" y="-73.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">0</text>
|
||||
</g>
|
||||
<!-- 0->2 -->
|
||||
<g id="edge8" class="edge">
|
||||
<title>0->2</title>
|
||||
<path fill="none" stroke="black" d="M34.05,-85.9C40.13,-89.3 47.29,-93.06 54,-96 91.85,-112.58 101.38,-118.44 142,-126 149.67,-127.43 158.09,-128.11 165.84,-128.39"/>
|
||||
<polygon fill="black" stroke="black" points="165.81,-131.89 175.86,-128.56 165.92,-124.89 165.81,-131.89"/>
|
||||
<text text-anchor="middle" x="106" y="-125.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">8</text>
|
||||
</g>
|
||||
<!-- 0->3 -->
|
||||
<g id="edge10" class="edge">
|
||||
<title>0->3</title>
|
||||
<path fill="none" stroke="black" d="M36.4,-77C48.25,-77 64.18,-77 77.71,-77"/>
|
||||
<polygon fill="black" stroke="black" points="77.92,-80.5 87.92,-77 77.92,-73.5 77.92,-80.5"/>
|
||||
<text text-anchor="middle" x="62" y="-80.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">15</text>
|
||||
</g>
|
||||
<!-- 0->1 -->
|
||||
<g id="edge9" class="edge">
|
||||
<title>0->1</title>
|
||||
<path fill="none" stroke="black" d="M32.71,-66.44C46.07,-56.69 67.35,-42.63 88,-35 113.34,-25.64 144.01,-21.43 165.64,-19.54"/>
|
||||
<polygon fill="black" stroke="black" points="166.05,-23.01 175.76,-18.76 165.52,-16.03 166.05,-23.01"/>
|
||||
<text text-anchor="middle" x="106" y="-38.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">7</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 6 KiB |
Loading…
Reference in a new issue