iconofthestoneage-doodl 0.0.2 → 0.0.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 (42) hide show
  1. data/lib/app/selfrunning.rb +185 -0
  2. data/lib/app/simple_app.rb +49 -0
  3. data/lib/app/simple_controller.rb +584 -0
  4. data/lib/app/simple_model.rb +292 -0
  5. data/lib/app/simple_view.rb +148 -0
  6. data/lib/breadth_first_search.rb +69 -0
  7. data/lib/connected_components.rb +29 -0
  8. data/lib/depth_first_search.rb +73 -0
  9. data/lib/edge.rb +57 -0
  10. data/lib/graph.rb +365 -0
  11. data/lib/graph_canvas.rb +187 -0
  12. data/lib/graph_generator.rb +121 -0
  13. data/lib/jruby/renderer.rb +413 -0
  14. data/lib/layout/collapse_layout.rb +23 -0
  15. data/lib/layout/fr_layout.rb +105 -0
  16. data/lib/layout/isom_layout.rb +77 -0
  17. data/lib/layout/kk_layout.rb +203 -0
  18. data/lib/layout/layout.rb +240 -0
  19. data/lib/layout/morph_layout.rb +65 -0
  20. data/lib/node.rb +57 -0
  21. data/lib/shortest_path/all_pair.rb +35 -0
  22. data/lib/shortest_path/bellman_ford.rb +60 -0
  23. data/lib/shortest_path/dijkstra.rb +74 -0
  24. data/lib/shortest_path/floyd_warshall.rb +68 -0
  25. data/lib/shortest_path/johnson_all_pair.rb +64 -0
  26. data/lib/shortest_path/single_source.rb +32 -0
  27. data/spec/breadth_first_search_spec.rb +145 -0
  28. data/spec/connected_components_spec.rb +50 -0
  29. data/spec/depth_first_search_spec.rb +89 -0
  30. data/spec/edge_spec.rb +58 -0
  31. data/spec/graph_generator_spec.rb +277 -0
  32. data/spec/graph_spec.rb +269 -0
  33. data/spec/jruby/renderer_spec.rb +214 -0
  34. data/spec/layout/layout_spec.rb +146 -0
  35. data/spec/node_spec.rb +179 -0
  36. data/spec/rspec_helper.rb +9 -0
  37. data/spec/rspec_suite.rb +12 -0
  38. data/spec/shortest_path/bellman_ford_spec.rb +101 -0
  39. data/spec/shortest_path/dijkstra_spec.rb +133 -0
  40. data/spec/shortest_path/floyd_warshall_spec.rb +84 -0
  41. data/spec/shortest_path/johnson_all_pair_spec.rb +90 -0
  42. metadata +43 -2
@@ -0,0 +1,133 @@
1
+ require "rspec_helper"
2
+
3
+ require "shortest_path/dijkstra"
4
+
5
+ include Doodl
6
+
7
+ describe "DijkstraShortestPath with Directed Graph n[@u, @v, @w, @x, @y, @z] e[(uv), (uw), (ux), (vx), (xz), (wy), (yz)]" do
8
+
9
+ before(:each) do
10
+ @g = DirectedGraph.new
11
+ @n = @g.add_node
12
+
13
+ @graph = DirectedGraph.new
14
+ @u = @graph.add_node
15
+ @v = @graph.add_node
16
+ @w = @graph.add_node
17
+ @x = @graph.add_node
18
+ @y = @graph.add_node
19
+ @z = @graph.add_node
20
+
21
+ @uv = @graph.add_edge(@u, @v)
22
+ @uw = @graph.add_edge(@u, @w)
23
+ @ux = @graph.add_edge(@u, @x)
24
+ @vx = @graph.add_edge(@v, @x)
25
+ @xz = @graph.add_edge(@x, @z)
26
+ @wy = @graph.add_edge(@w, @y)
27
+ @yz = @graph.add_edge(@y, @z)
28
+ end
29
+
30
+ it "should raise an ArgumentError when not initialized with a Graph" do
31
+ lambda { DijkstraShortestPath.new(:something, :else) }.should raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should raise an ArgumentError when initialized with a source that is not part of the graph" do
35
+ lambda { DijkstraShortestPath.new(DirectedGraph.new, :node) }.should raise_error(ArgumentError)
36
+ lambda { DijkstraShortestPath.new(@g, @n) }.should_not raise_error(ArgumentError)
37
+ end
38
+
39
+ it "should raise ArgumentError when initialized with a weight_key that isn't part of the graph" do
40
+ lambda { DijkstraShortestPath.new(@g, @n, :key) }.should raise_error(ArgumentError)
41
+ @g.attach_edge_data(:key)
42
+ lambda { DijkstraShortestPath.new(@g, @n, :key) }.should_not raise_error(ArgumentError)
43
+ end
44
+
45
+ it "should return the shortest distance d(u,x) with u being the source and x being a node of the unweighted graph when sent #dist[x]" do
46
+ @dsp = DijkstraShortestPath.new(@graph, @u)
47
+ @dsp.dist[@u].should == 0
48
+ @dsp.dist[@v].should == 1
49
+ @dsp.dist[@x].should == 1
50
+ @dsp.dist[@w].should == 1
51
+ @dsp.dist[@y].should == 2
52
+ @dsp.dist[@z].should == 2
53
+ end
54
+
55
+ it "should return INFINITY when sent #dist[x] if x is not reachable" do
56
+ n = @graph.add_node
57
+ @dsp = DijkstraShortestPath.new(@graph, @u)
58
+ @dsp.dist[n].should == INFINITY
59
+ @dsp = DijkstraShortestPath.new(@graph, @z)
60
+ @dsp.dist[@u].should == INFINITY
61
+ end
62
+
63
+ it "should return the previous node of x in the shortes path tree when sent #prev[x]" do
64
+ @dsp = DijkstraShortestPath.new(@graph, @u)
65
+ @dsp.prev[@u].should == nil
66
+ @dsp.prev[@v].should == @u
67
+ @dsp.prev[@x].should == @u
68
+ @dsp.prev[@y].should == @w
69
+ @dsp.prev[@z].should == @x
70
+ end
71
+
72
+ it "should return nil when sent #prev[x] and x is not reachable" do
73
+ n = @graph.add_node
74
+ @dsp = DijkstraShortestPath.new(@graph, @u)
75
+ @dsp.prev[n].should == nil
76
+ end
77
+
78
+ it "should return an array containing the nodes of the shortest path when sent node_path_to(x)" do
79
+ @dsp = DijkstraShortestPath.new(@graph, @u)
80
+ @dsp.node_path_to(@u).should == [@u]
81
+ @dsp.node_path_to(@v).should == [@u, @v]
82
+ @dsp.node_path_to(@z).should == [@u, @x, @z]
83
+ end
84
+
85
+ it "should return an array of edge representing the shortest path, when sent edge_path_to" do
86
+ @dsp = DijkstraShortestPath.new(@graph, @u)
87
+ @dsp.edge_path_to(@u).should == []
88
+ @dsp.edge_path_to(@v).should == [@graph.get_edge(@u, @v)]
89
+ @dsp.edge_path_to(@z).should == [@graph.get_edge(@u, @x), @graph.get_edge(@x, @z)]
90
+ end
91
+
92
+ end
93
+
94
+ describe "DijkstraShortestPath with Undirected Graph n = [a, b, c, d] e[(ab), (bc), (cd), (da)]" do
95
+ before(:each) do
96
+ @graph = UndirectedGraph.new
97
+ @a = @graph.add_node
98
+ @b = @graph.add_node
99
+ @c = @graph.add_node
100
+ @d = @graph.add_node
101
+ @ab = @graph.add_edge(@a, @b)
102
+ @bc = @graph.add_edge(@b, @c)
103
+ @cd = @graph.add_edge(@c, @d)
104
+ @da = @graph.add_edge(@d, @a)
105
+ end
106
+
107
+
108
+ it "should return the shortest distance d(u,x) with u being the source and x being a node of the unweighted undirected graph when sent #dist[x]" do
109
+ @dsp = DijkstraShortestPath.new(@graph, @a)
110
+ @dsp.dist[@a].should == 0
111
+ @dsp.dist[@b].should == 1
112
+ @dsp.dist[@c].should == 2
113
+ @dsp.dist[@d].should == 1
114
+ end
115
+
116
+ it "should return the previous node of x in the shortes path tree when sent #prev[x]" do
117
+ @dsp = DijkstraShortestPath.new(@graph, @a)
118
+ @dsp.prev[@a].should == nil
119
+ @dsp.prev[@b].should == @a
120
+ @dsp.prev[@c].should == @b
121
+ @dsp.prev[@d].should == @a
122
+ end
123
+
124
+ it "should return an array containing the nodes of the shortest path when sent node_path_to(x)" do
125
+ @dsp = DijkstraShortestPath.new(@graph, @a)
126
+ @dsp.node_path_to(@a).should == [@a]
127
+ @dsp.node_path_to(@b).should == [@a, @b]
128
+ @dsp.node_path_to(@c).should == [@a, @b, @c]
129
+ @dsp.node_path_to(@d).should == [@a, @d]
130
+ end
131
+
132
+
133
+ end
@@ -0,0 +1,84 @@
1
+ require "rspec_helper"
2
+ require "shortest_path/floyd_warshall"
3
+
4
+ include Doodl
5
+
6
+ describe "floyd_warshall" do
7
+
8
+ before(:each) do
9
+ @graph = DirectedGraph.new
10
+ @u = @graph.add_node
11
+ @v = @graph.add_node
12
+ @w = @graph.add_node
13
+ @x = @graph.add_node
14
+ @y = @graph.add_node
15
+ @z = @graph.add_node
16
+
17
+ @uv = @graph.add_edge(@u, @v)
18
+ @uw = @graph.add_edge(@u, @w)
19
+ @ux = @graph.add_edge(@u, @x)
20
+ @vx = @graph.add_edge(@v, @x)
21
+ @xz = @graph.add_edge(@x, @z)
22
+ @wy = @graph.add_edge(@w, @y)
23
+ @yz = @graph.add_edge(@y, @z)
24
+ end
25
+
26
+ it "should raise an ArgumentError when not initialized with a Graph" do
27
+ lambda { FloydWarshall.new(:something, :else) }.should raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should raise an ArgumentError when initialized with a source that is not part of the graph" do
31
+ lambda { FloydWarshall.new(DirectedGraph.new, :node) }.should raise_error(ArgumentError)
32
+ lambda { FloydWarshall.new(DirectedGraph.new) }.should_not raise_error(ArgumentError)
33
+ end
34
+
35
+ it "should raise ArgumentError when initialized with a weight_key that isn't part of the graph" do
36
+ graph = DirectedGraph.new
37
+ lambda { FloydWarshall.new(graph, :key) }.should raise_error(ArgumentError)
38
+ graph.attach_edge_data(:key)
39
+ lambda { FloydWarshall.new(graph, :key) }.should_not raise_error(ArgumentError)
40
+ end
41
+
42
+ it "should calculate all shortest paths" do
43
+ fw = FloydWarshall.new(@graph)
44
+ fw.dist[[@u,@u]].should == 0
45
+ fw.dist[[@u,@v]].should == 1
46
+ fw.dist[[@u,@x]].should == 1
47
+ fw.dist[[@u,@w]].should == 1
48
+ fw.dist[[@u,@y]].should == 2
49
+ fw.dist[[@u,@z]].should == 2
50
+ end
51
+
52
+ it "should return INFINITY when sent #dist[x] if x is not reachable" do
53
+ n = @graph.add_node
54
+ fw = FloydWarshall.new(@graph)
55
+ fw.dist[[@u,n]].should == INFINITY
56
+ fw = FloydWarshall.new(@graph)
57
+ fw.dist[[@z,@u]].should == INFINITY
58
+ end
59
+
60
+ it "should return the previous node of x in the shortes path tree when sent #prev[x]" do
61
+ fw = FloydWarshall.new(@graph)
62
+ fw.prev[[@u,@u]].should == nil
63
+ fw.prev[[@u,@v]].should == @u
64
+ fw.prev[[@u,@x]].should == @u
65
+ fw.prev[[@u,@y]].should == @w
66
+ fw.prev[[@u,@z]].should == @x
67
+ end
68
+
69
+ it "should return an array containing the nodes of the shortest path when sent node_path(x, y)" do
70
+ fw = FloydWarshall.new(@graph)
71
+ fw.node_path(@u, @u).should == [@u]
72
+ fw.node_path(@u, @v).should == [@u, @v]
73
+ fw.node_path(@u, @z).should == [@u, @x, @z]
74
+ end
75
+
76
+ it "should return an array of edge representing the shortest path, when sent edge_path(x, y)" do
77
+ fw = FloydWarshall.new(@graph)
78
+ fw.edge_path(@u, @u).should == []
79
+ fw.edge_path(@u, @v).should == [@graph.get_edge(@u, @v)]
80
+ fw.edge_path(@u, @z).should == [@graph.get_edge(@u, @x), @graph.get_edge(@x, @z)]
81
+ end
82
+
83
+
84
+ end
@@ -0,0 +1,90 @@
1
+ require 'rspec_helper'
2
+ require 'shortest_path/johnson_all_pair'
3
+
4
+ include Doodl
5
+
6
+ describe "JohnsonAllPairShortestPaths" do
7
+
8
+ before(:each) do
9
+ @graph = DirectedGraph.new
10
+ @u = @graph.add_node
11
+ @v = @graph.add_node
12
+ @w = @graph.add_node
13
+ @x = @graph.add_node
14
+ @y = @graph.add_node
15
+ @z = @graph.add_node
16
+
17
+ @uv = @graph.add_edge(@u, @v)
18
+ @uw = @graph.add_edge(@u, @w)
19
+ @ux = @graph.add_edge(@u, @x)
20
+ @vx = @graph.add_edge(@v, @x)
21
+ @xz = @graph.add_edge(@x, @z)
22
+ @wy = @graph.add_edge(@w, @y)
23
+ @yz = @graph.add_edge(@y, @z)
24
+
25
+ @weight = @graph.attach_edge_data(@weight)
26
+ @weight[@uv] = 1
27
+ @weight[@uw] = 1
28
+ @weight[@ux] = 1
29
+ @weight[@vx] = 1
30
+ @weight[@xz] = 1
31
+ @weight[@wy] = 1
32
+ @weight[@yz] = 1
33
+ end
34
+
35
+ it "should raise an ArgumentError when not initialized with a Graph" do
36
+ lambda { JohnsonAllPairShortestPaths.new(:something, :else) }.should raise_error(ArgumentError)
37
+ end
38
+
39
+ it "should NOT raise an ArgumentError when called without a weight key" do
40
+ lambda { JohnsonAllPairShortestPaths.new(DirectedGraph.new) }.should_not raise_error(ArgumentError)
41
+ end
42
+
43
+ it "should calculate all shortest paths" do
44
+ japsp = JohnsonAllPairShortestPaths.new(@graph, @weight)
45
+ japsp.dist[[@u,@u]].should == 0
46
+ japsp.dist[[@u,@v]].should == 1
47
+ japsp.dist[[@u,@x]].should == 1
48
+ japsp.dist[[@u,@w]].should == 1
49
+ japsp.dist[[@u,@y]].should == 2
50
+ japsp.dist[[@u,@z]].should == 2
51
+ end
52
+
53
+ it "should return INFINITY when sent #dist[x] if x is not reachable" do
54
+ n = @graph.add_node
55
+ japsp = JohnsonAllPairShortestPaths.new(@graph, @weight)
56
+ japsp.dist[[@u,n]].should == INFINITY
57
+ japsp = JohnsonAllPairShortestPaths.new(@graph, @weight)
58
+ japsp.dist[[@z,@u]].should == INFINITY
59
+ end
60
+
61
+ it "should return the previous node of x in the shortes path tree when sent #prev[x]" do
62
+ japsp = JohnsonAllPairShortestPaths.new(@graph, @weight)
63
+ japsp.prev[[@u,@u]].should == nil
64
+ japsp.prev[[@u,@v]].should == @u
65
+ japsp.prev[[@u,@x]].should == @u
66
+ japsp.prev[[@u,@y]].should == @w
67
+ japsp.prev[[@u,@z]].should == @x
68
+ end
69
+
70
+ it "should return an array containing the nodes of the shortest path when sent node_path(x, y)" do
71
+ japsp = JohnsonAllPairShortestPaths.new(@graph, @weight)
72
+ japsp.node_path(@u, @u).should == [@u]
73
+ japsp.node_path(@u, @v).should == [@u, @v]
74
+ japsp.node_path(@u, @z).should == [@u, @x, @z]
75
+ end
76
+
77
+ it "should return an array of edge representing the shortest path, when sent edge_path(x, y)" do
78
+ japsp = JohnsonAllPairShortestPaths.new(@graph, @weight)
79
+ japsp.edge_path(@u, @u).should == []
80
+ japsp.edge_path(@u, @v).should == [@graph.get_edge(@u, @v)]
81
+ japsp.edge_path(@u, @z).should == [@graph.get_edge(@u, @x), @graph.get_edge(@x, @z)]
82
+ end
83
+
84
+ it "should return the diameter when sent #diameter" do
85
+ japsp = JohnsonAllPairShortestPaths.new(@graph, @weight)
86
+ japsp.diameter.should == 2
87
+ end
88
+
89
+
90
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iconofthestoneage-doodl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Rummel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-05 00:00:00 -08:00
12
+ date: 2009-02-06 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,8 +40,49 @@ extensions: []
40
40
  extra_rdoc_files: []
41
41
 
42
42
  files:
43
+ - lib/app/selfrunning.rb
44
+ - lib/app/simple_app.rb
45
+ - lib/app/simple_controller.rb
46
+ - lib/app/simple_model.rb
47
+ - lib/app/simple_view.rb
48
+ - lib/breadth_first_search.rb
49
+ - lib/connected_components.rb
50
+ - lib/depth_first_search.rb
51
+ - lib/edge.rb
52
+ - lib/graph.rb
53
+ - lib/graph_canvas.rb
54
+ - lib/graph_generator.rb
55
+ - lib/jruby/renderer.rb
56
+ - lib/layout/collapse_layout.rb
57
+ - lib/layout/fr_layout.rb
58
+ - lib/layout/isom_layout.rb
59
+ - lib/layout/kk_layout.rb
60
+ - lib/layout/layout.rb
61
+ - lib/layout/morph_layout.rb
62
+ - lib/node.rb
63
+ - lib/shortest_path/all_pair.rb
64
+ - lib/shortest_path/bellman_ford.rb
65
+ - lib/shortest_path/dijkstra.rb
66
+ - lib/shortest_path/floyd_warshall.rb
67
+ - lib/shortest_path/johnson_all_pair.rb
68
+ - lib/shortest_path/single_source.rb
43
69
  - bin/doodl-app
44
70
  - bin/doodl-demo
71
+ - spec/breadth_first_search_spec.rb
72
+ - spec/connected_components_spec.rb
73
+ - spec/depth_first_search_spec.rb
74
+ - spec/edge_spec.rb
75
+ - spec/graph_generator_spec.rb
76
+ - spec/graph_spec.rb
77
+ - spec/jruby/renderer_spec.rb
78
+ - spec/layout/layout_spec.rb
79
+ - spec/node_spec.rb
80
+ - spec/rspec_helper.rb
81
+ - spec/rspec_suite.rb
82
+ - spec/shortest_path/bellman_ford_spec.rb
83
+ - spec/shortest_path/dijkstra_spec.rb
84
+ - spec/shortest_path/floyd_warshall_spec.rb
85
+ - spec/shortest_path/johnson_all_pair_spec.rb
45
86
  has_rdoc: true
46
87
  homepage: http://iconofthestoneage.github.com/doodl
47
88
  post_install_message: