47 #ifdef CHECK_MEMORY_LEAKS
49 #endif // CHECK_MEMORY_LEAKS
56 :
RONet(), myAmInHighwayMode(amInHighwayMode),
57 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0) {
69 const std::map<std::string, ROEdge*> &edges =
getEdgeMap();
70 for (std::map<std::string, ROEdge*>::const_iterator rit = edges.begin(); rit != edges.end(); ++rit) {
71 ROEdge* ce = (*rit).second;
74 for (i = 0; i < length_size; i++) {
103 const std::vector<RODFDetector*> &dets = detcont.
getDetectors();
104 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
114 bool sourcesStrict)
const {
116 const std::vector< RODFDetector*> &dets = detcont.
getDetectors();
120 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
121 if (
isSource(**i, detcont, sourcesStrict)) {
135 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
157 std::vector<std::string>::const_iterator i;
158 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
173 std::vector<std::string>::const_iterator i;
174 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
187 bool keepUnfoundEnds,
188 bool keepShortestOnly,
189 std::vector<ROEdge*> &,
192 int maxFollowingLength,
193 std::vector<ROEdge*> &seen)
const {
194 std::vector<RODFRouteDesc> unfoundEnds;
196 std::map<ROEdge*, std::vector<ROEdge*> > dets2Follow;
197 dets2Follow[edge] = std::vector<ROEdge*>();
201 while (!toSolve.empty()) {
206 if (dets2Follow.find(last) == dets2Follow.end()) {
207 dets2Follow[last] = std::vector<ROEdge*>();
209 for (std::vector<ROEdge*>::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
211 dets2Follow[*i].push_back(last);
218 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
221 seen.push_back(last);
227 if (minDist < cdist) {
234 bool addNextNoFurther =
false;
241 addNextNoFurther =
true;
251 if (minDist < cdist) {
272 addNextNoFurther =
true;
278 if (!addNextNoFurther) {
281 if (current.
passedNo > maxFollowingLength) {
284 unfoundEnds.push_back(current);
287 if (minDist < cdist) {
296 for (
size_t i = 0; i < appr.size(); i++) {
302 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeed());
305 if (!addNextNoFurther) {
312 if (minDist < cdist) {
321 if (!keepUnfoundEnds) {
322 std::vector<RODFRouteDesc>::iterator i;
323 std::vector<const ROEdge*> lastDetEdges;
324 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
325 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
326 lastDetEdges.push_back((*i).lastDetectorEdge);
335 while (!toSolve.empty()) {
345 bool keepUnfoundEnds,
bool includeInBetween,
346 bool keepShortestOnly,
int maxFollowingLength)
const {
350 std::map<ROEdge*, RODFRouteCont* > doneEdges;
351 const std::vector< RODFDetector*> &dets = detcont.
getDetectors();
352 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
358 if (doneEdges.find(e) != doneEdges.end()) {
363 std::vector<ROEdge*> seen;
365 doneEdges[e] = routes;
377 std::vector<ROEdge*> visited;
378 visited.push_back(e);
380 visited, **i, *routes, detcont, maxFollowingLength, seen);
381 if (allEndFollower) {
385 (*i)->addRoutes(routes);
388 if (includeInBetween) {
390 const std::vector<RODFRouteDesc> &r = routes->
get();
391 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
396 std::vector<ROEdge*>::const_iterator routeend = mrd.
edges2Pass.end();
397 for (std::vector<ROEdge*>::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
400 duration -= (*k)->getLength() / (*k)->getSpeed();
401 distance -= (*k)->getLength();
407 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
411 copy(k, routeend, back_inserter(nrd.
edges2Pass));
423 duration -= (*k)->getLength() / (*k)->getSpeed();
424 distance -= (*k)->getLength();
440 const std::vector<FlowDef> &detFlows = flows.
getFlowDefs(detector->
getID());
441 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
442 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
450 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
452 std::vector<ROEdge*> previous;
454 std::vector<IterationEdge> missing;
458 missing.push_back(ie);
459 bool maxDepthReached =
false;
460 while (!missing.empty() && !maxDepthReached) {
464 for (std::vector<ROEdge*>::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
466 previous.push_back(*j);
470 missing.push_back(ie);
472 maxDepthReached =
true;
477 if (maxDepthReached) {
483 std::vector<ROEdge*> latter;
485 std::vector<IterationEdge> missing;
486 for (std::vector<ROEdge*>::const_iterator k = previous.begin(); k != previous.end(); ++k) {
490 missing.push_back(ie);
492 bool maxDepthReached =
false;
493 while (!missing.empty() && !maxDepthReached) {
497 for (std::vector<ROEdge*>::const_iterator j = approached.begin(); j != approached.end(); ++j) {
502 latter.push_back(*j);
507 missing.push_back(ie);
509 maxDepthReached =
true;
514 if (maxDepthReached) {
523 std::vector<FlowDef> mflows;
525 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
534 for (std::vector<ROEdge*>::iterator i = previous.begin(); i != previous.end(); ++i) {
535 const std::vector<FlowDef> &flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
536 if (flows.size() != 0) {
537 const FlowDef& srcFD = flows[index];
555 for (std::vector<ROEdge*>::iterator i = latter.begin(); i != latter.end(); ++i) {
556 const std::vector<FlowDef> &flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
557 if (flows.size() != 0) {
558 const FlowDef& srcFD = flows[index];
574 mflows.push_back(mFlow);
586 const std::vector<RODFDetector*> &dets = detectors.
getDetectors();
587 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
598 const std::vector<RODFDetector*> &dets = detectors.
getDetectors();
599 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
602 if (flows.
knows((*i)->getID())) {
606 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
621 const std::vector<RODFDetector*> &dets = detectors.
getDetectors();
622 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
625 if (flows.
knows((*i)->getID())) {
629 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
639 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
642 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
675 const std::vector<std::string> &
692 std::vector<ROEdge*> seen;
699 std::vector<ROEdge*> seen;
706 std::vector<ROEdge*> seen;
713 std::vector<ROEdge*> &seen,
716 if (seen.size() == 1000) {
717 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
724 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
725 if ((*i) == det.
getID()) {
758 size_t noSkipped = 0;
759 for (
size_t i = 0; i < appr.size(); i++) {
766 if ((noFalse + noSkipped) == appr.size()) {
792 size_t noSkipped = 0;
793 seen.push_back(edge);
794 for (
size_t i = 0; i < appr.size(); i++) {
795 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
797 if (
isSource(det, appr[i], seen, detectors, strict)) {
807 return (noFalse + noSkipped) != appr.size();
809 return (noOk + noSkipped) == appr.size();
817 if (seen.size() == 1000) {
818 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
825 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
826 if ((*i) == det.
getID()) {
877 seen.push_back(edge);
878 for (
size_t i = 0; i < appr.size() && isall; i++) {
879 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
893 if (seen.size() == 1000) {
894 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
897 seen.push_back(edge);
902 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
926 for (
size_t i = 0; i < appr.size() && !isall; i++) {
928 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
944 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
946 ROEdge* into = (*i).first;
947 const std::vector<std::string> &dets = (*i).second;
948 std::map<SUMOReal, std::vector<std::string> > cliques;
949 std::vector<std::string>* maxClique = 0;
950 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
951 if (!flows.
knows(*j)) {
956 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
957 if (fabs((*k).first - det.
getPos()) < 1) {
958 (*k).second.push_back(*j);
959 if ((*k).second.size() > maxClique->size()) {
960 maxClique = &(*k).second;
966 cliques[det.
getPos()].push_back(*j);
967 maxClique = &cliques[det.
getPos()];
970 if (maxClique == 0) {
973 std::vector<FlowDef> mflows;
974 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
982 mflows.push_back(fd);
984 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
985 bool didWarn =
false;
986 const std::vector<FlowDef> &dflows = flows.
getFlowDefs(*l);
988 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
989 const FlowDef& srcFD = dflows[index];
998 WRITE_MESSAGE(
"Detected PKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1002 WRITE_MESSAGE(
"Detected LKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1007 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1019 std::map<std::string, ROEdge*>::const_iterator i;
1026 std::vector<RODFDetector*> last;
1028 const std::vector<std::string> &detNames =
myDetectorsOnEdges.find((*i).second)->second;
1029 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1035 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1036 const std::vector<ROEdge*> &edges2Pass = (*j).edges2Pass;
1037 for (std::vector<ROEdge*>::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1041 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1043 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1049 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1062 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1064 const std::vector<std::string> &dets = (*i).second;
1065 std::map<SUMOReal, std::vector<std::string> > cliques;
1067 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1070 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1071 if (fabs((*k).first - det.
getPos()) < 10.) {
1072 (*k).second.push_back(*j);
1077 cliques[det.
getPos()] = std::vector<std::string>();
1078 cliques[det.
getPos()].push_back(*j);
1082 for (std::map<
SUMOReal, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1083 std::vector<std::string> clique = (*m).second;
1085 if (clique.size() == 1) {
1089 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1090 std::cout << *n <<
" ";
1091 if (n != clique.begin()) {
1096 std::cout <<
":" << nid << std::endl;
1098 detectors.
mesoJoin(nid, (*m).second);