45 template<
class E,
class V>
57 :
edge(e),
effort(std::numeric_limits<double>::max()),
84 effort = std::numeric_limits<double>::max();
96 typedef double(*
Operation)(
const E*
const,
const V*
const, double);
100 const bool havePermissions,
const bool haveRestrictions) :
147 for (
auto& edgeInfo :
myFound) {
154 fromInfo.effort = 0.;
155 fromInfo.heuristicEffort = 0.;
156 fromInfo.prev =
nullptr;
165 virtual void reset(
const V*
const vehicle) {
179 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
180 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) = 0;
188 const E* from,
double fromPos,
189 const E* to,
double toPos,
190 const V*
const vehicle,
191 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
192 if (from != to || fromPos <= toPos) {
193 return compute(from, to, vehicle, msTime, into, silent);
195 return computeLooped(from, to, vehicle, msTime, into, silent);
202 inline bool computeLooped(
const E* from,
const E* to,
const V*
const vehicle,
203 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
205 return compute(from, to, vehicle, msTime, into, silent);
207 double minEffort = std::numeric_limits<double>::max();
208 std::vector<const E*> best;
210 for (
const std::pair<const E*, const E*>& follower : from->getViaSuccessors(vClass)) {
211 std::vector<const E*> tmp;
212 compute(follower.first, to, vehicle, msTime, tmp,
true);
213 if (tmp.size() > 0) {
215 if (effort < minEffort) {
221 if (minEffort != std::numeric_limits<double>::max()) {
222 into.push_back(from);
223 std::copy(best.begin(), best.end(), std::back_inserter(into));
231 inline bool isProhibited(
const E*
const edge,
const V*
const vehicle)
const {
235 inline double getTravelTime(
const E*
const e,
const V*
const v,
const double t,
const double effort)
const {
236 return myTTOperation ==
nullptr ? effort : (*myTTOperation)(e, v, t);
239 inline void updateViaEdgeCost(
const E* viaEdge,
const V*
const v,
double& time,
double& effort,
double& length)
const {
240 while (viaEdge !=
nullptr && viaEdge->isInternal()) {
241 const double viaEffortDelta = this->
getEffort(viaEdge, v, time);
243 effort += viaEffortDelta;
244 length += viaEdge->getLength();
245 viaEdge = viaEdge->getViaSuccessors().front().second;
249 inline void updateViaCost(
const E*
const prev,
const E*
const e,
const V*
const v,
double& time,
double& effort,
double& length)
const {
250 if (prev !=
nullptr) {
251 for (
const std::pair<const E*, const E*>& follower : prev->getViaSuccessors()) {
252 if (follower.first == e) {
258 const double effortDelta = this->
getEffort(e, v, time);
259 effort += effortDelta;
261 length += e->getLength();
265 inline double recomputeCosts(
const std::vector<const E*>& edges,
const V*
const v,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
269 if (lengthp ==
nullptr) {
274 const E* prev =
nullptr;
275 for (
const E*
const e : edges) {
286 inline double recomputeCosts(
const std::vector<const E*>& edges,
const V*
const v,
double fromPos,
double toPos,
SUMOTime msTime,
double* lengthp =
nullptr)
const {
288 if (!edges.empty()) {
291 effort -= firstEffort * fromPos / edges.front()->getLength();
292 effort -= lastEffort * (edges.back()->getLength() - toPos) / edges.back()->getLength();
298 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) {
303 init((*routeBegin)->getNumericalID(), msTime);
304 for (
auto e = routeBegin + 1; e != routeEnd; ++e) {
308 auto& edgeInfo =
myEdgeInfos[(*e)->getNumericalID()];
309 edgeInfo.heuristicEffort = effort;
310 edgeInfo.prev = prev;
312 edgeInfo.effort = effort;
313 edgeInfo.leaveTime = time;
316 #ifdef ROUTER_DEBUG_HINT
317 if (ROUTER_DEBUG_COND) {
318 std::cout <<
"DEBUG: hit=" << (*e)->getID()
319 <<
" TT=" << edgeInfo.
effort
320 <<
" EF=" << this->
getEffort(*e, v, edgeInfo.leaveTime)
321 <<
" HT=" << edgeInfo.heuristicEffort <<
"\n";
329 inline double getEffort(
const E*
const e,
const V*
const v,
double t)
const {
351 virtual void prohibit(
const std::vector<E*>& toProhibit) {
353 myEdgeInfos[edge->getNumericalID()].prohibited =
false;
355 for (E*
const edge : toProhibit) {
356 myEdgeInfos[edge->getNumericalID()].prohibited =
true;
358 this->myProhibited = toProhibit;
364 std::vector<const E*> tmp;
365 while (rbegin !=
nullptr) {
366 tmp.push_back(rbegin->
edge);
367 rbegin = rbegin->
prev;
369 std::copy(tmp.rbegin(), tmp.rend(), std::back_inserter(edges));
401 std::vector<typename SUMOAbstractRouter<E, V>::EdgeInfo>
myEdgeInfos;
406 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)
EdgeInfo & operator=(const EdgeInfo &s)=delete
Invalidated assignment operator.
virtual SUMOAbstractRouter * clone()=0
Operation myTTOperation
The object's operation to perform for travel times.
long long int myNumQueries
MsgHandler *const myErrorMsgHandler
the handler for routing errors
const std::string & getType() const
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,...
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
long long int myQueryStartTime
the time spent querying in milliseconds
virtual void setBulkMode(const bool mode)
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
double getEffort(const E *const e, const V *const v, double t) const
const SUMOAbstractRouter< E, V >::EdgeInfo & getEdgeInfo(int index) 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)
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, double fromPos, double toPos, SUMOTime msTime, double *lengthp=nullptr) const
void setAutoBulkMode(const bool mode)
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 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...
SUMOAbstractRouter & operator=(const SUMOAbstractRouter &s)=delete
Invalidated assignment operator.
void endQuery(int visits)
virtual ~SUMOAbstractRouter()
Destructor.
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)
const std::string myType
the type of this router
static long getCurrentMillis()
Returns the current time in milliseconds.