46 RONet(), myAmInHighwayMode(amInHighwayMode),
47 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0),
48 myMaxSpeedFactorPKW(1),
49 myMaxSpeedFactorLKW(1),
50 myAvgSpeedFactorPKW(1),
51 myAvgSpeedFactorLKW(1) {
69 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
98 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
99 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
109 bool sourcesStrict)
const {
111 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
115 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
116 if (
isSource(**i, detcont, sourcesStrict)) {
130 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
152 std::vector<std::string>::const_iterator i;
153 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
168 std::vector<std::string>::const_iterator i;
169 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
182 bool keepUnfoundEnds,
183 bool keepShortestOnly,
187 int maxFollowingLength,
189 std::vector<RODFRouteDesc> unfoundEnds;
191 std::map<ROEdge*, ROEdgeVector > dets2Follow;
196 while (!toSolve.empty()) {
201 if (dets2Follow.find(last) == dets2Follow.end()) {
204 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
206 dets2Follow[*i].push_back(last);
213 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
216 seen.push_back(last);
221 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
222 if (minDist < cdist) {
229 bool addNextNoFurther =
false;
236 addNextNoFurther =
true;
245 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
246 if (minDist < cdist) {
267 addNextNoFurther =
true;
273 if (!addNextNoFurther) {
276 if (current.
passedNo > maxFollowingLength) {
279 unfoundEnds.push_back(current);
281 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
282 if (minDist < cdist) {
291 for (
int i = 0; i < (int)appr.size(); i++) {
297 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
300 if (!addNextNoFurther) {
305 t.
factor = (double) 1. / (
double) appr.size();
306 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
307 if (minDist < cdist) {
316 if (!keepUnfoundEnds) {
317 std::vector<RODFRouteDesc>::iterator i;
319 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
320 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
321 lastDetEdges.push_back((*i).lastDetectorEdge);
331 while (!toSolve.empty()) {
341 bool keepShortestOnly,
int maxFollowingLength)
const {
345 std::map<ROEdge*, RODFRouteCont* > doneEdges;
346 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
347 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
349 if (doneEdges.find(e) != doneEdges.end()) {
356 doneEdges[e] = routes;
369 visited.push_back(e);
371 visited, **i, *routes, detcont, maxFollowingLength, seen);
373 (*i)->addRoutes(routes);
376 if (includeInBetween) {
378 const std::vector<RODFRouteDesc>& r = routes->
get();
379 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
384 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
385 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
388 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
389 distance -= (*k)->getLength();
395 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
399 copy(k, routeend, back_inserter(nrd.
edges2Pass));
411 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
412 distance -= (*k)->getLength();
428 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
429 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
430 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
438 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
442 std::vector<IterationEdge> missing;
446 missing.push_back(ie);
447 bool maxDepthReached =
false;
448 while (!missing.empty() && !maxDepthReached) {
452 for (ROEdgeVector::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
454 previous.push_back(*j);
458 missing.push_back(ie);
460 maxDepthReached =
true;
465 if (maxDepthReached) {
473 std::vector<IterationEdge> missing;
474 for (ROEdgeVector::const_iterator k = previous.begin(); k != previous.end(); ++k) {
478 missing.push_back(ie);
480 bool maxDepthReached =
false;
481 while (!missing.empty() && !maxDepthReached) {
485 for (ROEdgeVector::const_iterator j = approached.begin(); j != approached.end(); ++j) {
490 latter.push_back(*j);
495 missing.push_back(ie);
497 maxDepthReached =
true;
502 if (maxDepthReached) {
511 std::vector<FlowDef> mflows;
513 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
522 for (ROEdgeVector::iterator i = previous.begin(); i != previous.end(); ++i) {
523 const std::vector<FlowDef>& flows = static_cast<const RODFEdge*>(*i)->getFlows();
524 if (flows.size() != 0) {
525 const FlowDef& srcFD = flows[index];
533 inFlow.
vLKW /= (double) previous.size();
534 inFlow.
vPKW /= (double) previous.size();
543 for (ROEdgeVector::iterator i = latter.begin(); i != latter.end(); ++i) {
544 const std::vector<FlowDef>& flows = static_cast<const RODFEdge*>(*i)->getFlows();
545 if (flows.size() != 0) {
546 const FlowDef& srcFD = flows[index];
554 outFlow.
vLKW /= (double) latter.size();
555 outFlow.
vPKW /= (double) latter.size();
560 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
561 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
562 mflows.push_back(mFlow);
574 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
575 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
586 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
587 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
590 if (flows.
knows((*i)->getID())) {
594 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
609 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
610 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
613 if (flows.
knows((*i)->getID())) {
617 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
627 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
629 if (ret ==
nullptr) {
630 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
663 const std::vector<std::string>&
704 if (seen.size() == 1000) {
705 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
712 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
713 if ((*i) == det.
getID()) {
747 for (
int i = 0; i < (int)appr.size(); i++) {
754 if (noFalse + noSkipped == (
int)appr.size()) {
781 seen.push_back(edge);
782 for (
int i = 0; i < (int)appr.size(); i++) {
783 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
785 if (
isSource(det, appr[i], seen, detectors, strict)) {
795 return numOk + numSkipped == (int)appr.size();
797 return numFalse + numSkipped != (int)appr.size();
804 if (seen.size() == 1000) {
805 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
812 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
813 if ((*i) == det.
getID()) {
864 seen.push_back(edge);
865 for (
int i = 0; i < (int)appr.size() && isall; i++) {
866 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
880 if (seen.size() == 1000) {
881 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
884 seen.push_back(edge);
889 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
913 for (
int i = 0; i < (int)appr.size() && !isall; i++) {
915 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
931 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
932 double speedFactorSumPKW = 0;
933 double speedFactorSumLKW = 0;
934 double speedFactorCountPKW = 0;
935 double speedFactorCountLKW = 0;
937 ROEdge* into = (*i).first;
941 const std::vector<std::string>& dets = (*i).second;
942 std::map<double, std::vector<std::string> > cliques;
943 std::vector<std::string>* maxClique =
nullptr;
944 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
945 if (!flows.
knows(*j)) {
950 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
951 if (fabs((*k).first - det.
getPos()) < 1) {
952 (*k).second.push_back(*j);
953 if ((*k).second.size() > maxClique->size()) {
954 maxClique = &(*k).second;
960 cliques[det.
getPos()].push_back(*j);
961 maxClique = &cliques[det.
getPos()];
964 if (maxClique ==
nullptr) {
967 std::vector<FlowDef> mflows;
968 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
976 mflows.push_back(
fd);
978 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
979 bool didWarn =
false;
980 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
982 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
983 const FlowDef& srcFD = dflows[index];
987 fd.vLKW += srcFD.
vLKW / (double) maxClique->size();
988 fd.vPKW += srcFD.
vPKW / (double) maxClique->size();
989 fd.fLKW += srcFD.
fLKW / (double) maxClique->size();
990 fd.isLKW += srcFD.
isLKW / (double) maxClique->size();
991 const double speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
992 const double speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
995 speedFactorCountPKW += srcFD.
qPKW;
996 speedFactorCountLKW += srcFD.
qLKW;
997 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
998 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
1009 static_cast<RODFEdge*>(into)->setFlows(mflows);
1012 if (speedFactorCountPKW > 0) {
1016 if (speedFactorCountLKW > 0) {
1031 std::map<std::string, ROEdge*>::const_iterator i;
1038 std::vector<RODFDetector*> last;
1040 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1041 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1047 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1049 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1053 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1055 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1057 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1061 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1074 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1076 const std::vector<std::string>& dets = (*i).second;
1077 std::map<double, std::vector<std::string> > cliques;
1079 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1082 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1083 if (fabs((*k).first - det.
getPos()) < 10.) {
1084 (*k).second.push_back(*j);
1089 cliques[det.
getPos()] = std::vector<std::string>();
1090 cliques[det.
getPos()].push_back(*j);
1094 for (std::map<
double, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1095 std::vector<std::string> clique = (*m).second;
1097 if (clique.size() == 1) {
1101 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1102 std::cout << *n <<
" ";
1103 if (n != clique.begin()) {
1108 std::cout <<
":" << nid << std::endl;
1110 detectors.
mesoJoin(nid, (*m).second);