3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
24 ///\brief Algorithm for the Resource Constrained Shortest Path problem.
27 ///\todo dijkstraZero() solution should be revised.
29 #include <lemon/list_graph.h>
30 #include <lemon/graph_utils.h>
31 #include <lemon/error.h>
32 #include <lemon/maps.h>
33 #include <lemon/tolerance.h>
34 #include <lemon/dijkstra.h>
35 #include <lemon/path.h>
36 #include <lemon/counter.h>
39 ///Algorithms for the Resource Constrained Shortest Path Problem
44 class CM=typename Graph:: template EdgeMap<double>,
46 class ConstrainedShortestPath
50 GRAPH_TYPEDEFS(typename Graph);
52 typedef SimplePath<Graph> Path;
55 Tolerance<double> tol;
66 typedef typename CM::Key Key;
68 CoMap(CM &c,DM &d) :_cost(c), _delay(d), _lambda(0) {}
69 double lambda() const { return _lambda; }
70 void lambda(double l) { _lambda=l; }
71 Value operator[](Key &e) const
73 return _cost[e]+_lambda*_delay[e];
78 Dijkstra<Graph, CoMap> _dij;
83 ConstrainedShortestPath(Graph &g, CM &cost, DM &delay)
84 : _g(g), _cost(cost), _delay(delay),
85 _co_map(cost,delay), _dij(_g,_co_map) {}
88 ///Compute the cost of a path
89 double cost(const Path &p)
93 for(typename Path::EdgeIt e(p);e!=INVALID;++e) s+=_cost[e];
97 ///Compute the delay of a path
98 double delay(const Path &p)
101 for(typename Path::EdgeIt e(p);e!=INVALID;++e) s+=_delay[e];
105 ///Runs the LARAC algorithm
107 ///This function runs a Lagrange relaxation based heuristic to find
108 ///a delay constrained least cost path.
109 ///\param s source node
110 ///\param t target node
111 ///\retval lo_bo a lower bound on the optimal solution
112 ///\return the found path or an empty
113 Path larac(Node s, Node t, double delta, double &lo_bo)
115 NoCounter cnt("LARAC iterations: ");
117 double cp,cq,dp,dq,cr,dr;
122 Dijkstra<Graph,CM> dij(_g,_cost);
125 if(!dij.reached(t)) return Path();
130 if(delay(p)<=delta) return p;
132 Dijkstra<Graph,DM> dij(_g,_delay);
139 if(delay(q)>delta) return Path();
141 lambda=(cp-cq)/(dq-dp);
142 _co_map.lambda(lambda);
148 if(!tol.less(cr+lambda*dr,cp+lambda*dp)) {
149 lo_bo=cq+lambda*(dq-delta);
152 else if(tol.less(dr,delta))
158 else if(tol.less(delta,dr))
170 } //END OF NAMESPACE LEMON