test/examples/calculate_shortest_path.rb
# This is the method that starts the work. Called from initialize.
This is the method that starts the work. Called from initialize.
This is the method that starts the work . Called from initialize .
def execute (path_vector, unvisited_hash, pathto_hash, tentative_distance_values_hash)
    do_inits(path_vector, unvisited_hash, pathto_hash,
             tentative_distance_values_hash)
    unvisited_neighbors = current.unvisited_neighbors
    if unvisited_neighbors != nil
      unvisited_neighbors.each {
          |neighbor|
        bind :neighbor => :neighbor_node        
        tentative_distance = current.tentative_distance
        raise 'tentative distance cannot be nil' if tentative_distance == nil
        distance_between = map.distance_between(current, neighbor)
        raise 'distance between cannot be nil' if distance_between == nil
        net_distance = tentative_distance + distance_between
        if neighbor_node.relable_node_as(net_distance) == :distance_was_udated
          pathTo[neighbor] = @current
        end
      }
    end
    unvisited.delete(@current)
    if unvisited.size == 0
      save_path(@path)
    else
      selection = map.nearest_unvisited_node_to_target
      CalculateShortestPath.new(selection, destination, map, path, @unvisited,
                                pathTo, tentative_distance_values)
    end
  end
def execute ( path_vector , unvisited_hash , pathto_hash , tentative_distance_values_hash ) do_inits ( path_vector , unvisited_hash , pathto_hash , tentative_distance_values_hash ) unvisited_neighbors = current . unvisited_neighbors if unvisited_neighbors != nil unvisited_neighbors . each { | neighbor | bind :neighbor => :neighbor_node tentative_distance = current . tentative_distance raise 'tentative distance cannot be nil' if tentative_distance == nil distance_between = map . distance_between ( current , neighbor ) raise 'distance between cannot be nil' if distance_between == nil net_distance = tentative_distance + distance_between if neighbor_node . relable_node_as ( net_distance ) == :distance_was_udated pathTo [ neighbor ] = @current end } end unvisited . delete ( @current ) if unvisited . size == 0 save_path ( @path ) else selection = map . nearest_unvisited_node_to_target CalculateShortestPath . new ( selection , destination , map , path , @unvisited , pathTo , tentative_distance_values ) end end
This is the method that starts the work.
This is the method that starts the work .
# Calculate tentative distances of unvisited neighbors # Are we done? # The next current node is the one with the least distance in the # unvisited set # Recur
path_vector
unvisited_hash
pathto_hash
tentative_distance_values_hash