resource_constrained_path#
- graph_tool.structure.resource_constrained_path(g, source, target, cost, resources, limits, pareto=False)[git][source]#
Return a shortest path subject to constraints on the resources it consumes.
- Parameters:
- g
Graph Graph to be used.
- source
Vertexorint Source vertex.
- target
Vertexorint Target vertex.
- cost
EdgePropertyMap Nonnegative edge costs, whose sum along the path is minimized.
- resources
listofEdgePropertyMap Nonnegative consumption of each resource by each edge.
- limitsiterable of
float Upper limit of the total consumption of each resource along the path.
- pareto
bool(optional, default:False) If
True, all Pareto-optimal paths are returned (see below).
- g
- Returns:
- path
numpy.ndarrayorNone The edge indices of a feasible path of minimum cost (
Noneif there is none).- cost
float Its cost.
- consumption
numpy.ndarray Its consumption of each resource.
- If
pareto == True, a list of such(path, cost, consumption) - tuples is returned instead, ordered by cost, and then lexicographically
- by consumption.
- path
See also
shortest_pathUnconstrained shortest path
k_shortest_pathsThe k shortest simple paths
Notes
With \(c_e\) the cost of edge \(e\), \(r^i_e\) its consumption of resource \(i\), and \(L_i\) the limit of that resource, the problem solved is
\[\min_{P:\,s\to t}\sum_{e\in P}c_e \quad\text{subject to}\quad \sum_{e\in P}r^i_e \le L_i \text{ for every } i,\]where \(P\) runs over the paths from the source \(s\) to the target \(t\). With
pareto == True, the feasible paths returned are the Pareto-optimal ones, i.e. those for which no other feasible path has a cost and a consumption of every resource that are all at most as large, with at least one of them smaller. Of several Pareto-optimal paths with the same cost and the same consumption of every resource, only one is returned, which depends on the order in which the partial paths are extended. Ifpareto == False, the first of these paths is returned, i.e. among the feasible paths of minimum cost, one whose consumption vector is the smallest in lexicographic order. The paths are found with the labeling algorithm for resource-constrained shortest paths [irnich-shortest-2005], which extends partial paths along the edges, discards the infeasible ones, and keeps only those not dominated by another partial path at the same vertex. The problem is NP-hard, and the number of labels, and hence the running time, can grow exponentially; it is typically fast for few resources and tight limits. For undirected graphs, both directions of every edge can be used.References
[irnich-shortest-2005]Stefan Irnich and Guy Desaulniers, “Shortest path problems with resource constraints”, in Column Generation, Springer, 33-65 (2005), DOI: 10.1007/0-387-25486-2_2 [sci-hub, @tor]
Examples
>>> g = gt.Graph([(0, 1), (1, 3), (0, 2), (2, 3)]) >>> c = g.new_ep("double", vals=[1, 1, 2, 2]) >>> r = g.new_ep("double", vals=[3, 3, 1, 1]) >>> path, cost, used = gt.resource_constrained_path(g, 0, 3, c, [r], [4]) >>> print(path, cost, used) [2 3] 4.0 [2.]