void RODFNet::buildRoutes(RODFDetectorCon& detcont, bool allEndFollower, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const { // build needed information first buildDetectorEdgeDependencies(detcont); // then build the routes std::map<ROEdge*, RODFRouteCont* > doneEdges; const std::vector< RODFDetector*>& dets = detcont.getDetectors(); for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) { ROEdge* e = getDetectorEdge(**i); if (doneEdges.find(e) != doneEdges.end()) { // use previously build routes (*i)->addRoutes(new RODFRouteCont(*doneEdges[e])); continue; } std::vector<ROEdge*> seen; RODFRouteCont* routes = new RODFRouteCont(); doneEdges[e] = routes; RODFRouteDesc rd; rd.edges2Pass.push_back(e); rd.duration_2 = (e->getLength() / e->getSpeed()); //!!!; rd.endDetectorEdge = 0; rd.lastDetectorEdge = 0; rd.distance = e->getLength(); rd.distance2Last = 0; rd.duration2Last = 0; rd.overallProb = 0; std::vector<ROEdge*> visited; visited.push_back(e); computeRoutesFor(e, rd, 0, keepUnfoundEnds, keepShortestOnly, visited, **i, *routes, detcont, maxFollowingLength, seen); if (allEndFollower) { routes->addAllEndFollower(); } //!!!routes->removeIllegal(illegals); (*i)->addRoutes(routes); // add routes to in-between detectors if wished if (includeInBetween) { // go through the routes const std::vector<RODFRouteDesc>& r = routes->get(); for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) { const RODFRouteDesc& mrd = *j; SUMOReal duration = mrd.duration_2; SUMOReal distance = mrd.distance; // go through each route's edges std::vector<ROEdge*>::const_iterator routeend = mrd.edges2Pass.end(); for (std::vector<ROEdge*>::const_iterator k = mrd.edges2Pass.begin(); k != routeend; ++k) { // check whether any detectors lies on the current edge if (myDetectorsOnEdges.find(*k) == myDetectorsOnEdges.end()) { duration -= (*k)->getLength() / (*k)->getSpeed(); distance -= (*k)->getLength(); continue; } // get the detectors const std::vector<std::string>& dets = myDetectorsOnEdges.find(*k)->second; // go through the detectors for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) { const RODFDetector& m = detcont.getDetector(*l); if (m.getType() == BETWEEN_DETECTOR) { RODFRouteDesc nrd; copy(k, routeend, back_inserter(nrd.edges2Pass)); nrd.duration_2 = duration;//!!!; nrd.endDetectorEdge = mrd.endDetectorEdge; nrd.lastDetectorEdge = mrd.lastDetectorEdge; nrd.distance = distance; nrd.distance2Last = mrd.distance2Last; nrd.duration2Last = mrd.duration2Last; nrd.overallProb = mrd.overallProb; nrd.factor = mrd.factor; ((RODFDetector&) m).addRoute(nrd); } } duration -= (*k)->getLength() / (*k)->getSpeed(); distance -= (*k)->getLength(); } } } } }
void RODFNet::buildEdgeFlowMap(const RODFDetectorFlows& flows, const RODFDetectorCon& detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset) { std::map<ROEdge*, std::vector<std::string>, idComp>::iterator i; for (i = myDetectorsOnEdges.begin(); i != myDetectorsOnEdges.end(); ++i) { ROEdge* into = (*i).first; const std::vector<std::string>& dets = (*i).second; std::map<SUMOReal, std::vector<std::string> > cliques; std::vector<std::string>* maxClique = 0; for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) { if (!flows.knows(*j)) { continue; } const RODFDetector& det = detectors.getDetector(*j); bool found = false; for (std::map<SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) { if (fabs((*k).first - det.getPos()) < 1) { (*k).second.push_back(*j); if ((*k).second.size() > maxClique->size()) { maxClique = &(*k).second; } found = true; } } if (!found) { cliques[det.getPos()].push_back(*j); maxClique = &cliques[det.getPos()]; } } if (maxClique == 0) { continue; } std::vector<FlowDef> mflows; // !!! reserve for (SUMOTime t = startTime; t < endTime; t += stepOffset) { FlowDef fd; fd.qPKW = 0; fd.qLKW = 0; fd.vLKW = 0; fd.vPKW = 0; fd.fLKW = 0; fd.isLKW = 0; mflows.push_back(fd); } for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) { bool didWarn = false; const std::vector<FlowDef>& dflows = flows.getFlowDefs(*l); int index = 0; for (SUMOTime t = startTime; t < endTime; t += stepOffset, index++) { const FlowDef& srcFD = dflows[index]; FlowDef& fd = mflows[index]; fd.qPKW += srcFD.qPKW; fd.qLKW += srcFD.qLKW; fd.vLKW += (srcFD.vLKW / (SUMOReal) maxClique->size()); fd.vPKW += (srcFD.vPKW / (SUMOReal) maxClique->size()); fd.fLKW += (srcFD.fLKW / (SUMOReal) maxClique->size()); fd.isLKW += (srcFD.isLKW / (SUMOReal) maxClique->size()); if (!didWarn && srcFD.vPKW > 0 && srcFD.vPKW < 255 && srcFD.vPKW / 3.6 > into->getSpeed()) { WRITE_MESSAGE("Detected PKW speed higher than allowed speed at '" + (*l) + "' on '" + into->getID() + "'."); didWarn = true; } if (!didWarn && srcFD.vLKW > 0 && srcFD.vLKW < 255 && srcFD.vLKW / 3.6 > into->getSpeed()) { WRITE_MESSAGE("Detected LKW speed higher than allowed speed at '" + (*l) + "' on '" + into->getID() + "'."); didWarn = true; } } } static_cast<RODFEdge*>(into)->setFlows(mflows); } }
void RODFNet::computeRoutesFor(ROEdge* edge, RODFRouteDesc& base, int /*no*/, bool keepUnfoundEnds, bool keepShortestOnly, std::vector<ROEdge*>& /*visited*/, const RODFDetector& det, RODFRouteCont& into, const RODFDetectorCon& detectors, int maxFollowingLength, std::vector<ROEdge*>& seen) const { std::vector<RODFRouteDesc> unfoundEnds; std::priority_queue<RODFRouteDesc, std::vector<RODFRouteDesc>, DFRouteDescByTimeComperator> toSolve; std::map<ROEdge*, std::vector<ROEdge*> > dets2Follow; dets2Follow[edge] = std::vector<ROEdge*>(); base.passedNo = 0; SUMOReal minDist = OptionsCont::getOptions().getFloat("min-route-length"); toSolve.push(base); while (!toSolve.empty()) { RODFRouteDesc current = toSolve.top(); toSolve.pop(); ROEdge* last = *(current.edges2Pass.end() - 1); if (hasDetector(last)) { if (dets2Follow.find(last) == dets2Follow.end()) { dets2Follow[last] = std::vector<ROEdge*>(); } for (std::vector<ROEdge*>::reverse_iterator i = current.edges2Pass.rbegin() + 1; i != current.edges2Pass.rend(); ++i) { if (hasDetector(*i)) { dets2Follow[*i].push_back(last); break; } } } // do not process an edge twice if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) { continue; } seen.push_back(last); // end if the edge has no further connections if (!hasApproached(last)) { // ok, no further connections to follow current.factor = 1.; SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(current); } continue; } // check for passing detectors: // if the current last edge is not the one the detector is placed on ... bool addNextNoFurther = false; if (last != getDetectorEdge(det)) { // ... if there is a detector ... if (hasDetector(last)) { if (!hasInBetweenDetectorsOnly(last, detectors)) { // ... and it's not an in-between-detector // -> let's add this edge and the following, but not any further addNextNoFurther = true; current.lastDetectorEdge = last; current.duration2Last = (SUMOTime) current.duration_2; current.distance2Last = current.distance; current.endDetectorEdge = last; if (hasSourceDetector(last, detectors)) { ///!!! //toDiscard.push_back(current); } current.factor = 1.; SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(current); } continue; } else { // ... if it's an in-between-detector // -> mark the current route as to be continued current.passedNo = 0; current.duration2Last = (SUMOTime) current.duration_2; current.distance2Last = current.distance; current.lastDetectorEdge = last; } } } // check for highway off-ramps if (myAmInHighwayMode) { // if it's beside the highway... if (last->getSpeed() < 19.4 && last != getDetectorEdge(det)) { // ... and has more than one following edge if (myApproachedEdges.find(last)->second.size() > 1) { // -> let's add this edge and the following, but not any further addNextNoFurther = true; } } } // check for missing end connections if (!addNextNoFurther) { // ... if this one would be processed, but already too many edge // without a detector occured if (current.passedNo > maxFollowingLength) { // mark not to process any further WRITE_WARNING("Could not close route for '" + det.getID() + "'"); unfoundEnds.push_back(current); current.factor = 1.; SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(current); } continue; } } // ... else: loop over the next edges const std::vector<ROEdge*>& appr = myApproachedEdges.find(last)->second; bool hadOne = false; for (size_t i = 0; i < appr.size(); i++) { if (find(current.edges2Pass.begin(), current.edges2Pass.end(), appr[i]) != current.edges2Pass.end()) { // do not append an edge twice (do not build loops) continue; } RODFRouteDesc t(current); t.duration_2 += (appr[i]->getLength() / appr[i]->getSpeed()); //!!! t.distance += appr[i]->getLength(); t.edges2Pass.push_back(appr[i]); if (!addNextNoFurther) { t.passedNo = t.passedNo + 1; toSolve.push(t); } else { if (!hadOne) { t.factor = (SUMOReal) 1. / (SUMOReal) appr.size(); SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(t); } hadOne = true; } } } } // if (!keepUnfoundEnds) { std::vector<RODFRouteDesc>::iterator i; std::vector<const ROEdge*> lastDetEdges; for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) { if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) { lastDetEdges.push_back((*i).lastDetectorEdge); } else { bool ok = into.removeRouteDesc(*i); assert(ok); } } } else { // !!! patch the factors } while (!toSolve.empty()) { // RODFRouteDesc d = toSolve.top(); toSolve.pop(); // delete d; } }