Class: Abuelo::Edge
- Inherits:
-
Object
- Object
- Abuelo::Edge
- Defined in:
- lib/abuelo/edge.rb
Overview
Class Edge provides a representation of an edge. An edge connects two nodes(start-node and end-node) and has a weight.
Instance Attribute Summary collapse
-
#node_1 ⇒ Abuelo::Node
readonly
Start-node.
-
#node_2 ⇒ Abuelo::Node
readonly
End-node.
-
#weight ⇒ Numeric
readonly
Weight.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Comparison based on weight.
-
#==(other) ⇒ Boolean
Equality check.
-
#initialize(node_1, node_2, weight = 1) ⇒ Edge
constructor
Initialiazises the edge with its two nodes and its weight.
-
#symmetric ⇒ Abuelo::Edge
A new edge with same weight but reversed start- and end-node.
-
#to_s ⇒ String
Human readable representation of edge.
Constructor Details
#initialize(node_1, node_2, weight = 1) ⇒ Edge
Initialiazises the edge with its two nodes and its weight.
25 26 27 28 29 |
# File 'lib/abuelo/edge.rb', line 25 def initialize(node_1, node_2, weight = 1) @node_1 = node_1 @node_2 = node_2 @weight = weight end |
Instance Attribute Details
#node_1 ⇒ Abuelo::Node (readonly)
10 11 12 |
# File 'lib/abuelo/edge.rb', line 10 def node_1 @node_1 end |
#node_2 ⇒ Abuelo::Node (readonly)
13 14 15 |
# File 'lib/abuelo/edge.rb', line 13 def node_2 @node_2 end |
#weight ⇒ Numeric (readonly)
16 17 18 |
# File 'lib/abuelo/edge.rb', line 16 def weight @weight end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Comparison based on weight.
45 46 47 |
# File 'lib/abuelo/edge.rb', line 45 def <=>(other) weight <=> other.weight end |
#==(other) ⇒ Boolean
Equality check.
56 57 58 59 60 |
# File 'lib/abuelo/edge.rb', line 56 def ==(other) node_1 == other.node_1 && node_2 == other.node_2 && weight == other.weight end |
#symmetric ⇒ Abuelo::Edge
34 35 36 |
# File 'lib/abuelo/edge.rb', line 34 def symmetric Abuelo::Edge.new(node_2, node_1, weight) end |
#to_s ⇒ String
65 66 67 |
# File 'lib/abuelo/edge.rb', line 65 def to_s "#{node_1} -> #{node_2} with weight #{weight}" end |