45#define DijkstraRouter_DEBUG_QUERY_VISITED_OUT std::cerr
63template<
class E,
class V>
75 return nod1->
edge->getNumericalID() > nod2->
edge->getNumericalID();
85 const bool havePermissions =
false,
const bool haveRestrictions =
false) :
86 SUMOAbstractRouter<E, V>(
"DijkstraRouter", unbuildIsWarning, effortOperation, ttOperation, havePermissions, haveRestrictions),
88 for (
typename std::vector<E*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
106 bool compute(
const E* from,
const E* to,
const V*
const vehicle,
107 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
108 assert(from !=
nullptr && (vehicle ==
nullptr || to !=
nullptr));
125#ifdef DijkstraRouter_DEBUG_QUERY
129 const bool ignoreTransient = vehicle ==
nullptr ? false : vehicle->ignoreTransientPermissions();
130 std::tuple<const E*, const V*, SUMOTime> query = std::make_tuple(from, vehicle, msTime);
132#ifdef DijkstraRouter_DEBUG_BULKMODE
134 std::cout <<
" invalid bulk mode. myLastQuery="
139 << std::get<0>(query)->getID() <<
","
140 << std::get<1>(query)->getID() <<
","
144 std::cout <<
" using bulk mode\n";
147 const auto& toInfo = this->
myEdgeInfos[to->getNumericalID()];
148 if (toInfo.visited) {
151#ifdef DijkstraRouter_DEBUG_QUERY_PERF
152 std::cout <<
" instant bulk success for vehicle " << vehicle->getID() <<
"\n";
157 this->
init(from->getNumericalID(), msTime);
166#ifdef DijkstraRouter_DEBUG_QUERY_VISITED
173 const E*
const minEdge = minimumInfo->edge;
174#ifdef DijkstraRouter_DEBUG_QUERY
175 std::cout <<
"DEBUG: hit=" << minEdge->getID()
176 <<
" TT=" << minimumInfo->effort
177 <<
" EF=" << this->
getEffort(minEdge, vehicle, minimumInfo->leaveTime)
178 <<
" Leave: " << minimumInfo->leaveTime <<
" Q: ";
179#ifdef DijkstraRouter_DEBUG_QUERY_FRONTIER
181 std::cout <<
"\n " << edgeInfo->effort <<
", " << edgeInfo->edge->getID();
186#ifdef DijkstraRouter_DEBUG_QUERY_VISITED
187 DijkstraRouter_DEBUG_QUERY_VISITED_OUT <<
" <edge id=\"" << minEdge->getID() <<
"\" index=\"" << num_visited <<
"\" cost=\"" << minimumInfo->effort <<
"\" time=\"" << minimumInfo->leaveTime <<
"\"/>\n";
189 minimumInfo->visited =
true;
194 myExternalEffort->
update(minEdge->getNumericalID(), minimumInfo->prev->edge->getNumericalID(), minEdge->getLength());
198#ifdef DijkstraRouter_DEBUG_QUERY_PERF
200 std::cout <<
"visited " +
toString(num_visited) +
" edges (final path length=" +
toString(into.size()) +
" cost=" << cost <<
" edges=" +
toString(into) +
")\n";
202#ifdef DijkstraRouter_DEBUG_QUERY_VISITED
209 this->
myFound.push_back(minimumInfo);
210 const double effortDelta = this->
getEffort(minEdge, vehicle, minimumInfo->leaveTime);
211 const double leaveTime = minimumInfo->leaveTime + this->
getTravelTime(minEdge, vehicle, minimumInfo->leaveTime, effortDelta);
213 myExternalEffort->
update(minEdge->getNumericalID(), minimumInfo->prev->edge->getNumericalID(), minEdge->getLength());
216 for (
const std::pair<const E*, const E*>& follower : minEdge->getViaSuccessors(vClass, ignoreTransient)) {
217 auto& followerInfo = this->
myEdgeInfos[follower.first->getNumericalID()];
219 if (this->
isProhibited(follower.first, vehicle, leaveTime)) {
222 double effort = minimumInfo->effort + effortDelta;
223 double time = leaveTime;
225 assert(effort >= minimumInfo->effort);
226 assert(time >= minimumInfo->leaveTime);
227 const double oldEffort = followerInfo.effort;
228 if (!followerInfo.visited && effort < oldEffort) {
229 followerInfo.effort = effort;
230 followerInfo.leaveTime = time;
231 followerInfo.prev = minimumInfo;
232 if (oldEffort == std::numeric_limits<double>::max()) {
237 std::find(this->myFrontierList.begin(), this->myFrontierList.end(), &followerInfo) + 1,
244#ifdef DijkstraRouter_DEBUG_QUERY_PERF
245 std::cout <<
"visited " +
toString(num_visited) +
" edges (unsuccessful path length: " +
toString(into.size()) +
")\n";
247 if (to !=
nullptr && !
mySilent && !silent) {
250#ifdef DijkstraRouter_DEBUG_QUERY_VISITED
259 const bool havePermissions,
const bool haveRestrictions) :
260 SUMOAbstractRouter<E, V>(
"DijkstraRouter", unbuildIsWarning, effortOperation, ttOperation, havePermissions, haveRestrictions),
263 for (
const auto& edgeInfo : edgeInfos) {
#define DijkstraRouter_DEBUG_QUERY_VISITED_OUT
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool operator()(const typename SUMOAbstractRouter< E, V >::EdgeInfo *nod1, const typename SUMOAbstractRouter< E, V >::EdgeInfo *nod2) const
Comparing method.
Computes the shortest path through a network using the Dijkstra algorithm.
bool mySilent
whether to suppress warning/error if no route was found
std::tuple< const E *, const V *, SUMOTime > myLastQuery
cache of the last query to enable automated bulk routing
EffortCalculator *const myExternalEffort
bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual SUMOAbstractRouter< E, V > * clone()
DijkstraRouter(const std::vector< E * > &edges, bool unbuildIsWarning, typename SUMOAbstractRouter< E, V >::Operation effortOperation, typename SUMOAbstractRouter< E, V >::Operation ttOperation=nullptr, bool silent=false, EffortCalculator *calc=nullptr, const bool havePermissions=false, const bool haveRestrictions=false)
Constructor.
EdgeInfoByEffortComparator myComparator
virtual ~DijkstraRouter()
Destructor.
DijkstraRouter(const std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo > &edgeInfos, bool unbuildIsWarning, typename SUMOAbstractRouter< E, V >::Operation effortOperation, typename SUMOAbstractRouter< E, V >::Operation ttOperation, bool silent, EffortCalculator *calc, const bool havePermissions, const bool haveRestrictions)
the effort calculator interface
virtual void setInitialState(const int edge)=0
virtual void update(const int edge, const int prev, const double length)=0
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
void informf(const std::string &format, T value, Targs... Fargs)
adds a new formatted message
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const E *const edge
The current edge.
double effort
Effort to reach the edge.
Operation myTTOperation
The object's operation to perform for travel times.
const bool myHavePermissions
whether edge permissions need to be considered
bool myBulkMode
whether we are currently operating several route queries in a bulk
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo > myEdgeInfos
The container of edge information.
Operation myOperation
The object's operation to perform.
double getTravelTime(const E *const e, const V *const v, const double t, const double effort) const
double getEffort(const E *const e, const V *const v, double t) const
bool isProhibited(const E *const edge, const V *const vehicle, double t) const
void updateViaEdgeCost(const E *viaEdge, const V *const v, double &time, double &effort, double &length) const
void init(const int edgeID, const SUMOTime msTime)
bool myAmClean
whether we are already initialized
const bool myHaveRestrictions
whether edge restrictions need to be considered
void buildPathFrom(const typename SUMOAbstractRouter< E, V >::EdgeInfo *rbegin, std::vector< const E * > &edges)
Builds the path from marked edges.
bool myAutoBulkMode
whether we are currently trying to detect bulk mode automatically
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
void endQuery(int visits)
MsgHandler * myErrorMsgHandler
the handler for routing errors
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo * > myFrontierList
A container for reusage of the min edge heap.
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo * > myFound
list of visited Edges (for resetting)