49 #ifdef CHECK_MEMORY_LEAKS 51 #endif // CHECK_MEMORY_LEAKS 58 RONet(), myAmInHighwayMode(amInHighwayMode),
59 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0),
60 myMaxSpeedFactorPKW(1),
61 myMaxSpeedFactorLKW(1),
62 myAvgSpeedFactorPKW(1),
63 myAvgSpeedFactorLKW(1) {
75 const std::map<std::string, ROEdge*>& edges =
getEdgeMap();
76 for (std::map<std::string, ROEdge*>::const_iterator rit = edges.begin(); rit != edges.end(); ++rit) {
77 ROEdge* ce = (*rit).second;
79 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
108 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
109 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
119 bool sourcesStrict)
const {
121 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
125 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
126 if (
isSource(**i, detcont, sourcesStrict)) {
140 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
162 std::vector<std::string>::const_iterator i;
163 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
178 std::vector<std::string>::const_iterator i;
179 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
192 bool keepUnfoundEnds,
193 bool keepShortestOnly,
197 int maxFollowingLength,
199 std::vector<RODFRouteDesc> unfoundEnds;
201 std::map<ROEdge*, ROEdgeVector > dets2Follow;
206 while (!toSolve.empty()) {
211 if (dets2Follow.find(last) == dets2Follow.end()) {
214 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
216 dets2Follow[*i].push_back(last);
223 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
226 seen.push_back(last);
231 SUMOReal cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
232 if (minDist < cdist) {
239 bool addNextNoFurther =
false;
246 addNextNoFurther =
true;
255 SUMOReal cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
256 if (minDist < cdist) {
277 addNextNoFurther =
true;
283 if (!addNextNoFurther) {
286 if (current.
passedNo > maxFollowingLength) {
289 unfoundEnds.push_back(current);
291 SUMOReal cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
292 if (minDist < cdist) {
301 for (
int i = 0; i < (int)appr.size(); i++) {
307 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeed());
310 if (!addNextNoFurther) {
316 SUMOReal cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
317 if (minDist < cdist) {
326 if (!keepUnfoundEnds) {
327 std::vector<RODFRouteDesc>::iterator i;
329 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
330 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
331 lastDetEdges.push_back((*i).lastDetectorEdge);
341 while (!toSolve.empty()) {
351 bool keepShortestOnly,
int maxFollowingLength)
const {
355 std::map<ROEdge*, RODFRouteCont* > doneEdges;
356 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
357 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
359 if (doneEdges.find(e) != doneEdges.end()) {
366 doneEdges[e] = routes;
379 visited.push_back(e);
381 visited, **i, *routes, detcont, maxFollowingLength, seen);
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 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
395 for (ROEdgeVector::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.");
452 std::vector<IterationEdge> missing;
456 missing.push_back(ie);
457 bool maxDepthReached =
false;
458 while (!missing.empty() && !maxDepthReached) {
462 for (ROEdgeVector::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) {
483 std::vector<IterationEdge> missing;
484 for (ROEdgeVector::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 (ROEdgeVector::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 (ROEdgeVector::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 (ROEdgeVector::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>&
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()) {
757 for (
int i = 0; i < (int)appr.size(); i++) {
764 if (noFalse + noSkipped == (
int)appr.size()) {
791 seen.push_back(edge);
792 for (
int i = 0; i < (int)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 numOk + numSkipped == (int)appr.size();
807 return numFalse + numSkipped != (int)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 (
int i = 0; i < (int)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 (
int i = 0; i < (int)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;
947 ROEdge* into = (*i).first;
951 const std::vector<std::string>& dets = (*i).second;
952 std::map<SUMOReal, std::vector<std::string> > cliques;
953 std::vector<std::string>* maxClique = 0;
954 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
955 if (!flows.
knows(*j)) {
960 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
961 if (fabs((*k).first - det.
getPos()) < 1) {
962 (*k).second.push_back(*j);
963 if ((*k).second.size() > maxClique->size()) {
964 maxClique = &(*k).second;
970 cliques[det.
getPos()].push_back(*j);
971 maxClique = &cliques[det.
getPos()];
974 if (maxClique == 0) {
977 std::vector<FlowDef> mflows;
978 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
986 mflows.push_back(fd);
988 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
989 bool didWarn =
false;
990 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
992 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
993 const FlowDef& srcFD = dflows[index];
1001 const SUMOReal speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
1002 const SUMOReal speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
1005 speedFactorCountPKW += srcFD.
qPKW;
1006 speedFactorCountLKW += srcFD.
qLKW;
1007 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
1008 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
1019 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1022 if (speedFactorCountPKW > 0) {
1026 if (speedFactorCountLKW > 0) {
1041 std::map<std::string, ROEdge*>::const_iterator i;
1048 std::vector<RODFDetector*> last;
1050 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1051 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1057 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1059 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1063 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1065 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1067 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1071 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1084 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1086 const std::vector<std::string>& dets = (*i).second;
1087 std::map<SUMOReal, std::vector<std::string> > cliques;
1089 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1092 for (std::map<
SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1093 if (fabs((*k).first - det.
getPos()) < 10.) {
1094 (*k).second.push_back(*j);
1099 cliques[det.
getPos()] = std::vector<std::string>();
1100 cliques[det.
getPos()].push_back(*j);
1104 for (std::map<
SUMOReal, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1105 std::vector<std::string> clique = (*m).second;
1107 if (clique.size() == 1) {
1111 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1112 std::cout << *n <<
" ";
1113 if (n != clique.begin()) {
1118 std::cout <<
":" << nid << std::endl;
1120 detectors.
mesoJoin(nid, (*m).second);
SUMOReal getLength() const
Returns the length of the edge.
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.
RODFDetector & getModifiableDetector(const std::string &id) const
SUMOReal getAbsPos(const RODFDetector &det) const
void removeDetector(const std::string &id)
const RODFDetector & getDetector(const std::string &id) const
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
const RONode * getFromJunction() const
bool isSource(const RODFDetector &det, const RODFDetectorCon &detectors, bool strict) const
void computeTypes(RODFDetectorCon &dets, bool sourcesStrict) 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)
ROEdgeVector edges2Pass
The edges the route is made of.
void addPriorDetector(const RODFDetector *det)
bool hasDetector(ROEdge *edge) const
const std::vector< RODFDetector * > & getDetectors() const
std::vector< const ROEdge * > ConstROEdgeVector
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
ROEdge * getDetectorEdge(const RODFDetector &det) const
RODFDetectorType getType() const
Returns the type of the detector.
const RONode * getToJunction() const
const std::vector< RODFRouteDesc > & getRouteVector() const
bool knows(const std::string &det_id) const
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
A container for RODFDetectors.
#define UNUSED_PARAMETER(x)
const std::vector< FlowDef > & getFlows() const
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
vehicle is a large transport vehicle
SUMOReal getVClassMaxSpeed(SUMOVehicleClass vclass) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
comparator for maps using edges as key, used only in myDetectorsOnEdges to make tests comparable ...
A not yet defined detector.
SUMOReal myAvgSpeedFactorLKW
bool removeRouteDesc(RODFRouteDesc &desc)
Removes the given route description from the container.
SUMOReal getPos() const
Returns the position at which the detector lies.
RODFNet(bool amInHighwayMode)
Constructor.
std::vector< ROEdge * > ROEdgeVector
A detector which had to be discarded (!!!)
const std::vector< std::string > & getDetectorList(ROEdge *edge) const
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) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
void setFlows(const std::string &detector_id, std::vector< FlowDef > &)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition of the traffic during a certain time containing the flows and speeds.
vehicle is a passenger car (a "normal" car)
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.
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
bool hasApproached(ROEdge *edge) const
void buildRoutes(RODFDetectorCon &det, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
bool hasApproaching(ROEdge *edge) const
The router's network representation.
bool hasSourceDetector(ROEdge *edge, const RODFDetectorCon &detectors) const
void buildEdgeFlowMap(const RODFDetectorFlows &flows, const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
const ROEdgeVector & getSuccessors() const
Returns the following edges.
void buildDetectorDependencies(RODFDetectorCon &detectors)
Class representing a detector within the DFROUTER.
const ROEdge * endDetectorEdge
const std::map< std::string, ROEdge * > & getEdgeMap() const
std::map< std::string, ROEdge * > myDetectorEdges
SUMOReal myAvgSpeedFactorPKW
A container for DFROUTER-routes.
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
bool isDestination(const RODFDetector &det, const RODFDetectorCon &detectors) const
std::map< ROEdge *, std::vector< std::string >, idComp > myDetectorsOnEdges
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
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
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
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
SUMOReal myMaxSpeedFactorLKW
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
#define WRITE_MESSAGE(msg)
SUMOReal myMaxSpeedFactorPKW
maximum speed factor in measurements
void buildDetectorEdgeDependencies(RODFDetectorCon &dets) const
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)