Class: GRATR::Cycle
- Inherits:
-
Object
- Object
- GRATR::Cycle
- Defined in:
- lib/gratr/common.rb
Overview
This class defines a cycle 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
Direct Known Subclasses
Instance Method Summary collapse
- #directed? ⇒ Boolean
- #edge?(u, v = nil) ⇒ Boolean
- #edges ⇒ Object
-
#initialize(n) ⇒ Cycle
constructor
A new instance of Cycle.
- #vertex?(v) ⇒ Boolean
- #vertices ⇒ Object
Constructor Details
#initialize(n) ⇒ Cycle
Returns a new instance of Cycle.
40 |
# File 'lib/gratr/common.rb', line 40 def initialize(n) @size = n; end |
Instance Method Details
#directed? ⇒ Boolean
41 |
# File 'lib/gratr/common.rb', line 41 def directed?() false; end |
#edge?(u, v = nil) ⇒ Boolean
44 45 46 47 |
# File 'lib/gratr/common.rb', line 44 def edge?(u,v=nil) u, v = [u.source, v.target] if u.kind_of? GRATR::Arc vertex?(u) && vertex?(v) && ((v-u == 1) or (u==@size && v=1)) end |
#edges ⇒ Object
48 |
# File 'lib/gratr/common.rb', line 48 def edges() Array.new(@size) {|i| GRATR::Edge[i+1, (i+1)==@size ? 1 : i+2]}; end |
#vertex?(v) ⇒ Boolean
43 |
# File 'lib/gratr/common.rb', line 43 def vertex?(v) v > 0 and v <= @size; end |
#vertices ⇒ Object
42 |
# File 'lib/gratr/common.rb', line 42 def vertices() (1..@size).to_a; end |