54 RONet(), myAmInHighwayMode(amInHighwayMode),
55 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0),
56 myMaxSpeedFactorPKW(1),
57 myMaxSpeedFactorLKW(1),
58 myAvgSpeedFactorPKW(1),
59 myAvgSpeedFactorLKW(1) {
71 const std::map<std::string, ROEdge*>& edges =
getEdgeMap();
72 for (std::map<std::string, ROEdge*>::const_iterator rit = edges.begin(); rit != edges.end(); ++rit) {
73 ROEdge* ce = (*rit).second;
78 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
107 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
108 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
118 bool sourcesStrict)
const {
120 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
124 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
125 if (
isSource(**i, detcont, sourcesStrict)) {
139 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
161 std::vector<std::string>::const_iterator i;
162 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
177 std::vector<std::string>::const_iterator i;
178 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
191 bool keepUnfoundEnds,
192 bool keepShortestOnly,
196 int maxFollowingLength,
198 std::vector<RODFRouteDesc> unfoundEnds;
200 std::map<ROEdge*, ROEdgeVector > dets2Follow;
205 while (!toSolve.empty()) {
210 if (dets2Follow.find(last) == dets2Follow.end()) {
213 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
215 dets2Follow[*i].push_back(last);
222 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
225 seen.push_back(last);
230 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
231 if (minDist < cdist) {
238 bool addNextNoFurther =
false;
245 addNextNoFurther =
true;
254 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
255 if (minDist < cdist) {
276 addNextNoFurther =
true;
282 if (!addNextNoFurther) {
285 if (current.
passedNo > maxFollowingLength) {
288 unfoundEnds.push_back(current);
290 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
291 if (minDist < cdist) {
300 for (
int i = 0; i < (int)appr.size(); i++) {
306 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
309 if (!addNextNoFurther) {
314 t.
factor = (double) 1. / (
double) appr.size();
315 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
316 if (minDist < cdist) {
325 if (!keepUnfoundEnds) {
326 std::vector<RODFRouteDesc>::iterator i;
328 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
329 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
330 lastDetEdges.push_back((*i).lastDetectorEdge);
340 while (!toSolve.empty()) {
350 bool keepShortestOnly,
int maxFollowingLength)
const {
354 std::map<ROEdge*, RODFRouteCont* > doneEdges;
355 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
356 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
358 if (doneEdges.find(e) != doneEdges.end()) {
365 doneEdges[e] = routes;
378 visited.push_back(e);
380 visited, **i, *routes, detcont, maxFollowingLength, seen);
382 (*i)->addRoutes(routes);
385 if (includeInBetween) {
387 const std::vector<RODFRouteDesc>& r = routes->
get();
388 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
393 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
394 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
397 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
398 distance -= (*k)->getLength();
404 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
408 copy(k, routeend, back_inserter(nrd.
edges2Pass));
420 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
421 distance -= (*k)->getLength();
437 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
438 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
439 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
447 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
451 std::vector<IterationEdge> missing;
455 missing.push_back(ie);
456 bool maxDepthReached =
false;
457 while (!missing.empty() && !maxDepthReached) {
461 for (ROEdgeVector::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
463 previous.push_back(*j);
467 missing.push_back(ie);
469 maxDepthReached =
true;
474 if (maxDepthReached) {
482 std::vector<IterationEdge> missing;
483 for (ROEdgeVector::const_iterator k = previous.begin(); k != previous.end(); ++k) {
487 missing.push_back(ie);
489 bool maxDepthReached =
false;
490 while (!missing.empty() && !maxDepthReached) {
494 for (ROEdgeVector::const_iterator j = approached.begin(); j != approached.end(); ++j) {
499 latter.push_back(*j);
504 missing.push_back(ie);
506 maxDepthReached =
true;
511 if (maxDepthReached) {
520 std::vector<FlowDef> mflows;
522 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
531 for (ROEdgeVector::iterator i = previous.begin(); i != previous.end(); ++i) {
532 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
533 if (flows.size() != 0) {
534 const FlowDef& srcFD = flows[index];
542 inFlow.
vLKW /= (double) previous.size();
543 inFlow.
vPKW /= (double) previous.size();
552 for (ROEdgeVector::iterator i = latter.begin(); i != latter.end(); ++i) {
553 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
554 if (flows.size() != 0) {
555 const FlowDef& srcFD = flows[index];
563 outFlow.
vLKW /= (double) latter.size();
564 outFlow.
vPKW /= (double) latter.size();
569 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
570 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
571 mflows.push_back(mFlow);
583 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
584 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
595 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
596 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
599 if (flows.
knows((*i)->getID())) {
603 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
618 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
619 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
622 if (flows.
knows((*i)->getID())) {
626 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
636 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
639 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
672 const std::vector<std::string>&
713 if (seen.size() == 1000) {
714 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
721 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
722 if ((*i) == det.
getID()) {
756 for (
int i = 0; i < (int)appr.size(); i++) {
763 if (noFalse + noSkipped == (
int)appr.size()) {
790 seen.push_back(edge);
791 for (
int i = 0; i < (int)appr.size(); i++) {
792 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
794 if (
isSource(det, appr[i], seen, detectors, strict)) {
804 return numOk + numSkipped == (int)appr.size();
806 return numFalse + numSkipped != (int)appr.size();
813 if (seen.size() == 1000) {
814 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
821 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
822 if ((*i) == det.
getID()) {
873 seen.push_back(edge);
874 for (
int i = 0; i < (int)appr.size() && isall; i++) {
875 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
889 if (seen.size() == 1000) {
890 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
893 seen.push_back(edge);
898 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
922 for (
int i = 0; i < (int)appr.size() && !isall; i++) {
924 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
940 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
941 double speedFactorSumPKW = 0;
942 double speedFactorSumLKW = 0;
943 double speedFactorCountPKW = 0;
944 double speedFactorCountLKW = 0;
946 ROEdge* into = (*i).first;
950 const std::vector<std::string>& dets = (*i).second;
951 std::map<double, std::vector<std::string> > cliques;
952 std::vector<std::string>* maxClique = 0;
953 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
954 if (!flows.
knows(*j)) {
959 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
960 if (fabs((*k).first - det.
getPos()) < 1) {
961 (*k).second.push_back(*j);
962 if ((*k).second.size() > maxClique->size()) {
963 maxClique = &(*k).second;
969 cliques[det.
getPos()].push_back(*j);
970 maxClique = &cliques[det.
getPos()];
973 if (maxClique == 0) {
976 std::vector<FlowDef> mflows;
977 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
985 mflows.push_back(fd);
987 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
988 bool didWarn =
false;
989 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
991 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
992 const FlowDef& srcFD = dflows[index];
996 fd.
vLKW += srcFD.
vLKW / (double) maxClique->size();
997 fd.
vPKW += srcFD.
vPKW / (double) maxClique->size();
998 fd.
fLKW += srcFD.
fLKW / (double) maxClique->size();
999 fd.
isLKW += srcFD.
isLKW / (double) maxClique->size();
1000 const double speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
1001 const double speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
1004 speedFactorCountPKW += srcFD.
qPKW;
1005 speedFactorCountLKW += srcFD.
qLKW;
1006 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
1007 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
1018 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1021 if (speedFactorCountPKW > 0) {
1025 if (speedFactorCountLKW > 0) {
1040 std::map<std::string, ROEdge*>::const_iterator i;
1047 std::vector<RODFDetector*> last;
1049 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1050 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1056 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1058 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1062 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1064 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1066 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1070 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1083 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1085 const std::vector<std::string>& dets = (*i).second;
1086 std::map<double, std::vector<std::string> > cliques;
1088 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1091 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1092 if (fabs((*k).first - det.
getPos()) < 10.) {
1093 (*k).second.push_back(*j);
1098 cliques[det.
getPos()] = std::vector<std::string>();
1099 cliques[det.
getPos()].push_back(*j);
1103 for (std::map<
double, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1104 std::vector<std::string> clique = (*m).second;
1106 if (clique.size() == 1) {
1110 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1111 std::cout << *n <<
" ";
1112 if (n != clique.begin()) {
1117 std::cout <<
":" << nid << std::endl;
1119 detectors.
mesoJoin(nid, (*m).second);
void mesoJoin(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
void revalidateFlows(const RODFDetectorCon &detectors, RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
RODFDetector & getModifiableDetector(const std::string &id) const
std::vector< std::string > myDisallowedEdges
List of ids of edges that shall not be used.
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) ...
double getSpeedLimit() const
Returns the speed allowed on this edge.
double myAvgSpeedFactorLKW
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
double myAvgSpeedFactorPKW
double getVClassMaxSpeed(SUMOVehicleClass vclass) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
ROEdge * getDetectorEdge(const RODFDetector &det) const
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
void removeDetector(const std::string &id)
double getLength() const
Returns the length of the edge.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool isSource(const RODFDetector &det, const RODFDetectorCon &detectors, bool strict) const
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::vector< FlowDef > & getFlows() 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)
const std::vector< RODFRouteDesc > & getRouteVector() const
ROEdgeVector edges2Pass
The edges the route is made of.
void computeTypes(RODFDetectorCon &dets, bool sourcesStrict) const
void addPriorDetector(const RODFDetector *det)
const std::vector< RODFDetector * > & getDetectors() const
std::vector< const ROEdge * > ConstROEdgeVector
bool hasSourceDetector(ROEdge *edge, const RODFDetectorCon &detectors) const
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
A container for RODFDetectors.
#define UNUSED_PARAMETER(x)
bool hasDetector(ROEdge *edge) const
#define WRITE_WARNING(msg)
const std::map< std::string, ROEdge * > & getEdgeMap() const
static OptionsCont & getOptions()
Retrieves the options.
vehicle is a large transport vehicle
void buildRoutes(RODFDetectorCon &det, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const
RODFDetectorType getType() const
Returns the type of the detector.
comparator for maps using edges as key, used only in myDetectorsOnEdges to make tests comparable ...
A not yet defined detector.
bool isDestination(const RODFDetector &det, const RODFDetectorCon &detectors) const
const std::string & getID() const
Returns the id.
const RONode * getToJunction() const
bool removeRouteDesc(RODFRouteDesc &desc)
Removes the given route description from the container.
bool isInternal() const
return whether this edge is an internal edge
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool hasApproaching(ROEdge *edge) const
RODFNet(bool amInHighwayMode)
Constructor.
std::vector< ROEdge * > ROEdgeVector
A detector which had to be discarded (!!!)
#define PROGRESS_BEGIN_MESSAGE(msg)
void setFlows(const std::string &detector_id, std::vector< FlowDef > &)
const std::vector< std::string > & getDetectorList(ROEdge *edge) const
void buildDetectorEdgeDependencies(RODFDetectorCon &dets) const
bool knows(const std::string &det_id) 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
Definition of the traffic during a certain time containing the flows and speeds.
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
double getPos() const
Returns the position at which the detector lies.
double myMaxSpeedFactorLKW
const RONode * getFromJunction() const
The router's network representation.
void buildEdgeFlowMap(const RODFDetectorFlows &flows, const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
double getAbsPos(const RODFDetector &det) const
const RODFDetector & getDetector(const std::string &id) const
void buildDetectorDependencies(RODFDetectorCon &detectors)
Class representing a detector within the DFROUTER.
const ROEdge * endDetectorEdge
const ROEdgeVector & getSuccessors() const
Returns the following edges.
std::map< std::string, ROEdge * > myDetectorEdges
bool hasApproached(ROEdge *edge) const
A container for DFROUTER-routes.
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
std::map< ROEdge *, std::vector< std::string >, idComp > myDetectorsOnEdges
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
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)
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.