jumoku 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/lib/jumoku.rb +4 -2
- data/lib/jumoku/version.rb +1 -1
- data/spec/raw_tree_spec.rb +353 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/tree_spec.rb +553 -0
- data/vendor/git/graphy/CREDITS.md +31 -0
- data/vendor/git/graphy/LICENSE +35 -0
- data/vendor/git/graphy/README.md +186 -0
- data/vendor/git/graphy/Rakefile +61 -0
- data/vendor/git/graphy/TODO.md +20 -0
- data/vendor/git/graphy/VERSION +1 -0
- data/vendor/git/graphy/examples/graph_self.rb +56 -0
- data/vendor/git/graphy/examples/module_graph.jpg +0 -0
- data/vendor/git/graphy/examples/module_graph.rb +14 -0
- data/vendor/git/graphy/examples/self_graph.jpg +0 -0
- data/vendor/git/graphy/examples/visualize.jpg +0 -0
- data/vendor/git/graphy/examples/visualize.rb +10 -0
- data/vendor/git/graphy/graphy.gemspec +149 -0
- data/vendor/git/graphy/lib/graphy.rb +90 -0
- data/vendor/git/graphy/lib/graphy/adjacency_graph.rb +224 -0
- data/vendor/git/graphy/lib/graphy/arc.rb +65 -0
- data/vendor/git/graphy/lib/graphy/arc_number.rb +52 -0
- data/vendor/git/graphy/lib/graphy/biconnected.rb +84 -0
- data/vendor/git/graphy/lib/graphy/chinese_postman.rb +91 -0
- data/vendor/git/graphy/lib/graphy/classes/graph_classes.rb +28 -0
- data/vendor/git/graphy/lib/graphy/common.rb +63 -0
- data/vendor/git/graphy/lib/graphy/comparability.rb +63 -0
- data/vendor/git/graphy/lib/graphy/directed_graph.rb +76 -0
- data/vendor/git/graphy/lib/graphy/directed_graph/algorithms.rb +92 -0
- data/vendor/git/graphy/lib/graphy/directed_graph/distance.rb +167 -0
- data/vendor/git/graphy/lib/graphy/dot.rb +94 -0
- data/vendor/git/graphy/lib/graphy/edge.rb +37 -0
- data/vendor/git/graphy/lib/graphy/ext.rb +79 -0
- data/vendor/git/graphy/lib/graphy/graph.rb +631 -0
- data/vendor/git/graphy/lib/graphy/graph_api.rb +35 -0
- data/vendor/git/graphy/lib/graphy/labels.rb +113 -0
- data/vendor/git/graphy/lib/graphy/maximum_flow.rb +77 -0
- data/vendor/git/graphy/lib/graphy/ruby_compatibility.rb +17 -0
- data/vendor/git/graphy/lib/graphy/search.rb +511 -0
- data/vendor/git/graphy/lib/graphy/strong_components.rb +93 -0
- data/vendor/git/graphy/lib/graphy/support/support.rb +9 -0
- data/vendor/git/graphy/lib/graphy/undirected_graph.rb +57 -0
- data/vendor/git/graphy/lib/graphy/undirected_graph/algorithms.rb +90 -0
- data/vendor/git/graphy/spec/biconnected_spec.rb +27 -0
- data/vendor/git/graphy/spec/chinese_postman_spec.rb +27 -0
- data/vendor/git/graphy/spec/community_spec.rb +44 -0
- data/vendor/git/graphy/spec/complement_spec.rb +27 -0
- data/vendor/git/graphy/spec/digraph_distance_spec.rb +121 -0
- data/vendor/git/graphy/spec/digraph_spec.rb +339 -0
- data/vendor/git/graphy/spec/dot_spec.rb +48 -0
- data/vendor/git/graphy/spec/edge_spec.rb +159 -0
- data/vendor/git/graphy/spec/inspection_spec.rb +40 -0
- data/vendor/git/graphy/spec/multi_edge_spec.rb +32 -0
- data/vendor/git/graphy/spec/neighborhood_spec.rb +38 -0
- data/vendor/git/graphy/spec/properties_spec.rb +146 -0
- data/vendor/git/graphy/spec/search_spec.rb +227 -0
- data/vendor/git/graphy/spec/spec.opts +4 -0
- data/vendor/git/graphy/spec/spec_helper.rb +56 -0
- data/vendor/git/graphy/spec/strong_components_spec.rb +61 -0
- data/vendor/git/graphy/spec/triangulated_spec.rb +125 -0
- data/vendor/git/graphy/spec/undirected_graph_spec.rb +220 -0
- data/vendor/git/graphy/vendor/priority-queue/CHANGELOG +33 -0
- data/vendor/git/graphy/vendor/priority-queue/Makefile +140 -0
- data/vendor/git/graphy/vendor/priority-queue/README +133 -0
- data/vendor/git/graphy/vendor/priority-queue/benchmark/dijkstra.rb +171 -0
- data/vendor/git/graphy/vendor/priority-queue/compare_comments.rb +49 -0
- data/vendor/git/graphy/vendor/priority-queue/doc/c-vs-rb.png +0 -0
- data/vendor/git/graphy/vendor/priority-queue/doc/compare_big.gp +14 -0
- data/vendor/git/graphy/vendor/priority-queue/doc/compare_big.png +0 -0
- data/vendor/git/graphy/vendor/priority-queue/doc/compare_small.gp +15 -0
- data/vendor/git/graphy/vendor/priority-queue/doc/compare_small.png +0 -0
- data/vendor/git/graphy/vendor/priority-queue/doc/results.csv +37 -0
- data/vendor/git/graphy/vendor/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb +2 -0
- data/vendor/git/graphy/vendor/priority-queue/ext/priority_queue/CPriorityQueue/priority_queue.c +947 -0
- data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue.rb +14 -0
- data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue/c_priority_queue.rb +1 -0
- data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue/poor_priority_queue.rb +46 -0
- data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue/ruby_priority_queue.rb +526 -0
- data/vendor/git/graphy/vendor/priority-queue/priority_queue.so +0 -0
- data/vendor/git/graphy/vendor/priority-queue/setup.rb +1551 -0
- data/vendor/git/graphy/vendor/priority-queue/test/priority_queue_test.rb +371 -0
- data/vendor/git/graphy/vendor/rdot.rb +360 -0
- metadata +83 -1
@@ -0,0 +1,31 @@
|
|
1
|
+
Credits
|
2
|
+
=======
|
3
|
+
|
4
|
+
From GRATR
|
5
|
+
----------
|
6
|
+
|
7
|
+
Shawn Garbett provided the following credits in GRATR:
|
8
|
+
|
9
|
+
Many thanks to Robert Feldt which also worked on a graph library
|
10
|
+
(http://rockit.sf.net/subprojects/graphr) who pointed me to BGL and many other
|
11
|
+
graph resources. Manuel Simoni found a subtle bug in a preliminary version
|
12
|
+
announced at http://rubygarden.com/ruby?RubyAlgorithmPackage/Graph.
|
13
|
+
|
14
|
+
Robert kindly allowed to integrate his work on graphr, which I did not yet
|
15
|
+
succeed. Especially his work to output graphs for
|
16
|
+
GraphViz[http://www.research.att.com/sw/tools/graphviz/download.html] is much
|
17
|
+
more elaborated than the minimal support in dot.rb.
|
18
|
+
|
19
|
+
Jeremy Siek one of the authors of the nice book "The Boost Graph Library (BGL)"
|
20
|
+
(http://www.boost.org/libs/graph/doc) kindly allowed to use the
|
21
|
+
BGL documentation as a _cheap_ reference for GRATR. He and Robert also gave
|
22
|
+
feedback and many ideas for GRATR.
|
23
|
+
|
24
|
+
Dave Thomas for RDoc[http://rdoc.sourceforge.net] which generated what you read
|
25
|
+
and Matz for Ruby. Dave included in the latest version of RDoc (alpha9) the
|
26
|
+
module dot/dot.rb which I use instead of Roberts module to visualize graphs
|
27
|
+
(see gratr/dot.rb).
|
28
|
+
|
29
|
+
Horst Duchene for RGL which provided the basis for this library and his vision.
|
30
|
+
|
31
|
+
Rick Bradley who reworked the library and added many graph theoretic constructs.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Copyright (c) 2009 Bruce Williams
|
2
|
+
|
3
|
+
Copyright (c) 2007,2006 Shawn Patrick Garbett
|
4
|
+
|
5
|
+
Copyright (c) 2002,2004,2005 by Horst Duchene
|
6
|
+
|
7
|
+
Copyright (c) 2000,2001 Jeremy Siek, Indiana University (jsiek@osl.iu.edu)
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Jeremy Siek was one of the principal developers of the Boost Graph library.
|
12
|
+
Since this work is derivative, his name is included in the copyright list.
|
13
|
+
|
14
|
+
Redistribution and use in source and binary forms, with or without modification,
|
15
|
+
are permitted provided that the following conditions are met:
|
16
|
+
|
17
|
+
* Redistributions of source code must retain the above copyright notice(s),
|
18
|
+
this list of conditions and the following disclaimer.
|
19
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
20
|
+
this list of conditions and the following disclaimer in the documentation
|
21
|
+
and/or other materials provided with the distribution.
|
22
|
+
* Neither the name of the Bruce Williams nor the names of its contributors
|
23
|
+
may be used to endorse or promote products derived from this software
|
24
|
+
without specific prior written permission.
|
25
|
+
|
26
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
27
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
28
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
29
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
30
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
31
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
32
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
33
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
34
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
35
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# Graphy. A framework for graph theory, graph data structures and associated algorithms.
|
2
|
+
|
3
|
+
Graph algorithms currently provided are:
|
4
|
+
|
5
|
+
* Topological Sort
|
6
|
+
* Strongly Connected Components
|
7
|
+
* Transitive Closure
|
8
|
+
* Rural Chinese Postman
|
9
|
+
* Biconnected
|
10
|
+
|
11
|
+
These are based on more general algorithm patterns:
|
12
|
+
|
13
|
+
* Breadth First Search
|
14
|
+
* Depth First Search
|
15
|
+
* A* Search
|
16
|
+
* Floyd-Warshall
|
17
|
+
* Best First Search
|
18
|
+
* Djikstra's Algorithm
|
19
|
+
* Lexicographic Search
|
20
|
+
|
21
|
+
## A quick Tour
|
22
|
+
|
23
|
+
### Arcs
|
24
|
+
|
25
|
+
There are two vertices bound classes, `Graphy::Arc` and `Graphy::Edge`. The
|
26
|
+
former defines directional edges, the latter undirected edges.
|
27
|
+
|
28
|
+
### Vertices
|
29
|
+
|
30
|
+
Vertices can be any `Object`.
|
31
|
+
|
32
|
+
### Graph Types
|
33
|
+
|
34
|
+
There are a number of different graph types, each of which provide
|
35
|
+
different features and constraints:
|
36
|
+
|
37
|
+
`Graphy::Digraph` and its alias `Graphy::DirectedGraph`:
|
38
|
+
|
39
|
+
* Single directed edges (arcs) between vertices
|
40
|
+
* Loops are forbidden
|
41
|
+
|
42
|
+
`Graphy::DirectedPseudoGraph`:
|
43
|
+
|
44
|
+
* Multiple directed edges (arcs) between vertices
|
45
|
+
* Loops are forbidden
|
46
|
+
|
47
|
+
`Graphy::DirectedMultiGraph`:
|
48
|
+
|
49
|
+
* Multiple directed edges (arcs) between vertices
|
50
|
+
* Loops on vertices
|
51
|
+
|
52
|
+
`Graphy::UndirectedGraph`, `Graphy::UndirectedPseudoGraph`, and
|
53
|
+
`Graph::UndirectedMultiGraph` are similar but all edges are undirected.
|
54
|
+
|
55
|
+
### Data Structures
|
56
|
+
|
57
|
+
In order to modelize data structures, make use of the `Graphy::AdjacencyGraph`
|
58
|
+
module which provides a generalized adjacency list and an edge list adaptor.
|
59
|
+
|
60
|
+
The `Graphy::Digraph` class is the general purpose "swiss army knife" of graph
|
61
|
+
classes, most of the other classes are just modifications to this class.
|
62
|
+
It is optimized for efficient access to just the out-edges, fast vertex
|
63
|
+
insertion and removal at the cost of extra space overhead, etc.
|
64
|
+
|
65
|
+
## Example Usage
|
66
|
+
|
67
|
+
Using IRB, first require the library:
|
68
|
+
|
69
|
+
require 'rubygems' # only if you are using ruby 1.8.x
|
70
|
+
require 'graphy'
|
71
|
+
|
72
|
+
If you'd like to include all the classes in the current scope (so you
|
73
|
+
don't have to prefix with `Graphy::`), just:
|
74
|
+
|
75
|
+
include Graphy
|
76
|
+
|
77
|
+
Let's play with the library a bit in IRB:
|
78
|
+
|
79
|
+
>> dg = Digraph[1,2, 2,3, 2,4, 4,5, 6,4, 1,6]
|
80
|
+
=> Graphy::Digraph[[2, 3], [1, 6], [2, 4], [4, 5], [1, 2], [6, 4]]
|
81
|
+
|
82
|
+
A few properties of the graph we just created:
|
83
|
+
|
84
|
+
>> dg.directed?
|
85
|
+
=> true
|
86
|
+
>> dg.vertex?(4)
|
87
|
+
=> true
|
88
|
+
>> dg.edge?(2,4)
|
89
|
+
=> true
|
90
|
+
>> dg.edge?(4,2)
|
91
|
+
=> false
|
92
|
+
>> dg.vertices
|
93
|
+
=> [1, 2, 3, 4, 5, 6]
|
94
|
+
|
95
|
+
Every object could be a vertex, even the class object `Object`:
|
96
|
+
|
97
|
+
>> dg.vertex?(Object)
|
98
|
+
=> false
|
99
|
+
|
100
|
+
>> UndirectedGraph.new(dg).edges.sort.to_s
|
101
|
+
=> "[Graphy::Edge[1,2,nil], Graphy::Edge[2,3,nil], Graphy::Edge[2,4,nil],
|
102
|
+
Graphy::Edge[4,5,nil], Graphy::Edge[1,6,nil], Graphy::Edge[6,4,nil]]"
|
103
|
+
|
104
|
+
Add inverse edge `(4-2)` to directed graph:
|
105
|
+
|
106
|
+
>> dg.add_edge!(4,2)
|
107
|
+
=> Graphy::DirectedGraph[Graphy::Arc[1,2,nil], Graphy::Arc[1,6,nil], Graphy::Arc[2,3,nil],
|
108
|
+
Graphy::Arc[2,4,nil], Graphy::Arc[4,5,nil], Graphy::Arc[4,2,nil],
|
109
|
+
Graphy::Arc[6,4,nil]]
|
110
|
+
|
111
|
+
`(4-2) == (2-4)` in the undirected graph (4-2 doesn't show up):
|
112
|
+
|
113
|
+
>> UndirectedGraph.new(dg).edges.sort.to_s
|
114
|
+
=> "[Graphy::Edge[1,2,nil], Graphy::Edge[2,3,nil], Graphy::Edge[2,4,nil],
|
115
|
+
Graphy::Edge[4,5,nil], Graphy::Edge[1,6,nil], Graphy::Edge[6,4,nil]]"
|
116
|
+
|
117
|
+
`(4-2) != (2-4)` in directed graphs (both show up):
|
118
|
+
|
119
|
+
>> dg.edges.sort.to_s
|
120
|
+
=> "[Graphy::Arc[1,2,nil], Graphy::Arc[1,6,nil], Graphy::Arc[2,3,nil],
|
121
|
+
Graphy::Arc[2,4,nil], Graphy::Arc[4,2,nil], Graphy::Arc[4,5,nil],
|
122
|
+
Graphy::Arc[6,4,nil]]"
|
123
|
+
|
124
|
+
>> dg.remove_edge! 4,2
|
125
|
+
=> Graphy::DirectedGraph[Graphy::Arc[1,2,nil], Graphy::Arc[1,6,nil], Graphy::Arc[2,3,nil],
|
126
|
+
Graphy::Arc[2,4,nil], Graphy::Arc[4,5,nil], Graphy::Arc[6,4,nil]]
|
127
|
+
|
128
|
+
Topological sorting is realized with an iterator:
|
129
|
+
|
130
|
+
>> dg.topsort
|
131
|
+
=> [1, 6, 2, 4, 5, 3]
|
132
|
+
>> y = 0; dg.topsort { |v| y += v }; y
|
133
|
+
=> 21
|
134
|
+
|
135
|
+
You can use DOT to visualize the graph:
|
136
|
+
|
137
|
+
>> require 'graphy/dot'
|
138
|
+
>> dg.write_to_graphic_file('jpg','visualize')
|
139
|
+
|
140
|
+
Here's an example showing the module inheritance hierarchy:
|
141
|
+
|
142
|
+
>> module_graph = Digraph.new
|
143
|
+
>> ObjectSpace.each_object(Module) do |m|
|
144
|
+
>> m.ancestors.each {|a| module_graph.add_edge!(m,a) if m != a}
|
145
|
+
>> end
|
146
|
+
>> gv = module_graph.vertices.select {|v| v.to_s.match(/Graphy/) }
|
147
|
+
>> module_graph.induced_subgraph(gv).write_to_graphic_file('jpg','module_graph')
|
148
|
+
|
149
|
+
Look for more in the examples directory.
|
150
|
+
|
151
|
+
## History
|
152
|
+
|
153
|
+
This library is based on [GRATR][1] by Shawn Garbett (itself a fork of
|
154
|
+
Horst Duchene's [RGL][2] library) which is heavily influenced by the [Boost][3]
|
155
|
+
Graph Library (BGL).
|
156
|
+
|
157
|
+
This fork attempts to modernize and extend the API and tests.
|
158
|
+
|
159
|
+
## References
|
160
|
+
|
161
|
+
For more information on Graph Theory, you may want to read:
|
162
|
+
|
163
|
+
* the [documentation][3] for the Boost Graph Library
|
164
|
+
* [the Dictionary of Algorithms and Data Structures][4]
|
165
|
+
|
166
|
+
## Credits
|
167
|
+
|
168
|
+
See CREDITS.markdown
|
169
|
+
|
170
|
+
## TODO
|
171
|
+
|
172
|
+
See TODO.markdown
|
173
|
+
|
174
|
+
## CHANGELOG
|
175
|
+
|
176
|
+
See CHANGELOG.markdown
|
177
|
+
|
178
|
+
## License
|
179
|
+
|
180
|
+
See LICENSE
|
181
|
+
|
182
|
+
[1]: http://gratr.rubyforge.org
|
183
|
+
[2]: http://rgl.rubyforge.org
|
184
|
+
[3]: http://www.boost.org/libs/graph/doc
|
185
|
+
[4]: http://www.nist.gov/dads/HTML/graph.html
|
186
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "graphy"
|
9
|
+
gem.summary = "A Graph Theory Ruby library"
|
10
|
+
gem.description =<<-EOD
|
11
|
+
A framework for graph data structures and algorithms.
|
12
|
+
|
13
|
+
This library is based on GRATR and RGL.
|
14
|
+
|
15
|
+
Graph algorithms currently provided are:
|
16
|
+
|
17
|
+
* Topological Sort
|
18
|
+
* Strongly Connected Components
|
19
|
+
* Transitive Closure
|
20
|
+
* Rural Chinese Postman
|
21
|
+
* Biconnected
|
22
|
+
EOD
|
23
|
+
gem.email = "bruce@codefluency.com"
|
24
|
+
gem.homepage = "http://github.com/bruce/graphy"
|
25
|
+
gem.authors = ["Bruce Williams"]
|
26
|
+
end
|
27
|
+
Jeweler::GemcutterTasks.new
|
28
|
+
rescue LoadError
|
29
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
30
|
+
end
|
31
|
+
|
32
|
+
require 'rake/rdoctask'
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
35
|
+
|
36
|
+
rdoc.rdoc_dir = 'rdoc'
|
37
|
+
rdoc.title = "graphy #{version}"
|
38
|
+
rdoc.rdoc_files.include('README*')
|
39
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
40
|
+
end
|
41
|
+
|
42
|
+
#require 'spec/rake/spectask'
|
43
|
+
#Spec::Rake::SpecTask.new(:spec) do |spec|
|
44
|
+
#spec.libs << 'lib' << 'spec'
|
45
|
+
#spec.spec_files = FileList['spec/**/*_spec.rb']
|
46
|
+
#end
|
47
|
+
|
48
|
+
#Spec::Rake::SpecTask.new(:rcov) do |spec|
|
49
|
+
#spec.libs << 'lib' << 'spec'
|
50
|
+
#spec.pattern = 'spec/**/*_spec.rb'
|
51
|
+
#spec.rcov = true
|
52
|
+
#end
|
53
|
+
|
54
|
+
#task :spec => :check_dependencies
|
55
|
+
|
56
|
+
#task :default => :spec
|
57
|
+
|
58
|
+
YARD::Rake::YardocTask.new do |t|
|
59
|
+
t.files = ['lib/**/*.rb', 'README.md', 'TODO.md', 'CREDITS.md', 'LICENSE', 'VERSION']
|
60
|
+
#t.options = ['--any', '--extra', '--opts'] # optional
|
61
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# TODO
|
2
|
+
|
3
|
+
## From the current Graphy project
|
4
|
+
|
5
|
+
* code cleanup: syntax, typo
|
6
|
+
* YARD documentation
|
7
|
+
* hunt for buggy behaviors
|
8
|
+
* a solid helper to check graphy object type in replacement of the current `is_a?` hack
|
9
|
+
* have the `[]` class method propagate through nested module inclusions [see this topic](http://www.ruby-forum.com/topic/68638)
|
10
|
+
* [Incremental heuristic search algorithms](http://en.wikipedia.org/wiki/Incremental_heuristic_search)?
|
11
|
+
|
12
|
+
## From GRATR
|
13
|
+
|
14
|
+
The following list was present in GRATR, and items may (or may not) be added to this library:
|
15
|
+
|
16
|
+
* Primal Dual for combinatorial optimization problems
|
17
|
+
* Min-Max Flow
|
18
|
+
* Near optimal traveling salesman problem
|
19
|
+
* Orientation of undirected graphs
|
20
|
+
* Undirected graphs from ActiveRecord
|
@@ -0,0 +1 @@
|
|
1
|
+
0.5.2
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/ruby -I../lib
|
2
|
+
|
3
|
+
require 'gratr'
|
4
|
+
require 'gratr/dot'
|
5
|
+
|
6
|
+
include GRATR
|
7
|
+
|
8
|
+
# This program gives an example of dynamic analysis of a program's call stack,
|
9
|
+
# that exports to dot and creates a jpg visualization of the call diagram.
|
10
|
+
|
11
|
+
class GraphSelf
|
12
|
+
|
13
|
+
# Setup some data to call Dijkstra's Algorithm
|
14
|
+
def initialize
|
15
|
+
@d = Digraph[ [:a,:b] => 9, [:a,:e] => 3,
|
16
|
+
[:b,:c] => 2, [:b,:e] => 6,
|
17
|
+
[:c,:d] => 1,
|
18
|
+
[:d,:c] => 2,
|
19
|
+
[:e,:b] => 2, [:e,:f] => 1,
|
20
|
+
[:f,:c] => 2, [:f,:d] => 7, [:f,:e] => 2 ]
|
21
|
+
|
22
|
+
@call_stack = []
|
23
|
+
@call_graph = Digraph.new
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get the call graph variable
|
27
|
+
def call_graph() @call_graph; end
|
28
|
+
|
29
|
+
# Turn capturing of call graph on
|
30
|
+
def capture_func
|
31
|
+
Proc.new do |event, f, l, id, b, klass|
|
32
|
+
# Only interested in the GRATR library itself
|
33
|
+
if ( klass.to_s =~ /GRATR/ )
|
34
|
+
case event.to_s
|
35
|
+
when /call/
|
36
|
+
method = "#{klass.to_s.split('::')[1]}.#{id}" # Removes GRATR::
|
37
|
+
@call_graph.add_edge!(@call_stack[-1],method) if @call_stack[-1]
|
38
|
+
@call_stack.push(method)
|
39
|
+
when /return/ : @call_stack.pop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Run a capture of the call graph for Dijkstra's algorithm
|
46
|
+
def run
|
47
|
+
set_trace_func capture_func
|
48
|
+
@d.dijkstras_algorithm(:a)
|
49
|
+
set_trace_func nil
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# Run a capture and generate the resulting jpg file
|
56
|
+
GraphSelf.new.run.call_graph.write_to_graphic_file('jpg','self_graph')
|
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/ruby -I../lib
|
2
|
+
|
3
|
+
require 'gratr'
|
4
|
+
require 'gratr/dot'
|
5
|
+
|
6
|
+
include GRATR
|
7
|
+
|
8
|
+
module_graph=Digraph.new
|
9
|
+
ObjectSpace.each_object(Module) do |m|
|
10
|
+
m.ancestors.each {|a| module_graph.add_edge!(m,a) if m != a}
|
11
|
+
end
|
12
|
+
|
13
|
+
gv = module_graph.vertices.select {|v| v.to_s.match(/GRATR/) && v.to_s != 'GRATR'}
|
14
|
+
module_graph.induced_subgraph(gv).write_to_graphic_file('jpg','module_graph')
|
Binary file
|
Binary file
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{graphy}
|
8
|
+
s.version = "0.5.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Bruce Williams"]
|
12
|
+
s.date = %q{2010-04-04}
|
13
|
+
s.description = %q{A framework for graph data structures and algorithms.
|
14
|
+
|
15
|
+
This library is based on GRATR and RGL.
|
16
|
+
|
17
|
+
Graph algorithms currently provided are:
|
18
|
+
|
19
|
+
* Topological Sort
|
20
|
+
* Strongly Connected Components
|
21
|
+
* Transitive Closure
|
22
|
+
* Rural Chinese Postman
|
23
|
+
* Biconnected
|
24
|
+
}
|
25
|
+
s.email = %q{bruce@codefluency.com}
|
26
|
+
s.extra_rdoc_files = [
|
27
|
+
"LICENSE",
|
28
|
+
"README.md"
|
29
|
+
]
|
30
|
+
s.files = [
|
31
|
+
".document",
|
32
|
+
".gitignore",
|
33
|
+
"CREDITS.md",
|
34
|
+
"LICENSE",
|
35
|
+
"README.md",
|
36
|
+
"Rakefile",
|
37
|
+
"TODO.md",
|
38
|
+
"VERSION",
|
39
|
+
"examples/graph_self.rb",
|
40
|
+
"examples/module_graph.jpg",
|
41
|
+
"examples/module_graph.rb",
|
42
|
+
"examples/self_graph.jpg",
|
43
|
+
"examples/visualize.jpg",
|
44
|
+
"examples/visualize.rb",
|
45
|
+
"graphy.gemspec",
|
46
|
+
"lib/graphy.rb",
|
47
|
+
"lib/graphy/adjacency_graph.rb",
|
48
|
+
"lib/graphy/arc.rb",
|
49
|
+
"lib/graphy/arc_number.rb",
|
50
|
+
"lib/graphy/biconnected.rb",
|
51
|
+
"lib/graphy/chinese_postman.rb",
|
52
|
+
"lib/graphy/classes/graph_classes.rb",
|
53
|
+
"lib/graphy/common.rb",
|
54
|
+
"lib/graphy/comparability.rb",
|
55
|
+
"lib/graphy/directed_graph.rb",
|
56
|
+
"lib/graphy/directed_graph/algorithms.rb",
|
57
|
+
"lib/graphy/directed_graph/distance.rb",
|
58
|
+
"lib/graphy/dot.rb",
|
59
|
+
"lib/graphy/edge.rb",
|
60
|
+
"lib/graphy/ext.rb",
|
61
|
+
"lib/graphy/graph.rb",
|
62
|
+
"lib/graphy/graph_api.rb",
|
63
|
+
"lib/graphy/labels.rb",
|
64
|
+
"lib/graphy/maximum_flow.rb",
|
65
|
+
"lib/graphy/ruby_compatibility.rb",
|
66
|
+
"lib/graphy/search.rb",
|
67
|
+
"lib/graphy/strong_components.rb",
|
68
|
+
"lib/graphy/support/support.rb",
|
69
|
+
"lib/graphy/undirected_graph.rb",
|
70
|
+
"lib/graphy/undirected_graph/algorithms.rb",
|
71
|
+
"spec/biconnected_spec.rb",
|
72
|
+
"spec/chinese_postman_spec.rb",
|
73
|
+
"spec/community_spec.rb",
|
74
|
+
"spec/complement_spec.rb",
|
75
|
+
"spec/digraph_distance_spec.rb",
|
76
|
+
"spec/digraph_spec.rb",
|
77
|
+
"spec/dot_spec.rb",
|
78
|
+
"spec/edge_spec.rb",
|
79
|
+
"spec/inspection_spec.rb",
|
80
|
+
"spec/multi_edge_spec.rb",
|
81
|
+
"spec/neighborhood_spec.rb",
|
82
|
+
"spec/properties_spec.rb",
|
83
|
+
"spec/search_spec.rb",
|
84
|
+
"spec/spec.opts",
|
85
|
+
"spec/spec_helper.rb",
|
86
|
+
"spec/strong_components_spec.rb",
|
87
|
+
"spec/triangulated_spec.rb",
|
88
|
+
"spec/undirected_graph_spec.rb",
|
89
|
+
"vendor/priority-queue/CHANGELOG",
|
90
|
+
"vendor/priority-queue/Makefile",
|
91
|
+
"vendor/priority-queue/README",
|
92
|
+
"vendor/priority-queue/benchmark/dijkstra.rb",
|
93
|
+
"vendor/priority-queue/compare_comments.rb",
|
94
|
+
"vendor/priority-queue/doc/c-vs-rb.png",
|
95
|
+
"vendor/priority-queue/doc/compare_big.gp",
|
96
|
+
"vendor/priority-queue/doc/compare_big.png",
|
97
|
+
"vendor/priority-queue/doc/compare_small.gp",
|
98
|
+
"vendor/priority-queue/doc/compare_small.png",
|
99
|
+
"vendor/priority-queue/doc/results.csv",
|
100
|
+
"vendor/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb",
|
101
|
+
"vendor/priority-queue/ext/priority_queue/CPriorityQueue/priority_queue.c",
|
102
|
+
"vendor/priority-queue/lib/priority_queue.rb",
|
103
|
+
"vendor/priority-queue/lib/priority_queue/c_priority_queue.rb",
|
104
|
+
"vendor/priority-queue/lib/priority_queue/poor_priority_queue.rb",
|
105
|
+
"vendor/priority-queue/lib/priority_queue/ruby_priority_queue.rb",
|
106
|
+
"vendor/priority-queue/priority_queue.so",
|
107
|
+
"vendor/priority-queue/setup.rb",
|
108
|
+
"vendor/priority-queue/test/priority_queue_test.rb",
|
109
|
+
"vendor/rdot.rb"
|
110
|
+
]
|
111
|
+
s.homepage = %q{http://github.com/bruce/graphy}
|
112
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
113
|
+
s.require_paths = ["lib"]
|
114
|
+
s.rubygems_version = %q{1.3.6}
|
115
|
+
s.summary = %q{A Graph Theory Ruby library}
|
116
|
+
s.test_files = [
|
117
|
+
"spec/edge_spec.rb",
|
118
|
+
"spec/triangulated_spec.rb",
|
119
|
+
"spec/undirected_graph_spec.rb",
|
120
|
+
"spec/properties_spec.rb",
|
121
|
+
"spec/complement_spec.rb",
|
122
|
+
"spec/search_spec.rb",
|
123
|
+
"spec/digraph_spec.rb",
|
124
|
+
"spec/inspection_spec.rb",
|
125
|
+
"spec/community_spec.rb",
|
126
|
+
"spec/multi_edge_spec.rb",
|
127
|
+
"spec/neighborhood_spec.rb",
|
128
|
+
"spec/biconnected_spec.rb",
|
129
|
+
"spec/spec_helper.rb",
|
130
|
+
"spec/chinese_postman_spec.rb",
|
131
|
+
"spec/dot_spec.rb",
|
132
|
+
"spec/digraph_distance_spec.rb",
|
133
|
+
"spec/strong_components_spec.rb",
|
134
|
+
"examples/visualize.rb",
|
135
|
+
"examples/module_graph.rb",
|
136
|
+
"examples/graph_self.rb"
|
137
|
+
]
|
138
|
+
|
139
|
+
if s.respond_to? :specification_version then
|
140
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
141
|
+
s.specification_version = 3
|
142
|
+
|
143
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
144
|
+
else
|
145
|
+
end
|
146
|
+
else
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|