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;
74 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
103 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
104 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
114 bool sourcesStrict)
const {
116 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
120 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
121 if (
isSource(**i, detcont, sourcesStrict)) {
135 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
157 std::vector<std::string>::const_iterator i;
158 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
173 std::vector<std::string>::const_iterator i;
174 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
187 bool keepUnfoundEnds,
188 bool keepShortestOnly,
192 int maxFollowingLength,
194 std::vector<RODFRouteDesc> unfoundEnds;
196 std::map<ROEdge*, ROEdgeVector > dets2Follow;
201 while (!toSolve.empty()) {
206 if (dets2Follow.find(last) == dets2Follow.end()) {
209 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
211 dets2Follow[*i].push_back(last);
218 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
221 seen.push_back(last);
227 if (minDist < cdist) {
234 bool addNextNoFurther =
false;
241 addNextNoFurther =
true;
251 if (minDist < cdist) {
272 addNextNoFurther =
true;
278 if (!addNextNoFurther) {
281 if (current.
passedNo > maxFollowingLength) {
284 unfoundEnds.push_back(current);
287 if (minDist < cdist) {
296 for (
size_t i = 0; i < appr.size(); i++) {
302 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeed());
305 if (!addNextNoFurther) {
312 if (minDist < cdist) {
321 if (!keepUnfoundEnds) {
322 std::vector<RODFRouteDesc>::iterator i;
324 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
325 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
326 lastDetEdges.push_back((*i).lastDetectorEdge);
336 while (!toSolve.empty()) {
346 bool keepShortestOnly,
int maxFollowingLength)
const {
350 std::map<ROEdge*, RODFRouteCont* > doneEdges;
351 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
352 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
354 if (doneEdges.find(e) != doneEdges.end()) {
361 doneEdges[e] = routes;
374 visited.push_back(e);
376 visited, **i, *routes, detcont, maxFollowingLength, seen);
378 (*i)->addRoutes(routes);
381 if (includeInBetween) {
383 const std::vector<RODFRouteDesc>& r = routes->
get();
384 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
389 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
390 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
393 duration -= (*k)->getLength() / (*k)->getSpeed();
394 distance -= (*k)->getLength();
400 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
404 copy(k, routeend, back_inserter(nrd.
edges2Pass));
416 duration -= (*k)->getLength() / (*k)->getSpeed();
417 distance -= (*k)->getLength();
433 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
434 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
435 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
443 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
447 std::vector<IterationEdge> missing;
451 missing.push_back(ie);
452 bool maxDepthReached =
false;
453 while (!missing.empty() && !maxDepthReached) {
457 for (ROEdgeVector::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
459 previous.push_back(*j);
463 missing.push_back(ie);
465 maxDepthReached =
true;
470 if (maxDepthReached) {
478 std::vector<IterationEdge> missing;
479 for (ROEdgeVector::const_iterator k = previous.begin(); k != previous.end(); ++k) {
483 missing.push_back(ie);
485 bool maxDepthReached =
false;
486 while (!missing.empty() && !maxDepthReached) {
490 for (ROEdgeVector::const_iterator j = approached.begin(); j != approached.end(); ++j) {
495 latter.push_back(*j);
500 missing.push_back(ie);
502 maxDepthReached =
true;
507 if (maxDepthReached) {
516 std::vector<FlowDef> mflows;
518 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
527 for (ROEdgeVector::iterator i = previous.begin(); i != previous.end(); ++i) {
528 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
529 if (flows.size() != 0) {
530 const FlowDef& srcFD = flows[index];
548 for (ROEdgeVector::iterator i = latter.begin(); i != latter.end(); ++i) {
549 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
550 if (flows.size() != 0) {
551 const FlowDef& srcFD = flows[index];
567 mflows.push_back(mFlow);
579 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
580 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
591 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
592 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
595 if (flows.
knows((*i)->getID())) {
599 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
614 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
615 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
618 if (flows.
knows((*i)->getID())) {
622 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
632 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
635 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
668 const std::vector<std::string>&
709 if (seen.size() == 1000) {
710 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
717 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
718 if ((*i) == det.
getID()) {
751 size_t noSkipped = 0;
752 for (
size_t i = 0; i < appr.size(); i++) {
759 if ((noFalse + noSkipped) == appr.size()) {
785 size_t noSkipped = 0;
786 seen.push_back(edge);
787 for (
size_t i = 0; i < appr.size(); i++) {
788 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
790 if (
isSource(det, appr[i], seen, detectors, strict)) {
800 return (noFalse + noSkipped) != appr.size();
802 return (noOk + noSkipped) == appr.size();
810 if (seen.size() == 1000) {
811 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
818 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
819 if ((*i) == det.
getID()) {
870 seen.push_back(edge);
871 for (
size_t i = 0; i < appr.size() && isall; i++) {
872 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
886 if (seen.size() == 1000) {
887 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
890 seen.push_back(edge);
895 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
919 for (
size_t i = 0; i < appr.size() && !isall; i++) {
921 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
937 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
939 ROEdge* into = (*i).first;
940 const std::vector<std::string>& dets = (*i).second;
941 std::map<SUMOReal, std::vector<std::string> > cliques;
942 std::vector<std::string>* maxClique = 0;
943 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
944 if (!flows.
knows(*j)) {
949 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
950 if (fabs((*k).first - det.
getPos()) < 1) {
951 (*k).second.push_back(*j);
952 if ((*k).second.size() > maxClique->size()) {
953 maxClique = &(*k).second;
959 cliques[det.
getPos()].push_back(*j);
960 maxClique = &cliques[det.
getPos()];
963 if (maxClique == 0) {
966 std::vector<FlowDef> mflows;
967 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
975 mflows.push_back(fd);
977 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
978 bool didWarn =
false;
979 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
981 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
982 const FlowDef& srcFD = dflows[index];
991 WRITE_MESSAGE(
"Detected PKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
995 WRITE_MESSAGE(
"Detected LKW speed higher than allowed speed at '" + (*l) +
"' on '" + into->
getID() +
"'.");
1000 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1012 std::map<std::string, ROEdge*>::const_iterator i;
1019 std::vector<RODFDetector*> last;
1021 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1022 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1028 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1030 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1034 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1036 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1038 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1042 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1055 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1057 const std::vector<std::string>& dets = (*i).second;
1058 std::map<SUMOReal, std::vector<std::string> > cliques;
1060 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1063 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1064 if (fabs((*k).first - det.
getPos()) < 10.) {
1065 (*k).second.push_back(*j);
1070 cliques[det.
getPos()] = std::vector<std::string>();
1071 cliques[det.
getPos()].push_back(*j);
1075 for (std::map<
SUMOReal, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1076 std::vector<std::string> clique = (*m).second;
1078 if (clique.size() == 1) {
1082 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1083 std::cout << *n <<
" ";
1084 if (n != clique.begin()) {
1089 std::cout <<
":" << nid << std::endl;
1091 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.
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
ROEdge * getDetectorEdge(const RODFDetector &det) const
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
void removeDetector(const std::string &id)
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)
std::map< ROEdge *, ROEdgeVector > myApproachedEdges
Map of edge name->list of names of edges approached by this edge.
void reportEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
const std::vector< RODFRouteDesc > & getRouteVector() const
ROEdgeVector edges2Pass
The edges the route is made of.
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)
std::vector< const ROEdge * > ConstROEdgeVector
bool hasSourceDetector(ROEdge *edge, const RODFDetectorCon &detectors) 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.
std::vector< ROEdge * > ROEdgeVector
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
void computeRoutesFor(ROEdge *edge, RODFRouteDesc &base, int no, bool keepUnfoundEnds, bool keepShortestOnly, ROEdgeVector &visited, const RODFDetector &det, RODFRouteCont &into, const RODFDetectorCon &detectors, int maxFollowingLength, ROEdgeVector &seen) 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.
std::map< ROEdge *, ROEdgeVector > myApproachingEdges
Map of edge name->list of names of this edge approaching edges.
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
const ROEdgeVector & getSuccessors() const
Returns the following edges.
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)
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.