lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb
# Returns the path between two vertices
# @raise [ArgumentError] if there is no path between the vertices
# @param [Vertex] from
# @param [Vertex] to
# @return [Array<Vertex>] the shortest path from `from` to `to`
Returns the path between two vertices
Returns the path between two vertices
def path(from, to)
      distances = Hash.new(vertices.size + 1)
      distances[from.name] = 0
      predecessors = {}
      each do |vertex|
        vertex.successors.each do |successor|
          if distances[successor.name] > distances[vertex.name] + 1
            distances[successor.name] = distances[vertex.name] + 1
            predecessors[successor] = vertex
          end
        end
      end
      path = [to]
      while before = predecessors[to]
        path << before
        to = before
        break if to == from
      end
      unless path.last.equal?(from)
        raise ArgumentError, "There is no path from #{from.name} to #{to.name}"
      end
      path.reverse
    end
def path ( from , to ) distances = Hash . new ( vertices . size + 1 ) distances [ from . name ] = 0 predecessors = { } each do | vertex | vertex . successors . each do | successor | if distances [ successor . name ] > distances [ vertex . name ] + 1 distances [ successor . name ] = distances [ vertex . name ] + 1 predecessors [ successor ] = vertex end end end path = [ to ] while before = predecessors [ to ] path << before to = before break if to == from end unless path . last . equal? ( from ) raise ArgumentError , "There is no path from #{from.name} to #{to.name}" end path . reverse end
Returns the path between two vertices
Returns the path between two vertices
the shortest path from `from` to `to`
the shortest path from ` from ` to ` to `
Array<Vertex>
[ArgumentError] if there is no path between the vertices
[ ArgumentError ] if there is no path between the vertices
from
<not_specific>
to
<not_specific>
<not_specific>
None