45template<
class E,
class V>
84 effort = std::numeric_limits<double>::max();
92 typedef double(*
Operation)(
const E*
const,
const V*
const, double);
96 const bool havePermissions,
const bool haveRestrictions) :
143 for (
auto& edgeInfo :
myFound) {
150 fromInfo.effort = 0.;
151 fromInfo.heuristicEffort = 0.;
152 fromInfo.prev =
nullptr;
161 virtual void reset(
const V*
const vehicle) {
175 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
176 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) = 0;
184 const E* from,
double fromPos,
185 const E* to,
double toPos,
186 const V*
const vehicle,
187 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
188 if (from != to || fromPos <= toPos) {
189 return compute(from, to, vehicle, msTime, into, silent);
191 return computeLooped(from, to, vehicle, msTime, into, silent);
198 inline bool computeLooped(
const E* from,
const E* to,
const V*
const vehicle,
199 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
201 return compute(from, to, vehicle, msTime, into, silent);
203 double minEffort = std::numeric_limits<double>::max();
204 std::vector<const E*> best;
206 for (
const std::pair<const E*, const E*>& follower : from->getViaSuccessors(vClass)) {
207 std::vector<const E*> tmp;
208 compute(follower.first, to, vehicle, msTime, tmp,
true);
209 if (tmp.size() > 0) {
211 if (effort < minEffort) {
217 if (minEffort != std::numeric_limits<double>::max()) {
218 into.push_back(from);
219 std::copy(best.begin(), best.end(), std::back_inserter(into));
227 inline bool isProhibited(
const E*
const edge,
const V*
const vehicle)
const {
231 inline double getTravelTime(
const E*
const e,
const V*
const v,
const double t,
const double effort)
const {
232 return myTTOperation ==
nullptr ? effort : (*myTTOperation)(e, v, t);
235 inline void updateViaEdgeCost(
const E* viaEdge,
const V*
const v,
double& time,
double& effort,
double& length)
const {
236 while (viaEdge !=
nullptr && viaEdge->isInternal()) {
237 const double viaEffortDelta = this->
getEffort(viaEdge, v, time);
239 effort += viaEffortDelta;
240 length += viaEdge->getLength();
241 viaEdge = viaEdge->getViaSuccessors().front().second;
245 inline void updateViaCost(
const E*
const prev,
const E*
const e,
const V*
const v,
double& time,
double& effort,
double& length)
const {
246 if (prev !=
nullptr) {
247 for (
const std::pair<const E*, const E*>& follower : prev->getViaSuccessors()) {
248 if (follower.first == e) {
254 const double effortDelta = this->
getEffort(e, v, time);
255 effort += effortDelta;
257 length += e->getLength();
260 bool isValid(
const std::vector<const E*>& edges,
const V*
const v)
const {
261 for (
const E*
const e : edges) {
269 virtual double recomputeCosts(
const std::vector<const E*>& edges,
const V*
const v,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
273 if (lengthp ==
nullptr) {
278 const E* prev =
nullptr;
279 for (
const E*
const e : edges) {
287 inline double recomputeCostsPos(
const std::vector<const E*>& edges,
const V*
const v,
double fromPos,
double toPos,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
289 if (!edges.empty()) {
292 effort -= firstEffort * fromPos / edges.front()->getLength();
293 effort -= lastEffort * (edges.back()->getLength() - toPos) / edges.back()->getLength();
299 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) {
304 init((*routeBegin)->getNumericalID(), msTime);
305 for (
auto e = routeBegin + 1; e != routeEnd; ++e) {
309 auto& edgeInfo =
myEdgeInfos[(*e)->getNumericalID()];
310 edgeInfo.heuristicEffort = effort;
311 edgeInfo.prev = prev;
313 edgeInfo.effort = effort;
314 edgeInfo.leaveTime = time;
317#ifdef ROUTER_DEBUG_HINT
318 if (ROUTER_DEBUG_COND) {
319 std::cout <<
"DEBUG: hit=" << (*e)->getID()
320 <<
" TT=" << edgeInfo.
effort
321 <<
" EF=" << this->
getEffort(*e, v, edgeInfo.leaveTime)
322 <<
" HT=" << edgeInfo.heuristicEffort <<
"\n";
330 inline double getEffort(
const E*
const e,
const V*
const v,
double t)
const {
352 virtual void prohibit(
const std::vector<E*>& toProhibit) {
354 myEdgeInfos[edge->getNumericalID()].prohibited =
false;
356 for (E*
const edge : toProhibit) {
357 myEdgeInfos[edge->getNumericalID()].prohibited =
true;
365 std::vector<const E*> tmp;
366 while (rbegin !=
nullptr) {
367 tmp.push_back(rbegin->
edge);
368 rbegin = rbegin->
prev;
370 std::copy(tmp.rbegin(), tmp.rend(), std::back_inserter(edges));
402 std::vector<typename SUMOAbstractRouter<E, V>::EdgeInfo>
myEdgeInfos;
407 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
#define UNUSED_PARAMETER(x)
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
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)
Operation myTTOperation
The object's operation to perform for travel times.
long long int myNumQueries
MsgHandler *const myErrorMsgHandler
the handler for routing errors
std::vector< E * > myProhibited
The list of explicitly prohibited edges.
bool isProhibited(const E *const edge, const V *const vehicle) const
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::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
virtual void prohibit(const std::vector< E * > &toProhibit)
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.
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
bool myAmClean
whether we are already initialized
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...
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< 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.