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) {
75 ROEdge*
const ce = rit.second;
101 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
102 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
112 bool sourcesStrict)
const {
114 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
118 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
119 if (
isSource(**i, detcont, sourcesStrict)) {
133 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
155 std::vector<std::string>::const_iterator i;
156 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
171 std::vector<std::string>::const_iterator i;
172 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
185 bool keepUnfoundEnds,
186 bool keepShortestOnly,
190 int maxFollowingLength,
192 std::vector<RODFRouteDesc> unfoundEnds;
194 std::map<ROEdge*, ROEdgeVector > dets2Follow;
199 while (!toSolve.empty()) {
204 if (dets2Follow.find(last) == dets2Follow.end()) {
207 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
209 dets2Follow[*i].push_back(last);
216 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
219 seen.push_back(last);
224 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
225 if (minDist < cdist) {
232 bool addNextNoFurther =
false;
239 addNextNoFurther =
true;
248 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
249 if (minDist < cdist) {
270 addNextNoFurther =
true;
276 if (!addNextNoFurther) {
279 if (current.
passedNo > maxFollowingLength) {
282 unfoundEnds.push_back(current);
284 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
285 if (minDist < cdist) {
294 for (
int i = 0; i < (int)appr.size(); i++) {
300 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
303 if (!addNextNoFurther) {
308 t.
factor = (double) 1. / (
double) appr.size();
309 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
310 if (minDist < cdist) {
319 if (!keepUnfoundEnds) {
320 std::vector<RODFRouteDesc>::iterator i;
322 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
323 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
324 lastDetEdges.push_back((*i).lastDetectorEdge);
334 while (!toSolve.empty()) {
344 bool keepShortestOnly,
int maxFollowingLength)
const {
348 std::map<ROEdge*, RODFRouteCont* > doneEdges;
349 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
350 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
352 if (doneEdges.find(e) != doneEdges.end()) {
359 doneEdges[e] = routes;
372 visited.push_back(e);
374 visited, **i, *routes, detcont, maxFollowingLength, seen);
376 (*i)->addRoutes(routes);
379 if (includeInBetween) {
381 const std::vector<RODFRouteDesc>& r = routes->
get();
382 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
387 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
388 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
391 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
392 distance -= (*k)->getLength();
400 copy(k, routeend, back_inserter(nrd.
edges2Pass));
412 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
413 distance -= (*k)->getLength();
429 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
430 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
431 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
443 std::vector<IterationEdge> missing;
447 missing.push_back(ie);
448 bool maxDepthReached =
false;
449 while (!missing.empty() && !maxDepthReached) {
453 for (ROEdgeVector::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
455 previous.push_back(*j);
459 missing.push_back(ie);
461 maxDepthReached =
true;
466 if (maxDepthReached) {
474 std::vector<IterationEdge> missing;
475 for (ROEdgeVector::const_iterator k = previous.begin(); k != previous.end(); ++k) {
479 missing.push_back(ie);
481 bool maxDepthReached =
false;
482 while (!missing.empty() && !maxDepthReached) {
486 for (ROEdgeVector::const_iterator j = approached.begin(); j != approached.end(); ++j) {
491 latter.push_back(*j);
496 missing.push_back(ie);
498 maxDepthReached =
true;
503 if (maxDepthReached) {
512 std::vector<FlowDef> mflows;
514 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
522 for (
const ROEdge*
const e : previous) {
523 const std::vector<FlowDef>& eflows =
static_cast<const RODFEdge*
>(e)->getFlows();
524 if (eflows.size() != 0) {
525 const FlowDef& srcFD = eflows[index];
532 inFlow.
vLKW /= (double) previous.size();
533 inFlow.
vPKW /= (double) previous.size();
541 for (
const ROEdge*
const e : latter) {
542 const std::vector<FlowDef>& eflows =
static_cast<const RODFEdge*
>(e)->getFlows();
543 if (eflows.size() != 0) {
544 const FlowDef& srcFD = eflows[index];
551 outFlow.
vLKW /= (double) latter.size();
552 outFlow.
vPKW /= (double) latter.size();
557 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
558 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
559 mflows.push_back(mFlow);
571 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
572 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
583 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
584 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
587 if (flows.
knows((*i)->getID())) {
591 WRITE_MESSAGEF(
TL(
"Removed detector '%' because no flows for him exist."), (*i)->getID());
606 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
607 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
610 if (flows.
knows((*i)->getID())) {
625 if (ret ==
nullptr) {
626 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
653const std::vector<std::string>&
692 if (seen.size() == 1000) {
693 WRITE_WARNINGF(
TL(
"Quitting checking for being a source for detector '%' due to seen edge limit."), det.
getID());
700 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
701 if ((*i) == det.
getID()) {
734 for (
int i = 0; i < (int)appr.size(); i++) {
739 if (noFalse + noSkipped == (
int)appr.size()) {
766 seen.push_back(edge);
767 for (
int i = 0; i < (int)appr.size(); i++) {
768 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
770 if (
isSource(det, appr[i], seen, detectors, strict)) {
780 return numOk + numSkipped == (int)appr.size();
782 return numFalse + numSkipped != (int)appr.size();
789 if (seen.size() == 1000) {
790 WRITE_WARNINGF(
TL(
"Quitting checking for being a destination for detector '%' due to seen edge limit."), det.
getID());
797 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
798 if ((*i) == det.
getID()) {
848 seen.push_back(edge);
849 for (
int i = 0; i < (int)appr.size() && isall; i++) {
850 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
863 if (seen.size() == 1000) {
864 WRITE_WARNINGF(
TL(
"Quitting checking for being a false source for detector '%' due to seen edge limit."), det.
getID());
867 seen.push_back(edge);
872 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
896 for (
int i = 0; i < (int)appr.size() && !isall; i++) {
898 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
914 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
915 double speedFactorSumPKW = 0;
916 double speedFactorSumLKW = 0;
917 double speedFactorCountPKW = 0;
918 double speedFactorCountLKW = 0;
920 ROEdge* into = (*i).first;
924 const std::vector<std::string>& dets = (*i).second;
925 std::map<double, std::vector<std::string> > cliques;
926 std::vector<std::string>* maxClique =
nullptr;
927 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
928 if (!flows.
knows(*j)) {
933 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
934 if (fabs((*k).first - det.
getPos()) < 1) {
935 (*k).second.push_back(*j);
936 if ((*k).second.size() > maxClique->size()) {
937 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)
#define UNUSED_PARAMETER(x)
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.
const RONode * getFromJunction() const
double getSpeedLimit() const
Returns the speed allowed on this edge.
bool isInternal() const
return whether this edge is an internal edge
SVCPermissions getPermissions() const
const ROEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
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
The router's network representation.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
const NamedObjectCont< ROEdge * > & getEdgeMap() const
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
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