jumoku 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +12 -12
- data/lib/jumoku.rb +2 -2
- data/lib/jumoku/builders/raw_tree.rb +4 -4
- data/lib/jumoku/builders/tree.rb +5 -5
- data/lib/jumoku/support/branch.rb +1 -1
- data/lib/jumoku/tree_api.rb +1 -1
- data/lib/jumoku/version.rb +1 -1
- data/spec/raw_tree_spec.rb +1 -1
- data/vendor/git/{graphy → plexus}/CREDITS.md +0 -0
- data/vendor/git/plexus/Gemfile +3 -0
- data/vendor/git/plexus/Gemfile.lock +28 -0
- data/vendor/git/{graphy → plexus}/LICENSE +3 -1
- data/vendor/git/plexus/README.md +208 -0
- data/vendor/git/plexus/Rakefile +25 -0
- data/vendor/git/{graphy → plexus}/TODO.md +1 -1
- data/vendor/git/{graphy → plexus}/VERSION +0 -0
- data/vendor/git/{graphy → plexus}/examples/graph_self.rb +0 -0
- data/vendor/git/{graphy → plexus}/examples/module_graph.jpg +0 -0
- data/vendor/git/{graphy → plexus}/examples/module_graph.rb +0 -0
- data/vendor/git/{graphy → plexus}/examples/self_graph.jpg +0 -0
- data/vendor/git/{graphy → plexus}/examples/visualize.jpg +0 -0
- data/vendor/git/{graphy → plexus}/examples/visualize.rb +0 -0
- data/vendor/git/plexus/lib/plexus.rb +90 -0
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/adjacency_graph.rb +9 -9
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/arc.rb +16 -22
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/arc_number.rb +2 -2
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/biconnected.rb +2 -2
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/chinese_postman.rb +2 -2
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/classes/graph_classes.rb +10 -10
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/common.rb +6 -6
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/comparability.rb +10 -10
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/directed_graph.rb +15 -13
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/directed_graph/algorithms.rb +21 -18
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/directed_graph/distance.rb +2 -2
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/dot.rb +2 -2
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/edge.rb +8 -9
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/ext.rb +3 -3
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/graph.rb +51 -56
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/graph_api.rb +2 -2
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/labels.rb +8 -8
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/maximum_flow.rb +2 -2
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/ruby_compatibility.rb +0 -0
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/search.rb +43 -44
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/strong_components.rb +4 -4
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/support/support.rb +3 -3
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/undirected_graph.rb +13 -14
- data/vendor/git/{graphy/lib/graphy → plexus/lib/plexus}/undirected_graph/algorithms.rb +4 -4
- data/vendor/git/plexus/lib/plexus/version.rb +6 -0
- data/vendor/git/plexus/plexus.gemspec +24 -0
- data/vendor/git/{graphy → plexus}/spec/biconnected_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/chinese_postman_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/community_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/complement_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/digraph_distance_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/digraph_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/dot_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/edge_spec.rb +17 -18
- data/vendor/git/{graphy → plexus}/spec/inspection_spec.rb +13 -15
- data/vendor/git/{graphy → plexus}/spec/multi_edge_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/neighborhood_spec.rb +3 -5
- data/vendor/git/{graphy → plexus}/spec/properties_spec.rb +1 -1
- data/vendor/git/{graphy → plexus}/spec/search_spec.rb +45 -45
- data/vendor/git/{graphy → plexus}/spec/spec.opts +0 -0
- data/vendor/git/{graphy → plexus}/spec/spec_helper.rb +13 -10
- data/vendor/git/{graphy → plexus}/spec/strong_components_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/spec/triangulated_spec.rb +1 -1
- data/vendor/git/{graphy → plexus}/spec/undirected_graph_spec.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/CHANGELOG +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/Makefile +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/README +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/benchmark/dijkstra.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/compare_comments.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/doc/c-vs-rb.png +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/doc/compare_big.gp +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/doc/compare_big.png +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/doc/compare_small.gp +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/doc/compare_small.png +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/doc/results.csv +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/ext/priority_queue/CPriorityQueue/priority_queue.c +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/lib/priority_queue.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/lib/priority_queue/c_priority_queue.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/lib/priority_queue/poor_priority_queue.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/lib/priority_queue/ruby_priority_queue.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/priority_queue.so +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/setup.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/priority-queue/test/priority_queue_test.rb +0 -0
- data/vendor/git/{graphy → plexus}/vendor/rdot.rb +0 -0
- metadata +81 -78
- data/vendor/git/graphy/README.md +0 -186
- data/vendor/git/graphy/Rakefile +0 -61
- data/vendor/git/graphy/graphy.gemspec +0 -149
- data/vendor/git/graphy/lib/graphy.rb +0 -90
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'Plexus'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
@@ -14,7 +14,7 @@
|
|
14
14
|
The following list was present in GRATR, and items may (or may not) be added to this library:
|
15
15
|
|
16
16
|
* Primal Dual for combinatorial optimization problems
|
17
|
-
* Min-Max Flow
|
17
|
+
* Min-Max Flow
|
18
18
|
* Near optimal traveling salesman problem
|
19
19
|
* Orientation of undirected graphs
|
20
20
|
* Undirected graphs from ActiveRecord
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2006 Shawn Patrick Garbett
|
3
|
+
# Copyright (c) 2002,2004,2005 by Horst Duchene
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
# are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice(s),
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of the Shawn Garbett nor the names of its contributors
|
14
|
+
# may be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'set'
|
30
|
+
|
31
|
+
module Plexus
|
32
|
+
# Plexus internals: graph builders and additionnal behaviors
|
33
|
+
autoload :GraphAPI, 'plexus/graph_api'
|
34
|
+
|
35
|
+
autoload :GraphBuilder, 'plexus/graph'
|
36
|
+
autoload :AdjacencyGraphBuilder, 'plexus/adjacency_graph'
|
37
|
+
|
38
|
+
autoload :DirectedGraphBuilder, 'plexus/directed_graph'
|
39
|
+
autoload :DigraphBuilder, 'plexus/directed_graph'
|
40
|
+
autoload :DirectedPseudoGraphBuilder, 'plexus/directed_graph'
|
41
|
+
autoload :DirectedMultiGraphBuilder, 'plexus/directed_graph'
|
42
|
+
|
43
|
+
autoload :UndirectedGraphBuilder, 'plexus/undirected_graph'
|
44
|
+
autoload :UndirectedPseudoGraphBuilder, 'plexus/undirected_graph'
|
45
|
+
autoload :UndirectedMultiGraphBuilder, 'plexus/undirected_graph'
|
46
|
+
|
47
|
+
autoload :Arc, 'plexus/arc'
|
48
|
+
autoload :ArcNumber, 'plexus/arc_number'
|
49
|
+
autoload :Biconnected, 'plexus/biconnected'
|
50
|
+
autoload :ChinesePostman, 'plexus/chinese_postman'
|
51
|
+
autoload :Common, 'plexus/common'
|
52
|
+
autoload :Comparability, 'plexus/comparability'
|
53
|
+
|
54
|
+
autoload :Dot, 'plexus/dot'
|
55
|
+
autoload :Edge, 'plexus/edge'
|
56
|
+
autoload :Labels, 'plexus/labels'
|
57
|
+
autoload :MaximumFlow, 'plexus/maximum_flow'
|
58
|
+
#autoload :Rdot, 'plexus/dot'
|
59
|
+
autoload :Search, 'plexus/search'
|
60
|
+
autoload :StrongComponents, 'plexus/strong_components'
|
61
|
+
|
62
|
+
# Plexus classes
|
63
|
+
autoload :AdjacencyGraph, 'plexus/classes/graph_classes'
|
64
|
+
autoload :DirectedGraph, 'plexus/classes/graph_classes'
|
65
|
+
autoload :Digraph, 'plexus/classes/graph_classes'
|
66
|
+
autoload :DirectedPseudoGraph, 'plexus/classes/graph_classes'
|
67
|
+
autoload :DirectedMultiGraph, 'plexus/classes/graph_classes'
|
68
|
+
autoload :UndirectedGraph, 'plexus/classes/graph_classes'
|
69
|
+
autoload :UndirectedPseudoGraph, 'plexus/classes/graph_classes'
|
70
|
+
autoload :UndirectedMultiGraph, 'plexus/classes/graph_classes'
|
71
|
+
|
72
|
+
# ruby stdlib extensions
|
73
|
+
require 'plexus/ext'
|
74
|
+
# ruby 1.8.x/1.9.x compatibility
|
75
|
+
require 'plexus/ruby_compatibility'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Vendored libraries
|
79
|
+
|
80
|
+
require 'pathname'
|
81
|
+
path = Pathname.new(__FILE__)
|
82
|
+
$LOAD_PATH.unshift(path + '../../vendor') # http://ruby.brian-amberg.de/priority-queue/
|
83
|
+
$LOAD_PATH.unshift(path + '../../vendor/priority-queue/lib')
|
84
|
+
|
85
|
+
require 'rdot'
|
86
|
+
require 'facets/hash'
|
87
|
+
|
88
|
+
require 'priority_queue/ruby_priority_queue'
|
89
|
+
PriorityQueue = RubyPriorityQueue
|
90
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Plexus
|
2
2
|
|
3
3
|
# This module provides the basic routines needed to implement the specialized builders:
|
4
4
|
# {DigraphBuilder}, {UndirectedGraphBuilder}, {DirectedPseudoGraphBuilder},
|
@@ -42,7 +42,7 @@ module Graphy
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Copy any given graph into this graph.
|
45
|
-
params.select { |p| p.is_a?
|
45
|
+
params.select { |p| p.is_a? Plexus::GraphBuilder }.each do |g|
|
46
46
|
g.edges.each do |e|
|
47
47
|
add_edge!(e)
|
48
48
|
edge_label_set(e, edge_label(e)) if edge_label(e)
|
@@ -75,7 +75,7 @@ module Graphy
|
|
75
75
|
# @param [vertex] v (nil)
|
76
76
|
# @return [Boolean]
|
77
77
|
def edge?(u, v = nil)
|
78
|
-
u, v = u.source, u.target if u.is_a?
|
78
|
+
u, v = u.source, u.target if u.is_a? Plexus::Arc
|
79
79
|
vertex?(u) and @vertex_dict[u].include?(v)
|
80
80
|
end
|
81
81
|
|
@@ -106,7 +106,7 @@ module Graphy
|
|
106
106
|
# @return [AdjacencyGraph] `self`
|
107
107
|
def add_edge!(u, v = nil, l = nil, n = nil)
|
108
108
|
n = u.number if u.class.include? ArcNumber and n.nil?
|
109
|
-
u, v, l = u.source, u.target, u.label if u.is_a?
|
109
|
+
u, v, l = u.source, u.target, u.label if u.is_a? Plexus::Arc
|
110
110
|
|
111
111
|
return self if not @allow_loops and u == v
|
112
112
|
|
@@ -144,10 +144,10 @@ module Graphy
|
|
144
144
|
# Removes an edge from the graph.
|
145
145
|
#
|
146
146
|
# Can be called with both source and target as vertex,
|
147
|
-
# or with source and object of {
|
147
|
+
# or with source and object of {Plexus::Arc} derivation.
|
148
148
|
#
|
149
149
|
# @overload remove_edge!(a)
|
150
|
-
# @param [
|
150
|
+
# @param [Plexus::Arc] a
|
151
151
|
# @return [AdjacencyGraph] `self`
|
152
152
|
# @raise [ArgumentError] if parallel edges are enabled
|
153
153
|
# @overload remove_edge!(u, v)
|
@@ -156,7 +156,7 @@ module Graphy
|
|
156
156
|
# @return [AdjacencyGraph] `self`
|
157
157
|
# @raise [ArgumentError] if parallel edges are enabled and the {ArcNumber} of `u` is zero
|
158
158
|
def remove_edge!(u, v = nil)
|
159
|
-
unless u.is_a?
|
159
|
+
unless u.is_a? Plexus::Arc
|
160
160
|
raise ArgumentError if @parallel_edges
|
161
161
|
u = edge_class[u,v]
|
162
162
|
end
|
@@ -206,7 +206,7 @@ module Graphy
|
|
206
206
|
# @fixme
|
207
207
|
def adjacent(x, options = {})
|
208
208
|
options[:direction] ||= :out
|
209
|
-
if !x.is_a?(
|
209
|
+
if !x.is_a?(Plexus::Arc) and (options[:direction] == :out || !directed?)
|
210
210
|
if options[:type] == :edges
|
211
211
|
i = -1
|
212
212
|
@parallel_edges ?
|
@@ -221,4 +221,4 @@ module Graphy
|
|
221
221
|
end
|
222
222
|
|
223
223
|
end # Adjacency Graph
|
224
|
-
end #
|
224
|
+
end # Plexus
|
@@ -1,14 +1,12 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module Plexus
|
3
2
|
# Arc includes classes for representing egdes of directed and
|
4
3
|
# undirected graphs. There is no need for a Vertex class, because any ruby
|
5
4
|
# object can be a vertex of a graph.
|
6
5
|
#
|
7
|
-
# Arc's base is a Struct with a :source, a :target and a :label
|
6
|
+
# Arc's base is a Struct with a :source, a :target and a :label.
|
8
7
|
Struct.new("ArcBase", :source, :target, :label)
|
9
8
|
|
10
9
|
class Arc < Struct::ArcBase
|
11
|
-
|
12
10
|
def initialize(p_source, p_target, p_label = nil)
|
13
11
|
super(p_source, p_target, p_label)
|
14
12
|
end
|
@@ -20,7 +18,9 @@ module Graphy
|
|
20
18
|
alias == eql?
|
21
19
|
|
22
20
|
# Returns (v,u) if self == (u,v).
|
23
|
-
def reverse()
|
21
|
+
def reverse()
|
22
|
+
self.class.new(target, source, label)
|
23
|
+
end
|
24
24
|
|
25
25
|
# Sort support.
|
26
26
|
def <=>(rhs)
|
@@ -32,18 +32,14 @@ module Graphy
|
|
32
32
|
l = label ? " '#{label.to_s}'" : ''
|
33
33
|
"(#{source}-#{target}#{l})"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# Hash is defined in such a way that label is not
|
37
37
|
# part of the hash value
|
38
38
|
# FIXME: I had to get rid of that in order to make to_dot_graph
|
39
39
|
# work, but I can't figure it out (doesn't show up in the stack!)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
##puts target.inspect
|
44
|
-
#source.hash ^ (target.hash + 1)
|
45
|
-
#puts "---"
|
46
|
-
#end
|
40
|
+
def hash
|
41
|
+
source.hash ^ (target.hash + 1)
|
42
|
+
end
|
47
43
|
|
48
44
|
# Shortcut constructor.
|
49
45
|
#
|
@@ -51,15 +47,13 @@ module Graphy
|
|
51
47
|
def self.[](p_source, p_target, p_label = nil)
|
52
48
|
new(p_source, p_target, p_label)
|
53
49
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
|
51
|
+
def inspect
|
52
|
+
"#{self.class.to_s}[#{source.inspect},#{target.inspect},#{label.inspect}]"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
61
56
|
class MultiArc < Arc
|
62
57
|
include ArcNumber
|
63
58
|
end
|
64
|
-
|
65
|
-
end # Graphy
|
59
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
module
|
1
|
+
module Plexus
|
2
2
|
# A generic {GraphBuilder Graph} class you can inherit from.
|
3
|
-
class Graph;
|
3
|
+
class Graph; include GraphBuilder; end
|
4
4
|
|
5
5
|
# A generic {AdjacencyGraphBuilder AdjacencyGraph} class you can inherit from.
|
6
|
-
class AdjacencyGraph; include AdjacencyGraphBuilder; end
|
6
|
+
class AdjacencyGraph < Graph; include AdjacencyGraphBuilder; end
|
7
7
|
|
8
8
|
# A generic {DirectedGraphBuilder DirectedGraph} class you can inherit from.
|
9
|
-
class DirectedGraph; include DirectedGraphBuilder; end
|
9
|
+
class DirectedGraph < Graph; include DirectedGraphBuilder; end
|
10
10
|
|
11
11
|
# A generic {DigraphBuilder Digraph} class you can inherit from.
|
12
|
-
class Digraph; include DigraphBuilder; end
|
12
|
+
class Digraph < Graph; include DigraphBuilder; end
|
13
13
|
|
14
14
|
# A generic {DirectedPseudoGraphBuilder DirectedPseudoGraph} class you can inherit from.
|
15
|
-
class DirectedPseudoGraph; include DirectedPseudoGraphBuilder; end
|
15
|
+
class DirectedPseudoGraph < Graph; include DirectedPseudoGraphBuilder; end
|
16
16
|
|
17
17
|
# A generic {DirectedMultiGraphBuilder DirectedMultiGraph} class you can inherit from.
|
18
|
-
class DirectedMultiGraph; include DirectedMultiGraphBuilder; end
|
18
|
+
class DirectedMultiGraph < Graph; include DirectedMultiGraphBuilder; end
|
19
19
|
|
20
20
|
# A generic {UndirectedGraphBuilder UndirectedGraph} class you can inherit from.
|
21
|
-
class UndirectedGraph; include UndirectedGraphBuilder; end
|
21
|
+
class UndirectedGraph < Graph; include UndirectedGraphBuilder; end
|
22
22
|
|
23
23
|
# A generic {UndirectedPseudoGraphBuilder UndirectedPseudoGraph} class you can inherit from.
|
24
|
-
class UndirectedPseudoGraph; include UndirectedPseudoGraphBuilder; end
|
24
|
+
class UndirectedPseudoGraph < Graph; include UndirectedPseudoGraphBuilder; end
|
25
25
|
|
26
26
|
# A generic {UndirectedMultiGraphBuilder UndirectedMultiGraph} class you can inherit from.
|
27
|
-
class UndirectedMultiGraph; include UndirectedMultiGraphBuilder; end
|
27
|
+
class UndirectedMultiGraph < Graph; include UndirectedMultiGraphBuilder; end
|
28
28
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Plexus
|
2
2
|
|
3
3
|
# This class defines a cycle graph of size n.
|
4
4
|
# This is easily done by using the base Graph
|
@@ -23,12 +23,12 @@ module Graphy
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def edge?(u,v = nil)
|
26
|
-
u, v = [u.source, v.target] if u.is_a?
|
26
|
+
u, v = [u.source, v.target] if u.is_a? Plexus::Arc
|
27
27
|
vertex?(u) && vertex?(v) && ((v-u == 1) or (u == @size && v = 1))
|
28
28
|
end
|
29
29
|
|
30
30
|
def edges
|
31
|
-
Array.new(@size) { |i|
|
31
|
+
Array.new(@size) { |i| Plexus::Edge[i+1, (i+1) == @size ? 1 : i+2]}
|
32
32
|
end
|
33
33
|
end # CycleBuilder
|
34
34
|
|
@@ -49,15 +49,15 @@ module Graphy
|
|
49
49
|
return @edges if @edges # cache edges
|
50
50
|
@edges = []
|
51
51
|
@size.times do |u|
|
52
|
-
@size.times { |v| @edges <<
|
52
|
+
@size.times { |v| @edges << Plexus::Edge[u+1, v+1]}
|
53
53
|
end
|
54
54
|
@edges
|
55
55
|
end
|
56
56
|
|
57
57
|
def edge?(u, v = nil)
|
58
|
-
u, v = [u.source, v.target] if u.kind_of?
|
58
|
+
u, v = [u.source, v.target] if u.kind_of? Plexus::Arc
|
59
59
|
vertex?(u) && vertex?(v)
|
60
60
|
end
|
61
61
|
end # CompleteBuilder
|
62
62
|
|
63
|
-
end #
|
63
|
+
end # Plexus
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Plexus
|
2
2
|
module Comparability
|
3
3
|
|
4
4
|
# A comparability graph is an UndirectedGraph that has a transitive
|
@@ -19,7 +19,7 @@ module Graphy
|
|
19
19
|
if classification[e].nil?
|
20
20
|
k += 1
|
21
21
|
classification[e] = k; classification[e.reverse] = -k
|
22
|
-
comparability &&=
|
22
|
+
comparability &&= plexus_comparability_explore(e, k, classification)
|
23
23
|
end
|
24
24
|
end; [classification, comparability]
|
25
25
|
end
|
@@ -34,12 +34,12 @@ module Graphy
|
|
34
34
|
|
35
35
|
# Taken from Figure 5.10, on pg. 130 of Martin Golumbic's, _Algorithmic_Graph_
|
36
36
|
# _Theory_and_Perfect_Graphs.
|
37
|
-
def
|
38
|
-
ret =
|
39
|
-
|
37
|
+
def plexus_comparability_explore(edge, k, classification, space='')
|
38
|
+
ret = plexus_comparability_explore_inner(edge, k, classification, :forward, space)
|
39
|
+
plexus_comparability_explore_inner(edge.reverse, k, classification, :backward, space) && ret
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def plexus_comparability_explore_inner(edge, k, classification, direction,space)
|
43
43
|
comparability = true
|
44
44
|
adj_target = adjacent(edge[1])
|
45
45
|
adjacent(edge[0]).select do |mt|
|
@@ -50,14 +50,14 @@ module Graphy
|
|
50
50
|
if classification[e].nil?
|
51
51
|
classification[e] = k
|
52
52
|
classification[e.reverse] = -k
|
53
|
-
comparability =
|
53
|
+
comparability = plexus_comparability_explore(e, k, classification, ' '+space) && comparability
|
54
54
|
elsif classification[e] == -k
|
55
55
|
classification[e] = k
|
56
|
-
|
56
|
+
plexus_comparability_explore(e, k, classification, ' '+space)
|
57
57
|
comparability = false
|
58
58
|
end
|
59
59
|
end; comparability
|
60
|
-
end #
|
60
|
+
end # plexus_comparability_explore_inner
|
61
61
|
|
62
62
|
end # Comparability
|
63
|
-
end #
|
63
|
+
end # Plexus
|