46 double end = std::numeric_limits<double>::max();
54template<
class E,
class V>
99 effort = std::numeric_limits<double>::max();
107 typedef double(*
Operation)(
const E*
const,
const V*
const, double);
113 const bool havePermissions,
const bool haveRestrictions) :
162 for (
auto& edgeInfo :
myFound) {
169 fromInfo.effort = 0.;
170 fromInfo.heuristicEffort = 0.;
171 fromInfo.prev =
nullptr;
180 virtual void reset(
const V*
const vehicle) {
198 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
199 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) = 0;
207 const E* from,
double fromPos,
208 const E* to,
double toPos,
209 const V*
const vehicle,
210 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
211 if (from != to || fromPos <= toPos) {
212 return compute(from, to, vehicle, msTime, into, silent);
214 return computeLooped(from, to, vehicle, msTime, into, silent);
221 inline bool computeLooped(
const E* from,
const E* to,
const V*
const vehicle,
222 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
224 return compute(from, to, vehicle, msTime, into, silent);
226 double minEffort = std::numeric_limits<double>::max();
227 std::vector<const E*> best;
229 for (
const std::pair<const E*, const E*>& follower : from->getViaSuccessors(vClass)) {
230 std::vector<const E*> tmp;
231 compute(follower.first, to, vehicle, msTime, tmp,
true);
232 if (tmp.size() > 0) {
234 if (effort < minEffort) {
240 if (minEffort != std::numeric_limits<double>::max()) {
241 into.push_back(from);
242 std::copy(best.begin(), best.end(), std::back_inserter(into));
245 myErrorMsgHandler->informf(
TL(
"No connection between edge '%' and edge '%' found."), from->getID(), to->getID());
250 inline bool isProhibited(
const E*
const edge,
const V*
const vehicle,
double t)
const {
252 && (
myEdgeInfos[edge->getNumericalID()].prohibitedPermissions & vehicle->getVClass()) != vehicle->getVClass()
253 &&
myEdgeInfos[edge->getNumericalID()].prohibitionBegin <= t
254 &&
myEdgeInfos[edge->getNumericalID()].prohibitionEnd == std::numeric_limits<double>::max())
258 inline double getTravelTime(
const E*
const e,
const V*
const v,
const double t,
const double effort)
const {
259 return myTTOperation ==
nullptr ? effort : (*myTTOperation)(e, v, t);
262 inline void updateViaEdgeCost(
const E* viaEdge,
const V*
const v,
double& time,
double& effort,
double& length)
const {
263 while (viaEdge !=
nullptr && viaEdge->isInternal()) {
264 const double viaEffortDelta = this->
getEffort(viaEdge, v, time);
266 effort += viaEffortDelta;
267 length += viaEdge->getLength();
268 viaEdge = viaEdge->getViaSuccessors().front().second;
272 inline void updateViaCost(
const E*
const prev,
const E*
const e,
const V*
const v,
double& time,
double& effort,
double& length)
const {
273 if (prev !=
nullptr) {
274 for (
const std::pair<const E*, const E*>& follower : prev->getViaSuccessors()) {
275 if (follower.first == e) {
281 const double effortDelta = this->
getEffort(e, v, time);
282 effort += effortDelta;
284 length += e->getLength();
287 bool isValid(
const std::vector<const E*>& edges,
const V*
const v,
double t)
const {
288 for (
const E*
const e : edges) {
296 virtual double recomputeCosts(
const std::vector<const E*>& edges,
const V*
const v,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
300 if (lengthp ==
nullptr) {
305 const E* prev =
nullptr;
306 for (
const E*
const e : edges) {
314 inline double recomputeCostsPos(
const std::vector<const E*>& edges,
const V*
const v,
double fromPos,
double toPos,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
316 if (!edges.empty()) {
317 const E* first = edges.front();
318 if (first->getLength() == 0) {
319 if (edges.size() > 1 && edges[1]->getLength() > 0) {
325 const E* last = edges.back();
326 if (last->getLength() == 0) {
327 if (edges.size() > 1 && edges[edges.size() - 2]->getLength() > 0) {
328 last = edges[edges.size() - 2];
333 assert(first->getLength() > 0);
334 assert(last->getLength() > 0);
337 effort -= firstEffort * fromPos / first->getLength();
338 effort -= lastEffort * (last->getLength() - toPos) / last->getLength();
339 if (lengthp !=
nullptr) {
340 (*lengthp) -= fromPos + last->getLength() - toPos;
347 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) {
351 const EdgeInfo* prev = &
myEdgeInfos[(*routeBegin)->getNumericalID()];
352 init((*routeBegin)->getNumericalID(), msTime);
353 for (
auto e = routeBegin + 1; e != routeEnd; ++e) {
357 auto& edgeInfo =
myEdgeInfos[(*e)->getNumericalID()];
358 edgeInfo.heuristicEffort = effort;
359 edgeInfo.prev = prev;
361 edgeInfo.effort = effort;
362 edgeInfo.leaveTime = time;
365#ifdef ROUTER_DEBUG_HINT
366 if (ROUTER_DEBUG_COND) {
367 std::cout <<
"DEBUG: hit=" << (*e)->getID()
368 <<
" TT=" << edgeInfo.effort
369 <<
" EF=" << this->
getEffort(*e, v, edgeInfo.leaveTime)
370 <<
" HT=" << edgeInfo.heuristicEffort <<
"\n";
378 inline double getEffort(
const E*
const e,
const V*
const v,
double t)
const {
380 &&
myEdgeInfos[e->getNumericalID()].prohibitionEnd > t
381 &&
myEdgeInfos[e->getNumericalID()].prohibitionBegin <= t
382 && (
myEdgeInfos[e->getNumericalID()].prohibitedPermissions & v->getVClass()) != v->getVClass()) {
384 return (
myEdgeInfos[e->getNumericalID()].prohibitionEnd - t) + (*myOperation)(e, v,
myEdgeInfos[e->getNumericalID()].prohibitionEnd);
411 myEdgeInfos[item.first->getNumericalID()].prohibitionBegin = -1;
412 myEdgeInfos[item.first->getNumericalID()].prohibitionEnd = -1;
414 for (
auto item : toProhibit) {
415 myEdgeInfos[item.first->getNumericalID()].prohibitionBegin = item.second.begin;
416 myEdgeInfos[item.first->getNumericalID()].prohibitionEnd = item.second.end;
417 myEdgeInfos[item.first->getNumericalID()].prohibitedPermissions = item.second.permissions;
420 this->myProhibited = toProhibit;
433 std::vector<const E*> tmp;
434 while (rbegin !=
nullptr) {
435 tmp.push_back(rbegin->
edge);
436 rbegin = rbegin->
prev;
438 std::copy(tmp.rbegin(), tmp.rend(), std::back_inserter(edges));
470 std::vector<typename SUMOAbstractRouter<E, V>::EdgeInfo>
myEdgeInfos;
475 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)
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
long long int myNumQueries
const bool myHavePermissions
long long int myQueryVisits
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
virtual void setBulkMode(const bool mode)
SUMOAbstractRouter & operator=(const SUMOAbstractRouter &s)=delete
Invalidated assignment operator.
std::map< const MSEdge *, RouterProhibition > Prohibitions
std::vector< typename SUMOAbstractRouter< MSEdge, SUMOVehicle >::EdgeInfo > myEdgeInfos
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 MSEdge *const, const SUMOVehicle *const, double)
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
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)
virtual bool supportsProhibitions() const
const bool myHaveRestrictions
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.
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
std::vector< typename SUMOAbstractRouter< MSEdge, SUMOVehicle >::EdgeInfo * > myFrontierList
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< MSEdge, SUMOVehicle >::EdgeInfo * > myFound
static long getCurrentMillis()
Returns the current time in milliseconds.
#define UNUSED_PARAMETER(x)
Prohibitions and their estimated end time.
SVCPermissions permissions