Class: Graphos::Weighted::Graph
- Inherits:
-
Object
- Object
- Graphos::Weighted::Graph
- Defined in:
- lib/graphos/weighted/graph.rb
Overview
:nodoc:
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.
11 12 13 |
# File 'lib/graphos/weighted/graph.rb', line 11 def initialize size @nodes = (0..size-1).map{|i| Node.new i } end |
Instance Method Details
#[](i) ⇒ Object
28 29 30 |
# File 'lib/graphos/weighted/graph.rb', line 28 def [] i @nodes[i] end |
#add_edge(from, to, weight) ⇒ Object
19 20 21 22 |
# File 'lib/graphos/weighted/graph.rb', line 19 def add_edge from, to, weight @nodes[from].add_edge(@nodes[to],weight) @nodes[to].add_edge(@nodes[from],weight) end |
#each_node ⇒ Object
32 33 34 |
# File 'lib/graphos/weighted/graph.rb', line 32 def each_node @nodes.each{|n| yield n} end |
#edge(from, to) ⇒ Object
24 25 26 |
# File 'lib/graphos/weighted/graph.rb', line 24 def edge from, to @nodes[from].edge(to) end |
#size ⇒ Object
15 16 17 |
# File 'lib/graphos/weighted/graph.rb', line 15 def size @nodes.size end |