class Graphos::Path
This class represents a collection of edges When adding an edge that does not start at the last node, it raises an error
Attributes
cost[R]
path[R]
Public Class Methods
new(edge=nil)
click to toggle source
# File lib/graphos/path.rb, line 11 def initialize edge=nil if edge @cost = edge.weight @path = [edge] else @cost = 0 @path = [] end end
Public Instance Methods
+(path)
click to toggle source
# File lib/graphos/path.rb, line 34 def + path dup.tap{|d| d.merge! path } end
add_edge(edge)
click to toggle source
# File lib/graphos/path.rb, line 21 def add_edge edge if @path.last.to != edge.from raise IncorrectPathError.new end @path += [node] @cost += weight end
merge!(paf)
click to toggle source
# File lib/graphos/path.rb, line 29 def merge! paf @cost += paf.cost @path = @path + paf.path end