Class: Graphos::Weighted::Graph
- Inherits:
-
Object
- Object
- Graphos::Weighted::Graph
- Defined in:
- lib/graphos/weighted/graph.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #add_edge(from, to, weight) ⇒ Object
- #each_node ⇒ Object
- #edge(from, to) ⇒ Object
-
#initialize(size) ⇒ Graph
constructor
A new instance of Graph.
- #size ⇒ Object
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
#nodes ⇒ Object (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_node ⇒ Object
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 |
#size ⇒ Object
16 17 18 |
# File 'lib/graphos/weighted/graph.rb', line 16 def size @nodes.size end |