48 #ifdef CHECK_MEMORY_LEAKS
50 #endif // CHECK_MEMORY_LEAKS
57 :
RONet(), myAmInHighwayMode(amInHighwayMode),
58 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0) {
70 const std::map<std::string, ROEdge*>& edges =
getEdgeMap();
71 for (std::map<std::string, ROEdge*>::const_iterator rit = edges.begin(); rit != edges.end(); ++rit) {
72 ROEdge* ce = (*rit).second;
75 for (i = 0; i < length_size; i++) {
104 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
105 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
115 bool sourcesStrict)
const {
117 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
121 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
122 if (
isSource(**i, detcont, sourcesStrict)) {
136 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
158 std::vector<std::string>::const_iterator i;
159 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
174 std::vector<std::string>::const_iterator i;
175 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
188 bool keepUnfoundEnds,
189 bool keepShortestOnly,
190 std::vector<ROEdge*>& ,
193 int maxFollowingLength,
194 std::vector<ROEdge*>& seen)
const {
195 std::vector<RODFRouteDesc> unfoundEnds;
197 std::map<ROEdge*, std::vector<ROEdge*> > dets2Follow;
198 dets2Follow[edge] = std::vector<ROEdge*>();
202 while (!toSolve.empty()) {
207 if (dets2Follow.find(last) == dets2Follow.end()) {
208 dets2Follow[last] = std::vector<ROEdge*>();
210 for (std::vector<ROEdge*>::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
212 dets2Follow[*i].push_back(last);
219 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
222 seen.push_back(last);
228 if (minDist < cdist) {
235 bool addNextNoFurther =
false;
242 addNextNoFurther =
true;
252 if (minDist < cdist) {
273 addNextNoFurther =
true;
279 if (!addNextNoFurther) {
282 if (current.
passedNo > maxFollowingLength) {
285 unfoundEnds.push_back(current);
288 if (minDist < cdist) {
297 for (
size_t i = 0; i < appr.size(); i++) {
303 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeed());
306 if (!addNextNoFurther) {
313 if (minDist < cdist) {
322 if (!keepUnfoundEnds) {
323 std::vector<RODFRouteDesc>::iterator i;
324 std::vector<const ROEdge*> lastDetEdges;
325 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
326 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
327 lastDetEdges.push_back((*i).lastDetectorEdge);
336 while (!toSolve.empty()) {
346 bool keepUnfoundEnds,
bool includeInBetween,
347 bool keepShortestOnly,
int maxFollowingLength)
const {
351 std::map<ROEdge*, RODFRouteCont* > doneEdges;
352 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
353 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
359 if (doneEdges.find(e) != doneEdges.end()) {
364 std::vector<ROEdge*> seen;
366 doneEdges[e] = routes;
378 std::vector<ROEdge*> visited;
379 visited.push_back(e);
381 visited, **i, *routes, detcont, maxFollowingLength, seen);
382 if (allEndFollower) {
386 (*i)->addRoutes(routes);
389 if (includeInBetween) {
391 const std::vector<RODFRouteDesc>& r = routes->
get();
392 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
397 std::vector<ROEdge*>::const_iterator routeend = mrd.
edges2Pass.end();
398 for (std::vector<ROEdge*>::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
401 duration -= (*k)->getLength() / (*k)->getSpeed();
402 distance -= (*k)->getLength();
408 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
412 copy(k, routeend, back_inserter(nrd.
edges2Pass));
424 duration -= (*k)->getLength() / (*k)->getSpeed();
425 distance -= (*k)->getLength();
441 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
442 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
443 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
451 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
453 std::vector<ROEdge*> previous;
455 std::vector<IterationEdge> missing;
459 missing.push_back(ie);
460 bool maxDepthReached =
false;
461 while (!missing.empty() && !maxDepthReached) {
465 for (std::vector<ROEdge*>::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
467 previous.push_back(*j);
471 missing.push_back(ie);
473 maxDepthReached =
true;
478 if (maxDepthReached) {
484 std::vector<ROEdge*> latter;
486 std::vector<IterationEdge> missing;
487 for (std::vector<ROEdge*>::const_iterator k = previous.begin(); k != previous.end(); ++k) {
491 missing.push_back(ie);
493 bool maxDepthReached =
false;
494 while (!missing.empty() && !maxDepthReached) {
498 for (std::vector<ROEdge*>::const_iterator j = approached.begin(); j != approached.end(); ++j) {
503 latter.push_back(*j);
508 missing.push_back(ie);
510 maxDepthReached =
true;
515 if (maxDepthReached) {
524 std::vector<FlowDef> mflows;
526 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
535 for (std::vector<ROEdge*>::iterator i = previous.begin(); i != previous.end(); ++i) {
536 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
537 if (flows.size() != 0) {
538 const FlowDef& srcFD = flows[index];
556 for (std::vector<ROEdge*>::iterator i = latter.begin(); i != latter.end(); ++i) {
557 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
558 if (flows.size() != 0) {
559 const FlowDef& srcFD = flows[index];
575 mflows.push_back(mFlow);
587 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
588 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
599 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
600 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
603 if (flows.
knows((*i)->getID())) {
607 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
622 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
623 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
626 if (flows.
knows((*i)->getID())) {
630 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
640 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
643 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
676 const std::vector<std::string>&
693 std::vector<ROEdge*> seen;
700 std::vector<ROEdge*> seen;
707 std::vector<ROEdge*> seen;
714 std::vector<ROEdge*>& seen,
717 if (seen.size() == 1000) {
718 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
725 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
726 if ((*i) == det.
getID()) {
759 size_t noSkipped = 0;
760 for (
size_t i = 0; i < appr.size(); i++) {
767 if ((noFalse + noSkipped) == appr.size()) {
793 size_t noSkipped = 0;
794 seen.push_back(edge);
795 for (
size_t i = 0; i < appr.size(); i++) {
796 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
798 if (
isSource(det, appr[i], seen, detectors, strict)) {
808 return (noFalse + noSkipped) != appr.size();
810 return (noOk + noSkipped) == appr.size();
818 if (seen.size() == 1000) {
819 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
826 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
827 if ((*i) == det.
getID()) {
878 seen.push_back(edge);
879 for (
size_t i = 0; i < appr.size() && isall; i++) {
880 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
894 if (seen.size() == 1000) {
895 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
898 seen.push_back(edge);
903 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
927 for (
size_t i = 0; i < appr.size() && !isall; i++) {
929 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
945 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
947 ROEdge* into = (*i).first;
948 const std::vector<std::string>& dets = (*i).second;
949 std::map<SUMOReal, std::vector<std::string> > cliques;
950 std::vector<std::string>* maxClique = 0;
951 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
952 if (!flows.
knows(*j)) {
957 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
958 if (fabs((*k).first - det.
getPos()) < 1) {
959 (*k).second.push_back(*j);
960 if ((*k).second.size() > maxClique->size()) {
961 maxClique = &(*k).second;
967 cliques[det.
getPos()].push_back(*j);
968 maxClique = &cliques[det.
getPos()];
971 if (maxClique == 0) {
974 std::vector<FlowDef> mflows;
975 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
983 mflows.push_back(fd);
985 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
986 bool didWarn =
false;
987 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
989 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
990 const FlowDef& srcFD = dflows[index];
999 WRITE_MESSAGE(
"Detected PKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1003 WRITE_MESSAGE(
"Detected LKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1008 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1020 std::map<std::string, ROEdge*>::const_iterator i;
1027 std::vector<RODFDetector*> last;
1029 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1030 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1036 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1037 const std::vector<ROEdge*>& edges2Pass = (*j).edges2Pass;
1038 for (std::vector<ROEdge*>::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1042 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1044 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1050 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1063 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1065 const std::vector<std::string>& dets = (*i).second;
1066 std::map<SUMOReal, std::vector<std::string> > cliques;
1068 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1071 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1072 if (fabs((*k).first - det.
getPos()) < 10.) {
1073 (*k).second.push_back(*j);
1078 cliques[det.
getPos()] = std::vector<std::string>();
1079 cliques[det.
getPos()].push_back(*j);
1083 for (std::map<
SUMOReal, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1084 std::vector<std::string> clique = (*m).second;
1086 if (clique.size() == 1) {
1090 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1091 std::cout << *n <<
" ";
1092 if (n != clique.begin()) {
1097 std::cout <<
":" << nid << std::endl;
1099 detectors.
mesoJoin(nid, (*m).second);