Module: Plexus::CompleteBuilder

Includes:
CycleBuilder
Defined in:
lib/plexus/common.rb

Overview

This class defines a complete graph of size n. This is easily done by using the base Graph class and implemeting the minimum methods needed to make it work. This is a good example to look at for making one’s own graph classes.

Instance Method Summary collapse

Methods included from CycleBuilder

#directed?, #vertex?, #vertices

Instance Method Details

#edge?(u, v = nil) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/plexus/common.rb', line 57

def edge?(u, v = nil)
  u, v = [u.source, v.target] if u.kind_of? Plexus::Arc
  vertex?(u) && vertex?(v)
end

#edgesObject



48
49
50
51
52
53
54
55
# File 'lib/plexus/common.rb', line 48

def edges
  return @edges if @edges      # cache edges
  @edges = []
  @size.times do |u|
    @size.times { |v| @edges << Plexus::Edge[u+1, v+1]}
  end
  @edges
end

#initialize(n) ⇒ Object



43
44
45
46
# File 'lib/plexus/common.rb', line 43

def initialize(n)
  @size = n
  @edges = nil
end