rgl 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/ChangeLog +74 -0
  2. data/Makefile +72 -0
  3. data/README +240 -0
  4. data/Rakefile +210 -0
  5. data/TAGS +209 -0
  6. data/examples/canvas.rb +103 -0
  7. data/examples/codegraph +238 -0
  8. data/examples/example.jpg +0 -0
  9. data/examples/examples.rb +112 -0
  10. data/examples/graph.dot +54 -0
  11. data/examples/graph.png +0 -0
  12. data/examples/module_graph.jpg +0 -0
  13. data/examples/north.rb +12 -0
  14. data/examples/north/Graph.log +128 -0
  15. data/examples/north/g.10.0.graphml +28 -0
  16. data/examples/north/g.10.1.graphml +28 -0
  17. data/examples/north/g.10.11.graphml +31 -0
  18. data/examples/north/g.10.12.graphml +27 -0
  19. data/examples/north/g.10.13.graphml +27 -0
  20. data/examples/north/g.10.14.graphml +27 -0
  21. data/examples/north/g.10.15.graphml +26 -0
  22. data/examples/north/g.10.16.graphml +26 -0
  23. data/examples/north/g.10.17.graphml +26 -0
  24. data/examples/north/g.10.19.graphml +37 -0
  25. data/examples/north/g.10.2.graphml +28 -0
  26. data/examples/north/g.10.20.graphml +38 -0
  27. data/examples/north/g.10.22.graphml +43 -0
  28. data/examples/north/g.10.24.graphml +30 -0
  29. data/examples/north/g.10.25.graphml +45 -0
  30. data/examples/north/g.10.27.graphml +38 -0
  31. data/examples/north/g.10.28.graphml +30 -0
  32. data/examples/north/g.10.29.graphml +38 -0
  33. data/examples/north/g.10.3.graphml +26 -0
  34. data/examples/north/g.10.30.graphml +34 -0
  35. data/examples/north/g.10.31.graphml +42 -0
  36. data/examples/north/g.10.34.graphml +42 -0
  37. data/examples/north/g.10.37.graphml +28 -0
  38. data/examples/north/g.10.38.graphml +38 -0
  39. data/examples/north/g.10.39.graphml +36 -0
  40. data/examples/north/g.10.4.graphml +26 -0
  41. data/examples/north/g.10.40.graphml +37 -0
  42. data/examples/north/g.10.41.graphml +37 -0
  43. data/examples/north/g.10.42.graphml +26 -0
  44. data/examples/north/g.10.45.graphml +28 -0
  45. data/examples/north/g.10.46.graphml +32 -0
  46. data/examples/north/g.10.5.graphml +31 -0
  47. data/examples/north/g.10.50.graphml +30 -0
  48. data/examples/north/g.10.56.graphml +29 -0
  49. data/examples/north/g.10.57.graphml +32 -0
  50. data/examples/north/g.10.58.graphml +32 -0
  51. data/examples/north/g.10.6.graphml +26 -0
  52. data/examples/north/g.10.60.graphml +32 -0
  53. data/examples/north/g.10.61.graphml +34 -0
  54. data/examples/north/g.10.62.graphml +34 -0
  55. data/examples/north/g.10.68.graphml +30 -0
  56. data/examples/north/g.10.69.graphml +32 -0
  57. data/examples/north/g.10.7.graphml +29 -0
  58. data/examples/north/g.10.70.graphml +26 -0
  59. data/examples/north/g.10.71.graphml +27 -0
  60. data/examples/north/g.10.72.graphml +28 -0
  61. data/examples/north/g.10.74.graphml +29 -0
  62. data/examples/north/g.10.75.graphml +29 -0
  63. data/examples/north/g.10.78.graphml +27 -0
  64. data/examples/north/g.10.79.graphml +34 -0
  65. data/examples/north/g.10.8.graphml +29 -0
  66. data/examples/north/g.10.80.graphml +34 -0
  67. data/examples/north/g.10.82.graphml +35 -0
  68. data/examples/north/g.10.83.graphml +32 -0
  69. data/examples/north/g.10.85.graphml +34 -0
  70. data/examples/north/g.10.86.graphml +34 -0
  71. data/examples/north/g.10.88.graphml +37 -0
  72. data/examples/north/g.10.89.graphml +29 -0
  73. data/examples/north/g.10.9.graphml +26 -0
  74. data/examples/north/g.10.90.graphml +32 -0
  75. data/examples/north/g.10.91.graphml +31 -0
  76. data/examples/north/g.10.92.graphml +26 -0
  77. data/examples/north/g.10.93.graphml +32 -0
  78. data/examples/north/g.10.94.graphml +34 -0
  79. data/examples/north/g.12.8.graphml +40 -0
  80. data/examples/north/g.14.9.graphml +36 -0
  81. data/examples/north2.rb +21 -0
  82. data/examples/rdep-rgl.rb +395 -0
  83. data/install.rb +49 -0
  84. data/lib/rgl/adjacency.rb +151 -0
  85. data/lib/rgl/base.rb +299 -0
  86. data/lib/rgl/connected_components.rb +125 -0
  87. data/lib/rgl/dot.rb +63 -0
  88. data/lib/rgl/graphxml.rb +52 -0
  89. data/lib/rgl/implicit.rb +151 -0
  90. data/lib/rgl/mutable.rb +54 -0
  91. data/lib/rgl/rdot.rb +264 -0
  92. data/lib/rgl/topsort.rb +61 -0
  93. data/lib/rgl/transitiv_closure.rb +34 -0
  94. data/lib/rgl/traversal.rb +296 -0
  95. data/tests/TestComponents.rb +67 -0
  96. data/tests/TestDirectedGraph.rb +100 -0
  97. data/tests/TestEdge.rb +33 -0
  98. data/tests/TestGraphXML.rb +57 -0
  99. data/tests/TestImplicit.rb +52 -0
  100. data/tests/TestTransitiveClosure.rb +29 -0
  101. data/tests/TestTraversal.rb +222 -0
  102. data/tests/TestUnDirectedGraph.rb +98 -0
  103. metadata +163 -0
@@ -0,0 +1,74 @@
1
+ 2002-11-10 monora <monora@HDDESKTOP>
2
+
3
+ * lib/set.rb, lib/rgl/adjacency.rb, lib/utils.rb:
4
+ Use knus compatibility library for Ruby 1.8 esp. for set.rb and inject.
5
+
6
+ 2002-09-22 monora <monora@HDDESKTOP>
7
+
8
+ * lib/rgl/dot.rb:
9
+ to_dot_graph now also outputs vertices.
10
+
11
+ * lib/rgl/adjacency.rb: cosmetic.
12
+
13
+ 2002-09-17 monora <monora@HDDESKTOP>
14
+
15
+ * Makefile: Added releasedoc target.
16
+
17
+ * lib/rgl/base.rb, lib/rgl/implicit.rb:
18
+ Fixed typo.
19
+
20
+ 2002-08-29 monora <monora@HDDESKTOP>
21
+
22
+ * ChangeLog, lib/rgl/adjacency.rb, lib/rgl/base.rb, tests/TestDirectedGraph.rb, tests/TestUnDirectedGraph.rb:
23
+ Changed NameError to NoVertexError.
24
+
25
+ 2002-09-22 monora <monora@HDDESKTOP>
26
+
27
+ * lib/rgl/dot.rb:
28
+ to_dot_graph now also outputs vertices.
29
+
30
+ * lib/rgl/adjacency.rb: cosmetic.
31
+
32
+ 2002-09-17 monora <monora@HDDESKTOP>
33
+
34
+ * Makefile: Added releasedoc target.
35
+
36
+ * lib/rgl/base.rb, lib/rgl/implicit.rb:
37
+ Fixed typo.
38
+
39
+ 2002-08-29 monora <monora@HDDESKTOP>
40
+
41
+ * ChangeLog, lib/rgl/adjacency.rb, lib/rgl/base.rb, tests/TestDirectedGraph.rb, tests/TestUnDirectedGraph.rb:
42
+ Changed NameError to NoVertexError.
43
+
44
+ 2002-08-29 monora <monora@hddesktop>
45
+
46
+ * TestDirectedGraph.rb, TestUnDirectedGraph.rb:
47
+ * adjacency.rb, base.rb: Changed NameError to NoVertexError. Fixed Bug Nr. 599872.
48
+
49
+ 2002-08-23 monora <monora@hddesktop>
50
+
51
+ * base.rb, dot.rb, rdot.rb:
52
+ canvas.rb added. Collision with rdoc/dot.rb removed.
53
+
54
+ 2002-08-19 monora <monora@hddesktop>
55
+
56
+ * traversal.rb: New file.
57
+
58
+ * traversal.rb: started at sf
59
+
60
+ * adjacency.rb, base.rb, connected_components.rb, dot.rb, graphxml.rb, implicit.rb, mutable.rb, topsort.rb, transitiv_closure.rb:
61
+ New file.
62
+
63
+ * adjacency.rb, base.rb, connected_components.rb, dot.rb, graphxml.rb, implicit.rb, mutable.rb, topsort.rb, transitiv_closure.rb:
64
+ started at sf
65
+
66
+ 2002-06-10 Horst Duchene <horst@hduchene.de>
67
+
68
+ * lib/rgl/graphxml.rb: added + tests + examples from graphviz catalog
69
+
70
+ 2002-03-21 Horst Duchene <horst@hduchene.de>
71
+
72
+ * Ported tests to Test::Unit
73
+ * transitive_closure.rb
74
+
@@ -0,0 +1,72 @@
1
+ #
2
+ # make test - run the tests
3
+ # make clean - tidy up
4
+ #
5
+
6
+ LIB=./lib
7
+ RGL=rgl-$(VERSION)
8
+ BOOST_DOC=http://www.boost.org/libs/graph/doc
9
+ #BOOST_DOC=file://D:/Programme/bgl/boost_1_25_1/libs/graph/doc
10
+
11
+ default: test
12
+ test:
13
+ cd tests && ruby -I../lib runtests.rb
14
+
15
+ # Release must have VERSION variable set
16
+ #
17
+ # make VERSION=0.2 release
18
+ #
19
+
20
+ release: doc stamp clean tar
21
+
22
+ ftpput: ${RGL}.tgz
23
+ ftpput.rb $<
24
+
25
+ releasedoc: doc
26
+ rm -f htdocs
27
+ ln -fs doc htdocs
28
+ tar --dereference --exclude='*.bak' -czf htdocs.tgz htdocs
29
+ rm htdocs
30
+ scp htdocs.tgz monora@rgl.sf.net:/home/groups/r/rg/rgl
31
+
32
+ stamp:
33
+ ruby -i.bak -pe 'sub!(/V\d+(\.\d+)+/, "V$(VERSION)") if /_VERSION =/' ${LIB}/rgl/base.rb
34
+ rm ${LIB}/rgl/base.rb.bak
35
+ cvs commit
36
+ cvs rtag `echo V$(VERSION) | sed s/\\\\./_/g` rgl
37
+
38
+ doc: ${LIB}/rgl/*.rb README
39
+ # cd ${LIB} && rdoc --diagram --fileboxes --title RGL --main rgl/base.rb --op ../doc
40
+ cd ${LIB} && rdoc.bat --title RGL --main rgl/base.rb --op ../doc
41
+ cp examples/*.jpg doc
42
+ find doc -name \*.html -print | xargs ruby -i.bak -pe 'sub!(/BOOST_DOC.(.*.html)/,"<a href=${BOOST_DOC}/\\1>\\1<a>")'
43
+
44
+ install:
45
+ ruby install.rb
46
+
47
+ tags:
48
+ rtags `find ${LIB} -name '*.rb'`
49
+
50
+ tar: test
51
+ ln -fs rgl ../${RGL}
52
+ tar --directory=.. \
53
+ --create \
54
+ --dereference \
55
+ --file=${RGL}.tgz \
56
+ --gzip \
57
+ --exclude='CVS' \
58
+ --exclude='cvs' \
59
+ --exclude='misc' \
60
+ --exclude='doc' \
61
+ --exclude='homepage' \
62
+ --exclude='*.tgz' \
63
+ --exclude='*/.*' \
64
+ ${RGL}
65
+ rm ../${RGL}
66
+
67
+ clean:
68
+ rm -rf rgl*.tgz graph.dot TAGS examples/*/*.dot
69
+ find . -name \*~ -print | xargs rm -f
70
+ find . -name \*.bak -print | xargs rm -f
71
+ find . -name core -print | xargs rm -f
72
+
data/README ADDED
@@ -0,0 +1,240 @@
1
+ = Ruby Graph Library (RGL)
2
+
3
+ RGL is a framework for graph data structures and algorithms.
4
+
5
+ The design of the library is much influenced by the Boost Graph Library (BGL)
6
+ which is written in C++ heavily using its template mechanism. Refer to
7
+ http://www.boost.org/libs/graph/doc for further links and documentation on graph
8
+ data structures and algorithms and the design rationales of BGL.
9
+
10
+ A comprehensive summary of graph terminology can be found in the the graph
11
+ section of the <em>Dictionary of Algorithms and Data Structures</em> at
12
+ http://www.nist.gov/dads/HTML/graph.html.
13
+
14
+ == Design principles
15
+
16
+ This document concentrates on the special issues of the implementation in
17
+ Ruby. The main design goals directly taken from the BGL design are:
18
+
19
+ * An interface for how the structure of a graph can be accessed using a generic
20
+ interface that hides the details of the graph data structure
21
+ implementation. This interface is defined by the module Graph, which should be
22
+ included in concrete classes.
23
+
24
+ * A standardized generic interface for traversing graphs (RGL::GraphIterator)
25
+
26
+ RGL provides some general purpose graph classes that conform to this interface,
27
+ but they are not meant to be the *only* graph classes. As in BGL I believe that
28
+ the main contribution of the RGL is the formulation of this interface.
29
+
30
+ The BGL graph interface and graph components are generic in the sense of the C++
31
+ Standard Template Library (STL). In Ruby other techniques are available to
32
+ express the generic character of the algorithms and data structures mainly using
33
+ mixins and iterators. The BGL documentation mentions three means to achieve
34
+ genericity:
35
+
36
+ * Algorithm/Data-Structure Interoperability
37
+ * Extension through Function Objects and Visitors
38
+ * Element Type Parameterization
39
+ * Vertex and Edge Property Multi-Parameterization
40
+
41
+ The first is easily achieved in RGL using mixins, which of course is not as
42
+ efficient than C++ templates (but much more readable :-). The second one is even
43
+ more easily implemented using standard iterators with blocks or using the
44
+ Stream module. The third one is no issue since Ruby is dynamically typed: Each
45
+ object can be a graph vertex. There is no need for a vertex (or even edge
46
+ type). In the current version of RGL properties of vertices are simply attached
47
+ using hashes. At first there seems to be not much need for the graph property
48
+ machinery.
49
+
50
+ === Algorithms
51
+
52
+ The first version of RGL only contains a core set of algorithm patterns:
53
+
54
+ * Breadth First Search (RGL::BFSIterator)
55
+ * Depth First Search (RGL::DFSIterator)
56
+
57
+ The algorithm patterns by themselves do not compute any meaningful quantities
58
+ over graphs, they are merely building blocks for constructing graph
59
+ algorithms. The graph algorithms in RGL currently include:
60
+
61
+ * Topological Sort (RGL::TopsortIterator)
62
+ * Connected Components (RGL::Graph#each_connected_component)
63
+ * Strongly Connected Components (RGL::Graph#strongly_connected_components)
64
+ * Transitive Closure (RGL::Graph#transitive_closure)
65
+
66
+ === Data Structures
67
+
68
+ RGL currently provides two graph classes that implement a generalized adjacency
69
+ list and an edge list adaptor.
70
+
71
+ * RGL::AdjacencyGraph
72
+ * RGL::ImplicitGraph
73
+
74
+ The AdjacencyGraph class is the general purpose *swiss army knife* of graph
75
+ classes. It is highly parameterized so that it can be optimized for different
76
+ situations: the graph is directed or undirected, allow or disallow parallel
77
+ edges, efficient access to just the out-edges, fast vertex insertion and removal
78
+ at the cost of extra space overhead, etc.
79
+
80
+ === Differences to BGL
81
+
82
+ The concepts of IncidenceGraph, AdjacencyGraph and VertexListGraph (see
83
+ http://www.boost.org/libs/graph/doc/IncidenceGraph.html) are here bundled in the
84
+ base graph module. Most methods of IncidenceGraph should be standard in the base
85
+ module Graph. The complexity guarantees can not necessarily provided. See
86
+ http://www.boost.org/libs/graph/doc/graph_concepts.html
87
+
88
+ == Installation
89
+
90
+ RGL is depended on the _stream_ library which can also be downloaded from
91
+ http://rubyforge.org/frs/?group_id=110.
92
+
93
+ === GEM Installation
94
+
95
+ Download the GEM file and install it with ..
96
+
97
+ gem install rgl-VERSION.gem
98
+
99
+ or directly with
100
+
101
+ gem install rgl
102
+
103
+ Use the correct version number for VERSION (e.g. 0.2.2). You may need root
104
+ privileges to install.
105
+
106
+ === Normal Installation
107
+
108
+ You have to install stream library before. You can than install RGL with the
109
+ following command:
110
+
111
+ % ruby install.rb
112
+
113
+ from its distribution directory.
114
+
115
+ == Example irb session with RGL
116
+
117
+ irb> require 'rgl/adjacency'
118
+ irb> dg=RGL::DirectedAdjacencyGraph[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6]
119
+ # Use DOT to visualize this graph:
120
+ irb> require 'rgl/dot'
121
+ irb> dg.write_to_graphic_file('jpg')
122
+ "graph.jpg"
123
+
124
+ The result: link:../examples/example.jpg
125
+
126
+ irb> dg.directed?
127
+ true
128
+ irb> dg.vertices
129
+ [5, 6, 1, 2, 3, 4]
130
+ irb> dg.has_vertex? 4
131
+ true
132
+
133
+ Every object could be a vertex (there is no class Vertex), even the class object
134
+ _Object_:
135
+
136
+ irb> dg.has_vertex? Object
137
+ false
138
+ irb> dg.edges.sort.to_s
139
+ "(1-2)(1-6)(2-3)(2-4)(4-5)(6-4)"
140
+ irb> dg.to_undirected.edges.sort.to_s
141
+ "(1=2)(1=6)(2=3)(2=4)(5=4)(6=4)"
142
+
143
+ Add inverse edge (4-2) to directed graph:
144
+
145
+ irb> dg.add_edge 4,2
146
+
147
+ (4-2) == (2-4) in the undirected graph:
148
+
149
+ irb> dg.to_undirected.edges.sort.to_s
150
+ "(1=2)(1=6)(2=3)(2=4)(5=4)(6=4)"
151
+
152
+ (4-2) != (2-4) in directed graphs:
153
+
154
+ irb> dg.edges.sort.to_s
155
+ "(1-2)(1-6)(2-3)(2-4)(4-2)(4-5)(6-4)"
156
+ irb> dg.remove_edge 4,2
157
+ true
158
+
159
+ <em>Topological sort</em> is realized with as iterator:
160
+
161
+ require 'graph/traversal'
162
+ irb> dg.topsort_iterator.to_a
163
+ [1, 2, 3, 6, 4, 5]
164
+
165
+ A more elaborated example showing <em>implicit graphs</em>:
166
+
167
+ def module_graph
168
+ RGL::ImplicitGraph.new { |g|
169
+ g.vertex_iterator { |b|
170
+ ObjectSpace.each_object(Module, &b)
171
+ }
172
+ g.adjacent_iterator { |x, b|
173
+ x.ancestors.each { |y|
174
+ b.call(y) unless x == y || y == Kernel || y == Object
175
+ }
176
+ }
177
+ g.directed = true
178
+ }
179
+ end
180
+
181
+ This function creates a directed graph with vertices being all loaded modules:
182
+
183
+ g = module_graph
184
+
185
+ We only want to see the ancestors of RGL::AdjacencyGraph:
186
+
187
+ tree = bfs_search_tree_from(g,RGL::AdjacencyGraph)
188
+
189
+ Now we want to visualize this component of g with DOT. We therefore create a
190
+ subgraph of the original graph using a filtered graph:
191
+
192
+ g = g.vertices_filtered_by {|v| tree.has_vertex? v}
193
+
194
+ Create the graphics with DOT:
195
+
196
+ g.write_to_graphic_file
197
+
198
+ produces module_graph.jpg: link:../examples/module_graph.jpg
199
+
200
+ Look for more in the examples directory (i.e.
201
+ examples.rb[link:files/examples/examples_rb.html]).
202
+
203
+ == Credits
204
+
205
+ Many thanks to Robert Feldt which also worked on a graph library
206
+ (http://rockit.sf.net/subprojects/graphr) who pointed me to BGL and many other
207
+ graph resources. Manuel Simoni found a subtle bug in a preliminary version
208
+ announced at http://rubygarden.com/ruby?RubyAlgorithmPackage/Graph.
209
+
210
+ Robert kindly allowed to integrate his work on graphr, which I did not yet
211
+ succeed. Especially his work to output graphs for GraphViz (see
212
+ http://www.research.att.com/sw/tools/graphviz/download.html) is much more
213
+ elaborated than the minimal support in dot.rb.
214
+
215
+ Jason Voegele for set.rb implementing sets using hashes. These are used in the
216
+ implementation of adjacency lists in AdjacencyGraph.
217
+
218
+ Jeremy Siek one of the authors of the nice book "The Boost Graph Library (BGL)"
219
+ (http://cseng.awl.com/book/0,3828,0201729148,00.html) kindly allowed to use the
220
+ BGL documentation as a _cheap_ reference for RGL. He and Robert also gave
221
+ feedback and many ideas for RGL.
222
+
223
+ Dave Thomas for RDoc (http://rdoc.sourceforge.net) which generated what you read
224
+ and matz for Ruby. Dave included in the latest version of RDoc (alpha9) the
225
+ module dot/dot.rb which I use instead of Roberts module to visualize graphs (see
226
+ rgl/dot.rb).
227
+
228
+ == Copying
229
+
230
+ RGL is Copyright (c) 2002,2004 by Horst Duchene. It is free software, and may be
231
+ redistributed under the terms specified in the README file of the Ruby
232
+ distribution.
233
+
234
+ == Support
235
+
236
+ Please contact me at mailto:monora@users.sourceforge.net with bug reports
237
+ suggestions, and other comments. If you send patches, it would help if
238
+ they were in-line (not attachments) and generated using "diff -u".
239
+
240
+
@@ -0,0 +1,210 @@
1
+ # Rakefile for RGL -*- ruby -*-
2
+
3
+ begin
4
+ require 'rubygems'
5
+ require 'rake/gempackagetask'
6
+ rescue Exception
7
+ nil
8
+ end
9
+ require 'rake/clean'
10
+ require 'rake/testtask'
11
+ require 'rake/rdoctask'
12
+
13
+ # Determine the current version of the software
14
+
15
+ if `ruby -Ilib -rrgl/base -e'puts RGL_VERSION'` =~ /\S+$/
16
+ PKG_VERSION = $&
17
+ else
18
+ PKG_VERSION = "0.0.0"
19
+ end
20
+
21
+ SUMMARY = "Ruby Graph Library"
22
+ SOURCES = FileList['lib/**/*.rb']
23
+ RDOC_DIR = './rgl'
24
+
25
+ # The default task is run if rake is given no explicit arguments.
26
+
27
+ desc "Default Task"
28
+ task :default => :test
29
+
30
+ # Define a test task.
31
+
32
+ Rake::TestTask.new { |t|
33
+ t.libs << "tests"
34
+ t.pattern = 'tests/Test*.rb'
35
+ t.verbose = true
36
+ }
37
+
38
+ task :test
39
+
40
+ # Define a test that will run all the test targets.
41
+ desc "Run all test targets"
42
+ task :testall => [:test ]
43
+
44
+ # Install rgl using the standard install.rb script.
45
+
46
+ desc "Install the application"
47
+ task :install do
48
+ ruby "install.rb"
49
+ end
50
+
51
+ # CVS Tasks ----------------------------------------------------------
52
+
53
+ desc "Tag all the CVS files with the latest release number (TAG=x)"
54
+ task :tag do
55
+ rel = "REL_" + PKG_VERSION.gsub(/\./, '_')
56
+ rel << ENV['TAG'] if ENV['TAG']
57
+ puts rel
58
+ sh %{cvs commit -m 'pre-tag commit'}
59
+ sh %{cvs tag #{rel}}
60
+ end
61
+
62
+ # Create a task to build the RDOC documentation tree.
63
+
64
+ rd = Rake::RDocTask.new("rdoc") { |rdoc|
65
+ rdoc.rdoc_dir = RDOC_DIR
66
+ # rdoc.template = 'kilmer'
67
+ # rdoc.template = 'css2'
68
+ rdoc.title = SUMMARY
69
+ rdoc.options << '--line-numbers' << '--inline-source' <<
70
+ '--main' << 'README'
71
+ rdoc.rdoc_files.include(SOURCES, 'README', 'examples/examples.rb')
72
+ }
73
+
74
+ # ====================================================================
75
+ # Create a task that will package the rgl software into distributable
76
+ # tar, zip and gem files.
77
+
78
+ PKG_FILES = FileList[
79
+ 'install.rb',
80
+ '[A-Z]*',
81
+ 'tests/**/*.rb',
82
+ 'examples/**/*'
83
+ ] + SOURCES
84
+
85
+ if ! defined?(Gem)
86
+ puts "Package Target requires RubyGEMs"
87
+ else
88
+ spec = Gem::Specification.new do |s|
89
+
90
+ #### Basic information.
91
+
92
+ s.name = 'rgl'
93
+ s.version = PKG_VERSION
94
+ s.summary = SUMMARY
95
+
96
+ s.description = <<-EOF
97
+ RGL is a framework for graph data structures and algorithms.
98
+
99
+ The design of the library is much influenced by the Boost Graph Library (BGL)
100
+ which is written in C++ heavily using its template mechanism.
101
+
102
+
103
+ RGL currently contains a core set of algorithm patterns:
104
+
105
+
106
+ * Breadth First Search
107
+ * Depth First Search
108
+
109
+ The algorithm patterns by themselves do not compute any meaningful quantities
110
+ over graphs, they are merely building blocks for constructing graph
111
+ algorithms. The graph algorithms in RGL currently include:
112
+
113
+ * Topological Sort
114
+ * Connected Components
115
+ * Strongly Connected Components
116
+ * Transitive Closure
117
+ EOF
118
+
119
+ #### Dependencies and requirements.
120
+
121
+ s.add_dependency('stream', '>= 0.5')
122
+ s.requirements << "Stream library, v0.5 or later"
123
+
124
+ #### Which files are to be included in this gem? Everything! (Except CVS directories.)
125
+ s.files = PKG_FILES.to_a
126
+
127
+ #### Load-time details: library and application (you will need one or both).
128
+
129
+ s.require_path = 'lib' # Use these for libraries.
130
+ s.autorequire = 'rgl'
131
+
132
+ #### Documentation and testing.
133
+
134
+ s.has_rdoc = true
135
+ s.extra_rdoc_files = ['README']
136
+ s.rdoc_options <<
137
+ '--title' << 'RGL - Ruby Graph Library' <<
138
+ '--main' << 'README' <<
139
+ '--line-numbers'
140
+
141
+ #### Author and project details.
142
+ s.author = "Horst Duchene"
143
+ s.email = "hd.at.clr@hduchene.de"
144
+ s.homepage = "rgl.rubyforge.org"
145
+ s.rubyforge_project = "rgl"
146
+ end
147
+
148
+ Rake::GemPackageTask.new(spec) do |pkg|
149
+ #pkg.need_zip = true
150
+ pkg.need_tar = true
151
+ end
152
+ end
153
+
154
+ # TAGS ---------------------------------------------------------------
155
+
156
+ file 'tags' => SOURCES do
157
+ print "Running ctags..."
158
+ sh %{ctags #{SOURCES.join(' ')}} # vi tags
159
+ puts "done."
160
+ end
161
+
162
+ file 'TAGS' => SOURCES do
163
+ sh %{ctags -e #{SOURCES.join(' ')}} # emacs TAGS
164
+ end
165
+
166
+ # Misc tasks =========================================================
167
+
168
+ def count_lines(filename)
169
+ lines = 0
170
+ codelines = 0
171
+ open(filename) { |f|
172
+ f.each do |line|
173
+ lines += 1
174
+ next if line =~ /^\s*$/
175
+ next if line =~ /^\s*#/
176
+ codelines += 1
177
+ end
178
+ }
179
+ [lines, codelines]
180
+ end
181
+
182
+ def show_line(msg, lines, loc)
183
+ printf "%6s %6s %s\n", lines.to_s, loc.to_s, msg
184
+ end
185
+
186
+ desc "Count lines in the main files"
187
+ task :lines do
188
+ total_lines = 0
189
+ total_code = 0
190
+ show_line("File Name", "LINES", "LOC")
191
+ SOURCES.each do |fn|
192
+ lines, codelines = count_lines(fn)
193
+ show_line(fn, lines, codelines)
194
+ total_lines += lines
195
+ total_code += codelines
196
+ end
197
+ show_line("TOTAL", total_lines, total_code)
198
+ end
199
+
200
+ ARCHIVEDIR = '/mnt/flash'
201
+
202
+ task :archive => [:package] do
203
+ cp FileList["pkg/*.tgz", "pkg/*.zip", "pkg/*.gem"], ARCHIVEDIR
204
+ end
205
+
206
+ desc "Copy rdoc html to rubyforge"
207
+ task :rdoc2rf => [:rdoc] do
208
+ #sh "scp -r #{RDOC_DIR} monora@rubyforge.org:/var/www/gforge-projects/rgl"
209
+ sh "scp examples/*.jpg monora@rubyforge.org:/var/www/gforge-projects/rgl/examples"
210
+ end