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);
337 while (!toSolve.empty()) {
347 bool keepUnfoundEnds,
bool includeInBetween,
348 bool keepShortestOnly,
int maxFollowingLength)
const {
352 std::map<ROEdge*, RODFRouteCont* > doneEdges;
353 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
354 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
356 if (doneEdges.find(e) != doneEdges.end()) {
361 std::vector<ROEdge*> seen;
363 doneEdges[e] = routes;
375 std::vector<ROEdge*> visited;
376 visited.push_back(e);
378 visited, **i, *routes, detcont, maxFollowingLength, seen);
379 if (allEndFollower) {
383 (*i)->addRoutes(routes);
386 if (includeInBetween) {
388 const std::vector<RODFRouteDesc>& r = routes->
get();
389 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
394 std::vector<ROEdge*>::const_iterator routeend = mrd.
edges2Pass.end();
395 for (std::vector<ROEdge*>::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
398 duration -= (*k)->getLength() / (*k)->getSpeed();
399 distance -= (*k)->getLength();
405 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
409 copy(k, routeend, back_inserter(nrd.
edges2Pass));
421 duration -= (*k)->getLength() / (*k)->getSpeed();
422 distance -= (*k)->getLength();
438 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
439 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
440 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
448 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
450 std::vector<ROEdge*> previous;
452 std::vector<IterationEdge> missing;
456 missing.push_back(ie);
457 bool maxDepthReached =
false;
458 while (!missing.empty() && !maxDepthReached) {
462 for (std::vector<ROEdge*>::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
464 previous.push_back(*j);
468 missing.push_back(ie);
470 maxDepthReached =
true;
475 if (maxDepthReached) {
481 std::vector<ROEdge*> latter;
483 std::vector<IterationEdge> missing;
484 for (std::vector<ROEdge*>::const_iterator k = previous.begin(); k != previous.end(); ++k) {
488 missing.push_back(ie);
490 bool maxDepthReached =
false;
491 while (!missing.empty() && !maxDepthReached) {
495 for (std::vector<ROEdge*>::const_iterator j = approached.begin(); j != approached.end(); ++j) {
500 latter.push_back(*j);
505 missing.push_back(ie);
507 maxDepthReached =
true;
512 if (maxDepthReached) {
521 std::vector<FlowDef> mflows;
523 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
532 for (std::vector<ROEdge*>::iterator i = previous.begin(); i != previous.end(); ++i) {
533 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
534 if (flows.size() != 0) {
535 const FlowDef& srcFD = flows[index];
553 for (std::vector<ROEdge*>::iterator i = latter.begin(); i != latter.end(); ++i) {
554 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
555 if (flows.size() != 0) {
556 const FlowDef& srcFD = flows[index];
572 mflows.push_back(mFlow);
584 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
585 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
596 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
597 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
600 if (flows.
knows((*i)->getID())) {
604 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
619 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
620 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
623 if (flows.
knows((*i)->getID())) {
627 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
637 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
640 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
673 const std::vector<std::string>&
690 std::vector<ROEdge*> seen;
697 std::vector<ROEdge*> seen;
704 std::vector<ROEdge*> seen;
711 std::vector<ROEdge*>& seen,
714 if (seen.size() == 1000) {
715 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
722 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
723 if ((*i) == det.
getID()) {
756 size_t noSkipped = 0;
757 for (
size_t i = 0; i < appr.size(); i++) {
764 if ((noFalse + noSkipped) == appr.size()) {
790 size_t noSkipped = 0;
791 seen.push_back(edge);
792 for (
size_t i = 0; i < appr.size(); i++) {
793 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
795 if (
isSource(det, appr[i], seen, detectors, strict)) {
805 return (noFalse + noSkipped) != appr.size();
807 return (noOk + noSkipped) == appr.size();
815 if (seen.size() == 1000) {
816 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
823 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
824 if ((*i) == det.
getID()) {
875 seen.push_back(edge);
876 for (
size_t i = 0; i < appr.size() && isall; i++) {
877 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
891 if (seen.size() == 1000) {
892 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
895 seen.push_back(edge);
900 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
924 for (
size_t i = 0; i < appr.size() && !isall; i++) {
926 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
942 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
944 ROEdge* into = (*i).first;
945 const std::vector<std::string>& dets = (*i).second;
946 std::map<SUMOReal, std::vector<std::string> > cliques;
947 std::vector<std::string>* maxClique = 0;
948 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
949 if (!flows.
knows(*j)) {
954 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
955 if (fabs((*k).first - det.
getPos()) < 1) {
956 (*k).second.push_back(*j);
957 if ((*k).second.size() > maxClique->size()) {
958 maxClique = &(*k).second;
964 cliques[det.
getPos()].push_back(*j);
965 maxClique = &cliques[det.
getPos()];
968 if (maxClique == 0) {
971 std::vector<FlowDef> mflows;
972 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
980 mflows.push_back(fd);
982 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
983 bool didWarn =
false;
984 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
986 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
987 const FlowDef& srcFD = dflows[index];
996 WRITE_MESSAGE(
"Detected PKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1000 WRITE_MESSAGE(
"Detected LKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1005 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1017 std::map<std::string, ROEdge*>::const_iterator i;
1024 std::vector<RODFDetector*> last;
1026 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1027 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1033 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1034 const std::vector<ROEdge*>& edges2Pass = (*j).edges2Pass;
1035 for (std::vector<ROEdge*>::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1039 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1041 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1043 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1047 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1060 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1062 const std::vector<std::string>& dets = (*i).second;
1063 std::map<SUMOReal, std::vector<std::string> > cliques;
1065 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1068 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1069 if (fabs((*k).first - det.
getPos()) < 10.) {
1070 (*k).second.push_back(*j);
1075 cliques[det.
getPos()] = std::vector<std::string>();
1076 cliques[det.
getPos()].push_back(*j);
1080 for (std::map<
SUMOReal, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1081 std::vector<std::string> clique = (*m).second;
1083 if (clique.size() == 1) {
1087 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1088 std::cout << *n <<
" ";
1089 if (n != clique.begin()) {
1094 std::cout <<
":" << nid << std::endl;
1096 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) ...
RONode * getToNode() const
Returns the node this edge ends at.
std::map< ROEdge *, std::vector< ROEdge * > > myApproachingEdges
Map of edge name->list of names of this edge approaching edges.
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
ROEdge * getFollower(unsigned int pos) const
Returns the edge at the given position from the list of reachable edges.
ROEdge * getDetectorEdge(const RODFDetector &det) const
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
void removeDetector(const std::string &id)
std::vector< ROEdge * > edges2Pass
The edges the route is made of.
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)
void reportEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
const std::vector< RODFRouteDesc > & getRouteVector() const
void computeTypes(RODFDetectorCon &dets, bool sourcesStrict) const
void addPriorDetector(const RODFDetector *det)
const std::vector< RODFDetector * > & getDetectors() const
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
bool hasSourceDetector(ROEdge *edge, const RODFDetectorCon &detectors) const
void 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 > & get()
Returns the container of stored routes.
void buildRoutes(RODFDetectorCon &det, bool allEndFollower, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const
A container for RODFDetectors.
#define UNUSED_PARAMETER(x)
bool hasDetector(ROEdge *edge) const
#define WRITE_WARNING(msg)
SUMOReal getAbsPos(const RODFDetector &det) const
const std::map< std::string, ROEdge * > & getEdgeMap() const
static OptionsCont & getOptions()
Retrieves the options.
RONode * getFromNode() const
Returns the node this edge starts at.
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.
bool removeRouteDesc(RODFRouteDesc &desc)
Removes the given route description from the container.
bool hasApproaching(ROEdge *edge) const
RODFNet(bool amInHighwayMode)
Constructor.
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
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition of the traffic during a certain time containing the flows and speeds.
A route within the DFROUTER.
A basic edge for routing applications.
void addAllEndFollower()
All routes are replaced by their versions extended by follower edges.
unsigned int getNoFollowing() const
Returns the number of edges this edge is connected to.
The router's network representation.
SUMOReal getLength() const
Returns the length of the edge.
void buildEdgeFlowMap(const RODFDetectorFlows &flows, const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
const RODFDetector & getDetector(const std::string &id) const
void buildDetectorDependencies(RODFDetectorCon &detectors)
Class representing a detector within the DFROUTER.
const ROEdge * endDetectorEdge
std::map< std::string, ROEdge * > myDetectorEdges
bool hasApproached(ROEdge *edge) const
A container for DFROUTER-routes.
SUMOReal getPos() const
Returns the position at which the detector lies.
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)
std::map< ROEdge *, std::vector< ROEdge * > > myApproachedEdges
Map of edge name->list of names of edges approached by this edge.
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.