Permalink
Browse files

import

  • Loading branch information...
0 parents commit c3e88cdd12724588941e175915d544bcf2aa5845 @fmeyer fmeyer committed Apr 26, 2010
Showing with 8,049 additions and 0 deletions.
  1. +479 −0 ChangeLog
  2. +276 −0 README
  3. +232 −0 Rakefile
  4. +103 −0 examples/canvas.rb
  5. BIN examples/example.jpg
  6. +114 −0 examples/examples.rb
  7. +190 −0 examples/insel-der-tausend-gefahren.rb
  8. BIN examples/module_graph.jpg
  9. +12 −0 examples/north.rb
  10. +128 −0 examples/north/Graph.log
  11. +28 −0 examples/north/g.10.0.graphml
  12. +28 −0 examples/north/g.10.1.graphml
  13. +31 −0 examples/north/g.10.11.graphml
  14. +27 −0 examples/north/g.10.12.graphml
  15. +27 −0 examples/north/g.10.13.graphml
  16. +27 −0 examples/north/g.10.14.graphml
  17. +26 −0 examples/north/g.10.15.graphml
  18. +26 −0 examples/north/g.10.16.graphml
  19. +26 −0 examples/north/g.10.17.graphml
  20. +37 −0 examples/north/g.10.19.graphml
  21. +28 −0 examples/north/g.10.2.graphml
  22. +38 −0 examples/north/g.10.20.graphml
  23. +43 −0 examples/north/g.10.22.graphml
  24. +30 −0 examples/north/g.10.24.graphml
  25. +45 −0 examples/north/g.10.25.graphml
  26. +38 −0 examples/north/g.10.27.graphml
  27. +30 −0 examples/north/g.10.28.graphml
  28. +38 −0 examples/north/g.10.29.graphml
  29. +26 −0 examples/north/g.10.3.graphml
  30. +34 −0 examples/north/g.10.30.graphml
  31. +42 −0 examples/north/g.10.31.graphml
  32. +42 −0 examples/north/g.10.34.graphml
  33. +28 −0 examples/north/g.10.37.graphml
  34. +38 −0 examples/north/g.10.38.graphml
  35. +36 −0 examples/north/g.10.39.graphml
  36. +26 −0 examples/north/g.10.4.graphml
  37. +37 −0 examples/north/g.10.40.graphml
  38. +37 −0 examples/north/g.10.41.graphml
  39. +26 −0 examples/north/g.10.42.graphml
  40. +28 −0 examples/north/g.10.45.graphml
  41. +32 −0 examples/north/g.10.46.graphml
  42. +31 −0 examples/north/g.10.5.graphml
  43. +30 −0 examples/north/g.10.50.graphml
  44. +29 −0 examples/north/g.10.56.graphml
  45. +32 −0 examples/north/g.10.57.graphml
  46. +32 −0 examples/north/g.10.58.graphml
  47. +26 −0 examples/north/g.10.6.graphml
  48. +32 −0 examples/north/g.10.60.graphml
  49. +34 −0 examples/north/g.10.61.graphml
  50. +34 −0 examples/north/g.10.62.graphml
  51. +30 −0 examples/north/g.10.68.graphml
  52. +32 −0 examples/north/g.10.69.graphml
  53. +29 −0 examples/north/g.10.7.graphml
  54. +26 −0 examples/north/g.10.70.graphml
  55. +27 −0 examples/north/g.10.71.graphml
  56. +28 −0 examples/north/g.10.72.graphml
  57. +29 −0 examples/north/g.10.74.graphml
  58. +29 −0 examples/north/g.10.75.graphml
  59. +27 −0 examples/north/g.10.78.graphml
  60. +34 −0 examples/north/g.10.79.graphml
  61. +29 −0 examples/north/g.10.8.graphml
  62. +34 −0 examples/north/g.10.80.graphml
  63. +35 −0 examples/north/g.10.82.graphml
  64. +32 −0 examples/north/g.10.83.graphml
  65. +34 −0 examples/north/g.10.85.graphml
  66. +34 −0 examples/north/g.10.86.graphml
  67. +37 −0 examples/north/g.10.88.graphml
  68. +29 −0 examples/north/g.10.89.graphml
  69. +26 −0 examples/north/g.10.9.graphml
  70. +32 −0 examples/north/g.10.90.graphml
  71. +31 −0 examples/north/g.10.91.graphml
  72. +26 −0 examples/north/g.10.92.graphml
  73. +32 −0 examples/north/g.10.93.graphml
  74. +34 −0 examples/north/g.10.94.graphml
  75. +40 −0 examples/north/g.12.8.graphml
  76. +36 −0 examples/north/g.14.9.graphml
  77. +21 −0 examples/north2.rb
  78. +395 −0 examples/rdep-rgl.rb
  79. +49 −0 install.rb
  80. +206 −0 lib/rgl/adjacency.rb
  81. +229 −0 lib/rgl/base.rb
  82. +40 −0 lib/rgl/bidirectional.rb
  83. +47 −0 lib/rgl/condensation.rb
  84. +138 −0 lib/rgl/connected_components.rb
  85. +71 −0 lib/rgl/dot.rb
  86. +13 −0 lib/rgl/enumerable_ext.rb
  87. +51 −0 lib/rgl/graphxml.rb
  88. +174 −0 lib/rgl/implicit.rb
  89. +103 −0 lib/rgl/mutable.rb
  90. +445 −0 lib/rgl/rdot.rb
  91. +72 −0 lib/rgl/topsort.rb
  92. +2 −0 lib/rgl/transitiv_closure.rb
  93. +179 −0 lib/rgl/transitivity.rb
  94. +349 −0 lib/rgl/traversal.rb
  95. +30 −0 rakelib/dep_graph.rake
  96. +65 −0 tests/TestComponents.rb
  97. +61 −0 tests/TestCycles.rb
  98. +125 −0 tests/TestDirectedGraph.rb
  99. +18 −0 tests/TestDot.rb
  100. +34 −0 tests/TestEdge.rb
  101. +71 −0 tests/TestGraph.rb
  102. +57 −0 tests/TestGraphXML.rb
  103. +52 −0 tests/TestImplicit.rb
  104. +863 −0 tests/TestRdot.rb
  105. +129 −0 tests/TestTransitivity.rb
  106. +220 −0 tests/TestTraversal.rb
  107. +102 −0 tests/TestUnDirectedGraph.rb
  108. +7 −0 tests/test_helper.rb
479 ChangeLog
Oops, something went wrong.
276 README
@@ -0,0 +1,276 @@
+= Ruby Graph Library (RGL)
+
+RGL is a framework for graph data structures and algorithms.
+
+The design of the library is much influenced by the Boost Graph Library (BGL)
+which is written in C++ heavily using its template mechanism. Refer to
+http://www.boost.org/libs/graph/doc for further links and documentation on graph
+data structures and algorithms and the design rationales of BGL.
+
+A comprehensive summary of graph terminology can be found in the the graph
+section of the <em>Dictionary of Algorithms and Data Structures</em> at
+http://www.nist.gov/dads/HTML/graph.html.
+
+== Design principles
+
+This document concentrates on the special issues of the implementation in
+Ruby. The main design goals directly taken from the BGL design are:
+
+* An interface for how the structure of a graph can be accessed using a generic
+ interface that hides the details of the graph data structure
+ implementation. This interface is defined by the module Graph, which should be
+ included in concrete classes.
+
+* A standardized generic interface for traversing graphs (RGL::GraphIterator)
+
+RGL provides some general purpose graph classes that conform to this interface,
+but they are not meant to be the *only* graph classes. As in BGL I believe that
+the main contribution of the RGL is the formulation of this interface.
+
+The BGL graph interface and graph components are generic in the sense of the C++
+Standard Template Library (STL). In Ruby other techniques are available to
+express the generic character of the algorithms and data structures mainly using
+mixins and iterators. The BGL documentation mentions three means to achieve
+genericity:
+
+* Algorithm/Data-Structure Interoperability
+* Extension through Function Objects and Visitors
+* Element Type Parameterization
+* Vertex and Edge Property Multi-Parameterization
+
+The first is easily achieved in RGL using mixins, which of course is not as
+efficient than C++ templates (but much more readable :-). The second one is
+even more easily implemented using standard iterators with blocks or using the
+Stream[http://rgl.rubyforge.org/stream/files/README.html] module. The third one
+is no issue since Ruby is dynamically typed: Each object can be a graph
+vertex. There is no need for a vertex (or even edge type). In the current
+version of RGL properties of vertices are simply attached using hashes. At
+first there seems to be not much need for the graph property machinery.
+
+=== Algorithms
+
+The first version of RGL only contains a core set of algorithm patterns:
+
+* Breadth First Search (RGL::BFSIterator)
+* Depth First Search (RGL::DFSIterator)
+
+The algorithm patterns by themselves do not compute any meaningful quantities
+over graphs, they are merely building blocks for constructing graph
+algorithms. The graph algorithms in RGL currently include:
+
+* Topological Sort (RGL::TopsortIterator)
+* Connected Components (RGL::Graph#each_connected_component)
+* Strongly Connected Components (RGL::Graph#strongly_connected_components)
+* Transitive Closure (RGL::Graph#transitive_closure)
+
+=== Data Structures
+
+RGL currently provides two graph classes that implement a generalized adjacency
+list and an edge list adaptor.
+
+* RGL::AdjacencyGraph
+* RGL::ImplicitGraph
+
+The AdjacencyGraph class is the general purpose *swiss army knife* of graph
+classes. It is highly parameterized so that it can be optimized for different
+situations: the graph is directed or undirected, allow or disallow parallel
+edges, efficient access to just the out-edges, fast vertex insertion and removal
+at the cost of extra space overhead, etc.
+
+=== Differences to BGL
+
+The concepts of IncidenceGraph, AdjacencyGraph and VertexListGraph (see
+http://www.boost.org/libs/graph/doc/IncidenceGraph.html) are here bundled in the
+base graph module. Most methods of IncidenceGraph should be standard in the base
+module Graph. The complexity guarantees can not necessarily provided. See
+http://www.boost.org/libs/graph/doc/graph_concepts.html.
+
+== Installation
+
+RGL is depended on the
+stream[http://rgl.rubyforge.org/stream/files/README.html] library which can
+also be downloaded from http://rubyforge.org/frs/?group_id=110. If you use gem
+to install RGL the stream library will be installed as a prerequisite.
+
+=== GEM Installation
+
+Download the GEM file and install it with ..
+
+ % gem install rgl-VERSION.gem
+
+or directly with
+
+ % gem install rgl
+
+Use the correct version number for VERSION (e.g. 0.2.x). You may need root
+privileges to install.
+
+=== Running tests
+
+RGL comes with a Rakefile which automatically runs the tests. Goto the
+installation directory and start rake:
+
+ % gem env
+ Rubygems Environment:
+ - VERSION: 0.9.0 (0.9.0)
+ - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
+ - GEM PATH:
+ - /usr/lib/ruby/gems/1.8
+ - REMOTE SOURCES:
+ - http://gems.rubyforge.org
+
+ % cd /usr/lib/ruby/gems/1.8/gems/rgl-0.3.0/
+ % rake
+ (in /usr/lib/ruby/gems/1.8/gems/rgl-0.3.0)
+ /usr/bin/ruby1.8 -Ilib:tests "/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb" "tests/TestTransitiveClosure.rb" "tests/TestComponents.rb" "tests/TestCycles.rb" "tests/TestDirectedGraph.rb" "tests/TestEdge.rb" "tests/TestGraph.rb" "tests/TestGraphXML.rb" "tests/TestImplicit.rb" "tests/TestUnDirectedGraph.rb" "tests/TestTraversal.rb" "tests/TestDot.rb" "tests/TestRdot.rb"
+ Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader
+ Started
+ ......................................................................................................................................................
+ Finished in 0.750958 seconds.
+
+ 86 tests, 625 assertions, 0 failures, 0 errors
+
+=== Code coverage
+
+Running rcov[http://eigenclass.org/hiki.rb?rcov] on the test suite generates this[link:coverage/index.html] result.
+
+=== Normal Installation
+
+You have to install stream library before. You can than install RGL with the
+following command:
+
+ % ruby install.rb
+
+from its distribution directory. To uninstall it use
+
+ % ruby install.rb -u
+
+== Example irb session with RGL
+
+ irb> require 'rgl/adjacency'
+ irb> dg=RGL::DirectedAdjacencyGraph[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6]
+ # Use DOT to visualize this graph:
+ irb> require 'rgl/dot'
+ irb> dg.write_to_graphic_file('jpg')
+ "graph.jpg"
+
+The result: link:../examples/example.jpg
+
+ irb> dg.directed?
+ true
+ irb> dg.vertices
+ [5, 6, 1, 2, 3, 4]
+ irb> dg.has_vertex? 4
+ true
+
+Every object could be a vertex (there is no class Vertex), even the class
+object _Object_:
+
+ irb> dg.has_vertex? Object
+ false
+ irb> dg.edges.sort.to_s
+ "(1-2)(1-6)(2-3)(2-4)(4-5)(6-4)"
+ irb> dg.to_undirected.edges.sort.to_s
+ "(1=2)(1=6)(2=3)(2=4)(5=4)(6=4)"
+
+Add inverse edge (4-2) to directed graph:
+
+ irb> dg.add_edge 4,2
+
+(4-2) == (2-4) in the undirected graph:
+
+ irb> dg.to_undirected.edges.sort.to_s
+ "(1=2)(1=6)(2=3)(2=4)(5=4)(6=4)"
+
+(4-2) != (2-4) in directed graphs:
+
+ irb> dg.edges.sort.to_s
+ "(1-2)(1-6)(2-3)(2-4)(4-2)(4-5)(6-4)"
+ irb> dg.remove_edge 4,2
+ true
+
+<em>Topological sort</em> is realized with as iterator:
+
+ require 'rgl/topsort'
+ irb> dg.topsort_iterator.to_a
+ [1, 2, 3, 6, 4, 5]
+
+A more elaborated example showing <em>implicit graphs</em>:
+
+ def module_graph
+ RGL::ImplicitGraph.new { |g|
+ g.vertex_iterator { |b|
+ ObjectSpace.each_object(Module, &b)
+ }
+ g.adjacent_iterator { |x, b|
+ x.ancestors.each { |y|
+ b.call(y) unless x == y || y == Kernel || y == Object
+ }
+ }
+ g.directed = true
+ }
+ end
+
+This function creates a directed graph, with vertices being all loaded modules:
+
+ g = module_graph
+
+We only want to see the ancestors of RGL::AdjacencyGraph:
+
+ tree = bfs_search_tree_from(g,RGL::AdjacencyGraph)
+
+Now we want to visualize this component of g with DOT. We therefore create a
+subgraph of the original graph, using a filtered graph:
+
+ g = g.vertices_filtered_by {|v| tree.has_vertex? v}
+
+Create the graphics with DOT:
+
+ g.write_to_graphic_file
+
+produces module_graph.jpg: link:../examples/module_graph.jpg
+
+Look for more in the examples directory (i.e.
+examples.rb[link:files/examples/examples_rb.html]).
+
+== My del.icio.us links concerning RGL
+
+I collect some links to stuff around RGL at http://del.icio.us/monora/rgl. I
+registered RGL at SWiK[http://swik.net/rgl].
+
+== Credits
+
+Many thanks to Robert Feldt which also worked on a graph library
+(http://rockit.sf.net/subprojects/graphr) who pointed me to BGL and many other
+graph resources.
+
+Robert kindly allowed to integrate his work on graphr, which I did not yet
+succeed. Especially his work to output graphs for
+GraphViz[http://www.research.att.com/sw/tools/graphviz/download.html] is much
+more elaborated than the minimal support in dot.rb.
+
+Jeremy Siek one of the authors of the nice book "The Boost Graph Library (BGL)"
+(http://www.boost.org/libs/graph/doc) kindly allowed to use the
+BGL documentation as a _cheap_ reference for RGL. He and Robert also gave
+feedback and many ideas for RGL.
+
+Dave Thomas for RDoc[http://rdoc.sourceforge.net] which generated what you read
+and matz for Ruby. Dave included in the latest version of RDoc (alpha9) the
+module dot/dot.rb which I use instead of Roberts module to visualize graphs
+(see rgl/dot.rb).
+
+Jeremy Bopp, John Carter, Sascha Doerdelmann and Shawn Garbett for contributing
+additions, test cases and bugfixes.
+
+== Copying
+
+RGL is Copyright (c) 2002,2004,2005,2008 by Horst Duchene. It is free software, and may be
+redistributed under the terms specified in the README file of the Ruby distribution.
+
+== Support
+
+Please contact me at mailto:monora@gmail.com with bug reports
+suggestions, and other comments. If you send patches, it would help if
+they were in-line (not attachments) and generated using "diff -u".
+
+
Oops, something went wrong.

0 comments on commit c3e88cd

Please sign in to comment.