Class: GRATR::Complete

Inherits:
Cycle
  • Object
show all
Defined in:
lib/gratr/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 inherited from Cycle

#directed?, #vertex?, #vertices

Constructor Details

#initialize(n) ⇒ Complete

Returns a new instance of Complete.



57
# File 'lib/gratr/common.rb', line 57

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

Instance Method Details

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

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/gratr/common.rb', line 65

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

#edgesObject



58
59
60
61
62
63
64
# File 'lib/gratr/common.rb', line 58

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