jumoku 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/Gemfile +0 -1
  2. data/lib/jumoku.rb +2 -3
  3. data/lib/jumoku/builders/extended.rb +15 -23
  4. data/lib/jumoku/builders/raw_directed_tree.rb +15 -0
  5. data/lib/jumoku/builders/raw_undirected_tree.rb +15 -0
  6. data/lib/jumoku/builders/shared.rb +2 -5
  7. data/lib/jumoku/support/ruby_compatibility.rb +19 -0
  8. data/lib/jumoku/version.rb +1 -1
  9. data/spec/arborescence_spec.rb +14 -0
  10. data/spec/behaviors/core_tree.rb +281 -0
  11. data/spec/behaviors/extended.rb +530 -0
  12. data/spec/raw_directed_tree_spec.rb +14 -0
  13. data/spec/raw_undirected_tree_spec.rb +9 -310
  14. data/spec/spec_helper.rb +2 -0
  15. data/spec/tree_spec.rb +8 -535
  16. metadata +21 -86
  17. data/lib/jumoku/tree_api.rb +0 -27
  18. data/vendor/git/plexus/CREDITS.md +0 -31
  19. data/vendor/git/plexus/Gemfile +0 -3
  20. data/vendor/git/plexus/Gemfile.lock +0 -28
  21. data/vendor/git/plexus/LICENSE +0 -37
  22. data/vendor/git/plexus/README.md +0 -208
  23. data/vendor/git/plexus/Rakefile +0 -25
  24. data/vendor/git/plexus/TODO.md +0 -20
  25. data/vendor/git/plexus/VERSION +0 -1
  26. data/vendor/git/plexus/examples/graph_self.rb +0 -56
  27. data/vendor/git/plexus/examples/module_graph.jpg +0 -0
  28. data/vendor/git/plexus/examples/module_graph.rb +0 -14
  29. data/vendor/git/plexus/examples/self_graph.jpg +0 -0
  30. data/vendor/git/plexus/examples/visualize.jpg +0 -0
  31. data/vendor/git/plexus/examples/visualize.rb +0 -10
  32. data/vendor/git/plexus/lib/plexus.rb +0 -90
  33. data/vendor/git/plexus/lib/plexus/adjacency_graph.rb +0 -224
  34. data/vendor/git/plexus/lib/plexus/arc.rb +0 -59
  35. data/vendor/git/plexus/lib/plexus/arc_number.rb +0 -52
  36. data/vendor/git/plexus/lib/plexus/biconnected.rb +0 -84
  37. data/vendor/git/plexus/lib/plexus/chinese_postman.rb +0 -91
  38. data/vendor/git/plexus/lib/plexus/classes/graph_classes.rb +0 -28
  39. data/vendor/git/plexus/lib/plexus/common.rb +0 -63
  40. data/vendor/git/plexus/lib/plexus/comparability.rb +0 -63
  41. data/vendor/git/plexus/lib/plexus/directed_graph.rb +0 -78
  42. data/vendor/git/plexus/lib/plexus/directed_graph/algorithms.rb +0 -95
  43. data/vendor/git/plexus/lib/plexus/directed_graph/distance.rb +0 -167
  44. data/vendor/git/plexus/lib/plexus/dot.rb +0 -94
  45. data/vendor/git/plexus/lib/plexus/edge.rb +0 -36
  46. data/vendor/git/plexus/lib/plexus/ext.rb +0 -79
  47. data/vendor/git/plexus/lib/plexus/graph.rb +0 -626
  48. data/vendor/git/plexus/lib/plexus/graph_api.rb +0 -35
  49. data/vendor/git/plexus/lib/plexus/labels.rb +0 -113
  50. data/vendor/git/plexus/lib/plexus/maximum_flow.rb +0 -77
  51. data/vendor/git/plexus/lib/plexus/ruby_compatibility.rb +0 -17
  52. data/vendor/git/plexus/lib/plexus/search.rb +0 -510
  53. data/vendor/git/plexus/lib/plexus/strong_components.rb +0 -93
  54. data/vendor/git/plexus/lib/plexus/support/support.rb +0 -9
  55. data/vendor/git/plexus/lib/plexus/undirected_graph.rb +0 -56
  56. data/vendor/git/plexus/lib/plexus/undirected_graph/algorithms.rb +0 -90
  57. data/vendor/git/plexus/lib/plexus/version.rb +0 -6
  58. data/vendor/git/plexus/plexus.gemspec +0 -24
  59. data/vendor/git/plexus/spec/biconnected_spec.rb +0 -27
  60. data/vendor/git/plexus/spec/chinese_postman_spec.rb +0 -27
  61. data/vendor/git/plexus/spec/community_spec.rb +0 -44
  62. data/vendor/git/plexus/spec/complement_spec.rb +0 -27
  63. data/vendor/git/plexus/spec/digraph_distance_spec.rb +0 -121
  64. data/vendor/git/plexus/spec/digraph_spec.rb +0 -339
  65. data/vendor/git/plexus/spec/dot_spec.rb +0 -48
  66. data/vendor/git/plexus/spec/edge_spec.rb +0 -158
  67. data/vendor/git/plexus/spec/inspection_spec.rb +0 -38
  68. data/vendor/git/plexus/spec/multi_edge_spec.rb +0 -32
  69. data/vendor/git/plexus/spec/neighborhood_spec.rb +0 -36
  70. data/vendor/git/plexus/spec/properties_spec.rb +0 -146
  71. data/vendor/git/plexus/spec/search_spec.rb +0 -227
  72. data/vendor/git/plexus/spec/spec.opts +0 -4
  73. data/vendor/git/plexus/spec/spec_helper.rb +0 -59
  74. data/vendor/git/plexus/spec/strong_components_spec.rb +0 -61
  75. data/vendor/git/plexus/spec/triangulated_spec.rb +0 -125
  76. data/vendor/git/plexus/spec/undirected_graph_spec.rb +0 -220
  77. data/vendor/git/plexus/vendor/priority-queue/CHANGELOG +0 -33
  78. data/vendor/git/plexus/vendor/priority-queue/Makefile +0 -140
  79. data/vendor/git/plexus/vendor/priority-queue/README +0 -133
  80. data/vendor/git/plexus/vendor/priority-queue/benchmark/dijkstra.rb +0 -171
  81. data/vendor/git/plexus/vendor/priority-queue/compare_comments.rb +0 -49
  82. data/vendor/git/plexus/vendor/priority-queue/doc/c-vs-rb.png +0 -0
  83. data/vendor/git/plexus/vendor/priority-queue/doc/compare_big.gp +0 -14
  84. data/vendor/git/plexus/vendor/priority-queue/doc/compare_big.png +0 -0
  85. data/vendor/git/plexus/vendor/priority-queue/doc/compare_small.gp +0 -15
  86. data/vendor/git/plexus/vendor/priority-queue/doc/compare_small.png +0 -0
  87. data/vendor/git/plexus/vendor/priority-queue/doc/results.csv +0 -37
  88. data/vendor/git/plexus/vendor/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb +0 -2
  89. data/vendor/git/plexus/vendor/priority-queue/ext/priority_queue/CPriorityQueue/priority_queue.c +0 -947
  90. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue.rb +0 -14
  91. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue/c_priority_queue.rb +0 -1
  92. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue/poor_priority_queue.rb +0 -46
  93. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue/ruby_priority_queue.rb +0 -526
  94. data/vendor/git/plexus/vendor/priority-queue/priority_queue.so +0 -0
  95. data/vendor/git/plexus/vendor/priority-queue/setup.rb +0 -1551
  96. data/vendor/git/plexus/vendor/priority-queue/test/priority_queue_test.rb +0 -371
  97. data/vendor/git/plexus/vendor/rdot.rb +0 -360
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jumoku
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jean-Denis Vauguet <jd@vauguet.fr>
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-08 00:00:00 +02:00
13
+ date: 2011-07-10 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,7 +36,7 @@ dependencies:
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: rspec
39
+ name: plexus
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
@@ -44,10 +44,10 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: "0"
47
- type: :development
47
+ type: :runtime
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: yard
50
+ name: rspec
51
51
  prerelease: false
52
52
  requirement: &id004 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -57,6 +57,17 @@ dependencies:
57
57
  version: "0"
58
58
  type: :development
59
59
  version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: yard
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
60
71
  description: Jumoku provides you with tree behaviors to mixin and tree classes to inherit from. Raw tree, common binary trees, custom trees...
61
72
  email: jd@vauguet.fr
62
73
  executables: []
@@ -67,7 +78,6 @@ extra_rdoc_files: []
67
78
 
68
79
  files:
69
80
  - lib/jumoku.rb
70
- - lib/jumoku/tree_api.rb
71
81
  - lib/jumoku/ext/ext.rb
72
82
  - lib/jumoku/builders/raw_undirected_tree.rb
73
83
  - lib/jumoku/builders/tree.rb
@@ -78,92 +88,17 @@ files:
78
88
  - lib/jumoku/raw_tree_node.rb
79
89
  - lib/jumoku/classes/tree_classes.rb
80
90
  - lib/jumoku/support/support.rb
91
+ - lib/jumoku/support/ruby_compatibility.rb
81
92
  - lib/jumoku/support/branch.rb
82
93
  - lib/jumoku/version.rb
83
- - vendor/git/plexus/LICENSE
84
- - vendor/git/plexus/lib/plexus/biconnected.rb
85
- - vendor/git/plexus/lib/plexus/arc.rb
86
- - vendor/git/plexus/lib/plexus/ruby_compatibility.rb
87
- - vendor/git/plexus/lib/plexus/dot.rb
88
- - vendor/git/plexus/lib/plexus/directed_graph.rb
89
- - vendor/git/plexus/lib/plexus/comparability.rb
90
- - vendor/git/plexus/lib/plexus/chinese_postman.rb
91
- - vendor/git/plexus/lib/plexus/graph_api.rb
92
- - vendor/git/plexus/lib/plexus/classes/graph_classes.rb
93
- - vendor/git/plexus/lib/plexus/strong_components.rb
94
- - vendor/git/plexus/lib/plexus/support/support.rb
95
- - vendor/git/plexus/lib/plexus/common.rb
96
- - vendor/git/plexus/lib/plexus/search.rb
97
- - vendor/git/plexus/lib/plexus/arc_number.rb
98
- - vendor/git/plexus/lib/plexus/maximum_flow.rb
99
- - vendor/git/plexus/lib/plexus/ext.rb
100
- - vendor/git/plexus/lib/plexus/labels.rb
101
- - vendor/git/plexus/lib/plexus/undirected_graph.rb
102
- - vendor/git/plexus/lib/plexus/edge.rb
103
- - vendor/git/plexus/lib/plexus/directed_graph/distance.rb
104
- - vendor/git/plexus/lib/plexus/directed_graph/algorithms.rb
105
- - vendor/git/plexus/lib/plexus/undirected_graph/algorithms.rb
106
- - vendor/git/plexus/lib/plexus/adjacency_graph.rb
107
- - vendor/git/plexus/lib/plexus/version.rb
108
- - vendor/git/plexus/lib/plexus/graph.rb
109
- - vendor/git/plexus/lib/plexus.rb
110
- - vendor/git/plexus/Rakefile
111
- - vendor/git/plexus/VERSION
112
- - vendor/git/plexus/TODO.md
113
- - vendor/git/plexus/plexus.gemspec
114
- - vendor/git/plexus/spec/spec.opts
115
- - vendor/git/plexus/spec/edge_spec.rb
116
- - vendor/git/plexus/spec/inspection_spec.rb
117
- - vendor/git/plexus/spec/digraph_spec.rb
118
- - vendor/git/plexus/spec/spec_helper.rb
119
- - vendor/git/plexus/spec/search_spec.rb
120
- - vendor/git/plexus/spec/triangulated_spec.rb
121
- - vendor/git/plexus/spec/multi_edge_spec.rb
122
- - vendor/git/plexus/spec/dot_spec.rb
123
- - vendor/git/plexus/spec/neighborhood_spec.rb
124
- - vendor/git/plexus/spec/complement_spec.rb
125
- - vendor/git/plexus/spec/biconnected_spec.rb
126
- - vendor/git/plexus/spec/undirected_graph_spec.rb
127
- - vendor/git/plexus/spec/chinese_postman_spec.rb
128
- - vendor/git/plexus/spec/strong_components_spec.rb
129
- - vendor/git/plexus/spec/community_spec.rb
130
- - vendor/git/plexus/spec/digraph_distance_spec.rb
131
- - vendor/git/plexus/spec/properties_spec.rb
132
- - vendor/git/plexus/Gemfile.lock
133
- - vendor/git/plexus/examples/module_graph.rb
134
- - vendor/git/plexus/examples/self_graph.jpg
135
- - vendor/git/plexus/examples/visualize.rb
136
- - vendor/git/plexus/examples/visualize.jpg
137
- - vendor/git/plexus/examples/graph_self.rb
138
- - vendor/git/plexus/examples/module_graph.jpg
139
- - vendor/git/plexus/README.md
140
- - vendor/git/plexus/vendor/priority-queue/ext/priority_queue/CPriorityQueue/priority_queue.c
141
- - vendor/git/plexus/vendor/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb
142
- - vendor/git/plexus/vendor/priority-queue/README
143
- - vendor/git/plexus/vendor/priority-queue/Makefile
144
- - vendor/git/plexus/vendor/priority-queue/lib/priority_queue/c_priority_queue.rb
145
- - vendor/git/plexus/vendor/priority-queue/lib/priority_queue/poor_priority_queue.rb
146
- - vendor/git/plexus/vendor/priority-queue/lib/priority_queue/ruby_priority_queue.rb
147
- - vendor/git/plexus/vendor/priority-queue/lib/priority_queue.rb
148
- - vendor/git/plexus/vendor/priority-queue/benchmark/dijkstra.rb
149
- - vendor/git/plexus/vendor/priority-queue/CHANGELOG
150
- - vendor/git/plexus/vendor/priority-queue/doc/compare_big.gp
151
- - vendor/git/plexus/vendor/priority-queue/doc/compare_small.png
152
- - vendor/git/plexus/vendor/priority-queue/doc/compare_small.gp
153
- - vendor/git/plexus/vendor/priority-queue/doc/results.csv
154
- - vendor/git/plexus/vendor/priority-queue/doc/c-vs-rb.png
155
- - vendor/git/plexus/vendor/priority-queue/doc/compare_big.png
156
- - vendor/git/plexus/vendor/priority-queue/priority_queue.so
157
- - vendor/git/plexus/vendor/priority-queue/test/priority_queue_test.rb
158
- - vendor/git/plexus/vendor/priority-queue/setup.rb
159
- - vendor/git/plexus/vendor/priority-queue/compare_comments.rb
160
- - vendor/git/plexus/vendor/rdot.rb
161
- - vendor/git/plexus/Gemfile
162
- - vendor/git/plexus/CREDITS.md
163
94
  - spec/spec.opts
95
+ - spec/arborescence_spec.rb
164
96
  - spec/spec_helper.rb
97
+ - spec/raw_directed_tree_spec.rb
165
98
  - spec/raw_undirected_tree_spec.rb
166
99
  - spec/tree_spec.rb
100
+ - spec/behaviors/extended.rb
101
+ - spec/behaviors/core_tree.rb
167
102
  - Gemfile
168
103
  - LICENSE
169
104
  - Rakefile
@@ -1,27 +0,0 @@
1
- module Jumoku
2
- # This module defines the minimum set of methods required to build a tree
3
- # which can use the algorithms defined in this library.
4
- #
5
- # A module based abiding to the TreeAPI must implement the following routines:
6
- #
7
- # * add_node!(n, l = nil) — adds a node to the tree and return the tree; l is an optional label (see Plexus library).
8
- # * add_branch!(i, j = nil, l = nil) — adds a branch to the tree and return the tree. i can be a {Branch}, or (i,j) a node pair; l is an optional label.
9
- # * remove_node!(n) — removes a node from the tree and return the tree.
10
- # * remove_branch!(i, j = nil) — removes an edge from the graph and return the tree. i can be a {Branch}, or (i,j) a node pair.
11
- # * nodes — returns an array of all nodes.
12
- # * terminal_nodes — returns an array of all terminal nodes.
13
- # * branches — returns an array of all branches.
14
- #
15
- module TreeAPI
16
- # @raise [JumokuError] if the API is not completely implemented
17
- #
18
- def self.included(klass)
19
- @api_methods ||= [:add_node!, :add_branch!, :remove_node!, :remove_branch!, :nodes, :terminal_nodes, :branches]
20
- ruby_18 { @api_methods.each { |m| m.to_s } }
21
-
22
- @api_methods.each do |meth|
23
- raise JumokuError, "Must implement #{meth}" unless klass.instance_methods.include?(meth)
24
- end
25
- end
26
- end
27
- end
@@ -1,31 +0,0 @@
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.
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
@@ -1,28 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- plexus (0.5.3)
5
- facets
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- diff-lcs (1.1.2)
11
- facets (2.9.1)
12
- rspec (2.6.0)
13
- rspec-core (~> 2.6.0)
14
- rspec-expectations (~> 2.6.0)
15
- rspec-mocks (~> 2.6.0)
16
- rspec-core (2.6.4)
17
- rspec-expectations (2.6.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.6.0)
20
- yard (0.7.2)
21
-
22
- PLATFORMS
23
- ruby
24
-
25
- DEPENDENCIES
26
- plexus!
27
- rspec
28
- yard
@@ -1,37 +0,0 @@
1
- Copyright (c) 2010 Jean-Denis Vauguet <jd@vauguet.fr>
2
-
3
- Copyright (c) 2009 Bruce Williams
4
-
5
- Copyright (c) 2007,2006 Shawn Patrick Garbett
6
-
7
- Copyright (c) 2002,2004,2005 by Horst Duchene
8
-
9
- Copyright (c) 2000,2001 Jeremy Siek, Indiana University (jsiek@osl.iu.edu)
10
-
11
- All rights reserved.
12
-
13
- Jeremy Siek was one of the principal developers of the Boost Graph library.
14
- Since this work is derivative, his name is included in the copyright list.
15
-
16
- Redistribution and use in source and binary forms, with or without modification,
17
- are permitted provided that the following conditions are met:
18
-
19
- * Redistributions of source code must retain the above copyright notice(s),
20
- this list of conditions and the following disclaimer.
21
- * Redistributions in binary form must reproduce the above copyright notice,
22
- this list of conditions and the following disclaimer in the documentation
23
- and/or other materials provided with the distribution.
24
- * Neither the name of the Bruce Williams nor the names of its contributors
25
- may be used to endorse or promote products derived from this software
26
- without specific prior written permission.
27
-
28
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
32
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,208 +0,0 @@
1
- # Plexus (was 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, `Plexus::Arc` and `Plexus::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
- `Plexus::Digraph` and its alias `Plexus::DirectedGraph`:
38
-
39
- * Single directed edges (arcs) between vertices
40
- * Loops are forbidden
41
-
42
- `Plexus::DirectedPseudoGraph`:
43
-
44
- * Multiple directed edges (arcs) between vertices
45
- * Loops are forbidden
46
-
47
- `Plexus::DirectedMultiGraph`:
48
-
49
- * Multiple directed edges (arcs) between vertices
50
- * Loops on vertices
51
-
52
- `Plexus::UndirectedGraph`, `Plexus::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 `Plexus::AdjacencyGraph`
58
- module which provides a generalized adjacency list and an edge list adaptor.
59
-
60
- The `Plexus::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
- ``` bash
70
- require 'rubygems' # only if you are using ruby 1.8.x
71
- require 'plexus'
72
- ```
73
-
74
- If you'd like to include all the classes in the current scope (so you
75
- don't have to prefix with `Plexus::`), just:
76
-
77
- ``` bash
78
- include Plexus
79
- ```
80
-
81
- Let's play with the library a bit in IRB:
82
-
83
- ``` bash
84
- >> dg = Digraph[1,2, 2,3, 2,4, 4,5, 6,4, 1,6]
85
- => Plexus::Digraph[[2, 3], [1, 6], [2, 4], [4, 5], [1, 2], [6, 4]]
86
- ```
87
-
88
- A few properties of the graph we just created:
89
-
90
- ``` bash
91
- >> dg.directed?
92
- => true
93
- >> dg.vertex?(4)
94
- => true
95
- >> dg.edge?(2,4)
96
- => true
97
- >> dg.edge?(4,2)
98
- => false
99
- >> dg.vertices
100
- => [1, 2, 3, 4, 5, 6]
101
- ```
102
-
103
- Every object could be a vertex, even the class object `Object`:
104
-
105
- ``` bash
106
- >> dg.vertex?(Object)
107
- => false
108
-
109
- >> UndirectedGraph.new(dg).edges.sort.to_s
110
- => "[Plexus::Edge[1,2,nil], Plexus::Edge[2,3,nil], Plexus::Edge[2,4,nil],
111
- Plexus::Edge[4,5,nil], Plexus::Edge[1,6,nil], Plexus::Edge[6,4,nil]]"
112
- ```
113
-
114
- Add inverse edge `(4-2)` to directed graph:
115
-
116
- ``` bash
117
- >> dg.add_edge!(4,2)
118
- => Plexus::DirectedGraph[Plexus::Arc[1,2,nil], Plexus::Arc[1,6,nil], Plexus::Arc[2,3,nil],
119
- Plexus::Arc[2,4,nil], Plexus::Arc[4,5,nil], Plexus::Arc[4,2,nil],
120
- Plexus::Arc[6,4,nil]]
121
- ```
122
-
123
- `(4-2) == (2-4)` in the undirected graph (4-2 doesn't show up):
124
-
125
- ``` bash
126
- >> UndirectedGraph.new(dg).edges.sort.to_s
127
- => "[Plexus::Edge[1,2,nil], Plexus::Edge[2,3,nil], Plexus::Edge[2,4,nil],
128
- Plexus::Edge[4,5,nil], Plexus::Edge[1,6,nil], Plexus::Edge[6,4,nil]]"
129
- ```
130
-
131
- `(4-2) != (2-4)` in directed graphs (both show up):
132
-
133
- ``` bash
134
- >> dg.edges.sort.to_s
135
- => "[Plexus::Arc[1,2,nil], Plexus::Arc[1,6,nil], Plexus::Arc[2,3,nil],
136
- Plexus::Arc[2,4,nil], Plexus::Arc[4,2,nil], Plexus::Arc[4,5,nil],
137
- Plexus::Arc[6,4,nil]]"
138
-
139
- >> dg.remove_edge! 4,2
140
- => Plexus::DirectedGraph[Plexus::Arc[1,2,nil], Plexus::Arc[1,6,nil], Plexus::Arc[2,3,nil],
141
- Plexus::Arc[2,4,nil], Plexus::Arc[4,5,nil], Plexus::Arc[6,4,nil]]
142
- ```
143
-
144
- Topological sorting is realized with an iterator:
145
-
146
- ``` bash
147
- >> dg.topsort
148
- => [1, 6, 2, 4, 5, 3]
149
- >> y = 0; dg.topsort { |v| y += v }; y
150
- => 21
151
- ```
152
-
153
- You can use DOT to visualize the graph:
154
-
155
- ``` bash
156
- >> require 'plexus/dot'
157
- >> dg.write_to_graphic_file('jpg','visualize')
158
- ```
159
-
160
- Here's an example showing the module inheritance hierarchy:
161
-
162
- ``` bash
163
- >> module_graph = Digraph.new
164
- >> ObjectSpace.each_object(Module) do |m|
165
- >> m.ancestors.each {|a| module_graph.add_edge!(m,a) if m != a}
166
- >> end
167
- >> gv = module_graph.vertices.select {|v| v.to_s.match(/Plexus/) }
168
- >> module_graph.induced_subgraph(gv).write_to_graphic_file('jpg','module_graph')
169
- ```
170
-
171
- Look for more in the examples directory.
172
-
173
- ## History
174
-
175
- This library is based on [GRATR][1] by Shawn Garbett (itself a fork of
176
- Horst Duchene's [RGL][2] library) which is heavily influenced by the [Boost][3]
177
- Graph Library (BGL).
178
-
179
- This fork attempts to modernize and extend the API and tests.
180
-
181
- ## References
182
-
183
- For more information on Graph Theory, you may want to read:
184
-
185
- * the [documentation][3] for the Boost Graph Library
186
- * [the Dictionary of Algorithms and Data Structures][4]
187
-
188
- ## Credits
189
-
190
- See CREDITS.markdown
191
-
192
- ## TODO
193
-
194
- See TODO.markdown
195
-
196
- ## CHANGELOG
197
-
198
- See CHANGELOG.markdown
199
-
200
- ## License
201
-
202
- [MIT License](http://en.wikipedia.org/wiki/MIT_License). See the LICENSE file.
203
-
204
- [1]: http://gratr.rubyforge.org
205
- [2]: http://rgl.rubyforge.org
206
- [3]: http://www.boost.org/libs/graph/doc
207
- [4]: http://www.nist.gov/dads/HTML/graph.html
208
-