ruby-graphviz 0.9.16 → 0.9.17

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS CHANGED
@@ -7,6 +7,7 @@ reactive <http://github.com/reactive>
7
7
  Hugh Sasse <hgs@dmu.ac.uk>
8
8
  axgle <http://github.com/axgle>
9
9
  hipe <http://github.com/hipe>
10
+ Stefan Huber <http://github.com/MSNexploder>
10
11
 
11
12
  Thanks to :
12
13
 
data/README.rdoc CHANGED
@@ -16,6 +16,20 @@ Interface to the GraphViz graphing tool
16
16
 
17
17
  == CHANGELOG
18
18
 
19
+ === 0.9.17 :
20
+ * GraphViz::Edge#node_one and GraphViz::Edge#node_one now have un optional parameter to indicate if you want to (or not) get the port in the name (default: true)
21
+ * GraphViz#each_node now returns the Hash of nodes if there is no block given.
22
+ * GraphViz#each_edge now returns the list of edges if there is no block given.
23
+ * GraphViz#each_graph now returns the Hash of graphs if there is no block given.
24
+ * Add GraphViz::Node#index : return the node index
25
+ * Add GraphViz::Edge#index : return the edge index
26
+ * Add GraphViz#type : return the graph type (graph or digraph)
27
+ * Add GraphViz#get_edge_at_index and GraphViz#get_node_at_index
28
+ * Add GvDouble
29
+ * Add GraphViz::Theory (see examples/theory/tests.rb)
30
+ * Add GraphML[http://graphml.graphdrawing.org/] support (see sample57.rb)
31
+ * fixed "edge attribut 'to_ary' invalid" on mri 1.9.2 (by Stefan Huber)
32
+
19
33
  === 0.9.16 :
20
34
  * Add <tt>xml2gv</tt>
21
35
  * Rename <tt>GraphViz.parser2</tt> to <tt>GraphViz.parser</tt>
@@ -208,6 +222,13 @@ Create a graph from a file
208
222
  }
209
223
  }.output(:png => "sample.png")
210
224
 
225
+ GraphML[http://graphml.graphdrawing.org/] support
226
+
227
+ require 'graphviz/graphml'
228
+
229
+ g = GraphViz::GraphML.new( "graphml/cluster.graphml" )
230
+ g.graph.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
231
+
211
232
  At last, you can create familly tree with GraphViz::FamilyTree (<b>beta</b>) :
212
233
 
213
234
  require 'graphviz/family_tree'
@@ -270,6 +291,49 @@ Ruby/GraphViz also include :
270
291
 
271
292
  * <tt>xml2gv</tt>, a tools that's allow you to show a xml file as graph.
272
293
 
294
+ == GRAPH THEORY
295
+
296
+ require 'graphviz'
297
+ require 'graphviz/theory'
298
+
299
+ g = GraphViz.new( :G ) { ... }
300
+
301
+ t = GraphViz::Theory.new( g )
302
+
303
+ puts "Adjancy matrix : "
304
+ puts t.adjancy_matrix
305
+
306
+ puts "Symmetric ? #{t.symmetric?}"
307
+
308
+ puts "Incidence matrix :"
309
+ puts t.incidence_matrix
310
+
311
+ g.each_node do |name, node|
312
+ puts "Degree of node `#{name}' = #{t.degree(node)}"
313
+ end
314
+
315
+ puts "Laplacian matrix :"
316
+ puts t.laplacian_matrix
317
+
318
+ puts "Dijkstra between a and f"
319
+ r = t.moore_dijkstra(g.a, g.f)
320
+ if r.nil?
321
+ puts "No way !"
322
+ else
323
+ print "\tPath : "; p r[:path]
324
+ puts "\tDistance : #{r[:distance]}"
325
+ end
326
+
327
+ print "Ranges : "
328
+ rr = t.range
329
+ p rr
330
+ puts "Your graph contains circuits" if rr.include?(nil)
331
+
332
+ puts "Critical path : "
333
+ rrr = t.critical_path
334
+ print "\tPath "; p rrr[:path]
335
+ puts "\tDistance : #{rrr[:distance]}"
336
+
273
337
  == INSTALLATION
274
338
 
275
339
  sudo gem install ruby-graphviz
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <graphml xmlns="http://graphml.graphdrawing.org/xmlns"
3
+ xmlns:xlink="http://www.w3.org/1999/xlink"
4
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
6
+ graphml+xlink.xsd">
7
+ <graph edgedefault="directed">
8
+ <node id="n0" xlink:href="http://graphml.graphdrawing.org"/>
9
+ <node id="n1" />
10
+ <edge source="n0" target="n1"/>
11
+ </graph>
12
+ </graphml>
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- This file was written by the JAVA GraphML Library.-->
3
+ <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
5
+ <key id="d0" for="node" attr.name="color" attr.type="string">
6
+ <default>yellow</default>
7
+ </key>
8
+ <key id="d1" for="edge" attr.name="weight" attr.type="double"/>
9
+ <graph id="G" edgedefault="undirected">
10
+ <node id="n0">
11
+ <data key="d0">green</data>
12
+ </node>
13
+ <node id="n1"/>
14
+ <node id="n2">
15
+ <data key="d0">blue</data>
16
+ </node>
17
+ <node id="n3">
18
+ <data key="d0">red</data>
19
+ </node>
20
+ <node id="n4"/>
21
+ <node id="n5">
22
+ <data key="d0">turquoise</data>
23
+ </node>
24
+ <edge id="e0" source="n0" target="n2">
25
+ <data key="d1">1.0</data>
26
+ </edge>
27
+ <edge id="e1" source="n0" target="n1">
28
+ <data key="d1">1.0</data>
29
+ </edge>
30
+ <edge id="e2" source="n1" target="n3">
31
+ <data key="d1">2.0</data>
32
+ </edge>
33
+ <edge id="e3" source="n3" target="n2"/>
34
+ <edge id="e4" source="n2" target="n4"/>
35
+ <edge id="e5" source="n3" target="n5"/>
36
+ <edge id="e6" source="n5" target="n4">
37
+ <data key="d1">1.1</data>
38
+ </edge>
39
+ </graph>
40
+ </graphml>
@@ -0,0 +1,75 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- This file was written by the JAVA GraphML Library.-->
3
+ <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
5
+ <key id="color" for="all" attr.name="color" attr.type="string"/>
6
+ <key id="style" for="all" attr.name="style" attr.type="string"/>
7
+ <key id="label" for="all" attr.name="label" attr.type="string"/>
8
+ <key id="shape" for="node" attr.name="shape" attr.type="string"/>
9
+ <graph id="G" edgedefault="directed">
10
+
11
+ <node id="cluster_0:">
12
+ <graph id="cluster_0">
13
+ <data key="color">lightgrey</data>
14
+ <data key="style">filled</data>
15
+ <data key="label">process #1</data>
16
+ <node id="a0">
17
+ <data key="style">filled</data>
18
+ <data key="style">white</data>
19
+ </node>
20
+ <node id="a1">
21
+ <data key="style">filled</data>
22
+ <data key="style">white</data>
23
+ </node>
24
+ <node id="a2">
25
+ <data key="style">filled</data>
26
+ <data key="style">white</data>
27
+ </node>
28
+ <node id="a3">
29
+ <data key="style">filled</data>
30
+ <data key="style">white</data>
31
+ </node>
32
+ <edge id="e0" source="a0" target="a1"/>
33
+ <edge id="e1" source="a1" target="a2"/>
34
+ <edge id="e2" source="a2" target="a3"/>
35
+ </graph>
36
+ </node>
37
+
38
+ <node id="cluster_1:">
39
+ <graph id="cluster_1">
40
+ <data key="color">blue</data>
41
+ <data key="label">process #2</data>
42
+ <node id="b0">
43
+ <data key="style">filled</data>
44
+ </node>
45
+ <node id="b1">
46
+ <data key="style">filled</data>
47
+ </node>
48
+ <node id="b2">
49
+ <data key="style">filled</data>
50
+ </node>
51
+ <node id="b3">
52
+ <data key="style">filled</data>
53
+ </node>
54
+ <edge id="e3" source="b0" target="b1"/>
55
+ <edge id="e4" source="b1" target="b2"/>
56
+ <edge id="e5" source="b2" target="b3"/>
57
+ </graph>
58
+ </node>
59
+
60
+ <node id="start">
61
+ <data key="shape">Mdiamond</data>
62
+ </node>
63
+ <node id="end">
64
+ <data key="shape">Mdiamond</data>
65
+ </node>
66
+
67
+ <edge id="e6" source="start" target="a0"/>
68
+ <edge id="e7" source="start" target="b0"/>
69
+ <edge id="e8" source="a1" target="b3"/>
70
+ <edge id="e9" source="b2" target="a3"/>
71
+ <edge id="eA" source="a3" target="a0"/>
72
+ <edge id="eB" source="a3" target="end"/>
73
+ <edge id="eC" source="b3" target="end"/>
74
+ </graph>
75
+ </graphml>
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
4
+ <graph id="G" edgedefault="directed">
5
+ <node id="n0"/>
6
+ <node id="n1"/>
7
+ <node id="n2"/>
8
+ <node id="n3"/>
9
+ <node id="n4"/>
10
+ <node id="n5"/>
11
+ <node id="n6"/>
12
+ <hyperedge>
13
+ <endpoint node="n0"/>
14
+ <endpoint node="n1"/>
15
+ <endpoint node="n2"/>
16
+ </hyperedge>
17
+ <hyperedge>
18
+ <endpoint node="n3"/>
19
+ <endpoint node="n4"/>
20
+ <endpoint node="n5"/>
21
+ <endpoint node="n6"/>
22
+ </hyperedge>
23
+ <hyperedge>
24
+ <endpoint node="n1"/>
25
+ <endpoint node="n3"/>
26
+ </hyperedge>
27
+ <edge source="n0" target="n4"/>
28
+ </graph>
29
+ </graphml>
@@ -0,0 +1,54 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- This file was written by the JAVA GraphML Library.-->
3
+ <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
5
+ <key id="color" for="all" attr.name="color" attr.type="string"/>
6
+ <key id="style" for="graph" attr.name="style" attr.type="string"/>
7
+ <key id="label" for="all" attr.name="label" attr.type="string"/>
8
+ <graph id="G" edgedefault="directed">
9
+ <node id="n0"/>
10
+ <node id="n1"/>
11
+ <node id="n2"/>
12
+ <node id="n3"/>
13
+ <node id="n4"/>
14
+ <node id="n5">
15
+ <graph id="n5:" edgedefault="directed">
16
+ <data key="color">black</data>
17
+ <data key="style">filled</data>
18
+ <data key="label">SUB n5</data>
19
+ <node id="n5::n0"/>
20
+ <node id="n5::n1"/>
21
+ <node id="n5::n2"/>
22
+ <edge id="e0" source="n5::n0" target="n5::n2"/>
23
+ <edge id="e1" source="n5::n1" target="n5::n2"/>
24
+ </graph>
25
+ </node>
26
+ <node id="n6">
27
+ <graph id="n6:" edgedefault="directed">
28
+ <data key="color">red</data>
29
+ <data key="style">filled</data>
30
+ <data key="label">SUB n6</data>
31
+ <node id="n6::n0">
32
+ <graph id="n6::n0:" edgedefault="directed">
33
+ <data key="label">SUB n6::n0</data>
34
+ <data key="color">blue</data>
35
+ <data key="style">filled</data>
36
+ <node id="n6::n0::n0"/>
37
+ </graph>
38
+ </node>
39
+ <node id="n6::n1"/>
40
+ <node id="n6::n2"/>
41
+ <edge id="e10" source="n6::n1" target="n6::n0::n0"/>
42
+ <edge id="e11" source="n6::n1" target="n6::n2"/>
43
+ </graph>
44
+ </node>
45
+ <edge id="e2" source="n5::n2" target="n0"/>
46
+ <edge id="e3" source="n0" target="n2"/>
47
+ <edge id="e4" source="n0" target="n1"/>
48
+ <edge id="e5" source="n1" target="n3"/>
49
+ <edge id="e6" source="n3" target="n2"/>
50
+ <edge id="e7" source="n2" target="n4"/>
51
+ <edge id="e8" source="n3" target="n6::n1"/>
52
+ <edge id="e9" source="n6::n1" target="n4"/>
53
+ </graph>
54
+ </graphml>
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
4
+ <graph id="G" edgedefault="directed">
5
+ <node id="n0">
6
+ <port name="North"/>
7
+ <port name="South"/>
8
+ <port name="East"/>
9
+ <port name="West"/>
10
+ </node>
11
+ <node id="n1">
12
+ <port name="North"/>
13
+ <port name="South"/>
14
+ <port name="East"/>
15
+ <port name="West"/>
16
+ </node>
17
+ <node id="n2">
18
+ <port name="NorthWest"/>
19
+ <port name="SouthEast"/>
20
+ </node>
21
+ <node id="n3">
22
+ <port name="NorthEast"/>
23
+ <port name="SouthWest"/>
24
+ </node>
25
+ <edge source="n0" target="n3" sourceport="North" targetport="NorthEast"/>
26
+ <hyperedge>
27
+ <endpoint node="n0" port="North"/>
28
+ <endpoint node="n1" port="East"/>
29
+ <endpoint node="n2" port="SouthEast"/>
30
+ </hyperedge>
31
+ </graph>
32
+ </graphml>
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- This file was written by the JAVA GraphML Library.-->
3
+ <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
5
+ <graph id="G" edgedefault="directed">
6
+ <node id="n0"/>
7
+ <node id="n1"/>
8
+ <node id="n2"/>
9
+ <node id="n3"/>
10
+ <node id="n4"/>
11
+ <node id="n5"/>
12
+ <node id="n6"/>
13
+ <node id="n7"/>
14
+ <node id="n8"/>
15
+ <node id="n9"/>
16
+ <node id="n10"/>
17
+ <edge source="n0" target="n2"/>
18
+ <edge source="n1" target="n2"/>
19
+ <edge source="n2" target="n3"/>
20
+ <edge source="n3" target="n5"/>
21
+ <edge source="n3" target="n4"/>
22
+ <edge source="n4" target="n6"/>
23
+ <edge source="n6" target="n5"/>
24
+ <edge source="n5" target="n7"/>
25
+ <edge source="n6" target="n8"/>
26
+ <edge source="n8" target="n7"/>
27
+ <edge source="n8" target="n9"/>
28
+ <edge source="n8" target="n10"/>
29
+ </graph>
30
+ </graphml>
@@ -0,0 +1,6 @@
1
+ $:.unshift( "../lib" )
2
+
3
+ require 'graphviz/graphml'
4
+
5
+ g = GraphViz::GraphML.new( "graphml/cluster.graphml" )
6
+ g.graph.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
Binary file
Binary file
@@ -0,0 +1,47 @@
1
+ $:.unshift( "../../lib" )
2
+ require 'graphviz'
3
+ require 'graphviz/theory'
4
+
5
+ g = GraphViz.digraph( "G", :path => "/usr/local/bin", :use => "fdp" ) do |g|
6
+ g.node[:shape => "record"]
7
+
8
+ g.start[:label => "Start"]
9
+ g.task_1[:label => "Task #1 - Duration : 4d"]
10
+ g.task_2[:label => "Task #2 - Duration : 5.25d"]
11
+ g.task_3[:label => "Task #3 - Duration : 5.17d"]
12
+ g.task_4[:label => "Task #4 - Duration : 6.33d"]
13
+ g.task_5[:label => "Task #5 - Duration : 5.17d"]
14
+ g.task_6[:label => "Task #6 - Duration : 4.5d"]
15
+ g.task_7[:label => "Task #7 - Duration : 5.17d"]
16
+ g.finish[:label => "End"]
17
+
18
+ (g.start << g.task_1)[:weight => 0.0]
19
+ (g.start << g.task_2)[:weight => 0.0]
20
+ (g.task_1 << g.task_3)[:weight => 4.0]
21
+ (g.task_1 << g.task_4)[:weight => 4.0]
22
+ (g.task_2 << g.task_5)[:weight => 5.25]
23
+ (g.task_3 << g.task_5)[:weight => 5.17]
24
+ (g.task_4 << g.task_6)[:weight => 6.33]
25
+ (g.task_5 << g.task_7)[:weight => 5.17]
26
+ (g.task_6 << g.finish)[:weight => 4.5]
27
+ (g.task_7 << g.finish)[:weight => 5.17]
28
+ end
29
+ g.output( :png => "PERT.png" )
30
+
31
+ t = GraphViz::Theory.new( g )
32
+
33
+ print "Ranges : "
34
+ rr = t.range
35
+ p rr
36
+ puts "Your graph contains circuits" if rr.include?(nil)
37
+
38
+ puts "Critical path : "
39
+ rrr = t.critical_path
40
+ print "\tPath :"
41
+ _ = ""
42
+ rrr[:path].each do |i|
43
+ print _ + g.get_node_at_index(i-1).id
44
+ _ = " -> "
45
+ end
46
+ puts
47
+ puts "\tDistance : #{rrr[:distance]}"
@@ -0,0 +1,81 @@
1
+ $:.unshift( "../../lib" )
2
+ require 'graphviz'
3
+ require 'graphviz/theory'
4
+
5
+ g = GraphViz.digraph( "G", :path => "/usr/local/bin" ) do |g|
6
+ g.a[:label => "1"]
7
+ g.b[:label => "2"]
8
+ g.c[:label => "3"]
9
+ g.d[:label => "4"]
10
+ g.e[:label => "5"]
11
+ g.f[:label => "6"]
12
+
13
+ # g.a << g.a
14
+ g.a << g.b
15
+ g.a << g.d
16
+ (g.a << g.f)[:weight => 6, :label => "6"]
17
+ g.b << g.c
18
+ g.b << g.d
19
+ g.b << g.e
20
+ g.c << g.d
21
+ (g.c << g.f)[:weight => 2, :label => "2"]
22
+ g.d << g.e
23
+ # g.e << g.c
24
+ end
25
+ g.output( :png => "matrix.png" )
26
+
27
+ t = GraphViz::Theory.new( g )
28
+
29
+ puts "Adjancy matrix : "
30
+ puts t.adjancy_matrix
31
+ # => [ 0 1 0 1 0 1]
32
+ # [ 0 0 1 1 1 0]
33
+ # [ 0 0 0 1 0 1]
34
+ # [ 0 0 0 0 1 0]
35
+ # [ 0 0 0 0 0 0]
36
+ # [ 0 0 0 0 0 0]
37
+
38
+ puts "Symmetric ? #{t.symmetric?}"
39
+
40
+ puts "Incidence matrix :"
41
+ puts t.incidence_matrix
42
+ # => [ 1 1 1 1 0 0 0 0 0 0]
43
+ # [ 0 -1 0 0 1 1 1 0 0 0]
44
+ # [ 0 0 0 0 -1 0 0 1 1 0]
45
+ # [ 0 0 -1 0 0 -1 0 -1 0 1]
46
+ # [ 0 0 0 0 0 0 -1 0 0 -1]
47
+ # [ 0 0 0 -1 0 0 0 0 -1 0]
48
+
49
+ g.each_node do |name, node|
50
+ puts "Degree of node `#{name}' = #{t.degree(node)}"
51
+ end
52
+
53
+ puts "Laplacian matrix :"
54
+ puts t.laplacian_matrix
55
+ # => [ 3 -1 0 -1 0 -1]
56
+ # [ 0 4 -1 -1 -1 0]
57
+ # [ 0 0 3 -1 0 -1]
58
+ # [ 0 0 0 4 -1 0]
59
+ # [ 0 0 0 0 2 0]
60
+ # [ 0 0 0 0 0 2]
61
+
62
+ puts "Dijkstra between a and f"
63
+ r = t.moore_dijkstra(g.a, g.f)
64
+ if r.nil?
65
+ puts "No way !"
66
+ else
67
+ print "\tPath : "; p r[:path]
68
+ puts "\tDistance : #{r[:distance]}"
69
+ end
70
+ # => Path : ["a", "b", "c", "f"]
71
+ # Distance : 4.0
72
+
73
+ print "Ranges : "
74
+ rr = t.range
75
+ p rr
76
+ puts "Your graph contains circuits" if rr.include?(nil)
77
+
78
+ puts "Critical path : "
79
+ rrr = t.critical_path
80
+ print "\tPath "; p rrr[:path]
81
+ puts "\tDistance : #{rrr[:distance]}"