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 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);
379 (*i)->addRoutes(routes);
382 if (includeInBetween) {
384 const std::vector<RODFRouteDesc>& r = routes->
get();
385 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
390 std::vector<ROEdge*>::const_iterator routeend = mrd.
edges2Pass.end();
391 for (std::vector<ROEdge*>::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
394 duration -= (*k)->getLength() / (*k)->getSpeed();
395 distance -= (*k)->getLength();
401 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
405 copy(k, routeend, back_inserter(nrd.
edges2Pass));
417 duration -= (*k)->getLength() / (*k)->getSpeed();
418 distance -= (*k)->getLength();
434 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
435 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
436 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
444 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
446 std::vector<ROEdge*> previous;
448 std::vector<IterationEdge> missing;
452 missing.push_back(ie);
453 bool maxDepthReached =
false;
454 while (!missing.empty() && !maxDepthReached) {
458 for (std::vector<ROEdge*>::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
460 previous.push_back(*j);
464 missing.push_back(ie);
466 maxDepthReached =
true;
471 if (maxDepthReached) {
477 std::vector<ROEdge*> latter;
479 std::vector<IterationEdge> missing;
480 for (std::vector<ROEdge*>::const_iterator k = previous.begin(); k != previous.end(); ++k) {
484 missing.push_back(ie);
486 bool maxDepthReached =
false;
487 while (!missing.empty() && !maxDepthReached) {
491 for (std::vector<ROEdge*>::const_iterator j = approached.begin(); j != approached.end(); ++j) {
496 latter.push_back(*j);
501 missing.push_back(ie);
503 maxDepthReached =
true;
508 if (maxDepthReached) {
517 std::vector<FlowDef> mflows;
519 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
528 for (std::vector<ROEdge*>::iterator i = previous.begin(); i != previous.end(); ++i) {
529 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
530 if (flows.size() != 0) {
531 const FlowDef& srcFD = flows[index];
549 for (std::vector<ROEdge*>::iterator i = latter.begin(); i != latter.end(); ++i) {
550 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
551 if (flows.size() != 0) {
552 const FlowDef& srcFD = flows[index];
568 mflows.push_back(mFlow);
580 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
581 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
592 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
593 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
596 if (flows.
knows((*i)->getID())) {
600 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
615 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
616 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
619 if (flows.
knows((*i)->getID())) {
623 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
633 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
636 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
669 const std::vector<std::string>&
686 std::vector<ROEdge*> seen;
693 std::vector<ROEdge*> seen;
700 std::vector<ROEdge*> seen;
707 std::vector<ROEdge*>& seen,
710 if (seen.size() == 1000) {
711 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
718 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
719 if ((*i) == det.
getID()) {
752 size_t noSkipped = 0;
753 for (
size_t i = 0; i < appr.size(); i++) {
760 if ((noFalse + noSkipped) == appr.size()) {
786 size_t noSkipped = 0;
787 seen.push_back(edge);
788 for (
size_t i = 0; i < appr.size(); i++) {
789 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
791 if (
isSource(det, appr[i], seen, detectors, strict)) {
801 return (noFalse + noSkipped) != appr.size();
803 return (noOk + noSkipped) == appr.size();
811 if (seen.size() == 1000) {
812 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
819 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
820 if ((*i) == det.
getID()) {
871 seen.push_back(edge);
872 for (
size_t i = 0; i < appr.size() && isall; i++) {
873 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
887 if (seen.size() == 1000) {
888 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
891 seen.push_back(edge);
896 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
920 for (
size_t i = 0; i < appr.size() && !isall; i++) {
922 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
938 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
940 ROEdge* into = (*i).first;
941 const std::vector<std::string>& dets = (*i).second;
942 std::map<SUMOReal, std::vector<std::string> > cliques;
943 std::vector<std::string>* maxClique = 0;
944 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
945 if (!flows.
knows(*j)) {
950 for (std::map<
SUMOReal, 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 == 0) {
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];
992 WRITE_MESSAGE(
"Detected PKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
996 WRITE_MESSAGE(
"Detected LKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1001 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1013 std::map<std::string, ROEdge*>::const_iterator i;
1020 std::vector<RODFDetector*> last;
1022 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1023 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1029 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1030 const std::vector<ROEdge*>& edges2Pass = (*j).edges2Pass;
1031 for (std::vector<ROEdge*>::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1035 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1037 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1039 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1043 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1056 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1058 const std::vector<std::string>& dets = (*i).second;
1059 std::map<SUMOReal, std::vector<std::string> > cliques;
1061 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1064 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1065 if (fabs((*k).first - det.
getPos()) < 10.) {
1066 (*k).second.push_back(*j);
1071 cliques[det.
getPos()] = std::vector<std::string>();
1072 cliques[det.
getPos()].push_back(*j);
1076 for (std::map<
SUMOReal, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1077 std::vector<std::string> clique = (*m).second;
1079 if (clique.size() == 1) {
1083 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1084 std::cout << *n <<
" ";
1085 if (n != clique.begin()) {
1090 std::cout <<
":" << nid << std::endl;
1092 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.
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.
void buildRoutes(RODFDetectorCon &det, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const
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.
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.