47 RONet(), myAmInHighwayMode(amInHighwayMode),
48 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0),
49 myMaxSpeedFactorPKW(1),
50 myMaxSpeedFactorLKW(1),
51 myAvgSpeedFactorPKW(1),
52 myAvgSpeedFactorLKW(1) {
78 for (
ROEdge*
const help : ce->getSuccessors()) {
100 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
101 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
111 bool sourcesStrict)
const {
113 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
117 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
118 if (
isSource(**i, detcont, sourcesStrict)) {
132 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
154 std::vector<std::string>::const_iterator i;
155 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
170 std::vector<std::string>::const_iterator i;
171 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
184 bool keepUnfoundEnds,
185 bool keepShortestOnly,
189 int maxFollowingLength,
191 std::vector<RODFRouteDesc> unfoundEnds;
193 std::map<ROEdge*, ROEdgeVector > dets2Follow;
198 while (!toSolve.empty()) {
203 if (dets2Follow.find(last) == dets2Follow.end()) {
206 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
208 dets2Follow[*i].push_back(last);
215 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
218 seen.push_back(last);
223 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
224 if (minDist < cdist) {
231 bool addNextNoFurther =
false;
238 addNextNoFurther =
true;
247 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
248 if (minDist < cdist) {
269 addNextNoFurther =
true;
275 if (!addNextNoFurther) {
278 if (current.
passedNo > maxFollowingLength) {
281 unfoundEnds.push_back(current);
283 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
284 if (minDist < cdist) {
293 for (
int i = 0; i < (int)appr.size(); i++) {
299 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
302 if (!addNextNoFurther) {
307 t.
factor = (double) 1. / (
double) appr.size();
308 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
309 if (minDist < cdist) {
318 if (!keepUnfoundEnds) {
319 std::vector<RODFRouteDesc>::iterator i;
321 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
322 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
323 lastDetEdges.push_back((*i).lastDetectorEdge);
333 while (!toSolve.empty()) {
343 bool keepShortestOnly,
int maxFollowingLength)
const {
347 std::map<ROEdge*, RODFRouteCont* > doneEdges;
348 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
349 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
351 if (doneEdges.find(e) != doneEdges.end()) {
358 doneEdges[e] = routes;
371 visited.push_back(e);
373 visited, **i, *routes, detcont, maxFollowingLength, seen);
375 (*i)->addRoutes(routes);
378 if (includeInBetween) {
380 const std::vector<RODFRouteDesc>& r = routes->
get();
381 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
386 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
387 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
390 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
391 distance -= (*k)->getLength();
399 copy(k, routeend, back_inserter(nrd.
edges2Pass));
411 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
412 distance -= (*k)->getLength();
428 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
429 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
430 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
442 std::vector<IterationEdge> missing;
446 missing.push_back(ie);
447 bool maxDepthReached =
false;
448 while (!missing.empty() && !maxDepthReached) {
452 for (ROEdgeVector::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
454 previous.push_back(*j);
458 missing.push_back(ie);
460 maxDepthReached =
true;
465 if (maxDepthReached) {
473 std::vector<IterationEdge> missing;
474 for (ROEdgeVector::const_iterator k = previous.begin(); k != previous.end(); ++k) {
478 missing.push_back(ie);
480 bool maxDepthReached =
false;
481 while (!missing.empty() && !maxDepthReached) {
485 for (ROEdgeVector::const_iterator j = approached.begin(); j != approached.end(); ++j) {
490 latter.push_back(*j);
495 missing.push_back(ie);
497 maxDepthReached =
true;
502 if (maxDepthReached) {
511 std::vector<FlowDef> mflows;
513 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
521 for (
const ROEdge*
const e : previous) {
522 const std::vector<FlowDef>& eflows =
static_cast<const RODFEdge*
>(e)->getFlows();
523 if (eflows.size() != 0) {
524 const FlowDef& srcFD = eflows[index];
531 inFlow.
vLKW /= (double) previous.size();
532 inFlow.
vPKW /= (double) previous.size();
540 for (
const ROEdge*
const e : latter) {
541 const std::vector<FlowDef>& eflows =
static_cast<const RODFEdge*
>(e)->getFlows();
542 if (eflows.size() != 0) {
543 const FlowDef& srcFD = eflows[index];
550 outFlow.
vLKW /= (double) latter.size();
551 outFlow.
vPKW /= (double) latter.size();
556 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
557 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
558 mflows.push_back(mFlow);
570 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
571 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
582 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
583 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
586 if (flows.
knows((*i)->getID())) {
590 WRITE_MESSAGEF(
TL(
"Removed detector '%' because no flows for him exist."), (*i)->getID());
605 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
606 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
609 if (flows.
knows((*i)->getID())) {
624 if (ret ==
nullptr) {
625 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
652const std::vector<std::string>&
691 if (seen.size() == 1000) {
692 WRITE_WARNINGF(
TL(
"Quitting checking for being a source for detector '%' due to seen edge limit."), det.
getID());
699 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
700 if ((*i) == det.
getID()) {
733 for (
int i = 0; i < (int)appr.size(); i++) {
738 if (noFalse + noSkipped == (
int)appr.size()) {
765 seen.push_back(edge);
766 for (
int i = 0; i < (int)appr.size(); i++) {
767 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
769 if (
isSource(det, appr[i], seen, detectors, strict)) {
779 return numOk + numSkipped == (int)appr.size();
781 return numFalse + numSkipped != (int)appr.size();
788 if (seen.size() == 1000) {
789 WRITE_WARNINGF(
TL(
"Quitting checking for being a destination for detector '%' due to seen edge limit."), det.
getID());
796 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
797 if ((*i) == det.
getID()) {
847 seen.push_back(edge);
848 for (
int i = 0; i < (int)appr.size() && isall; i++) {
849 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
862 if (seen.size() == 1000) {
863 WRITE_WARNINGF(
TL(
"Quitting checking for being a false source for detector '%' due to seen edge limit."), det.
getID());
866 seen.push_back(edge);
871 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
895 for (
int i = 0; i < (int)appr.size() && !isall; i++) {
897 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
913 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
914 double speedFactorSumPKW = 0;
915 double speedFactorSumLKW = 0;
916 double speedFactorCountPKW = 0;
917 double speedFactorCountLKW = 0;
919 ROEdge* into = (*i).first;
923 const std::vector<std::string>& dets = (*i).second;
924 std::map<double, std::vector<std::string> > cliques;
925 std::vector<std::string>* maxClique =
nullptr;
926 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
927 if (!flows.
knows(*j)) {
932 for (
auto& k : cliques) {
933 if (fabs(k.first - det.
getPos()) < 1) {
934 k.second.push_back(*j);
935 if (maxClique ==
nullptr || k.second.size() > maxClique->size()) {
936 maxClique = &k.second;
943 cliques[det.
getPos()].push_back(*j);
944 maxClique = &cliques[det.
getPos()];
947 if (maxClique ==
nullptr) {
950 std::vector<FlowDef> mflows;
951 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
959 mflows.push_back(
fd);
961 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
962 bool didWarn =
false;
963 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
965 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
966 const FlowDef& srcFD = dflows[index];
970 fd.vLKW += srcFD.
vLKW / (double) maxClique->size();
971 fd.vPKW += srcFD.
vPKW / (double) maxClique->size();
972 fd.fLKW += srcFD.
fLKW / (double) maxClique->size();
973 fd.isLKW += srcFD.
isLKW / (double) maxClique->size();
974 const double speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
975 const double speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
978 speedFactorCountPKW += srcFD.
qPKW;
979 speedFactorCountLKW += srcFD.
qLKW;
980 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
981 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
992 static_cast<RODFEdge*
>(into)->setFlows(mflows);
995 if (speedFactorCountPKW > 0) {
999 if (speedFactorCountLKW > 0) {
1014 std::map<std::string, ROEdge*>::const_iterator i;
1021 std::vector<RODFDetector*> last;
1023 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1024 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1030 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1032 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1036 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1038 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1040 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1044 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1057 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1059 const std::vector<std::string>& dets = (*i).second;
1060 std::map<double, std::vector<std::string> > cliques;
1062 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1065 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1066 if (fabs((*k).first - det.
getPos()) < 10.) {
1067 (*k).second.push_back(*j);
1072 cliques[det.
getPos()] = std::vector<std::string>();
1073 cliques[det.
getPos()].push_back(*j);
1077 for (std::map<
double, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1078 std::vector<std::string> clique = (*m).second;
1080 if (clique.size() == 1) {
1084 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1085 std::cout << *n <<
" ";
1086 if (n != clique.begin()) {
1091 std::cout <<
":" << nid << std::endl;
1093 detectors.
mesoJoin(nid, (*m).second);
#define WRITE_WARNINGF(...)
#define WRITE_MESSAGEF(...)
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
#define PROGRESS_DONE_MESSAGE()
#define PROGRESS_BEGIN_MESSAGE(msg)
@ BETWEEN_DETECTOR
An in-between detector.
@ SOURCE_DETECTOR
A source detector.
@ DISCARDED_DETECTOR
A detector which had to be discarded (!!!)
@ TYPE_NOT_DEFINED
A not yet defined detector.
std::vector< ROEdge * > ROEdgeVector
std::vector< const ROEdge * > ConstROEdgeVector
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
@ SVC_TRUCK
vehicle is a large transport vehicle
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const std::string & getID() const
Returns the id.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
A container for RODFDetectors.
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
void removeDetector(const std::string &id)
const RODFDetector & getDetector(const std::string &id) const
RODFDetector & getModifiableDetector(const std::string &id) const
const std::vector< RODFDetector * > & getDetectors() const
void setFlows(const std::string &detector_id, std::vector< FlowDef > &)
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
void removeFlow(const std::string &detector_id)
bool knows(const std::string &det_id) const
Class representing a detector within the DFROUTER.
double getPos() const
Returns the position at which the detector lies.
void addPriorDetector(const RODFDetector *det)
const std::vector< RODFRouteDesc > & getRouteVector() const
RODFDetectorType getType() const
Returns the type of the detector.
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
void buildEdgeFlowMap(const RODFDetectorFlows &flows, const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
double myAvgSpeedFactorPKW
void computeTypes(RODFDetectorCon &dets, bool sourcesStrict) const
std::map< std::string, ROEdge * > myDetectorEdges
double myMaxSpeedFactorPKW
maximum speed factor in measurements
std::vector< std::string > myDisallowedEdges
List of ids of edges that shall not be used.
std::map< ROEdge *, std::vector< std::string >, idComp > myDetectorsOnEdges
void revalidateFlows(const RODFDetectorCon &detectors, RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
bool hasApproached(ROEdge *edge) const
void mesoJoin(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
void buildDetectorEdgeDependencies(RODFDetectorCon &dets) const
bool hasApproaching(ROEdge *edge) const
void buildRoutes(RODFDetectorCon &det, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const
RODFNet(bool amInHighwayMode)
Constructor.
bool isDestination(const RODFDetector &det, const RODFDetectorCon &detectors) const
void buildDetectorDependencies(RODFDetectorCon &detectors)
SUMOVehicleClass myAllowedVClass
void removeEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
bool isAllowed(const ROEdge *const edge) const
void computeRoutesFor(ROEdge *edge, RODFRouteDesc &base, int no, bool keepUnfoundEnds, bool keepShortestOnly, ROEdgeVector &visited, const RODFDetector &det, RODFRouteCont &into, const RODFDetectorCon &detectors, int maxFollowingLength, ROEdgeVector &seen) const
ROEdge * getDetectorEdge(const RODFDetector &det) const
double myMaxSpeedFactorLKW
bool hasSourceDetector(ROEdge *edge, const RODFDetectorCon &detectors) const
std::map< ROEdge *, ROEdgeVector > myApproachingEdges
Map of edge name->list of names of this edge approaching edges.
bool hasDetector(ROEdge *edge) const
const std::vector< std::string > & getDetectorList(ROEdge *edge) const
double getAbsPos(const RODFDetector &det) const
bool isSource(const RODFDetector &det, const RODFDetectorCon &detectors, bool strict) const
double myAvgSpeedFactorLKW
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
void reportEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
std::map< ROEdge *, ROEdgeVector > myApproachedEdges
Map of edge name->list of names of edges approached by this edge.
A container for DFROUTER-routes.
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
bool removeRouteDesc(RODFRouteDesc &desc)
Removes the given route description from the container.
A basic edge for routing applications.
double getVClassMaxSpeed(SUMOVehicleClass vclass) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
double getSpeedLimit() const
Returns the speed allowed on this edge.
bool isInternal() const
return whether this edge is an internal edge
SVCPermissions getPermissions() const
bool isWalkingArea() const
return whether this edge is walking area
double getLength() const
Returns the length of the edge.
bool isCrossing() const
return whether this edge is a pedestrian crossing
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
The router's network representation.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
#define UNUSED_PARAMETER(x)
Definition of the traffic during a certain time containing the flows and speeds.
comparator for maps using edges as key, used only in myDetectorsOnEdges to make tests comparable
A route within the DFROUTER.
ROEdgeVector edges2Pass
The edges the route is made of.
const ROEdge * lastDetectorEdge
const ROEdge * endDetectorEdge