54 RONet(), myAmInHighwayMode(amInHighwayMode),
55 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0),
56 myMaxSpeedFactorPKW(1),
57 myMaxSpeedFactorLKW(1),
58 myAvgSpeedFactorPKW(1),
59 myAvgSpeedFactorLKW(1) {
71 const std::map<std::string, ROEdge*>& edges =
getEdgeMap();
72 for (std::map<std::string, ROEdge*>::const_iterator rit = edges.begin(); rit != edges.end(); ++rit) {
73 ROEdge* ce = (*rit).second;
75 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
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,
193 int maxFollowingLength,
195 std::vector<RODFRouteDesc> unfoundEnds;
197 std::map<ROEdge*, ROEdgeVector > dets2Follow;
202 while (!toSolve.empty()) {
207 if (dets2Follow.find(last) == dets2Follow.end()) {
210 for (ROEdgeVector::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);
227 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
228 if (minDist < cdist) {
235 bool addNextNoFurther =
false;
242 addNextNoFurther =
true;
251 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
252 if (minDist < cdist) {
273 addNextNoFurther =
true;
279 if (!addNextNoFurther) {
282 if (current.
passedNo > maxFollowingLength) {
285 unfoundEnds.push_back(current);
287 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
288 if (minDist < cdist) {
297 for (
int i = 0; i < (int)appr.size(); i++) {
303 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
306 if (!addNextNoFurther) {
311 t.
factor = (double) 1. / (
double) appr.size();
312 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
313 if (minDist < cdist) {
322 if (!keepUnfoundEnds) {
323 std::vector<RODFRouteDesc>::iterator i;
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()) {
362 doneEdges[e] = routes;
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 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
391 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
394 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
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)->getSpeedLimit();
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.");
448 std::vector<IterationEdge> missing;
452 missing.push_back(ie);
453 bool maxDepthReached =
false;
454 while (!missing.empty() && !maxDepthReached) {
458 for (ROEdgeVector::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) {
479 std::vector<IterationEdge> missing;
480 for (ROEdgeVector::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 (ROEdgeVector::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 (ROEdgeVector::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];
539 inFlow.
vLKW /= (double) previous.size();
540 inFlow.
vPKW /= (double) previous.size();
549 for (ROEdgeVector::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];
560 outFlow.
vLKW /= (double) latter.size();
561 outFlow.
vPKW /= (double) latter.size();
566 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
567 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
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>&
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()) {
753 for (
int i = 0; i < (int)appr.size(); i++) {
760 if (noFalse + noSkipped == (
int)appr.size()) {
787 seen.push_back(edge);
788 for (
int i = 0; i < (int)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 numOk + numSkipped == (int)appr.size();
803 return numFalse + numSkipped != (int)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 (
int i = 0; i < (int)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 (
int i = 0; i < (int)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;
938 double speedFactorSumPKW = 0;
939 double speedFactorSumLKW = 0;
940 double speedFactorCountPKW = 0;
941 double speedFactorCountLKW = 0;
943 ROEdge* into = (*i).first;
947 const std::vector<std::string>& dets = (*i).second;
948 std::map<double, std::vector<std::string> > cliques;
949 std::vector<std::string>* maxClique = 0;
950 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
951 if (!flows.
knows(*j)) {
956 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
957 if (fabs((*k).first - det.
getPos()) < 1) {
958 (*k).second.push_back(*j);
959 if ((*k).second.size() > maxClique->size()) {
960 maxClique = &(*k).second;
966 cliques[det.
getPos()].push_back(*j);
967 maxClique = &cliques[det.
getPos()];
970 if (maxClique == 0) {
973 std::vector<FlowDef> mflows;
974 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
982 mflows.push_back(fd);
984 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
985 bool didWarn =
false;
986 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
988 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
989 const FlowDef& srcFD = dflows[index];
993 fd.
vLKW += srcFD.
vLKW / (double) maxClique->size();
994 fd.
vPKW += srcFD.
vPKW / (double) maxClique->size();
995 fd.
fLKW += srcFD.
fLKW / (double) maxClique->size();
996 fd.
isLKW += srcFD.
isLKW / (double) maxClique->size();
997 const double speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
998 const double speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
1001 speedFactorCountPKW += srcFD.
qPKW;
1002 speedFactorCountLKW += srcFD.
qLKW;
1003 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
1004 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
1015 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1018 if (speedFactorCountPKW > 0) {
1022 if (speedFactorCountLKW > 0) {
1037 std::map<std::string, ROEdge*>::const_iterator i;
1044 std::vector<RODFDetector*> last;
1046 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1047 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1053 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1055 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1059 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1061 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1063 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1067 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1080 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1082 const std::vector<std::string>& dets = (*i).second;
1083 std::map<double, std::vector<std::string> > cliques;
1085 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1088 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1089 if (fabs((*k).first - det.
getPos()) < 10.) {
1090 (*k).second.push_back(*j);
1095 cliques[det.
getPos()] = std::vector<std::string>();
1096 cliques[det.
getPos()].push_back(*j);
1100 for (std::map<
double, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1101 std::vector<std::string> clique = (*m).second;
1103 if (clique.size() == 1) {
1107 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1108 std::cout << *n <<
" ";
1109 if (n != clique.begin()) {
1114 std::cout <<
":" << nid << std::endl;
1116 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) ...
double getSpeedLimit() const
Returns the speed allowed on this edge.
double myAvgSpeedFactorLKW
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
double myAvgSpeedFactorPKW
double getVClassMaxSpeed(SUMOVehicleClass vclass) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
ROEdge * getDetectorEdge(const RODFDetector &det) const
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
void removeDetector(const std::string &id)
double getLength() const
Returns the length of the edge.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
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
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)
const std::map< std::string, ROEdge * > & getEdgeMap() const
static OptionsCont & getOptions()
Retrieves the options.
vehicle is a large transport vehicle
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.
const RONode * getToJunction() const
bool removeRouteDesc(RODFRouteDesc &desc)
Removes the given route description from the container.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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
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.
double myMaxSpeedFactorPKW
maximum speed factor in measurements
double getPos() const
Returns the position at which the detector lies.
double myMaxSpeedFactorLKW
const RONode * getFromJunction() const
The router's network representation.
void buildEdgeFlowMap(const RODFDetectorFlows &flows, const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
double getAbsPos(const RODFDetector &det) const
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.
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)
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.