feat: implement File exporting using dot format
This commit is contained in:
parent
52f2b6f24f
commit
931fa5c6ef
5 changed files with 163 additions and 1 deletions
17
graphs/graph-to-other.txt
Normal file
17
graphs/graph-to-other.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
digraph cool_generated_graph {
|
||||
fontname="Helvetica,Arial,sans-serif"
|
||||
node [fontname="Helvetica,Arial,sans-serif"]
|
||||
edge [fontname="Helvetica,Arial,sans-serif"]
|
||||
rankdir=LR;
|
||||
node [shape = circle];
|
||||
4 -> 5 [label = "14"];
|
||||
1 -> 5 [label = "21"];
|
||||
1 -> 4 [label = "1"];
|
||||
3 -> 1 [label = "11"];
|
||||
3 -> 2 [label = "2"];
|
||||
3 -> 4 [label = "5"];
|
||||
2 -> 4 [label = "12"];
|
||||
0 -> 1 [label = "7"];
|
||||
0 -> 3 [label = "10"];
|
||||
0 -> 2 [label = "8"];}
|
||||
119
graphs/other.svg
Normal file
119
graphs/other.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.43.0 (0)
|
||||
-->
|
||||
<!-- Title: cool_generated_graph Pages: 1 -->
|
||||
<svg width="396pt" height="155pt"
|
||||
viewBox="0.00 0.00 396.00 155.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 151)">
|
||||
<title>cool_generated_graph</title>
|
||||
<polygon fill="white" stroke="transparent" points="-4,4 -4,-151 392,-151 392,4 -4,4"/>
|
||||
<!-- 4 -->
|
||||
<g id="node1" class="node">
|
||||
<title>4</title>
|
||||
<ellipse fill="none" stroke="black" cx="282" cy="-77" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="282" y="-73.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">4</text>
|
||||
</g>
|
||||
<!-- 5 -->
|
||||
<g id="node2" class="node">
|
||||
<title>5</title>
|
||||
<ellipse fill="none" stroke="black" cx="370" cy="-108" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="370" y="-104.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">5</text>
|
||||
</g>
|
||||
<!-- 4->5 -->
|
||||
<g id="edge1" class="edge">
|
||||
<title>4->5</title>
|
||||
<path fill="none" stroke="black" d="M299.18,-82.83C311.55,-87.29 328.85,-93.53 343.14,-98.68"/>
|
||||
<polygon fill="black" stroke="black" points="342.3,-102.1 352.9,-102.2 344.68,-95.51 342.3,-102.1"/>
|
||||
<text text-anchor="middle" x="326" y="-98.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">14</text>
|
||||
</g>
|
||||
<!-- 1 -->
|
||||
<g id="node3" class="node">
|
||||
<title>1</title>
|
||||
<ellipse fill="none" stroke="black" cx="194" cy="-129" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="194" y="-125.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
|
||||
</g>
|
||||
<!-- 1->4 -->
|
||||
<g id="edge3" class="edge">
|
||||
<title>1->4</title>
|
||||
<path fill="none" stroke="black" d="M209.51,-119.16C215.76,-115.01 223.18,-110.18 230,-106 238.68,-100.69 248.35,-95.11 256.91,-90.28"/>
|
||||
<polygon fill="black" stroke="black" points="258.66,-93.31 265.68,-85.38 255.24,-87.2 258.66,-93.31"/>
|
||||
<text text-anchor="middle" x="238" y="-109.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">1</text>
|
||||
</g>
|
||||
<!-- 1->5 -->
|
||||
<g id="edge2" class="edge">
|
||||
<title>1->5</title>
|
||||
<path fill="none" stroke="black" d="M212.16,-127.49C238.45,-125.11 290.25,-120.1 334,-114 336.56,-113.64 339.23,-113.24 341.89,-112.82"/>
|
||||
<polygon fill="black" stroke="black" points="342.65,-116.24 351.94,-111.14 341.5,-109.34 342.65,-116.24"/>
|
||||
<text text-anchor="middle" x="282" y="-125.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">21</text>
|
||||
</g>
|
||||
<!-- 3 -->
|
||||
<g id="node4" class="node">
|
||||
<title>3</title>
|
||||
<ellipse fill="none" stroke="black" cx="106" cy="-72" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="106" y="-68.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">3</text>
|
||||
</g>
|
||||
<!-- 3->4 -->
|
||||
<g id="edge6" class="edge">
|
||||
<title>3->4</title>
|
||||
<path fill="none" stroke="black" d="M124,-72.49C154.15,-73.35 217.21,-75.17 253.57,-76.21"/>
|
||||
<polygon fill="black" stroke="black" points="253.83,-79.72 263.93,-76.51 254.04,-72.72 253.83,-79.72"/>
|
||||
<text text-anchor="middle" x="194" y="-77.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">5</text>
|
||||
</g>
|
||||
<!-- 3->1 -->
|
||||
<g id="edge4" class="edge">
|
||||
<title>3->1</title>
|
||||
<path fill="none" stroke="black" d="M121.59,-81.67C134.89,-90.48 154.75,-103.65 170.16,-113.86"/>
|
||||
<polygon fill="black" stroke="black" points="168.36,-116.87 178.63,-119.47 172.22,-111.03 168.36,-116.87"/>
|
||||
<text text-anchor="middle" x="150" y="-108.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">11</text>
|
||||
</g>
|
||||
<!-- 2 -->
|
||||
<g id="node5" class="node">
|
||||
<title>2</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">2</text>
|
||||
</g>
|
||||
<!-- 3->2 -->
|
||||
<g id="edge5" class="edge">
|
||||
<title>3->2</title>
|
||||
<path fill="none" stroke="black" d="M119.73,-60.21C126.13,-54.61 134.18,-48.05 142,-43 149.98,-37.84 159.17,-33.03 167.53,-29.03"/>
|
||||
<polygon fill="black" stroke="black" points="169.24,-32.1 176.85,-24.73 166.31,-25.74 169.24,-32.1"/>
|
||||
<text text-anchor="middle" x="150" y="-46.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">2</text>
|
||||
</g>
|
||||
<!-- 2->4 -->
|
||||
<g id="edge7" class="edge">
|
||||
<title>2->4</title>
|
||||
<path fill="none" stroke="black" d="M210.88,-24.24C221.33,-28.71 235.03,-35.28 246,-43 251.55,-46.9 257.05,-51.69 261.99,-56.43"/>
|
||||
<polygon fill="black" stroke="black" points="259.68,-59.07 269.22,-63.7 264.65,-54.14 259.68,-59.07"/>
|
||||
<text text-anchor="middle" x="238" y="-46.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">12</text>
|
||||
</g>
|
||||
<!-- 0 -->
|
||||
<g id="node6" class="node">
|
||||
<title>0</title>
|
||||
<ellipse fill="none" stroke="black" cx="18" cy="-72" rx="18" ry="18"/>
|
||||
<text text-anchor="middle" x="18" y="-68.3" font-family="Helvetica,Arial,sans-serif" font-size="14.00">0</text>
|
||||
</g>
|
||||
<!-- 0->1 -->
|
||||
<g id="edge8" class="edge">
|
||||
<title>0->1</title>
|
||||
<path fill="none" stroke="black" d="M34.05,-80.9C40.13,-84.3 47.29,-88.06 54,-91 91.85,-107.58 101.88,-111.09 142,-121 149.66,-122.89 158.08,-124.43 165.83,-125.63"/>
|
||||
<polygon fill="black" stroke="black" points="165.46,-129.11 175.85,-127.06 166.45,-122.18 165.46,-129.11"/>
|
||||
<text text-anchor="middle" x="106" y="-119.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">7</text>
|
||||
</g>
|
||||
<!-- 0->3 -->
|
||||
<g id="edge9" class="edge">
|
||||
<title>0->3</title>
|
||||
<path fill="none" stroke="black" d="M36.4,-72C48.25,-72 64.18,-72 77.71,-72"/>
|
||||
<polygon fill="black" stroke="black" points="77.92,-75.5 87.92,-72 77.92,-68.5 77.92,-75.5"/>
|
||||
<text text-anchor="middle" x="62" y="-75.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">10</text>
|
||||
</g>
|
||||
<!-- 0->2 -->
|
||||
<g id="edge10" class="edge">
|
||||
<title>0->2</title>
|
||||
<path fill="none" stroke="black" d="M32.63,-61.22C45.94,-51.32 67.17,-37.14 88,-30 113.39,-21.3 144.05,-18.62 165.66,-17.93"/>
|
||||
<polygon fill="black" stroke="black" points="165.85,-21.42 175.78,-17.72 165.71,-14.43 165.85,-21.42"/>
|
||||
<text text-anchor="middle" x="106" y="-33.8" font-family="Helvetica,Arial,sans-serif" font-size="14.00">8</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.1 KiB |
|
|
@ -29,7 +29,7 @@ let () =
|
|||
let graph = from_file infile in
|
||||
|
||||
(* Rewrite the graph that has been read. *)
|
||||
let () = write_file outfile graph in
|
||||
let () = export outfile graph in
|
||||
|
||||
()
|
||||
|
||||
|
|
|
|||
25
src/gfile.ml
25
src/gfile.ml
|
|
@ -3,6 +3,31 @@ open Printf
|
|||
|
||||
type path = string
|
||||
|
||||
let export path graph =
|
||||
let ff = open_out path in
|
||||
|
||||
fprintf ff
|
||||
"
|
||||
digraph cool_generated_graph {
|
||||
fontname=\"Helvetica,Arial,sans-serif\"
|
||||
node [fontname=\"Helvetica,Arial,sans-serif\"]
|
||||
edge [fontname=\"Helvetica,Arial,sans-serif\"]
|
||||
rankdir=LR;
|
||||
node [shape = circle];";
|
||||
|
||||
let print_arc arc =
|
||||
fprintf ff "
|
||||
%d -> %d [label = \"%s\"];"
|
||||
arc.src arc.tgt arc.lbl;
|
||||
in e_iter graph print_arc;
|
||||
|
||||
fprintf ff "
|
||||
}";
|
||||
|
||||
close_out ff
|
||||
;;
|
||||
|
||||
|
||||
(* Format of text files:
|
||||
% This is a comment
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ val from_file: path -> string graph
|
|||
* If necessary, use gmap (to be written by you) to prepare the input graph. *)
|
||||
val write_file: path -> string graph -> unit
|
||||
|
||||
val export: path -> string graph -> unit
|
||||
|
||||
(* The format of files is compatible with the files generated by:
|
||||
https://algorithms.discrete.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html
|
||||
|
|
|
|||
Loading…
Reference in a new issue