Class: Graphos::Weighted::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/graphos/weighted/graph.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ Graph

Returns a new instance of Graph.



12
13
14
# File 'lib/graphos/weighted/graph.rb', line 12

def initialize size
  @nodes = (0..size-1).map{|i| Node.new i }
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



10
11
12
# File 'lib/graphos/weighted/graph.rb', line 10

def nodes
  @nodes
end

Instance Method Details

#[](i) ⇒ Object



29
30
31
# File 'lib/graphos/weighted/graph.rb', line 29

def [] i
  @nodes[i]
end

#add_edge(from, to, weight) ⇒ Object



20
21
22
23
# File 'lib/graphos/weighted/graph.rb', line 20

def add_edge from, to, weight
  @nodes[from].add_edge(@nodes[to],weight)
  @nodes[to].add_edge(@nodes[from],weight)
end

#each_nodeObject



33
34
35
# File 'lib/graphos/weighted/graph.rb', line 33

def each_node
  @nodes.each{|n| yield n}
end

#edge(from, to) ⇒ Object



25
26
27
# File 'lib/graphos/weighted/graph.rb', line 25

def edge from, to
  @nodes[from].edge(to)
end

#sizeObject



16
17
18
# File 'lib/graphos/weighted/graph.rb', line 16

def size
  @nodes.size
end