test/examples/calculate_shortest_path.rb
# public initialize. It's overloaded so that the public version doesn't
# have to pass a lot of crap; the initialize method takes care of
# setting up internal data structures on the first invocation. On
# recursion we override the defaults
public initialize. It's overloaded so that the public version doesn't
have to pass a lot of crap; the initialize method takes care of
setting up internal data structures on the first invocation. On
recursion we override the defaults
public initialize . It ' s overloaded so that the public version doesn ' t have to pass a lot of crap ; the initialize method takes care of setting up internal data structures on the first invocation . On recursion we override the defaults
def do_inits(path_vector, unvisited_hash, pathto_hash, tentative_distance_values_hash)
    if path_vector.nil?
      def do_inits(path_vector, unvisited_hash, pathto_hash, tentative_distance_values_hash)
        if path_vector.nil?
          @tentative_distance_values = Hash.new
          @unvisited = Hash.new
          map.nodes.each { |node| @unvisited[node] = true }
          @unvisited.delete(map.origin)
          map.nodes.each { |node| 
            bind :node => :distance_labeled_graph_node
            distance_labeled_graph_node.set_tentative_distance_to(infinity) }
          tentative_distance_values[map.origin] = 0
          @path = Array.new
          @pathTo = Hash.new
        else
          @tentative_distance_values = tentative_distance_values_hash
          @unvisited = unvisited_hash
          @path = path_vector
          @pathTo = pathto_hash
        end
      end
      @tentative_distance_values = Hash.new
      @unvisited = Hash.new
      map.nodes.each { |node| @unvisited[node] = true }
      @unvisited.delete(map.origin)
      map.nodes.each { |node|
        bind :node => :distance_labeled_graph_node
        distance_labeled_graph_node.set_tentative_distance_to(infinity)
      }
      tentative_distance_values[map.origin] = 0
      @path = Array.new
      @pathTo = Hash.new
    else
      @tentative_distance_values = tentative_distance_values_hash
      @unvisited = unvisited_hash
      @path = path_vector
      @pathTo = pathto_hash
    end
  end
def do_inits ( path_vector , unvisited_hash , pathto_hash , tentative_distance_values_hash ) if path_vector . nil? def do_inits ( path_vector , unvisited_hash , pathto_hash , tentative_distance_values_hash ) if path_vector . nil? @tentative_distance_values = Hash . new @unvisited = Hash . new map . nodes . each { | node | @unvisited [ node ] = true } @unvisited . delete ( map . origin ) map . nodes . each { | node | bind :node => :distance_labeled_graph_node distance_labeled_graph_node . set_tentative_distance_to ( infinity ) } tentative_distance_values [ map . origin ] = 0 @path = Array . new @pathTo = Hash . new else @tentative_distance_values = tentative_distance_values_hash @unvisited = unvisited_hash @path = path_vector @pathTo = pathto_hash end end @tentative_distance_values = Hash . new @unvisited = Hash . new map . nodes . each { | node | @unvisited [ node ] = true } @unvisited . delete ( map . origin ) map . nodes . each { | node | bind :node => :distance_labeled_graph_node distance_labeled_graph_node . set_tentative_distance_to ( infinity ) } tentative_distance_values [ map . origin ] = 0 @path = Array . new @pathTo = Hash . new else @tentative_distance_values = tentative_distance_values_hash @unvisited = unvisited_hash @path = path_vector @pathTo = pathto_hash end end
public initialize.
public initialize .
# The conditional switches between the first and subsequent instances of the # recursion (the algorithm is recursive in graph contexts) # The conditional switches between the first and subsequent instances of the # recursion (the algorithm is recursive in graph contexts) # Since path_vector isn't set up, this is the first iteration of the recursion # This is the fundamental data structure for DijkstraTest's algorithm, called # Q in the Wikipedia description. It is a boolean hash that maps a # node onto false or true according to whether it has been visited # These initializations are directly from the description of the algorithm # The path array is kept in the outermost context and serves to store the # return path. Each recurring context may add something to the array along # the way. However, because of the nature of the algorithm, individual # Context instances don't deliver partial paths as partial answers. # The pathTo map is a local associative array that remembers the # arrows between nodes through the array and erases them if we # re-label a node with a shorter distance # We are recurring. Just copy the values copied in from the previous iteration # of the recursion # Since path_vector isn't set up, this is the first iteration of the recursion # This is the fundamental data structure for DijkstraTest's algorithm, called # Q in the Wikipedia description. It is a boolean hash that maps a # node onto false or true according to whether it has been visited # These initializations are directly from the description of the algorithm # The path array is kept in the outermost context and serves to store the # return path. Each recurring context may add something to the array along # the way. However, because of the nature of the algorithm, individual # Context instances don't deliver partial paths as partial answers. # The pathTo map is a local associative array that remembers the # arrows between nodes through the array and erases them if we # re-label a node with a shorter distance # We are recurring. Just copy the values copied in from the previous iteration # of the recursion
path_vector
unvisited_hash
pathto_hash
tentative_distance_values_hash