gratr19 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/README +335 -0
  2. data/examples/graph_self.rb +54 -0
  3. data/examples/module_graph.jpg +0 -0
  4. data/examples/module_graph.rb +12 -0
  5. data/examples/self_graph.jpg +0 -0
  6. data/examples/visualize.jpg +0 -0
  7. data/examples/visualize.rb +8 -0
  8. data/install.rb +49 -0
  9. data/lib/gratr.rb +42 -0
  10. data/lib/gratr/adjacency_graph.rb +230 -0
  11. data/lib/gratr/base.rb +34 -0
  12. data/lib/gratr/biconnected.rb +116 -0
  13. data/lib/gratr/chinese_postman.rb +123 -0
  14. data/lib/gratr/common.rb +74 -0
  15. data/lib/gratr/comparability.rb +92 -0
  16. data/lib/gratr/digraph.rb +115 -0
  17. data/lib/gratr/digraph_distance.rb +185 -0
  18. data/lib/gratr/dot.rb +90 -0
  19. data/lib/gratr/edge.rb +145 -0
  20. data/lib/gratr/graph.rb +314 -0
  21. data/lib/gratr/graph_api.rb +82 -0
  22. data/lib/gratr/import.rb +44 -0
  23. data/lib/gratr/labels.rb +103 -0
  24. data/lib/gratr/maximum_flow.rb +107 -0
  25. data/lib/gratr/rdot.rb +332 -0
  26. data/lib/gratr/search.rb +422 -0
  27. data/lib/gratr/strong_components.rb +127 -0
  28. data/lib/gratr/undirected_graph.rb +153 -0
  29. data/lib/gratr/version.rb +6 -0
  30. data/lib/priority-queue/benchmark/dijkstra.rb +171 -0
  31. data/lib/priority-queue/compare_comments.rb +49 -0
  32. data/lib/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb +2 -0
  33. data/lib/priority-queue/lib/priority_queue.rb +14 -0
  34. data/lib/priority-queue/lib/priority_queue/c_priority_queue.rb +1 -0
  35. data/lib/priority-queue/lib/priority_queue/poor_priority_queue.rb +46 -0
  36. data/lib/priority-queue/lib/priority_queue/ruby_priority_queue.rb +525 -0
  37. data/lib/priority-queue/setup.rb +1551 -0
  38. data/lib/priority-queue/test/priority_queue_test.rb +371 -0
  39. data/tests/TestBiconnected.rb +53 -0
  40. data/tests/TestChinesePostman.rb +53 -0
  41. data/tests/TestComplement.rb +54 -0
  42. data/tests/TestDigraph.rb +333 -0
  43. data/tests/TestDigraphDistance.rb +138 -0
  44. data/tests/TestDot.rb +75 -0
  45. data/tests/TestEdge.rb +171 -0
  46. data/tests/TestInspection.rb +57 -0
  47. data/tests/TestMultiEdge.rb +57 -0
  48. data/tests/TestNeighborhood.rb +64 -0
  49. data/tests/TestProperties.rb +160 -0
  50. data/tests/TestSearch.rb +277 -0
  51. data/tests/TestStrongComponents.rb +85 -0
  52. data/tests/TestTriagulated.rb +137 -0
  53. data/tests/TestUndirectedGraph.rb +219 -0
  54. metadata +152 -0
@@ -0,0 +1,75 @@
1
+ #--
2
+ # Copyright (c) 2006 Shawn Patrick Garbett
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice(s),
8
+ # this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+ # * Neither the name of the Shawn Garbett nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ #++
27
+
28
+ require 'test/unit'
29
+ require 'gratr/import'
30
+
31
+ class TestDot < Test::Unit::TestCase # :nodoc:
32
+
33
+ DG_DOT = <<-DOT
34
+ digraph {
35
+ label = "Datacenters"
36
+ Miranda [
37
+ color = green,
38
+ style = filled,
39
+ label = "Miranda"
40
+ ]
41
+
42
+ Miranda -> Hillview [
43
+
44
+ ]
45
+
46
+ Miranda -> "San Francisco" [
47
+
48
+ ]
49
+
50
+ Miranda -> "San Jose" [
51
+
52
+ ]
53
+
54
+ Sunnyvale -> Miranda [
55
+
56
+ ]
57
+
58
+ }
59
+ DOT
60
+
61
+ def setup
62
+ @dg = DOT::DOTDigraph.new('label' => 'Datacenters')
63
+ @dg << DOT::DOTNode.new('name' => 'Miranda', 'color' => 'green', 'style' => 'filled')
64
+ @dg << DOT::DOTDirectedArc.new('from' => 'Miranda', 'to' => 'Hillview')
65
+ @dg << DOT::DOTDirectedArc.new('from' => 'Miranda', 'to' => '"San Francisco"')
66
+ @dg << DOT::DOTDirectedArc.new('from' => 'Miranda', 'to' => '"San Jose"')
67
+ @dg << DOT::DOTDirectedArc.new('from' => 'Sunnyvale', 'to' => 'Miranda')
68
+ end
69
+
70
+ def test_generation
71
+ assert @dg.to_s
72
+ assert_equal DG_DOT, @dg.to_s
73
+ end
74
+
75
+ end
@@ -0,0 +1,171 @@
1
+ #--
2
+ # Copyright (c) 2006 Shawn Patrick Garbett
3
+ # Copyright (c) 2002,2004,2005 by Horst Duchene
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice(s),
9
+ # this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ # * Neither the name of the Shawn Garbett nor the names of its contributors
14
+ # may be used to endorse or promote products derived from this software
15
+ # without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #++
28
+
29
+
30
+ require 'test/unit'
31
+ require 'gratr/import'
32
+
33
+ class TestArc < Test::Unit::TestCase # :nodoc:
34
+
35
+ def setup
36
+ @e = Arc.new(1,2,'boo')
37
+ @u = Edge.new(1,2,'hoo')
38
+ end
39
+
40
+ def test_edge_new
41
+ assert_raises(ArgumentError) {Arc.new}
42
+ assert_raises(ArgumentError) {Arc.new(1)}
43
+ assert Arc.new(1,2)
44
+ assert Arc.new(1,2,'label')
45
+ end
46
+
47
+ def test_edge_getters
48
+
49
+ assert_equal(1, @e.source)
50
+ assert_equal(2, @e.target)
51
+ assert_equal('boo', @e.label)
52
+
53
+ assert_equal(1, @e[0])
54
+ assert_equal(2, @e[1])
55
+ assert_equal('boo', @e[2])
56
+
57
+ assert_equal(1, @e[-3])
58
+ assert_equal(2, @e[-2])
59
+ assert_equal('boo', @e[-1])
60
+
61
+ assert_raise(IndexError) {@e[-4]}
62
+ assert_raise(IndexError) {@e[3]}
63
+
64
+ assert_equal(1, @e['source'])
65
+ assert_equal(2, @e['target'])
66
+ assert_equal('boo', @e['label'])
67
+
68
+ assert_equal(1, @e[:source])
69
+ assert_equal(2, @e[:target])
70
+ assert_equal('boo', @e[:label])
71
+ end
72
+
73
+ def test_edge_setters
74
+ @e.source = 23
75
+ @e.target = 42
76
+ @e.label = 'Yabba'
77
+ assert_equal(23, @e.source)
78
+ assert_equal(42, @e.target)
79
+ assert_equal('Yabba',@e.label)
80
+
81
+ @e['source'] = 2
82
+ @e['target'] = 1
83
+ @e['label'] = 'Dabba'
84
+ assert_equal(2, @e.source)
85
+ assert_equal(1, @e.target)
86
+ assert_equal('Dabba',@e.label)
87
+
88
+ @e[:source] = 9
89
+ @e[:target] = 8
90
+ @e['label'] = 'Doooo!'
91
+ assert_equal(9, @e.source)
92
+ assert_equal(8, @e.target)
93
+ assert_equal('Doooo!',@e.label)
94
+
95
+ @e[0] = 'Fred'
96
+ @e[1] = 'Flintstone'
97
+ @e[2] = 'and'
98
+ assert_equal('Fred', @e.source)
99
+ assert_equal('Flintstone',@e.target)
100
+ assert_equal('and', @e.label)
101
+
102
+ @e[-3] = 'Barney'
103
+ @e[-2] = 'Rubble'
104
+ @e[-1] = nil
105
+ assert_equal('Barney', @e.source)
106
+ assert_equal('Rubble', @e.target)
107
+ assert_equal(nil, @e.label)
108
+ end
109
+
110
+ def test_edge_simple_methods
111
+ assert_equal([1,2,'boo'], @e.to_a)
112
+ assert_equal("(1-2 'boo')", @e.to_s)
113
+ @e.label = nil
114
+ assert_equal("(1-2)", @e.to_s)
115
+ assert(@e.eql?(Arc.new(1,2)))
116
+ assert(!@e.eql?(Arc.new(1,3)))
117
+ assert(!Arc.new(2,1).eql?(@e))
118
+
119
+ assert(@e == (Arc.new(1,2)))
120
+ assert(@e.reverse == (Arc.new(2,1)))
121
+ assert(Arc.new(1,2) != (Arc.new(1,3)))
122
+ assert(Arc.new(2,1) != @e)
123
+ end
124
+
125
+ def test_edge_sort
126
+ x = [ Arc.new(2,3), Arc.new(1,3), Arc.new(1,2), Arc.new(2,1) ].sort
127
+ assert_equal [Arc.new(1,2), Arc.new(1,3), Arc.new(2,1), Arc.new(2,3)], x
128
+ end
129
+
130
+ def test_undirected_edge_new
131
+ assert_raises(ArgumentError) {Edge.new}
132
+ assert_raises(ArgumentError) {Edge.new(1)}
133
+ assert Edge.new(1,2)
134
+ assert Edge.new(1,2,'label')
135
+ end
136
+
137
+ def test_undirected_edge_getters
138
+ assert_equal(1,@u.source)
139
+ assert_equal(2,@u.target)
140
+ assert_equal([1,2,'hoo'],@u.to_a)
141
+ assert_equal("(1=2 'hoo')",@u.to_s)
142
+ end
143
+
144
+ def test_undirected_edge_methods
145
+ @u.label = nil
146
+ assert_equal("(1=2)",@u.to_s)
147
+ assert_equal("(1=2)",Edge.new(2,1).to_s)
148
+
149
+ assert @u.eql?(Edge.new(2,1))
150
+ assert @u == Edge.new(2,1,'boo')
151
+ assert @u != Edge.new(2,3)
152
+
153
+ assert_equal(@u.hash,Edge.new(2,1).hash)
154
+ end
155
+
156
+ def test_undirected_edge_sort
157
+ x=[Edge.new(12, 1), Edge.new(2,11)].sort
158
+ assert_equal [Edge.new(2,11), Edge.new(1,12)], x
159
+ end
160
+
161
+ def test_hash
162
+ assert_equal Arc[1,2,:b], Arc[1,2,:c]
163
+ assert_equal Arc[1,2,:b].hash, Arc[1,2,:c].hash
164
+ assert Arc[1,2] != Arc[2,1]
165
+ assert Arc[1,2] != Edge[1,2]
166
+ assert_equal Edge[1,2], Edge[2,1]
167
+ assert_equal Edge[1,2,:a], Edge[2,1,:b]
168
+ end
169
+
170
+ end
171
+
@@ -0,0 +1,57 @@
1
+ #--
2
+ # Copyright (c) 2006 Shawn Patrick Garbett
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice(s),
8
+ # this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+ # * Neither the name of the Shawn Garbett nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ #++
27
+
28
+
29
+ require 'test/unit'
30
+ require 'gratr/import'
31
+
32
+ class TestInspection < Test::Unit::TestCase # :nodoc:
33
+
34
+ def setup
35
+ @dg = DirectedMultiGraph[
36
+ [0,0,1] => 1,
37
+ [1,2,2] => 2,
38
+ [1,3,3] => 4,
39
+ [1,4,4] => nil,
40
+ [4,1,5] => 8,
41
+ [1,2,6] => 16,
42
+ [3,3,7] => 32,
43
+ [3,3,8] => 64 ]
44
+ @dg[3] = 128
45
+ @dg[0] = 256
46
+ end
47
+
48
+ def test_inspection
49
+ inspect = @dg.inspect
50
+ assert_equal 384, @dg.vertices.inject(0) {|a,v| a += (@dg[v] || 0)}
51
+ assert_equal 127, @dg.edges.inject(0) {|a,e| a += (@dg[e] || 0)}
52
+ reflect = eval inspect
53
+ assert reflect == @dg
54
+ assert_equal 127, reflect.edges.inject(0) {|a,e| a += (reflect[e] || 0)}
55
+ assert_equal 384, reflect.vertices.inject(0) {|a,v| a += (reflect[v] || 0)}
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ #--
2
+ # Copyright (c) 2006 Shawn Patrick Garbett
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice(s),
8
+ # this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+ # * Neither the name of the Shawn Garbett nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ #++
27
+
28
+
29
+ require 'test/unit'
30
+ require 'gratr/import'
31
+
32
+ class TestMultiArc < Test::Unit::TestCase # :nodoc:
33
+
34
+ def test_directed_pseudo_graph
35
+ dpg=DirectedPseudoGraph[ :a,:b,
36
+ :a,:b,
37
+ :a,:b ]
38
+ assert_equal 3, dpg.edges.size
39
+ x=0
40
+ dpg.edges.each {|e| dpg[e] = (x+=1)}
41
+ assert_equal 6, dpg.edges.inject(0) {|a,v| a+=dpg[v]}
42
+ end
43
+
44
+ def test_directed_multi_graph
45
+ dmg=DirectedMultiGraph[ :a,:a,
46
+ :a,:a,
47
+ :a,:b,
48
+ :a,:b,
49
+ :b,:b,
50
+ :b,:b ]
51
+ assert_equal 6, dmg.edges.size
52
+ x = 0
53
+ dmg.edges.each {|e| dmg[e] = (x+=1)}
54
+ assert_equal 21, dmg.edges.inject(0) {|a,v| a+=dmg[v]}
55
+ end
56
+
57
+ end
@@ -0,0 +1,64 @@
1
+ #--
2
+ # Copyright (c) 2006 Shawn Patrick Garbett
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice(s),
8
+ # this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+ # * Neither the name of the Shawn Garbett nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ #++
27
+
28
+
29
+ require 'test/unit'
30
+ require 'gratr/import'
31
+
32
+ class TestNeighborhood < Test::Unit::TestCase # :nodoc:
33
+
34
+ def setup
35
+ @d = Digraph[:a,:b, :a,:f,
36
+ :b,:g,
37
+ :c,:b, :c,:g,
38
+ :d,:c, :d,:g,
39
+ :e,:d,
40
+ :f,:e, :f,:g,
41
+ :g,:a, :g,:e]
42
+ @w = [:a,:b]
43
+ end
44
+
45
+ def test_open_out_neighborhood
46
+ assert_equal [:g], @d.set_neighborhood([:a], :in)
47
+ assert_equal [], [:f,:g] - @d.set_neighborhood(@w, :out)
48
+ assert_equal [], @w - @d.open_pth_neighborhood(@w, 0, :out)
49
+ assert_equal [], [:f, :g] - @d.open_pth_neighborhood(@w, 1, :out)
50
+ assert_equal [], [:e] - @d.open_pth_neighborhood(@w, 2, :out)
51
+ assert_equal [], [:d] - @d.open_pth_neighborhood(@w, 3, :out)
52
+ assert_equal [], [:c] - @d.open_pth_neighborhood(@w, 4, :out)
53
+ end
54
+
55
+ def test_closed_out_neighborhood
56
+ assert_equal [], @w - @d.closed_pth_neighborhood(@w, 0, :out)
57
+ assert_equal [], [:a,:b,:f,:g] - @d.closed_pth_neighborhood(@w, 1, :out)
58
+ assert_equal [], [:a,:b,:e,:f,:g] - @d.closed_pth_neighborhood(@w, 2, :out)
59
+ assert_equal [], [:a,:b,:d,:e,:f,:g] - @d.closed_pth_neighborhood(@w, 3, :out)
60
+ assert_equal [], [:a,:b,:c,:d,:e,:f,:g] - @d.closed_pth_neighborhood(@w, 4, :out)
61
+ end
62
+
63
+
64
+ end
@@ -0,0 +1,160 @@
1
+ #--
2
+ # Copyright (c) 2006 Shawn Patrick Garbett
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice(s),
8
+ # this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+ # * Neither the name of the Shawn Garbett nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ #++
27
+
28
+
29
+ require 'test/unit'
30
+ require 'gratr/import'
31
+ require 'gratr/dot'
32
+
33
+ # This test runs the classes from Appendix F in
34
+ # _Algorithmic_Graph_Theory_and_Perfect_Graphs,
35
+ # by Martin Charles Golumbic
36
+ class TestProperties < Test::Unit::TestCase # :nodoc:
37
+
38
+ def test_g1
39
+ g1 = UndirectedGraph[ :a,:b, :a,:d, :a,:e, :a,:i, :a,:g, :a,:h,
40
+ :b,:c, :b,:f,
41
+ :c,:d, :c,:h,
42
+ :d,:h, :d,:e,
43
+ :e,:f,
44
+ :f,:g, :f,:h, :f,:i,
45
+ :h,:i ]
46
+
47
+ assert !g1.triangulated?
48
+ assert !g1.complement.triangulated? # Disagrees with Golumbic!
49
+ assert !g1.comparability?
50
+ assert !g1.complement.comparability?
51
+ assert !g1.interval?
52
+ assert !g1.complement.interval?
53
+ assert !g1.permutation?
54
+ assert !g1.split?
55
+
56
+ # g1.write_to_graphic_file('jpg','g1')
57
+ # g1.complement.write_to_graphic_file('jpg','g1_complement')
58
+ end
59
+
60
+ def test_g2
61
+ g2 = UndirectedGraph[ :a,:b, :a,:e,
62
+ :b,:c, :b,:e, :b,:f,
63
+ :c,:d, :c,:f, :c,:g,
64
+ :d,:g,
65
+ :e,:f,
66
+ :f,:g]
67
+
68
+ assert g2.triangulated?
69
+ assert !g2.complement.triangulated?
70
+ assert !g2.comparability?
71
+ assert g2.complement.comparability?
72
+ assert g2.interval?
73
+ assert !g2.complement.interval?
74
+ assert !g2.permutation?
75
+ assert !g2.split?
76
+ end
77
+
78
+ def test_g3
79
+ g3 = UndirectedGraph[ :a,:c,
80
+ :b,:e,
81
+ :c,:d, :c,:f,
82
+ :d,:f, :d,:g, :d,:e,
83
+ :e,:g,
84
+ :f,:g ]
85
+ assert g3.triangulated?
86
+ assert !g3.complement.triangulated?
87
+ assert !g3.comparability?
88
+ assert g3.complement.comparability?
89
+ assert g3.interval?
90
+ assert !g3.complement.interval?
91
+ assert !g3.permutation?
92
+ assert !g3.split?
93
+ end
94
+
95
+ def test_g4
96
+ g4 = UndirectedGraph[ :a,:b,
97
+ :b,:c,
98
+ :c,:d, :c,:e,
99
+ :d,:f,
100
+ :e,:g]
101
+ assert g4.triangulated?
102
+ assert !g4.complement.triangulated?
103
+ assert g4.comparability?
104
+ assert !g4.complement.comparability?
105
+ assert !g4.interval?
106
+ assert !g4.complement.interval?
107
+ assert !g4.permutation?
108
+ assert !g4.split?
109
+ end
110
+
111
+ def test_g5
112
+ g5 = UndirectedGraph[ :a,:b, :a,:c,
113
+ :b,:c, :b,:d, :b,:f, :b,:g,
114
+ :c,:e, :c,:f, :c,:g,
115
+ :d,:f,
116
+ :e,:g,
117
+ :f,:g]
118
+ assert g5.triangulated?
119
+ assert g5.complement.triangulated?
120
+ assert g5.comparability?
121
+ assert !g5.complement.comparability?
122
+ assert !g5.interval?
123
+ assert g5.complement.interval?
124
+ assert !g5.permutation?
125
+ assert g5.split?
126
+ end
127
+
128
+ def test_g6
129
+ g6 = UndirectedGraph[ :a,:c, :a,:d,
130
+ :b,:c,
131
+ :c,:f,
132
+ :d,:e, :d,:f]
133
+ assert !g6.triangulated?
134
+ assert !g6.complement.triangulated?
135
+ assert g6.comparability?
136
+ assert g6.complement.comparability?
137
+ assert !g6.interval?
138
+ assert !g6.complement.interval?
139
+ assert g6.permutation?
140
+ assert !g6.split?
141
+ end
142
+
143
+ def test_g7
144
+ g7 = UndirectedGraph[ :a,:b, :a,:c,
145
+ :b,:c, :b,:d, :b,:e,
146
+ :c,:e, :c,:f,
147
+ :d,:e,
148
+ :e,:f]
149
+ assert g7.triangulated?
150
+ assert g7.complement.triangulated?
151
+ assert !g7.comparability?
152
+ assert !g7.complement.comparability?
153
+ assert !g7.interval?
154
+ assert !g7.complement.interval?
155
+ assert !g7.permutation?
156
+ assert g7.split?
157
+
158
+ end
159
+
160
+ end