class Graph
Attributes
directed[RW]
edges[RW]
maxdist[RW]
Public Class Methods
new()
click to toggle source
# File lib/graph.rb, line 10 def initialize @edges = {} end
Public Instance Methods
add_edge(from:, to:, cost: 1)
click to toggle source
# File lib/graph.rb, line 14 def add_edge(from:, to:, cost: 1) edges[from.id] ||= [] edges[from.id] << Edge.new.tap { |e| e.from = from, e.to = to, e.cost = cost } if !directed edges[to.id] ||= [] edges[to.id] << Edge.new.tap { |e| e.from = to, e.to = from, e.cost = cost } end end