Examples/Dijkstra/data.rb in maroon-0.6.1 vs Examples/Dijkstra/data.rb in maroon-0.6.5

- old
+ new

@@ -1,40 +1,48 @@ -def infinity; (2**(0.size * 8 -2) -1) end +def infinity; + (2**(0.size * 8 -2) -1) +end + # Data classes Edge = Struct.new(:from, :to) class Node attr_reader :name - def initialize(n); @name = n end + + def initialize(n) + ; @name = n + end + def eql? (another_node) # Nodes are == equal if they have the same name. This is explicitly # defined here to call out the importance of the differnce between # object equality and identity name == another_node.name end end - # # --- Geometry is the interface to the data class that has all # --- the information about the map. This is kind of silly in Ruby # class ManhattanGeometry def initialize; @nodes = Array.new @distances = Hash.new end - def nodes; @nodes end + def nodes; + @nodes + end + def distances @distances end end - # # --- Here are some test data # #noinspection RubyTooManyInstanceVariablesInspection @@ -47,11 +55,10 @@ 3.times { |i| 3.times { |j| nodes << Node.new(names[(i*3)+j]) } } - # Aliases to help set up the grid. Grid is of Manhattan form: # # a - 2 - b - 3 - c @@ -112,15 +119,25 @@ @next_along_the_avenue_from[@node_d] = @node_g @next_along_the_avenue_from[@node_f] = @node_i @next_along_the_avenue_from.freeze end - def east_neighbor_of(a); @next_down_the_street_from[a] end - def south_neighbor_of(a); @next_along_the_avenue_from[a] end + def east_neighbor_of(a) + ; @next_down_the_street_from[a] + end - def root; @node_a end - def destination; @node_i end + def south_neighbor_of(a) + ; @next_along_the_avenue_from[a] + end + + def root; + @node_a + end + + def destination; + @node_i + end end #noinspection RubyTooManyInstanceVariablesInspection class ManhattanGeometry2 < ManhattanGeometry @@ -199,12 +216,22 @@ @next_along_the_avenue_from[@node_f] = @node_i @next_along_the_avenue_from[@node_j] = @node_k @next_along_the_avenue_from.freeze end - def east_neighbor_of(a); @next_down_the_street_from[a] end - def south_neighbor_of(a); @next_along_the_avenue_from[a] end + def east_neighbor_of(a) + ; @next_down_the_street_from[a] + end - def root; @node_a end - def destination; @node_k end + def south_neighbor_of(a) + ; @next_along_the_avenue_from[a] + end + + def root; + @node_a + end + + def destination; + @node_k + end end