47 double end = std::numeric_limits<double>::max();
55template<
class E,
class V>
100 effort = std::numeric_limits<double>::max();
108 typedef double(*
Operation)(
const E*
const,
const V*
const, double);
114 const bool havePermissions,
const bool haveRestrictions) :
163 for (
auto& edgeInfo :
myFound) {
170 fromInfo.effort = 0.;
171 fromInfo.heuristicEffort = 0.;
172 fromInfo.prev =
nullptr;
181 virtual void reset(
const V*
const vehicle) {
199 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
200 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) = 0;
208 const E* from,
double fromPos,
209 const E* to,
double toPos,
210 const V*
const vehicle,
211 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
212 if (from != to || fromPos <= toPos) {
213 return compute(from, to, vehicle, msTime, into, silent);
215 return computeLooped(from, to, vehicle, msTime, into, silent);
222 inline bool computeLooped(
const E* from,
const E* to,
const V*
const vehicle,
223 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
225 return compute(from, to, vehicle, msTime, into, silent);
227 double minEffort = std::numeric_limits<double>::max();
228 std::vector<const E*> best;
230 for (
const std::pair<const E*, const E*>& follower : from->getViaSuccessors(vClass)) {
231 std::vector<const E*> tmp;
232 compute(follower.first, to, vehicle, msTime, tmp,
true);
233 if (tmp.size() > 0) {
235 if (effort < minEffort) {
241 if (minEffort != std::numeric_limits<double>::max()) {
242 into.push_back(from);
243 std::copy(best.begin(), best.end(), std::back_inserter(into));
251 inline bool isProhibited(
const E*
const edge,
const V*
const vehicle,
double t)
const {
253 && (
myEdgeInfos[edge->getNumericalID()].prohibitedPermissions & vehicle->getVClass()) != vehicle->getVClass()
254 &&
myEdgeInfos[edge->getNumericalID()].prohibitionBegin <= t
255 &&
myEdgeInfos[edge->getNumericalID()].prohibitionEnd == std::numeric_limits<double>::max())
259 inline double getTravelTime(
const E*
const e,
const V*
const v,
const double t,
const double effort)
const {
260 return myTTOperation ==
nullptr ? effort : (*myTTOperation)(e, v, t);
263 inline void updateViaEdgeCost(
const E* viaEdge,
const V*
const v,
double& time,
double& effort,
double& length)
const {
264 while (viaEdge !=
nullptr && viaEdge->isInternal()) {
265 const double viaEffortDelta = this->
getEffort(viaEdge, v, time);
267 effort += viaEffortDelta;
268 length += viaEdge->getLength();
269 viaEdge = viaEdge->getViaSuccessors().front().second;
273 inline void updateViaCost(
const E*
const prev,
const E*
const e,
const V*
const v,
double& time,
double& effort,
double& length)
const {
274 if (prev !=
nullptr) {
275 for (
const std::pair<const E*, const E*>& follower : prev->getViaSuccessors()) {
276 if (follower.first == e) {
282 const double effortDelta = this->
getEffort(e, v, time);
283 effort += effortDelta;
285 length += e->getLength();
288 bool isValid(
const std::vector<const E*>& edges,
const V*
const v,
double t)
const {
289 for (
const E*
const e : edges) {
297 virtual double recomputeCosts(
const std::vector<const E*>& edges,
const V*
const v,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
301 if (lengthp ==
nullptr) {
306 const E* prev =
nullptr;
307 for (
const E*
const e : edges) {
315 inline double recomputeCostsPos(
const std::vector<const E*>& edges,
const V*
const v,
double fromPos,
double toPos,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
317 if (!edges.empty()) {
318 const E* first = edges.front();
319 if (first->getLength() == 0) {
320 if (edges.size() > 1 && edges[1]->getLength() > 0) {
326 const E* last = edges.back();
327 if (last->getLength() == 0) {
328 if (edges.size() > 1 && edges[edges.size() - 2]->getLength() > 0) {
329 last = edges[edges.size() - 2];
334 assert(first->getLength() > 0);
335 assert(last->getLength() > 0);
338 effort -= firstEffort * fromPos / first->getLength();
339 effort -= lastEffort * (last->getLength() - toPos) / last->getLength();
340 if (lengthp !=
nullptr) {
341 (*lengthp) -= fromPos + last->getLength() - toPos;
348 inline double setHint(
const typename std::vector<const E*>::const_iterator routeBegin,
const typename std::vector<const E*>::const_iterator routeEnd,
const V*
const v,
SUMOTime msTime) {
353 init((*routeBegin)->getNumericalID(), msTime);
354 for (
auto e = routeBegin + 1; e != routeEnd; ++e) {
358 auto& edgeInfo =
myEdgeInfos[(*e)->getNumericalID()];
359 edgeInfo.heuristicEffort = effort;
360 edgeInfo.prev = prev;
362 edgeInfo.effort = effort;
363 edgeInfo.leaveTime = time;
366#ifdef ROUTER_DEBUG_HINT
367 if (ROUTER_DEBUG_COND) {
368 std::cout <<
"DEBUG: hit=" << (*e)->getID()
369 <<
" TT=" << edgeInfo.
effort
370 <<
" EF=" << this->
getEffort(*e, v, edgeInfo.leaveTime)
371 <<
" HT=" << edgeInfo.heuristicEffort <<
"\n";
379 inline double getEffort(
const E*
const e,
const V*
const v,
double t)
const {
381 &&
myEdgeInfos[e->getNumericalID()].prohibitionEnd > t
382 &&
myEdgeInfos[e->getNumericalID()].prohibitionBegin <= t
383 && (
myEdgeInfos[e->getNumericalID()].prohibitedPermissions & v->getVClass()) != v->getVClass()) {
385 return (
myEdgeInfos[e->getNumericalID()].prohibitionEnd - t) + (*myOperation)(e, v,
myEdgeInfos[e->getNumericalID()].prohibitionEnd);
412 myEdgeInfos[item.first->getNumericalID()].prohibitionBegin = -1;
413 myEdgeInfos[item.first->getNumericalID()].prohibitionEnd = -1;
415 for (
auto item : toProhibit) {
416 myEdgeInfos[item.first->getNumericalID()].prohibitionBegin = item.second.begin;
417 myEdgeInfos[item.first->getNumericalID()].prohibitionEnd = item.second.end;
418 myEdgeInfos[item.first->getNumericalID()].prohibitedPermissions = item.second.permissions;
434 std::vector<const E*> tmp;
435 while (rbegin !=
nullptr) {
436 tmp.push_back(rbegin->
edge);
437 rbegin = rbegin->
prev;
439 std::copy(tmp.rbegin(), tmp.rend(), std::back_inserter(edges));
471 std::vector<typename SUMOAbstractRouter<E, V>::EdgeInfo>
myEdgeInfos;
476 std::vector<typename SUMOAbstractRouter<E, V>::EdgeInfo*>
myFound;
#define WRITE_MESSAGE(msg)
std::string elapsedMs2string(long long int t)
convert ms to string for log output
const SVCPermissions SVCAll
all VClasses are allowed
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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)
void informf(const std::string &format, T value, Targs... Fargs)
adds a new formatted message
double prohibitionBegin
the time at which a temporary prohibition begins
bool visited
whether the edge was already evaluated
EdgeInfo(const E *const e)
Constructor.
const E *const edge
The current edge.
double leaveTime
The time the vehicle leaves the edge.
double effort
Effort to reach the edge.
const EdgeInfo * prev
The previous edge.
double heuristicEffort
Estimated effort to reach the edge (effort + lower bound on remaining effort)
double prohibitionEnd
the time at which a temporary prohibition ends
SVCPermissions prohibitedPermissions
temporary permission change
Operation myTTOperation
The object's operation to perform for travel times.
long long int myNumQueries
const bool myHavePermissions
whether edge permissions need to be considered
bool myBulkMode
whether we are currently operating several route queries in a bulk
long long int myQueryVisits
counters for performance logging
bool computeLooped(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 if from == to,...
virtual SUMOAbstractRouter * clone()=0
long long int myQueryStartTime
the time spent querying in milliseconds
virtual void setBulkMode(const bool mode)
SUMOAbstractRouter & operator=(const SUMOAbstractRouter &s)=delete
Invalidated assignment operator.
std::map< const E *, RouterProhibition > Prohibitions
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo > myEdgeInfos
The container of edge information.
bool compute(const E *from, double fromPos, const E *to, double toPos, 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,...
SUMOAbstractRouter(SUMOAbstractRouter *other)
Copy Constructor.
double(* Operation)(const E *const, const V *const, double)
Type of the function that is used to retrieve the edge effort.
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
long long int myQueryTimeSum
void updateViaCost(const E *const prev, const E *const e, const V *const v, double &time, double &effort, double &length) const
virtual void reset(const V *const vehicle)
reset internal caches, used by CHRouter
bool hasProhibitions() const
const std::string & getType() 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
SUMOAbstractRouter(const std::string &type, bool unbuildIsWarning, Operation operation, Operation ttOperation, const bool havePermissions, const bool haveRestrictions)
Constructor.
virtual void prohibit(const Prohibitions &toProhibit)
Prohibitions myProhibited
The list of explicitly prohibited edges and estimated end time of prohibition.
void updateViaEdgeCost(const E *viaEdge, const V *const v, double &time, double &effort, double &length) const
double setHint(const typename std::vector< const E * >::const_iterator routeBegin, const typename std::vector< const E * >::const_iterator routeEnd, const V *const v, SUMOTime msTime)
void init(const int edgeID, const SUMOTime msTime)
void setAutoBulkMode(const bool mode)
bool myAmClean
whether we are already initialized
virtual bool supportsProhibitions() const
const bool myHaveRestrictions
whether edge restrictions need to be considered
const SUMOAbstractRouter< E, V >::EdgeInfo & getEdgeInfo(int index) const
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 bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
bool isValid(const std::vector< const E * > &edges, const V *const v, double t) const
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
virtual void setMsgHandler(MsgHandler *const errorMsgHandler)
void endQuery(int visits)
virtual ~SUMOAbstractRouter()
Destructor.
MsgHandler * myErrorMsgHandler
the handler for routing errors
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo * > myFrontierList
A container for reusage of the min edge heap.
double recomputeCostsPos(const std::vector< const E * > &edges, const V *const v, double fromPos, double toPos, SUMOTime msTime, double *lengthp=nullptr) const
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo * > myFound
list of visited Edges (for resetting)
const std::string myType
the type of this router
static long getCurrentMillis()
Returns the current time in milliseconds.
#define UNUSED_PARAMETER(x)
Prohibitions and their estimated end time.
SVCPermissions permissions