45template<
class E,
class V>
87 effort = std::numeric_limits<double>::max();
95 typedef double(*
Operation)(
const E*
const,
const V*
const, double);
102 const bool havePermissions,
const bool haveRestrictions) :
151 for (
auto& edgeInfo :
myFound) {
158 fromInfo.effort = 0.;
159 fromInfo.heuristicEffort = 0.;
160 fromInfo.prev =
nullptr;
169 virtual void reset(
const V*
const vehicle) {
183 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
184 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) = 0;
192 const E* from,
double fromPos,
193 const E* to,
double toPos,
194 const V*
const vehicle,
195 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
196 if (from != to || fromPos <= toPos) {
197 return compute(from, to, vehicle, msTime, into, silent);
199 return computeLooped(from, to, vehicle, msTime, into, silent);
206 inline bool computeLooped(
const E* from,
const E* to,
const V*
const vehicle,
207 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
209 return compute(from, to, vehicle, msTime, into, silent);
211 double minEffort = std::numeric_limits<double>::max();
212 std::vector<const E*> best;
214 for (
const std::pair<const E*, const E*>& follower : from->getViaSuccessors(vClass)) {
215 std::vector<const E*> tmp;
216 compute(follower.first, to, vehicle, msTime, tmp,
true);
217 if (tmp.size() > 0) {
219 if (effort < minEffort) {
225 if (minEffort != std::numeric_limits<double>::max()) {
226 into.push_back(from);
227 std::copy(best.begin(), best.end(), std::back_inserter(into));
230 myErrorMsgHandler->informf(
TL(
"No connection between edge '%' and edge '%' found."), from->getID(), to->getID());
235 inline bool isProhibited(
const E*
const edge,
const V*
const vehicle)
const {
239 inline double getTravelTime(
const E*
const e,
const V*
const v,
const double t,
const double effort)
const {
240 return myTTOperation ==
nullptr ? effort : (*myTTOperation)(e, v, t);
243 inline void updateViaEdgeCost(
const E* viaEdge,
const V*
const v,
double& time,
double& effort,
double& length)
const {
244 while (viaEdge !=
nullptr && viaEdge->isInternal()) {
245 const double viaEffortDelta = this->
getEffort(viaEdge, v, time);
247 effort += viaEffortDelta;
248 length += viaEdge->getLength();
249 viaEdge = viaEdge->getViaSuccessors().front().second;
253 inline void updateViaCost(
const E*
const prev,
const E*
const e,
const V*
const v,
double& time,
double& effort,
double& length)
const {
254 if (prev !=
nullptr) {
255 for (
const std::pair<const E*, const E*>& follower : prev->getViaSuccessors()) {
256 if (follower.first == e) {
262 const double effortDelta = this->
getEffort(e, v, time);
263 effort += effortDelta;
265 length += e->getLength();
268 bool isValid(
const std::vector<const E*>& edges,
const V*
const v)
const {
269 for (
const E*
const e : edges) {
277 virtual double recomputeCosts(
const std::vector<const E*>& edges,
const V*
const v,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
281 if (lengthp ==
nullptr) {
286 const E* prev =
nullptr;
287 for (
const E*
const e : edges) {
295 inline double recomputeCostsPos(
const std::vector<const E*>& edges,
const V*
const v,
double fromPos,
double toPos,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
297 if (!edges.empty()) {
300 effort -= firstEffort * fromPos / edges.front()->getLength();
301 effort -= lastEffort * (edges.back()->getLength() - toPos) / edges.back()->getLength();
307 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) {
311 const EdgeInfo* prev = &
myEdgeInfos[(*routeBegin)->getNumericalID()];
312 init((*routeBegin)->getNumericalID(), msTime);
313 for (
auto e = routeBegin + 1; e != routeEnd; ++e) {
317 auto& edgeInfo =
myEdgeInfos[(*e)->getNumericalID()];
318 edgeInfo.heuristicEffort = effort;
319 edgeInfo.prev = prev;
321 edgeInfo.effort = effort;
322 edgeInfo.leaveTime = time;
325#ifdef ROUTER_DEBUG_HINT
326 if (ROUTER_DEBUG_COND) {
327 std::cout <<
"DEBUG: hit=" << (*e)->getID()
328 <<
" TT=" << edgeInfo.effort
329 <<
" EF=" << this->
getEffort(*e, v, edgeInfo.leaveTime)
330 <<
" HT=" << edgeInfo.heuristicEffort <<
"\n";
338 inline double getEffort(
const E*
const e,
const V*
const v,
double t)
const {
341 return (
myEdgeInfos[e->getNumericalID()].prohibitionEnd - t) + (*myOperation)(e, v,
myEdgeInfos[e->getNumericalID()].prohibitionEnd);
367 myEdgeInfos[item.first->getNumericalID()].prohibited =
false;
368 myEdgeInfos[item.first->getNumericalID()].prohibitionEnd = 0;
370 for (
auto item : toProhibit) {
371 if (item.second >= 0 && item.second != std::numeric_limits<double>::max()) {
372 myEdgeInfos[item.first->getNumericalID()].prohibitionEnd = item.second;
374 myEdgeInfos[item.first->getNumericalID()].prohibited =
true;
377 this->myProhibited = toProhibit;
383 std::vector<const E*> tmp;
384 while (rbegin !=
nullptr) {
385 tmp.push_back(rbegin->
edge);
386 rbegin = rbegin->
prev;
388 std::copy(tmp.rbegin(), tmp.rend(), std::back_inserter(edges));
420 std::vector<typename SUMOAbstractRouter<E, V>::EdgeInfo>
myEdgeInfos;
425 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
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 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.
bool prohibited
whether the edge is currently not allowed
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 prohibitione ends
long long int myNumQueries
MsgHandler *const myErrorMsgHandler
std::map< const MSEdge *, double > Prohibitions
bool isProhibited(const E *const edge, const V *const vehicle) const
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::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
const std::string & getType() const
double getEffort(const E *const e, const V *const v, 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)
bool isValid(const std::vector< const E * > &edges, const V *const v) 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...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
void endQuery(int visits)
virtual ~SUMOAbstractRouter()
Destructor.
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)