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) {
70 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
99 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
100 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
110 bool sourcesStrict)
const {
112 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
116 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
117 if (
isSource(**i, detcont, sourcesStrict)) {
131 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
153 std::vector<std::string>::const_iterator i;
154 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
169 std::vector<std::string>::const_iterator i;
170 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
183 bool keepUnfoundEnds,
184 bool keepShortestOnly,
188 int maxFollowingLength,
190 std::vector<RODFRouteDesc> unfoundEnds;
192 std::map<ROEdge*, ROEdgeVector > dets2Follow;
197 while (!toSolve.empty()) {
202 if (dets2Follow.find(last) == dets2Follow.end()) {
205 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
207 dets2Follow[*i].push_back(last);
214 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
217 seen.push_back(last);
222 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
223 if (minDist < cdist) {
230 bool addNextNoFurther =
false;
237 addNextNoFurther =
true;
246 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
247 if (minDist < cdist) {
268 addNextNoFurther =
true;
274 if (!addNextNoFurther) {
277 if (current.
passedNo > maxFollowingLength) {
280 unfoundEnds.push_back(current);
282 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
283 if (minDist < cdist) {
292 for (
int i = 0; i < (int)appr.size(); i++) {
298 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
301 if (!addNextNoFurther) {
306 t.
factor = (double) 1. / (
double) appr.size();
307 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
308 if (minDist < cdist) {
317 if (!keepUnfoundEnds) {
318 std::vector<RODFRouteDesc>::iterator i;
320 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
321 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
322 lastDetEdges.push_back((*i).lastDetectorEdge);
332 while (!toSolve.empty()) {
342 bool keepShortestOnly,
int maxFollowingLength)
const {
346 std::map<ROEdge*, RODFRouteCont* > doneEdges;
347 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
348 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
350 if (doneEdges.find(e) != doneEdges.end()) {
357 doneEdges[e] = routes;
370 visited.push_back(e);
372 visited, **i, *routes, detcont, maxFollowingLength, seen);
374 (*i)->addRoutes(routes);
377 if (includeInBetween) {
379 const std::vector<RODFRouteDesc>& r = routes->
get();
380 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
385 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
386 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
389 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
390 distance -= (*k)->getLength();
396 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
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) {
439 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
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++) {
523 for (ROEdgeVector::iterator i = previous.begin(); i != previous.end(); ++i) {
524 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
525 if (flows.size() != 0) {
526 const FlowDef& srcFD = flows[index];
534 inFlow.
vLKW /= (double) previous.size();
535 inFlow.
vPKW /= (double) previous.size();
544 for (ROEdgeVector::iterator i = latter.begin(); i != latter.end(); ++i) {
545 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
546 if (flows.size() != 0) {
547 const FlowDef& srcFD = flows[index];
555 outFlow.
vLKW /= (double) latter.size();
556 outFlow.
vPKW /= (double) latter.size();
561 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
562 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
563 mflows.push_back(mFlow);
575 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
576 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
587 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
588 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
591 if (flows.
knows((*i)->getID())) {
595 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
610 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
611 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
614 if (flows.
knows((*i)->getID())) {
618 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
628 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
630 if (ret ==
nullptr) {
631 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
664 const std::vector<std::string>&
705 if (seen.size() == 1000) {
706 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
713 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
714 if ((*i) == det.
getID()) {
748 for (
int i = 0; i < (int)appr.size(); i++) {
755 if (noFalse + noSkipped == (
int)appr.size()) {
782 seen.push_back(edge);
783 for (
int i = 0; i < (int)appr.size(); i++) {
784 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
786 if (
isSource(det, appr[i], seen, detectors, strict)) {
796 return numOk + numSkipped == (int)appr.size();
798 return numFalse + numSkipped != (int)appr.size();
805 if (seen.size() == 1000) {
806 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
813 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
814 if ((*i) == det.
getID()) {
865 seen.push_back(edge);
866 for (
int i = 0; i < (int)appr.size() && isall; i++) {
867 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
881 if (seen.size() == 1000) {
882 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
885 seen.push_back(edge);
890 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
914 for (
int i = 0; i < (int)appr.size() && !isall; i++) {
916 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
932 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
933 double speedFactorSumPKW = 0;
934 double speedFactorSumLKW = 0;
935 double speedFactorCountPKW = 0;
936 double speedFactorCountLKW = 0;
938 ROEdge* into = (*i).first;
942 const std::vector<std::string>& dets = (*i).second;
943 std::map<double, std::vector<std::string> > cliques;
944 std::vector<std::string>* maxClique =
nullptr;
945 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
946 if (!flows.
knows(*j)) {
951 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
952 if (fabs((*k).first - det.
getPos()) < 1) {
953 (*k).second.push_back(*j);
954 if ((*k).second.size() > maxClique->size()) {
955 maxClique = &(*k).second;
961 cliques[det.
getPos()].push_back(*j);
962 maxClique = &cliques[det.
getPos()];
965 if (maxClique ==
nullptr) {
968 std::vector<FlowDef> mflows;
969 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
977 mflows.push_back(fd);
979 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
980 bool didWarn =
false;
981 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
983 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
984 const FlowDef& srcFD = dflows[index];
988 fd.
vLKW += srcFD.
vLKW / (double) maxClique->size();
989 fd.
vPKW += srcFD.
vPKW / (double) maxClique->size();
990 fd.
fLKW += srcFD.
fLKW / (double) maxClique->size();
991 fd.
isLKW += srcFD.
isLKW / (double) maxClique->size();
992 const double speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
993 const double speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
996 speedFactorCountPKW += srcFD.
qPKW;
997 speedFactorCountLKW += srcFD.
qLKW;
998 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
999 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
1010 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1013 if (speedFactorCountPKW > 0) {
1017 if (speedFactorCountLKW > 0) {
1032 std::map<std::string, ROEdge*>::const_iterator i;
1039 std::vector<RODFDetector*> last;
1041 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1042 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1048 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1050 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1054 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1056 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1058 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1062 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1075 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1077 const std::vector<std::string>& dets = (*i).second;
1078 std::map<double, std::vector<std::string> > cliques;
1080 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1083 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1084 if (fabs((*k).first - det.
getPos()) < 10.) {
1085 (*k).second.push_back(*j);
1090 cliques[det.
getPos()] = std::vector<std::string>();
1091 cliques[det.
getPos()].push_back(*j);
1095 for (std::map<
double, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1096 std::vector<std::string> clique = (*m).second;
1098 if (clique.size() == 1) {
1102 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1103 std::cout << *n <<
" ";
1104 if (n != clique.begin()) {
1109 std::cout <<
":" << nid << std::endl;
1111 detectors.
mesoJoin(nid, (*m).second);
void mesoJoin(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
void revalidateFlows(const RODFDetectorCon &detectors, RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
std::vector< std::string > myDisallowedEdges
List of ids of edges that shall not be used.
RODFDetector & getModifiableDetector(const std::string &id) const
double myAvgSpeedFactorLKW
double myAvgSpeedFactorPKW
void removeDetector(const std::string &id)
const RODFDetector & getDetector(const std::string &id) const
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
const RONode * getFromJunction() const
bool isSource(const RODFDetector &det, const RODFDetectorCon &detectors, bool strict) const
void computeTypes(RODFDetectorCon &dets, bool sourcesStrict) const
void removeFlow(const std::string &detector_id)
std::map< ROEdge *, ROEdgeVector > myApproachedEdges
Map of edge name->list of names of edges approached by this edge.
void reportEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
ROEdgeVector edges2Pass
The edges the route is made of.
void addPriorDetector(const RODFDetector *det)
bool hasDetector(ROEdge *edge) const
double getAbsPos(const RODFDetector &det) const
const std::vector< RODFDetector * > & getDetectors() const
double getLength() const
Returns the length of the edge.
std::vector< const ROEdge * > ConstROEdgeVector
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
ROEdge * getDetectorEdge(const RODFDetector &det) const
RODFDetectorType getType() const
Returns the type of the detector.
const RONode * getToJunction() const
const std::vector< RODFRouteDesc > & getRouteVector() const
bool knows(const std::string &det_id) const
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
A container for RODFDetectors.
#define UNUSED_PARAMETER(x)
const std::vector< FlowDef > & getFlows() const
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
vehicle is a large transport vehicle
comparator for maps using edges as key, used only in myDetectorsOnEdges to make tests comparable ...
A not yet defined detector.
bool removeRouteDesc(RODFRouteDesc &desc)
Removes the given route description from the container.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
RODFNet(bool amInHighwayMode)
Constructor.
std::vector< ROEdge * > ROEdgeVector
A detector which had to be discarded (!!!)
const std::vector< std::string > & getDetectorList(ROEdge *edge) const
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
void setFlows(const std::string &detector_id, std::vector< FlowDef > &)
Definition of the traffic during a certain time containing the flows and speeds.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
vehicle is a passenger car (a "normal" car)
A route within the DFROUTER.
A basic edge for routing applications.
std::map< ROEdge *, ROEdgeVector > myApproachingEdges
Map of edge name->list of names of this edge approaching edges.
double myMaxSpeedFactorPKW
maximum speed factor in measurements
bool isInternal() const
return whether this edge is an internal edge
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
bool hasApproached(ROEdge *edge) const
void buildRoutes(RODFDetectorCon &det, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const
double myMaxSpeedFactorLKW
bool hasApproaching(ROEdge *edge) const
The router's network representation.
bool hasSourceDetector(ROEdge *edge, const RODFDetectorCon &detectors) const
const NamedObjectCont< ROEdge * > & getEdgeMap() const
void buildEdgeFlowMap(const RODFDetectorFlows &flows, const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
void buildDetectorDependencies(RODFDetectorCon &detectors)
Class representing a detector within the DFROUTER.
const ROEdge * endDetectorEdge
double getSpeedLimit() const
Returns the speed allowed on this edge.
std::map< std::string, ROEdge * > myDetectorEdges
A container for DFROUTER-routes.
const ROEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
bool isDestination(const RODFDetector &det, const RODFDetectorCon &detectors) const
double getVClassMaxSpeed(SUMOVehicleClass vclass) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
std::map< ROEdge *, std::vector< std::string >, idComp > myDetectorsOnEdges
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
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 * getEdge(const std::string &name) const
Retrieves an edge from the network.
void removeEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
#define PROGRESS_DONE_MESSAGE()
const ROEdge * lastDetectorEdge
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
#define WRITE_MESSAGE(msg)
void buildDetectorEdgeDependencies(RODFDetectorCon &dets) const
double getPos() const
Returns the position at which the detector lies.