19 #ifndef DijkstraRouter_h 20 #define DijkstraRouter_h 62 template<
class E,
class V,
class BASE>
95 effort = std::numeric_limits<double>::max();
115 return nod1->
edge->getNumericalID() > nod2->
edge->getNumericalID();
123 DijkstraRouter(
const std::vector<E*>& edges,
bool unbuildIsWarning,
typename BASE::Operation effortOperation,
124 typename BASE::Operation ttOperation =
nullptr,
bool silent =
false,
EffortCalculator* calc =
nullptr) :
125 BASE(
"DijkstraRouter", effortOperation, ttOperation),
128 for (
typename std::vector<E*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
146 for (
typename std::vector<EdgeInfo*>::iterator i =
myFound.begin(); i !=
myFound.end(); i++) {
155 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
156 SUMOTime msTime, std::vector<const E*>& into) {
157 assert(from != 0 && (vehicle == 0 || to != 0));
159 if (this->isProhibited(from, vehicle)) {
160 myErrorMsgHandler->
inform(
"Vehicle '" + vehicle->getID() +
"' is not allowed on source edge '" + from->getID() +
"'.");
163 if (this->isProhibited(to, vehicle)) {
164 myErrorMsgHandler->
inform(
"Vehicle '" + vehicle->getID() +
"' is not allowed on destination edge '" + to->getID() +
"'.");
168 #ifdef DijkstraRouter_DEBUG_QUERY 169 std::cout <<
"DEBUG: starting search for '" << vehicle->getID() <<
"' time: " <<
STEPS2TIME(msTime) <<
"\n";
172 if (this->myBulkMode) {
194 const E*
const minEdge = minimumInfo->
edge;
195 #ifdef DijkstraRouter_DEBUG_QUERY 196 std::cout <<
"DEBUG: hit '" << minEdge->getID() <<
"' Eff: " << minimumInfo->
effort <<
", Leave: " << minimumInfo->
leaveTime <<
" Q: ";
198 std::cout << (*it)->effort <<
"," << (*it)->edge->getID() <<
" ";
205 this->endQuery(num_visited);
206 #ifdef DijkstraRouter_DEBUG_QUERY_PERF 207 std::cout <<
"visited " +
toString(num_visited) +
" edges (final path length=" +
toString(into.size()) +
" edges=" +
toString(into) +
")\n";
213 myFound.push_back(minimumInfo);
215 const E* viaEdge = minimumInfo->
via;
218 while (viaEdge !=
nullptr && viaEdge != minEdge) {
219 const double viaEffortDelta = this->getEffort(viaEdge, vehicle, leaveTime);
220 leaveTime += this->
getTravelTime(viaEdge, vehicle, leaveTime, viaEffortDelta);
221 effort += viaEffortDelta;
222 viaEdge = viaEdge->getViaSuccessors().front().first;
224 const double effortDelta = this->getEffort(minEdge, vehicle, leaveTime);
226 effort += effortDelta;
230 assert(effort >= minimumInfo->
effort);
231 assert(leaveTime >= minimumInfo->
leaveTime);
233 for (
const std::pair<const E*, const E*>& follower : minEdge->getViaSuccessors(vClass)) {
236 if (this->isProhibited(follower.first, vehicle)) {
239 const double oldEffort = followerInfo->
effort;
240 if (!followerInfo->
visited && effort < oldEffort) {
243 followerInfo->
prev = minimumInfo;
244 followerInfo->
via = follower.second;
245 if (oldEffort == std::numeric_limits<double>::max()) {
256 this->endQuery(num_visited);
257 #ifdef DijkstraRouter_DEBUG_QUERY_PERF 258 std::cout <<
"visited " +
toString(num_visited) +
" edges (unsuccessful path length: " +
toString(into.size()) +
")\n";
261 myErrorMsgHandler->
inform(
"No connection between edge '" + from->getID() +
"' and edge '" + to->getID() +
"' found.");
269 std::vector<const E*> tmp;
270 while (rbegin != 0) {
271 tmp.push_back(rbegin->
edge);
272 rbegin = rbegin->
prev;
274 std::copy(tmp.rbegin(), tmp.rend(), std::back_inserter(edges));
283 typename BASE::Operation effortOperation,
typename BASE::Operation ttOperation,
bool silent,
EffortCalculator* calc) :
284 BASE(
"DijkstraRouter", effortOperation, ttOperation),
288 for (
const EdgeInfo& ei : edgeInfos) {
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
void buildPathFrom(const EdgeInfo *rbegin, std::vector< const E *> &edges)
Builds the path from marked edges.
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)
Builds the route between the given edges using the minimum effort at the given time The definition of...
double leaveTime
The time the vehicle leaves the edge.
MsgHandler *const myErrorMsgHandler
the handler for routing errors
std::vector< EdgeInfo * > myFound
list of visited Edges (for resetting)
std::vector< EdgeInfo > myEdgeInfos
The container of edge information.
EdgeInfo & operator=(const EdgeInfo &s)=delete
Invalidated assignment operator.
double effort
Effort to reach the edge.
virtual SUMOAbstractRouter< E, V > * clone()
const EdgeInfo * prev
The previous edge.
the effort calculator interface
EffortCalculator *const myExternalEffort
const EdgeInfo & getEdgeInfo(int index) const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
virtual void update(const int edge, const int prev, const double length)=0
Computes the shortest path through a network using the Dijkstra algorithm.
double getTravelTime(const ROEdge *const edge, const ROVehicle *const, double)
bool visited
The previous edge.
const E *const edge
The current edge.
EdgeInfoByEffortComparator myComparator
DijkstraRouter(const std::vector< E *> &edges, bool unbuildIsWarning, typename BASE::Operation effortOperation, typename BASE::Operation ttOperation=nullptr, bool silent=false, EffortCalculator *calc=nullptr)
Constructor.
std::vector< EdgeInfo * > myFrontierList
A container for reusage of the min edge heap.
virtual ~DijkstraRouter()
Destructor.
void inform(std::string msg, bool addType=true)
adds a new error to the list
EdgeInfo(const E *const e)
Constructor.
const E * via
The optional internal edge corresponding to prev.
bool mySilent
whether to supress warning/error if no route was found
DijkstraRouter(const std::vector< EdgeInfo > &edgeInfos, bool unbuildIsWarning, typename BASE::Operation effortOperation, typename BASE::Operation ttOperation, bool silent, EffortCalculator *calc)
vehicles ignoring classes
bool operator()(const EdgeInfo *nod1, const EdgeInfo *nod2) const
Comparing method.