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) {
355 if (doneEdges.find(e) != doneEdges.end()) {
360 std::vector<ROEdge*> seen;
362 doneEdges[e] = routes;
374 std::vector<ROEdge*> visited;
375 visited.push_back(e);
377 visited, **i, *routes, detcont, maxFollowingLength, seen);
378 if (allEndFollower) {
382 (*i)->addRoutes(routes);
385 if (includeInBetween) {
387 const std::vector<RODFRouteDesc>& r = routes->
get();
388 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
393 std::vector<ROEdge*>::const_iterator routeend = mrd.
edges2Pass.end();
394 for (std::vector<ROEdge*>::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
397 duration -= (*k)->getLength() / (*k)->getSpeed();
398 distance -= (*k)->getLength();
404 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
408 copy(k, routeend, back_inserter(nrd.
edges2Pass));
420 duration -= (*k)->getLength() / (*k)->getSpeed();
421 distance -= (*k)->getLength();
437 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
438 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
439 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
447 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
449 std::vector<ROEdge*> previous;
451 std::vector<IterationEdge> missing;
455 missing.push_back(ie);
456 bool maxDepthReached =
false;
457 while (!missing.empty() && !maxDepthReached) {
461 for (std::vector<ROEdge*>::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
463 previous.push_back(*j);
467 missing.push_back(ie);
469 maxDepthReached =
true;
474 if (maxDepthReached) {
480 std::vector<ROEdge*> latter;
482 std::vector<IterationEdge> missing;
483 for (std::vector<ROEdge*>::const_iterator k = previous.begin(); k != previous.end(); ++k) {
487 missing.push_back(ie);
489 bool maxDepthReached =
false;
490 while (!missing.empty() && !maxDepthReached) {
494 for (std::vector<ROEdge*>::const_iterator j = approached.begin(); j != approached.end(); ++j) {
499 latter.push_back(*j);
504 missing.push_back(ie);
506 maxDepthReached =
true;
511 if (maxDepthReached) {
520 std::vector<FlowDef> mflows;
522 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
531 for (std::vector<ROEdge*>::iterator i = previous.begin(); i != previous.end(); ++i) {
532 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
533 if (flows.size() != 0) {
534 const FlowDef& srcFD = flows[index];
552 for (std::vector<ROEdge*>::iterator i = latter.begin(); i != latter.end(); ++i) {
553 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
554 if (flows.size() != 0) {
555 const FlowDef& srcFD = flows[index];
571 mflows.push_back(mFlow);
583 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
584 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
595 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
596 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
599 if (flows.
knows((*i)->getID())) {
603 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
618 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
619 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
622 if (flows.
knows((*i)->getID())) {
626 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
636 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
639 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
672 const std::vector<std::string>&
689 std::vector<ROEdge*> seen;
696 std::vector<ROEdge*> seen;
703 std::vector<ROEdge*> seen;
710 std::vector<ROEdge*>& seen,
713 if (seen.size() == 1000) {
714 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
721 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
722 if ((*i) == det.
getID()) {
755 size_t noSkipped = 0;
756 for (
size_t i = 0; i < appr.size(); i++) {
763 if ((noFalse + noSkipped) == appr.size()) {
789 size_t noSkipped = 0;
790 seen.push_back(edge);
791 for (
size_t i = 0; i < appr.size(); i++) {
792 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
794 if (
isSource(det, appr[i], seen, detectors, strict)) {
804 return (noFalse + noSkipped) != appr.size();
806 return (noOk + noSkipped) == appr.size();
814 if (seen.size() == 1000) {
815 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
822 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
823 if ((*i) == det.
getID()) {
874 seen.push_back(edge);
875 for (
size_t i = 0; i < appr.size() && isall; i++) {
876 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
890 if (seen.size() == 1000) {
891 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
894 seen.push_back(edge);
899 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
923 for (
size_t i = 0; i < appr.size() && !isall; i++) {
925 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
941 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
943 ROEdge* into = (*i).first;
944 const std::vector<std::string>& dets = (*i).second;
945 std::map<SUMOReal, std::vector<std::string> > cliques;
946 std::vector<std::string>* maxClique = 0;
947 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
948 if (!flows.
knows(*j)) {
953 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
954 if (fabs((*k).first - det.
getPos()) < 1) {
955 (*k).second.push_back(*j);
956 if ((*k).second.size() > maxClique->size()) {
957 maxClique = &(*k).second;
963 cliques[det.
getPos()].push_back(*j);
964 maxClique = &cliques[det.
getPos()];
967 if (maxClique == 0) {
970 std::vector<FlowDef> mflows;
971 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
979 mflows.push_back(fd);
981 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
982 bool didWarn =
false;
983 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
985 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
986 const FlowDef& srcFD = dflows[index];
995 WRITE_MESSAGE(
"Detected PKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
999 WRITE_MESSAGE(
"Detected LKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1004 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1016 std::map<std::string, ROEdge*>::const_iterator i;
1023 std::vector<RODFDetector*> last;
1025 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1026 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1032 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1033 const std::vector<ROEdge*>& edges2Pass = (*j).edges2Pass;
1034 for (std::vector<ROEdge*>::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1038 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1040 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1046 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1059 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1061 const std::vector<std::string>& dets = (*i).second;
1062 std::map<SUMOReal, std::vector<std::string> > cliques;
1064 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1067 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1068 if (fabs((*k).first - det.
getPos()) < 10.) {
1069 (*k).second.push_back(*j);
1074 cliques[det.
getPos()] = std::vector<std::string>();
1075 cliques[det.
getPos()].push_back(*j);
1079 for (std::map<
SUMOReal, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1080 std::vector<std::string> clique = (*m).second;
1082 if (clique.size() == 1) {
1086 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1087 std::cout << *n <<
" ";
1088 if (n != clique.begin()) {
1093 std::cout <<
":" << nid << std::endl;
1095 detectors.
mesoJoin(nid, (*m).second);
void mesoJoin(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
void revalidateFlows(const RODFDetectorCon &detectors, RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
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
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.
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.