573 lines
33 KiB
HTML
573 lines
33 KiB
HTML
<html>
|
|
<!--
|
|
Copyright Michael Drexl 2006, 2007.
|
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
(See accompanying file LICENSE_1_0.txt or copy at
|
|
http://boost.org/LICENSE_1_0.txt)
|
|
-->
|
|
<head>
|
|
<title>Boost Graph Library: Resource-Constrained Shortest Paths</title>
|
|
<body bgcolor="#ffffff" link="#0000ee" text="#000000" vlink="#551a8b"
|
|
alink="#ff0000">
|
|
<img src="../../../boost.png"
|
|
alt="C++ Boost" width="277" height="86">
|
|
|
|
<br Clear>
|
|
|
|
<h1><a name="sec:espprc"></a>
|
|
<tt>r_c_shortest_paths</tt>
|
|
</h1>
|
|
|
|
<p>
|
|
<pre>
|
|
|
|
template<class Graph,
|
|
class VertexIndexMap,
|
|
class EdgeIndexMap,
|
|
class Resource_Container,
|
|
class Resource_Extension_Function,
|
|
class Dominance_Function,
|
|
class Label_Allocator,
|
|
class Visitor>
|
|
void r_c_shortest_paths( const Graph& g,
|
|
const VertexIndexMap& vertex_index_map,
|
|
const EdgeIndexMap& edge_index_map,
|
|
typename graph_traits<Graph>::vertex_descriptor s,
|
|
typename graph_traits<Graph>::vertex_descriptor t,
|
|
std::vector<std::vector<typename graph_traits<Graph>::edge_descriptor> >& pareto_optimal_solutions,
|
|
std::vector<Resource_Container>& pareto_optimal_resource_containers,
|
|
const Resource_Container& rc,
|
|
const Resource_Extension_Function& ref,
|
|
const Dominance_Function& dominance,
|
|
Label_Allocator la,
|
|
Visitor vis )
|
|
|
|
template<class Graph,
|
|
class VertexIndexMap,
|
|
class EdgeIndexMap,
|
|
class Resource_Container,
|
|
class Resource_Extension_Function,
|
|
class Dominance_Function,
|
|
class Label_Allocator,
|
|
class Visitor>
|
|
void r_c_shortest_paths( const Graph& g,
|
|
const VertexIndexMap& vertex_index_map,
|
|
const EdgeIndexMap& edge_index_map,
|
|
typename graph_traits<Graph>::vertex_descriptor s,
|
|
typename graph_traits<Graph>::vertex_descriptor t,
|
|
std::vector<typename graph_traits<Graph>::edge_descriptor>& pareto_optimal_solution,
|
|
Resource_Container>& pareto_optimal_resource_container,
|
|
const Resource_Container& rc,
|
|
const Resource_Extension_Function& ref,
|
|
const Dominance_Function& dominance,
|
|
Label_Allocator la,
|
|
Visitor vis )
|
|
|
|
template<class Graph,
|
|
class VertexIndexMap,
|
|
class EdgeIndexMap,
|
|
class Resource_Container,
|
|
class Resource_Extension_Function,
|
|
class Dominance_Function>
|
|
void r_c_shortest_paths( const Graph& g,
|
|
const VertexIndexMap& vertex_index_map,
|
|
const EdgeIndexMap& edge_index_map,
|
|
typename graph_traits<Graph>::vertex_descriptor s,
|
|
typename graph_traits<Graph>::vertex_descriptor t,
|
|
std::vector<std::vector<typename graph_traits<Graph>::edge_descriptor> >& pareto_optimal_solutions,
|
|
std::vector<Resource_Container>& pareto_optimal_resource_containers,
|
|
const Resource_Container& rc,
|
|
const Resource_Extension_Function& ref,
|
|
const Dominance_Function& dominance )
|
|
|
|
template<class Graph,
|
|
class VertexIndexMap,
|
|
class EdgeIndexMap,
|
|
class Resource_Container,
|
|
class Resource_Extension_Function,
|
|
class Dominance_Function>
|
|
void r_c_shortest_paths( const Graph& g,
|
|
const VertexIndexMap& vertex_index_map,
|
|
const EdgeIndexMap& edge_index_map,
|
|
typename graph_traits<Graph>::vertex_descriptor s,
|
|
typename graph_traits<Graph>::vertex_descriptor t,
|
|
std::vector<typename graph_traits<Graph>::edge_descriptor>& pareto_optimal_solution,
|
|
Resource_Container>& pareto_optimal_resource_container,
|
|
const Resource_Container& rc,
|
|
const Resource_Extension_Function& ref,
|
|
const Dominance_Function& dominance )
|
|
|
|
</pre>
|
|
|
|
<h3>Introduction and Problem Description</h3>
|
|
|
|
The shortest path problem with resource constraints (SPPRC) seeks a shortest (cheapest, fastest) path in a directed graph with arbitrary arc lengths (travel times, costs) from an origin node to a destination node subject to one or more resource constraints. For example, one might seek a path of minimum length from <i>s</i> to <i>t</i> subject to the constraints that
|
|
<ul>
|
|
<li>
|
|
the total travel time must not exceed some upper bound and/or
|
|
<li>
|
|
the total amount of some good that has to be picked up at the vertices along the path be less than or equal to some capacity limit and/or
|
|
<li>
|
|
if two vertices <i>i</i> and <i>j</i> are visited on a path, then <i>i</i> must be visited before <i>j</i>
|
|
<li>
|
|
etc.
|
|
</ul>
|
|
|
|
<p>
|
|
The problem is NP-hard in the strong sense. If the path need not be elementary, i.e., if it is allowed that vertices are visited more than once, the problem can be solved in pseudopolynomial time. A central aspect is that two (partial) paths in an SPPRC can be incomparable, contrary to the SPP without resource constraints. This makes the SPPRC similar to a multi-criteria decision problem.<br>
|
|
A recent survey on the problem is:<br>
|
|
Irnich, S.; Desaulniers, G. (2005):<br>
|
|
Shortest Path Problems with Resource Constraints<br>
|
|
in:<br>
|
|
Desaulniers, G.; Desrosiers, J.; Solomon, M. (eds.) (2005):<br>
|
|
Column Generation<br>
|
|
Springer, New York, pp. 33–65<br>
|
|
(available online <a href="https://www.researchgate.net/publication/227142556_Shortest_Path_Problems_with_Resource_Constraints">
|
|
here</a>)
|
|
<p>
|
|
|
|
<p>
|
|
The present document cannot give a complete introduction to SPPRCs. To get a thorough understanding of the problem, the reader is referred to the above paper. However, to understand the algorithm and its implementation, it is necessary to explain some fundamental ideas and point out the differences to a labelling algorithm for the shortest path problem without resource constraints (SPP).
|
|
</p>
|
|
|
|
<p>
|
|
The standard solution technique for SPPRCs is a labelling algorithm based on dynamic programming. This approach uses the concepts of <i>resources</i> and <i>resource extension functions</i>. A resource is an arbitrarily scaled one-dimensional piece of information that can be determined or measured at the vertices of a directed walk in a graph. Examples are cost, time, load, or the information ‘Is a vertex <i>i</i> visited on the current path?’. A resource is <i>constrained</i> if there is at least one vertex in the graph where the resource must not take all possible values. The <i>resource window</i> of a resource at a vertex is the set of allowed values for the resource at this vertex.
|
|
</p>
|
|
|
|
<p>
|
|
A resource extension function is defined on each arc in a graph for each resource considered. A resource extension function for a resource maps the set of all possible vectors (in a mathematical sense, not to be confused with a <tt>std::vector</tt>) of resource values at the source of an arc to the set of possible values of the resource at the target of the arc. This means that the value of a resource at a vertex may depend on the values of one or more other resources at the preceding vertex.
|
|
</p>
|
|
|
|
<p>
|
|
<i>Labels</i> are used to store the information on the resource values for partial paths. A label in an SPPRC labelling algorithm is not a mere triple of resident vertex, current cost and predecessor vertex, as it is the case in labelling algorithms for the SPP. A label for an SPPRC labelling algorithm stores its resident vertex, its predecessor <i>arc</i> over which it has been extended, its predecessor label, and its current vector of resource values. The criterion to be minimized (cost, travel time, travel distance, whatsoever) is also treated as a (possibly unconstrained) resource. It is necessary to store the predecessor arc instead of the predecessor vertex, because, due to the resource constraints, one can not assume that the underlying graph is simple. Labels reside at vertices, and they are propagated via resource extension functions when they are extended along an arc. An <i>extension</i> of a label along an arc (<i>i</i>, <i>j</i>) is <i>feasible</i> if the resulting label <i>l</i> at <i>j</i> is feasible, which is the case if and only if all resource values of <i>l</i> are within their resource windows.
|
|
</p>
|
|
|
|
<p>
|
|
To keep the number of labels as small as possible, it is decisive to perform a <i>dominance step</i> for eliminating unnecessary labels. A label <i>l</i><sub>1</sub> <i>dominates</i> a label <i>l</i><sub>2</sub> if both reside at the same vertex and if, for each feasible extension of <i>l</i><sub>2</sub>, there is also a feasible extension of <i>l</i><sub>1</sub> where the value of each cardinally scaled resource is less than or equal to the value of the resource in the extension of <i>l</i><sub>2</sub>, and where the value of each nominally scaled resource is equal to the value of the resource in the extension of <i>l</i><sub>2</sub>. Dominated labels need not be extended. A label which is not dominated by any other label is called undominated or Pareto-optimal. The application of the dominance principle is optional—at least from a theoretical perspective.
|
|
</p>
|
|
|
|
<p>
|
|
The implementation is a label-setting algorithm. This means that there must be one or more resources whose cumulated consumption(s) after extension is/are always at least as high as before. This is similar to the Dijkstra algorithm for the SPP without resource constraints where the distance measure must be non-negative. It is sufficient if there is one resource with a non-negative resource consumption along all arcs (for example, non-negative arc lengths or non-negative arc traversal times).
|
|
</p>
|
|
|
|
<h3>Concepts</h3>
|
|
|
|
<h4>ResourceContainer</h4>
|
|
|
|
<p>
|
|
A type modelling the ResourceContainer concept is used to store the current resource consumptions of a label.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Refinement of</b><br>
|
|
<a href="http://www.boost.org/sgi/stl/DefaultConstructible.html">DefaultConstructible</a>, <a href="../../utility/CopyConstructible.html">CopyConstructible</a>, <a href="http://www.boost.org/sgi/stl/Assignable.html">Assignable</a>, <a href="http://www.boost.org/sgi/stl/LessThanComparable.html">LessThanComparable</a>, <a href="http://www.boost.org/sgi/stl/EqualityComparable.html">EqualityComparable</a>
|
|
</p>
|
|
|
|
<p>
|
|
<b>Valid Expressions</b><br>
|
|
See <a href="#ResourceExtensionFunction">ResourceExtensionFunction</a> concept.
|
|
</p>
|
|
|
|
<a name="Label"><h4>Label</h4></a>
|
|
|
|
<p>
|
|
This concept defines the interface for a label in the <tt>r_c_shortest_paths</tt> functions. It is a design decision not to parameterize the functions on the type of label. The type <tt>template<class Graph, class Resource_Container> struct r_c_shortest_paths_label</tt> is used to model this concept.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Valid Expressions</b><br>
|
|
If <tt>label</tt> is an object of type <tt>r_c_shortest_paths_label</tt>, the following expressions are valid:<br>
|
|
<table border>
|
|
<tr>
|
|
<td>
|
|
<tt>label.num</tt>
|
|
</td>
|
|
<td>
|
|
Returns an unsigned integer value specifying the number of the label. Labels are numbered consecutively in order of their creation.
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>label.cumulated_resource_consumption</tt>
|
|
</td>
|
|
<td>
|
|
Returns the object associated with <tt>label</tt> modelling the ResourceContainer concept.
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>label.p_pred_label</tt>
|
|
</td>
|
|
<td>
|
|
Returns a <tt>const</tt> pointer to the predecessor label, i.e., to the label whose extension along <tt>label.pred_edge</tt> yielded the <tt>label} object</tt>.
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>label.pred_edge</tt>
|
|
</td>
|
|
<td>
|
|
Returns an edge descriptor for the arc along which <tt>label.p_pred_label</tt> was extended to yield the <tt>label</tt> object.
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>label.resident_vertex</tt>
|
|
</td>
|
|
<td>
|
|
Returns a vertex descriptor for the vertex at which the <tt>label</tt> object resides.
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>label.b_is_dominated</tt>
|
|
</td>
|
|
<td>
|
|
Returns a boolean value indicating whether the <tt>label</tt> object is dominated by some other label residing at the vertex <tt>label.resident_vertex</tt>. Is useful only after dominance checking has been performed, i.e. only in the visitor functions <tt>on_label_dominated</tt> and <tt>on_label_not_dominated</tt> (see <a href="#ResourceConstrainedShortestPathsVisitor">below</a>).
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>
|
|
<b>Invariants</b><br>
|
|
Every <tt>r_c_shortest_paths_label</tt> object, except for the first label, has a valid (not null) <tt>p_pred_label</tt> pointer and a valid <tt>pred_edge</tt> member. The <tt>p_pred_label</tt> pointer of the label with <tt>num</tt> member equal to zero is a null pointer, and the <tt>pred_edge</tt> member of this label is a default-constructed edge descriptor.
|
|
</p>
|
|
|
|
<a name="ResourceExtensionFunction"><h4>ResourceExtensionFunction</h4></a>
|
|
|
|
<p>
|
|
A model of the ResourceExtensionFunction concept is used to specify how a label is to be extended along an arc.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Valid Expressions</b><br>
|
|
If <tt>ref</tt> models the ResourceExtensionFunction concept, and if the type <tt>Resource_Container</tt> models the ResourceContainer concept, the following expression is valid:<br>
|
|
<table border>
|
|
<tr>
|
|
<td>
|
|
<pre>
|
|
bool b = ref( const Graph& g,
|
|
Resource_Container& new_cont,
|
|
const Resource_Container& old_cont,
|
|
graph_traits<Graph>::edge_descriptor ed )
|
|
</pre>
|
|
</td>
|
|
<td>
|
|
<tt>ref</tt> must return <tt>true</tt> if and only if the extension is feasible, i.e., if <tt>new_cont</tt> fulfills all resource constraints at the target vertex of <tt>ed</tt>.
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
Moreover, a reference to a type modelling the ResourceExtensionFunction concept can be passed as a parameter to <tt>r_c_shortest_paths</tt>, see above.<br>
|
|
</p>
|
|
|
|
<p>
|
|
Hence, a type modelling the ResourceExtensionFunction concept is likely to be a function or a <a href="http://www.boost.org/sgi/stl/functors.html">function object</a>.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Invariants</b><br>
|
|
If <tt>ref</tt> models the ResourceExtensionFunction concept, and if the type <tt>Resource_Container</tt> models the ResourceContainer concept, after the call
|
|
<pre>
|
|
ref( const Graph& g,
|
|
Resource_Container& new_cont,
|
|
const Resource_Container& old_cont,
|
|
graph_traits<Graph>::edge_descriptor )
|
|
</pre>
|
|
the expression <tt>old_cont <= new_cont</tt> evaluates to <tt>true</tt>.<br>
|
|
This is because, as stated above, the implementation is a label-setting algorithm. Therefore, the Less-Than operator for ResourceContainer must compare one or more resource(s) whose resource consumption(s) along any arc is/are non-decreasing in order for the algorithm to work properly.
|
|
</p>
|
|
|
|
<h4>DominanceFunction</h4>
|
|
|
|
<p>
|
|
A model of DominanceFunction is used to specify a dominance relation between two labels.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Refinement of</b><br>
|
|
<a href="http://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>
|
|
</p>
|
|
|
|
<p>
|
|
<b>Valid Expressions</b><br>
|
|
If <tt>dominance</tt> models the DominanceFunction concept, and if the type <tt>Resource_Container</tt> models the ResourceContainer concept, the following expression is valid:
|
|
<table border>
|
|
<tr>
|
|
<td>
|
|
<pre>
|
|
bool b = dominance(const Resource_Container& rc1, const Resource_Container& rc2)
|
|
</pre>
|
|
</td>
|
|
<td>
|
|
<tt>dominance</tt> must return <tt>true</tt> if and only if <tt>rc1</tt> dominates <tt>rc2</tt>.
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
Moreover, a reference to a type modelling the DominanceFunction concept can be passed as a parameter to <tt>r_c_shortest_paths</tt>, see above.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Invariants</b><br>
|
|
A type modelling the DominanceFunction concept must return <tt>true</tt> if and only if <tt>rc1<=rc2</tt>. It must <i>not</i> return <tt>false</tt> if <tt>rc1==rc2</tt>. Then, it is guaranteed that no two labels with identical resource consumption dominate each other and are both considered as dominated by the <tt>r_c_shortest_paths</tt> functions.
|
|
</p>
|
|
|
|
<a name="ResourceConstrainedShortestPathsVisitor"><h4>ResourceConstrainedShortestPathsVisitor</h4></a>
|
|
|
|
<p>
|
|
This concept defines the visitor interface for <tt>r_c_shortest_paths</tt>. A user can define a type with this interface and pass an object of this type to <tt>r_c_shortest_paths</tt> to perform user-defined actions at the event points of the algorithm. Note that the object is passed by value.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Refinement of</b><br>
|
|
<a href="http://www.boost.org/sgi/stl/DefaultConstructible.html">DefaultConstructible</a>, <a href="../../utility/CopyConstructible.html">CopyConstructible</a>
|
|
</p>
|
|
|
|
<p>
|
|
<b>Valid Expressions</b><br>
|
|
If <tt>vis</tt> is an object of a type modelling the ResourceConstrainedShortestPathsVisitor concept, and if <tt>g</tt> is an object of a type <tt>Graph</tt> modelling the IncidenceGraph and the PropertyGraph concepts, and if it is a directed graph, and if <tt>l</tt> is an object of a type <tt>Label</tt> modelling the Label concept, the following expressions are valid:<br>
|
|
<table border>
|
|
<tr>
|
|
<td>
|
|
<tt>vis.on_label_popped( const Label& l, const Graph& g )</tt>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>vis.on_label_feasible( const Label& l, const Graph& g )</tt>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>vis.on_label_not_feasible( const Label& l, const Graph& g )</tt>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>vis.on_label_dominated( const Label& l, const Graph& g )</tt>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<tt>vis.on_label_not_dominated( const Label& l, const Graph& g )</tt>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
See the <a href="#Label">description of the Label concept</a> for the interface of a Label. See the <a href="#FunctionsDescription">algorithm description</a> for information on when these functions are called.
|
|
<p>
|
|
|
|
<a name="FunctionsDescription"><h3>Functions Description</h3></a>
|
|
|
|
<p>
|
|
The functions are an implementation of a priority-queue-based label-setting algorithm. At each iteration, the algorithm picks a label <i>l</i> from a priority queue (the set of unprocessed labels) and checks it for dominance against the current set of labels at the vertex <i>i</i> where <i>l</i> resides. If <i>l</i> is dominated by some other label residing at <i>i</i>, <i>l</i> is deleted from the set of labels residing at <i>i</i>. If <i>l</i> is undominated, it is extended along all out-edges of <i>i</i>. Each resulting new label is checked for feasibility, and if it is feasible, it is added to the set of unprocessed labels and to the set of labels residing at the respective successor vertex of <i>i</i>. If a new label is not feasible, it is discarded. The algorithm stops when there are no more unprocessed labels. It then checks whether the destination vertex could be reached (which may not be the case even for a strongly connected graph because of the resource constraints), constructs one or all Pareto-optimal (i.e., undominated) <i>s</i>-<i>t</i>-path(s) and returns. A pseudo-code of the algorithm follows.
|
|
</p>
|
|
|
|
<pre>
|
|
r_c_shortest_paths( g,
|
|
vertex_index_map,
|
|
edge_index_map,
|
|
s,
|
|
t,
|
|
pareto_optimal_solutions,
|
|
pareto_optimal_resource_containers,
|
|
rc,
|
|
ref,
|
|
dominance,
|
|
la,
|
|
vis )
|
|
{
|
|
Label first_label, cur_label, new_label
|
|
Set of Labels unprocessed_labels, labels_cur_vertex
|
|
initialize first_label with rc
|
|
INSERT(unprocessed_labels, first_label)
|
|
<b>while</b>(unprocessed_labels != Ø)
|
|
cur_label := EXTRACTMIN(unprocessed_labels) ◁ vis.on_label_popped(cur_label)
|
|
<b>if</b>(cur_label is not dominated)
|
|
vertex i = ResidentVertex(cur_label)
|
|
perform pairwise dominance check over labels resident at i
|
|
mark all dominated labels as dominated
|
|
DELETE all labels which are dominated AND processed
|
|
<b>if</b>(cur_label is not dominated) ◁ vis.on_label_not_dominated(cur_label)
|
|
mark cur_label as processed
|
|
<b>for each</b> arc (i, j) in the forward star of i
|
|
new_label := ref(cur_label)
|
|
<b>if</b>(new_label is not feasible) ◁ vis.on_label_not_feasible(new_label)
|
|
DELETE(new_label)
|
|
<b>else</b> ◁ vis.on_label_feasible(new_label)
|
|
INSERT(unprocessed_labels, new_label)
|
|
INSERT(set of labels resident at j,new_label)
|
|
<b>else</b> ◁ vis.on_label_dominated(cur_label)
|
|
DELETE(cur_label)
|
|
<b>if</b>(t could be reached from s)
|
|
<b>for each</b> label resident at t
|
|
INSERT(pareto_optimal_resource_containers, label.resource_container)
|
|
recursively construct pareto_optimal_path
|
|
INSERT(pareto_optimal_solutions, pareto_optimal_path)
|
|
<b>if</b>(only one Pareto-optimal solution is sought)
|
|
BREAK
|
|
}
|
|
</pre>
|
|
|
|
<h3>Where Defined</h3>
|
|
|
|
<a href="../../../boost/graph/r_c_shortest_paths.hpp"><tt>boost/graph/r_c_shortest_paths.hpp</tt></a>
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
IN: <tt>const Graph& g</tt>
|
|
<blockquote>
|
|
The graph object on which the algorithm is applied. The type <tt>Graph</tt> must be directed and must be a model of <a href="./IncidenceGraph.html">Incidence Graph</a> and <a href="./PropertyGraph.html">PropertyGraph</a>.
|
|
</blockquote>
|
|
IN: <tt>const VertexIndexMap& vertex_index_map</tt>
|
|
<blockquote>
|
|
A <a href="../../property_map/doc/ReadablePropertyMap.html">ReadablePropertyMap</a> mapping vertex descriptors to integers in [0, <tt>num_vertices(g)</tt>).
|
|
</blockquote>
|
|
IN: <tt>const EdgeIndexMap& edge_index_map</tt>
|
|
<blockquote>
|
|
A <a href="../../property_map/doc/ReadablePropertyMap.html">ReadablePropertyMap</a> mapping edge descriptors to integers in [0, <tt>num_edges(g)</tt>).
|
|
</blockquote>
|
|
IN: <tt>typename graph_traits<Graph>::vertex_descriptor s</tt>
|
|
<blockquote>
|
|
A vertex descriptor describing the start vertex of the path.
|
|
</blockquote>
|
|
IN: <tt>typename graph_traits<Graph>::vertex_descriptor t</tt>
|
|
<blockquote>
|
|
A vertex descriptor describing the end vertex of the path.
|
|
</blockquote>
|
|
OUT: <tt>std::vector<std::vector<typename graph_traits<Graph>::edge_descriptor> >&
|
|
pareto_optimal_solutions</tt>
|
|
<blockquote>
|
|
A container for storing the Pareto-optimal (undominated) solutions (<i>s</i>-<i>t</i>-paths) in the overloads where all Pareto-optimal solutions are returned. The paths are returned as sequences of edge descriptors in reverse order (from <tt>t</tt> to <tt>s</tt>).
|
|
</blockquote>
|
|
OUT: <tt>std::vector<Resource_Container>& pareto_optimal_resource_containers</tt>
|
|
<blockquote>
|
|
A container for storing the Pareto-optimal resource containers in the overloads where all Pareto-optimal solutions are returned.
|
|
</blockquote>
|
|
OUT: <tt>std::vector<typename graph_traits<Graph>::edge_descriptor>&
|
|
pareto_optimal_solution</tt>
|
|
<blockquote>
|
|
A container for storing the first Pareto-optimal (undominated) solution (<i>s</i>-<i>t</i>-path) in the overloads where only one Pareto-optimal solution is returned. The path is returned as a sequence of edge descriptors in reverse order (from <tt>t</tt> to <tt>s</tt>). This argument is not modified if there are no solutions.
|
|
</blockquote>
|
|
OUT: <tt>Resource_Container& pareto_optimal_resource_container</tt>
|
|
<blockquote>
|
|
A <tt>Resource_Container</tt> object for storing the Pareto-optimal resource container corresponding to the first Pareto-optimal path in the overloads where only one Pareto-optimal solution is returned. This argument is not modified if there are no solutions.
|
|
</blockquote>
|
|
IN: <tt>const Resource_Container& rc</tt>
|
|
<blockquote>
|
|
An object specifying the initial resource consumptions at vertex <tt>s</tt>. The type <tt>Resource_Container</tt> must be a model of the ResourceContainer concept.
|
|
</blockquote>
|
|
IN: <tt>Resource_Extension_Function& ref</tt>
|
|
<blockquote>
|
|
A <a href="http://www.boost.org/sgi/stl/functors.html">function object</a> or function pointer or function specifying how a label is to be extended along an arc. The type <tt>Resource_Extension_Function</tt> must be a model of the ResourceExtensionFunction concept.
|
|
</blockquote>
|
|
IN: <tt>Dominance_Function& dominance</tt>
|
|
<blockquote>
|
|
A <a href="http://www.boost.org/sgi/stl/functors.html">function object</a> or function pointer or function specifying a dominance relation between two labels. The type <tt>Dominance_Function</tt> must be a model of the DominanceFunction concept.
|
|
</blockquote>
|
|
IN: <tt>Label_Allocator la</tt>
|
|
<blockquote>
|
|
An object of type <tt>Label_Allocator</tt> specifying a strategy for the memory management of the labels. It must offer the same interface as <tt>std::allocator<r_c_shortest_paths_label<Graph, Resource_Container> ></tt>. There is a default type <tt>default_r_c_shortest_paths_allocator</tt> for this parameter using the STL standard allocator. If the third or the fourth overload of the function is used, an object of this type is used as <tt>Label_Allocator</tt> parameter. If the first or the second overload is used, one must specify both a <tt>Label_Allocator</tt> and a <tt>Visitor</tt> parameter. If one wants to develop a user-defined type only for <tt>Visitor</tt>, one can use <tt>default_r_c_shortest_paths_allocator</tt> as <tt>Label_Allocator</tt> parameter. If one wants to use a specialized allocator, one can specify an arbitrary type as template parameter for the value type to the allocator; it is rebound to the correct type.
|
|
</blockquote>
|
|
IN: <tt>Visitor vis</tt>
|
|
<blockquote>
|
|
A visitor object specifying what operations are to be performed at the event points in the algorithm. The type <tt>Visitor</tt> must be a model of the ResourceConstrainedShortestPathsVisitor concept. There is a default type <tt>default_r_c_shortest_paths_visitor</tt> for this parameter with empty function bodies. If the third or the fourth overload of the function is used, an object of this type is used as <tt>Visitor</tt> parameter. If the first or the second overload is used, one must specify both a <tt>Label_Allocator</tt> and a <tt>Visitor</tt> parameter. If one wants to use only a specialized allocator, one can use <tt>default_r_c_shortest_paths_visitor</tt> as <tt>Visitor</tt> parameter.
|
|
</blockquote>
|
|
|
|
<h4>Preconditions</h4>
|
|
|
|
<ul>
|
|
<li>
|
|
<tt>s</tt> and <tt>t</tt> are valid vertex descriptors for <tt>g</tt>.
|
|
<li>
|
|
<tt>rc</tt> is within the resource windows at <tt>s</tt>, i.e., it constitutes a feasible <tt>Resource_Container</tt> object at <tt>s</tt> (see <a href="#Discussion">discussion</a>).
|
|
</ul>
|
|
|
|
<h4>Throws</h4>
|
|
|
|
<p>
|
|
The function itself does not throw any exceptions. However, depending on the template parameters, exceptions may be thrown from within the function.
|
|
</p>
|
|
|
|
<h4>Complexity</h4>
|
|
|
|
<p>
|
|
The time complexity is problem-dependent. For a non-elementary problem or for a problem on a graph without negative cycles, the complexity is polynomial in the number of vertices and edges and a term dependent on the resources and resource extension functions used. For the elementary problem on a graph with negative cycles, the complexity is exponential in the number of vertices and edges and a term dependent on the resources and resource extension functions used.
|
|
</p>
|
|
|
|
<a name="Discussion"><h3>Discussion</h3></a>
|
|
|
|
<p>
|
|
The function leaves a lot of work to the user. It is almost like a small framework for SPPRCs. This, however, is a property inherent to the problem. It is entirely up to the user to make sure that he stores the ‘right’ resources in his resource container object, that the resource extension function extends a label in the desired way, and that the dominance function declares the ‘right’ labels as dominated and not dominated. In particular, the precondition that the initial ResourceContainer object supplied to the function must be feasible is as important as it is unpleasant. The implementation does not check this and, hence, sacrifices comfort for genericity here. It was a design decision not to make any assumptions with respect to the relationship between the type modelling ResourceContainer and the vertex properties of the graph type.
|
|
</p>
|
|
|
|
<p>
|
|
In case the underlying graph does not contain negative cycles (cycles with overall negative resource consumption for the unconstrained resource whose consumption is to be minimized, such as cost or distance), the resulting paths will always be elementary, i.e., without repetitions of vertices. In the presence of negative cycles, the algorithm is finite if there is at least one strictly increasing resource, i.e., one resource with strictly positive resource consumption on all arcs (this is a sufficient condition). Otherwise, one must provide a customized type for the ResourceContainer concept to ensure finiteness. See, for example<br>
|
|
Feillet, D.; Dejax, P.; Gendreau, M.; Gueguen, C. (2004):<br>
|
|
An Exact Algorithm for the Elementary Shortest Path Problem with Resource Constraints: Application to Some Vehicle Routing Problems<br>
|
|
Networks, vol. 44, pp. 216–229.
|
|
</p>
|
|
|
|
<p>
|
|
Experience shows that for ‘small’ resource containers, it may be useful to try a specialized small object allocator, e.g., from the Boost Pool library. For larger resource containers (i.e., for a large number of resources), the default allocator is the right choice.
|
|
</p>
|
|
|
|
<p>
|
|
There is a utility function called <tt>check_path</tt> that can be used for debugging purposes, if <tt>r_c_shortest_paths</tt> returns a path as feasible and Pareto-optimal and the user is of the opinion that the path is either infeasible or not optimal:
|
|
<pre>
|
|
template<class Graph,
|
|
class Resource_Container,
|
|
class Resource_Extension_Function>
|
|
void check_r_c_path( const Graph& g,
|
|
const std::vector<typename graph_traits<Graph>::edge_descriptor>& ed_vec_path,
|
|
const Resource_Container& initial_resource_levels,
|
|
bool b_result_must_be_equal_to_desired_final_resource_levels,
|
|
const Resource_Container& desired_final_resource_levels,
|
|
Resource_Container& actual_final_resource_levels,
|
|
const Resource_Extension_Function& ref,
|
|
bool& b_is_a_path_at_all,
|
|
bool& b_feasible,
|
|
bool& b_correctly_extended,
|
|
typename graph_traits<Graph>::edge_descriptor&
|
|
ed_last_extended_arc )
|
|
</pre>
|
|
</p>
|
|
|
|
The boolean parameters have the following meaning:
|
|
<ul>
|
|
<li>
|
|
If <tt>b_result_must_be_equal_to_desired_final_resource_levels==true</tt>, computed accumulated final resource levels must be equal to <tt>desired_final_resource_levels</tt>.
|
|
<li>
|
|
If <tt>b_result_must_be_equal_to_desired_final_resource_levels==false</tt>, computed accumulated final resource levels must be less than or equal to <tt>desired_final_resource_levels</tt>.
|
|
<li>
|
|
<tt>b_is_a_path_at_all==true</tt> if and only if <tt>ed_vec_path</tt> specifies a walk in a graph-theoretical sense, i.e., a sequence of arcs where the target of an arc is the source of the next arc, or a reverse walk, where the source of one arc is the target of the next arc. Note that in the world of resource-constrained shortest paths, a path need not be elementary: Repetitions of vertices or arcs are allowed. When the graph does not have any cycles of negative cost (traversal cost, travel time etc.), the paths returned by <tt>r_c_shortest_paths</tt> will be elementary. Otherwise, one must use appropriate resource containers and resource extension and dominance functions (see the abovementioned references).
|
|
<li>
|
|
<tt>b_feasible==true</tt> if and only if <tt>b_is_a_path_at_all==true</tt> and all resource windows at all vertices along the path are maintained.
|
|
<li>
|
|
When <tt>b_result_must_be_equal_to_desired_final_resource_levels==true</tt> (<tt>false</tt>), <tt>b_correctly_extended==true</tt> if and only if <tt>b_feasible==true</tt> and the computed resource levels at the end of the path are equal to (less than or equal to) the desired final resource levels as specified in <tt>desired_final_resource_levels</tt>.
|
|
</ul>
|
|
|
|
<p>
|
|
<tt>ed_last_extended_arc</tt> stores the edge descriptor of the last extended arc. If <tt>ed_vec_path</tt> is a path of positive length and <tt>b_feasible==false</tt>, <tt>ed_last_extended_arc</tt> is the edge descriptor of the arc at whose target vertex the first violation of a resource window occured.
|
|
</p>
|
|
|
|
<h3>Examples</h3>
|
|
|
|
<p>
|
|
The file <a href="../example/r_c_shortest_paths_example.cpp">
|
|
<rr>example/r_c_shortest_paths_example.cpp</tt></a> provides examples for how SPPRCs can be solved with the <tt>r_c_shortest_paths</tt> functions. There is an example for an SPP without resource constraints and an example for a shortest path problem with time windows.<br>
|
|
It is obvious that one would not use the algorithm for SPPs without resource constraints, because there are faster algorithms for this problem, but one would expect a code for the SPP with resource constraints to be able to handle such a case.
|
|
</p>
|
|
|
|
<br>
|
|
<hr>
|
|
<table>
|
|
<tr valign=top>
|
|
<td
|
|
nowrap>Copyright © 2006</td>
|
|
<td>
|
|
Michael Drexl (michaeldrexl at web dot de)
|
|
</td></tr></table>
|
|
|
|
</body>
|
|
</html>
|