Class: Graph
Direct Known Subclasses
Defined Under Namespace
Classes: Square
Instance Attribute Summary collapse
-
#directed ⇒ Object
Returns the value of attribute directed.
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#maxdist ⇒ Object
Returns the value of attribute maxdist.
Instance Method Summary collapse
- #add_edge(from:, to:, cost: 1) ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
Methods included from Search
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
10 11 12 |
# File 'lib/graph.rb', line 10 def initialize @edges = {} end |
Instance Attribute Details
#directed ⇒ Object
Returns the value of attribute directed.
8 9 10 |
# File 'lib/graph.rb', line 8 def directed @directed end |
#edges ⇒ Object
Returns the value of attribute edges.
8 9 10 |
# File 'lib/graph.rb', line 8 def edges @edges end |
#maxdist ⇒ Object
Returns the value of attribute maxdist.
8 9 10 |
# File 'lib/graph.rb', line 8 def maxdist @maxdist end |
Instance Method Details
#add_edge(from:, to:, cost: 1) ⇒ Object
14 15 16 17 18 19 20 21 |
# 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 |