53 RONet(), myAmInHighwayMode(amInHighwayMode),
54 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0),
55 myMaxSpeedFactorPKW(1),
56 myMaxSpeedFactorLKW(1),
57 myAvgSpeedFactorPKW(1),
58 myAvgSpeedFactorLKW(1) {
76 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
105 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
106 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
116 bool sourcesStrict)
const {
118 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
122 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
123 if (
isSource(**i, detcont, sourcesStrict)) {
137 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
159 std::vector<std::string>::const_iterator i;
160 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
175 std::vector<std::string>::const_iterator i;
176 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
189 bool keepUnfoundEnds,
190 bool keepShortestOnly,
194 int maxFollowingLength,
196 std::vector<RODFRouteDesc> unfoundEnds;
198 std::map<ROEdge*, ROEdgeVector > dets2Follow;
203 while (!toSolve.empty()) {
208 if (dets2Follow.find(last) == dets2Follow.end()) {
211 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
213 dets2Follow[*i].push_back(last);
220 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
223 seen.push_back(last);
228 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
229 if (minDist < cdist) {
236 bool addNextNoFurther =
false;
243 addNextNoFurther =
true;
252 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
253 if (minDist < cdist) {
274 addNextNoFurther =
true;
280 if (!addNextNoFurther) {
283 if (current.
passedNo > maxFollowingLength) {
286 unfoundEnds.push_back(current);
288 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
289 if (minDist < cdist) {
298 for (
int i = 0; i < (int)appr.size(); i++) {
304 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
307 if (!addNextNoFurther) {
312 t.
factor = (double) 1. / (
double) appr.size();
313 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
314 if (minDist < cdist) {
323 if (!keepUnfoundEnds) {
324 std::vector<RODFRouteDesc>::iterator i;
326 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
327 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
328 lastDetEdges.push_back((*i).lastDetectorEdge);
338 while (!toSolve.empty()) {
348 bool keepShortestOnly,
int maxFollowingLength)
const {
352 std::map<ROEdge*, RODFRouteCont* > doneEdges;
353 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
354 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
356 if (doneEdges.find(e) != doneEdges.end()) {
363 doneEdges[e] = routes;
376 visited.push_back(e);
378 visited, **i, *routes, detcont, maxFollowingLength, seen);
380 (*i)->addRoutes(routes);
383 if (includeInBetween) {
385 const std::vector<RODFRouteDesc>& r = routes->
get();
386 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
391 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
392 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
395 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
396 distance -= (*k)->getLength();
402 for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) {
406 copy(k, routeend, back_inserter(nrd.
edges2Pass));
418 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
419 distance -= (*k)->getLength();
435 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
436 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
437 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
445 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
449 std::vector<IterationEdge> missing;
453 missing.push_back(ie);
454 bool maxDepthReached =
false;
455 while (!missing.empty() && !maxDepthReached) {
459 for (ROEdgeVector::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
461 previous.push_back(*j);
465 missing.push_back(ie);
467 maxDepthReached =
true;
472 if (maxDepthReached) {
480 std::vector<IterationEdge> missing;
481 for (ROEdgeVector::const_iterator k = previous.begin(); k != previous.end(); ++k) {
485 missing.push_back(ie);
487 bool maxDepthReached =
false;
488 while (!missing.empty() && !maxDepthReached) {
492 for (ROEdgeVector::const_iterator j = approached.begin(); j != approached.end(); ++j) {
497 latter.push_back(*j);
502 missing.push_back(ie);
504 maxDepthReached =
true;
509 if (maxDepthReached) {
518 std::vector<FlowDef> mflows;
520 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
529 for (ROEdgeVector::iterator i = previous.begin(); i != previous.end(); ++i) {
530 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
531 if (flows.size() != 0) {
532 const FlowDef& srcFD = flows[index];
540 inFlow.
vLKW /= (double) previous.size();
541 inFlow.
vPKW /= (double) previous.size();
550 for (ROEdgeVector::iterator i = latter.begin(); i != latter.end(); ++i) {
551 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(*i)->
getFlows();
552 if (flows.size() != 0) {
553 const FlowDef& srcFD = flows[index];
561 outFlow.
vLKW /= (double) latter.size();
562 outFlow.
vPKW /= (double) latter.size();
567 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
568 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
569 mflows.push_back(mFlow);
581 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
582 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
593 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
594 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
597 if (flows.
knows((*i)->getID())) {
601 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
616 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
617 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
620 if (flows.
knows((*i)->getID())) {
624 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
634 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
637 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
670 const std::vector<std::string>&
711 if (seen.size() == 1000) {
712 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
719 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
720 if ((*i) == det.
getID()) {
754 for (
int i = 0; i < (int)appr.size(); i++) {
761 if (noFalse + noSkipped == (
int)appr.size()) {
788 seen.push_back(edge);
789 for (
int i = 0; i < (int)appr.size(); i++) {
790 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
792 if (
isSource(det, appr[i], seen, detectors, strict)) {
802 return numOk + numSkipped == (int)appr.size();
804 return numFalse + numSkipped != (int)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 (
int i = 0; i < (int)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 (
int i = 0; i < (int)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;
939 double speedFactorSumPKW = 0;
940 double speedFactorSumLKW = 0;
941 double speedFactorCountPKW = 0;
942 double speedFactorCountLKW = 0;
944 ROEdge* into = (*i).first;
948 const std::vector<std::string>& dets = (*i).second;
949 std::map<double, std::vector<std::string> > cliques;
950 std::vector<std::string>* maxClique = 0;
951 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
952 if (!flows.
knows(*j)) {
957 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
958 if (fabs((*k).first - det.
getPos()) < 1) {
959 (*k).second.push_back(*j);
960 if ((*k).second.size() > maxClique->size()) {
961 maxClique = &(*k).second;
967 cliques[det.
getPos()].push_back(*j);
968 maxClique = &cliques[det.
getPos()];
971 if (maxClique == 0) {
974 std::vector<FlowDef> mflows;
975 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
983 mflows.push_back(fd);
985 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
986 bool didWarn =
false;
987 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
989 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
990 const FlowDef& srcFD = dflows[index];
994 fd.
vLKW += srcFD.
vLKW / (double) maxClique->size();
995 fd.
vPKW += srcFD.
vPKW / (double) maxClique->size();
996 fd.
fLKW += srcFD.
fLKW / (double) maxClique->size();
997 fd.
isLKW += srcFD.
isLKW / (double) maxClique->size();
998 const double speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
999 const double speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
1002 speedFactorCountPKW += srcFD.
qPKW;
1003 speedFactorCountLKW += srcFD.
qLKW;
1004 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
1005 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
1016 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1019 if (speedFactorCountPKW > 0) {
1023 if (speedFactorCountLKW > 0) {
1038 std::map<std::string, ROEdge*>::const_iterator i;
1045 std::vector<RODFDetector*> last;
1047 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1048 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1054 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1056 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1060 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1062 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1064 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1068 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1081 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1083 const std::vector<std::string>& dets = (*i).second;
1084 std::map<double, std::vector<std::string> > cliques;
1086 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1089 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1090 if (fabs((*k).first - det.
getPos()) < 10.) {
1091 (*k).second.push_back(*j);
1096 cliques[det.
getPos()] = std::vector<std::string>();
1097 cliques[det.
getPos()].push_back(*j);
1101 for (std::map<
double, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1102 std::vector<std::string> clique = (*m).second;
1104 if (clique.size() == 1) {
1108 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1109 std::cout << *n <<
" ";
1110 if (n != clique.begin()) {
1115 std::cout <<
":" << nid << std::endl;
1117 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)
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.
bool isInternal() const
return whether this edge is an internal edge
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 NamedObjectCont< ROEdge * > & getEdgeMap() const
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.