47 RONet(), myAmInHighwayMode(amInHighwayMode),
48 mySourceNumber(0), mySinkNumber(0), myInBetweenNumber(0), myInvalidNumber(0),
49 myMaxSpeedFactorPKW(1),
50 myMaxSpeedFactorLKW(1),
51 myAvgSpeedFactorPKW(1),
52 myAvgSpeedFactorLKW(1) {
70 for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) {
99 const std::vector<RODFDetector*>& dets = detcont.
getDetectors();
100 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
110 bool sourcesStrict)
const {
112 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
116 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
117 if (
isSource(**i, detcont, sourcesStrict)) {
131 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
153 std::vector<std::string>::const_iterator i;
154 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
169 std::vector<std::string>::const_iterator i;
170 for (i = detIDs.begin(); i != detIDs.end(); ++i) {
183 bool keepUnfoundEnds,
184 bool keepShortestOnly,
188 int maxFollowingLength,
190 std::vector<RODFRouteDesc> unfoundEnds;
192 std::map<ROEdge*, ROEdgeVector > dets2Follow;
197 while (!toSolve.empty()) {
202 if (dets2Follow.find(last) == dets2Follow.end()) {
205 for (ROEdgeVector::reverse_iterator i = current.
edges2Pass.rbegin() + 1; i != current.
edges2Pass.rend(); ++i) {
207 dets2Follow[*i].push_back(last);
214 if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) {
217 seen.push_back(last);
222 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
223 if (minDist < cdist) {
230 bool addNextNoFurther =
false;
237 addNextNoFurther =
true;
246 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
247 if (minDist < cdist) {
268 addNextNoFurther =
true;
274 if (!addNextNoFurther) {
277 if (current.
passedNo > maxFollowingLength) {
280 unfoundEnds.push_back(current);
282 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
283 if (minDist < cdist) {
292 for (
int i = 0; i < (int)appr.size(); i++) {
298 t.
duration_2 += (appr[i]->getLength() / appr[i]->getSpeedLimit());
301 if (!addNextNoFurther) {
306 t.
factor = (double) 1. / (
double) appr.size();
307 double cdist = current.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(current.
edges2Pass.back()->getToJunction()->getPosition());
308 if (minDist < cdist) {
317 if (!keepUnfoundEnds) {
318 std::vector<RODFRouteDesc>::iterator i;
320 for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) {
321 if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) {
322 lastDetEdges.push_back((*i).lastDetectorEdge);
332 while (!toSolve.empty()) {
342 bool keepShortestOnly,
int maxFollowingLength)
const {
346 std::map<ROEdge*, RODFRouteCont* > doneEdges;
347 const std::vector< RODFDetector*>& dets = detcont.
getDetectors();
348 for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
350 if (doneEdges.find(e) != doneEdges.end()) {
357 doneEdges[e] = routes;
370 visited.push_back(e);
372 visited, **i, *routes, detcont, maxFollowingLength, seen);
374 (*i)->addRoutes(routes);
377 if (includeInBetween) {
379 const std::vector<RODFRouteDesc>& r = routes->
get();
380 for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) {
385 ROEdgeVector::const_iterator routeend = mrd.
edges2Pass.end();
386 for (ROEdgeVector::const_iterator k = mrd.
edges2Pass.begin(); k != routeend; ++k) {
389 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
390 distance -= (*k)->getLength();
398 copy(k, routeend, back_inserter(nrd.
edges2Pass));
410 duration -= (*k)->getLength() / (*k)->getSpeedLimit();
411 distance -= (*k)->getLength();
427 const std::vector<FlowDef>& detFlows = flows.
getFlowDefs(detector->
getID());
428 for (std::vector<FlowDef>::const_iterator j = detFlows.begin(); j != detFlows.end(); ++j) {
429 if ((*j).qPKW > 0 || (*j).qLKW > 0) {
437 WRITE_WARNING(
"Detector '" + detector->
getID() +
"' has no flows.\n Trying to rebuild.");
441 std::vector<IterationEdge> missing;
445 missing.push_back(ie);
446 bool maxDepthReached =
false;
447 while (!missing.empty() && !maxDepthReached) {
451 for (ROEdgeVector::const_iterator j = approaching.begin(); j != approaching.end(); ++j) {
453 previous.push_back(*j);
457 missing.push_back(ie);
459 maxDepthReached =
true;
464 if (maxDepthReached) {
472 std::vector<IterationEdge> missing;
473 for (ROEdgeVector::const_iterator k = previous.begin(); k != previous.end(); ++k) {
477 missing.push_back(ie);
479 bool maxDepthReached =
false;
480 while (!missing.empty() && !maxDepthReached) {
484 for (ROEdgeVector::const_iterator j = approached.begin(); j != approached.end(); ++j) {
489 latter.push_back(*j);
494 missing.push_back(ie);
496 maxDepthReached =
true;
501 if (maxDepthReached) {
510 std::vector<FlowDef> mflows;
512 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
520 for (
const ROEdge*
const e : previous) {
521 const std::vector<FlowDef>& eflows =
static_cast<const RODFEdge*
>(e)->getFlows();
522 if (eflows.size() != 0) {
523 const FlowDef& srcFD = eflows[index];
530 inFlow.
vLKW /= (double) previous.size();
531 inFlow.
vPKW /= (double) previous.size();
539 for (
const ROEdge*
const e : latter) {
540 const std::vector<FlowDef>& eflows =
static_cast<const RODFEdge*
>(e)->getFlows();
541 if (eflows.size() != 0) {
542 const FlowDef& srcFD = eflows[index];
549 outFlow.
vLKW /= (double) latter.size();
550 outFlow.
vPKW /= (double) latter.size();
555 mFlow.
vLKW = (inFlow.
vLKW + outFlow.
vLKW) / (
double) 2.;
556 mFlow.
vPKW = (inFlow.
vPKW + outFlow.
vPKW) / (
double) 2.;
557 mflows.push_back(mFlow);
569 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
570 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
581 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
582 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) {
585 if (flows.
knows((*i)->getID())) {
589 WRITE_MESSAGE(
"Removed detector '" + (*i)->getID() +
"' because no flows for him exist.");
604 const std::vector<RODFDetector*>& dets = detectors.
getDetectors();
605 for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
608 if (flows.
knows((*i)->getID())) {
612 WRITE_MESSAGE(
"Detector '" + (*i)->getID() +
"' has no flow.");
622 edgeName = edgeName.substr(0, edgeName.rfind(
'_'));
624 if (ret ==
nullptr) {
625 throw ProcessError(
"Edge '" + edgeName +
"' used by detector '" + det.
getID() +
"' is not known.");
658 const std::vector<std::string>&
699 if (seen.size() == 1000) {
700 WRITE_WARNING(
"Quitting checking for being a source for detector '" + det.
getID() +
"' due to seen edge limit.");
707 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
708 if ((*i) == det.
getID()) {
742 for (
int i = 0; i < (int)appr.size(); i++) {
749 if (noFalse + noSkipped == (
int)appr.size()) {
776 seen.push_back(edge);
777 for (
int i = 0; i < (int)appr.size(); i++) {
778 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
780 if (
isSource(det, appr[i], seen, detectors, strict)) {
790 return numOk + numSkipped == (int)appr.size();
792 return numFalse + numSkipped != (int)appr.size();
799 if (seen.size() == 1000) {
800 WRITE_WARNING(
"Quitting checking for being a destination for detector '" + det.
getID() +
"' due to seen edge limit.");
807 for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
808 if ((*i) == det.
getID()) {
859 seen.push_back(edge);
860 for (
int i = 0; i < (int)appr.size() && isall; i++) {
861 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
875 if (seen.size() == 1000) {
876 WRITE_WARNING(
"Quitting checking for being a false source for detector '" + det.
getID() +
"' due to seen edge limit.");
879 seen.push_back(edge);
884 for (std::vector<std::string>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
908 for (
int i = 0; i < (int)appr.size() && !isall; i++) {
910 bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
926 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
927 double speedFactorSumPKW = 0;
928 double speedFactorSumLKW = 0;
929 double speedFactorCountPKW = 0;
930 double speedFactorCountLKW = 0;
932 ROEdge* into = (*i).first;
936 const std::vector<std::string>& dets = (*i).second;
937 std::map<double, std::vector<std::string> > cliques;
938 std::vector<std::string>* maxClique =
nullptr;
939 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
940 if (!flows.
knows(*j)) {
945 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
946 if (fabs((*k).first - det.
getPos()) < 1) {
947 (*k).second.push_back(*j);
948 if ((*k).second.size() > maxClique->size()) {
949 maxClique = &(*k).second;
955 cliques[det.
getPos()].push_back(*j);
956 maxClique = &cliques[det.
getPos()];
959 if (maxClique ==
nullptr) {
962 std::vector<FlowDef> mflows;
963 for (
SUMOTime t = startTime; t < endTime; t += stepOffset) {
971 mflows.push_back(
fd);
973 for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) {
974 bool didWarn =
false;
975 const std::vector<FlowDef>& dflows = flows.
getFlowDefs(*l);
977 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
978 const FlowDef& srcFD = dflows[index];
982 fd.vLKW += srcFD.
vLKW / (double) maxClique->size();
983 fd.vPKW += srcFD.
vPKW / (double) maxClique->size();
984 fd.fLKW += srcFD.
fLKW / (double) maxClique->size();
985 fd.isLKW += srcFD.
isLKW / (double) maxClique->size();
986 const double speedFactorPKW = srcFD.
vPKW / 3.6 / maxSpeedPKW;
987 const double speedFactorLKW = srcFD.
vLKW / 3.6 / maxSpeedLKW;
990 speedFactorCountPKW += srcFD.
qPKW;
991 speedFactorCountLKW += srcFD.
qLKW;
992 speedFactorSumPKW += srcFD.
qPKW * speedFactorPKW;
993 speedFactorSumLKW += srcFD.
qLKW * speedFactorLKW;
1004 static_cast<RODFEdge*
>(into)->setFlows(mflows);
1007 if (speedFactorCountPKW > 0) {
1011 if (speedFactorCountLKW > 0) {
1026 std::map<std::string, ROEdge*>::const_iterator i;
1033 std::vector<RODFDetector*> last;
1035 const std::vector<std::string>& detNames =
myDetectorsOnEdges.find((*i).second)->second;
1036 for (std::vector<std::string>::const_iterator j = detNames.begin(); j != detNames.end(); ++j) {
1042 for (std::vector<RODFRouteDesc>::const_iterator j = routes.begin(); j != routes.end(); ++j) {
1044 for (ROEdgeVector::const_iterator k = edges2Pass.begin() + 1; k != edges2Pass.end(); ++k) {
1048 for (std::vector<RODFDetector*>::iterator l = last.begin(); l != last.end(); ++l) {
1050 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1052 (*l)->addFollowingDetector(&detectors.
getDetector(*m));
1056 for (std::vector<std::string>::const_iterator m = detNames.begin(); m != detNames.end(); ++m) {
1069 std::map<ROEdge*, std::vector<std::string>,
idComp>::iterator i;
1071 const std::vector<std::string>& dets = (*i).second;
1072 std::map<double, std::vector<std::string> > cliques;
1074 for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) {
1077 for (std::map<
double, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) {
1078 if (fabs((*k).first - det.
getPos()) < 10.) {
1079 (*k).second.push_back(*j);
1084 cliques[det.
getPos()] = std::vector<std::string>();
1085 cliques[det.
getPos()].push_back(*j);
1089 for (std::map<
double, std::vector<std::string> >::iterator m = cliques.begin(); m != cliques.end(); ++m) {
1090 std::vector<std::string> clique = (*m).second;
1092 if (clique.size() == 1) {
1096 for (std::vector<std::string>::iterator n = clique.begin(); n != clique.end(); ++n) {
1097 std::cout << *n <<
" ";
1098 if (n != clique.begin()) {
1103 std::cout <<
":" << nid << std::endl;
1105 detectors.
mesoJoin(nid, (*m).second);
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
#define PROGRESS_DONE_MESSAGE()
#define PROGRESS_BEGIN_MESSAGE(msg)
@ BETWEEN_DETECTOR
An in-between detector.
@ SOURCE_DETECTOR
A source detector.
@ DISCARDED_DETECTOR
A detector which had to be discarded (!!!)
@ TYPE_NOT_DEFINED
A not yet defined detector.
std::vector< ROEdge * > ROEdgeVector
std::vector< const ROEdge * > ConstROEdgeVector
@ SVC_TRUCK
vehicle is a large transport vehicle
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const std::string & getID() const
Returns the id.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
A container for RODFDetectors.
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
void removeDetector(const std::string &id)
const RODFDetector & getDetector(const std::string &id) const
RODFDetector & getModifiableDetector(const std::string &id) const
const std::vector< RODFDetector * > & getDetectors() const
void setFlows(const std::string &detector_id, std::vector< FlowDef > &)
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
void removeFlow(const std::string &detector_id)
bool knows(const std::string &det_id) const
Class representing a detector within the DFROUTER.
double getPos() const
Returns the position at which the detector lies.
void addPriorDetector(const RODFDetector *det)
const std::vector< RODFRouteDesc > & getRouteVector() const
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
RODFDetectorType getType() const
Returns the type of the detector.
void buildEdgeFlowMap(const RODFDetectorFlows &flows, const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
double myAvgSpeedFactorPKW
void computeTypes(RODFDetectorCon &dets, bool sourcesStrict) const
std::map< std::string, ROEdge * > myDetectorEdges
double myMaxSpeedFactorPKW
maximum speed factor in measurements
std::vector< std::string > myDisallowedEdges
List of ids of edges that shall not be used.
std::map< ROEdge *, std::vector< std::string >, idComp > myDetectorsOnEdges
void revalidateFlows(const RODFDetectorCon &detectors, RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
bool isFalseSource(const RODFDetector &det, const RODFDetectorCon &detectors) const
bool hasApproached(ROEdge *edge) const
void mesoJoin(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
void buildDetectorEdgeDependencies(RODFDetectorCon &dets) const
bool hasApproaching(ROEdge *edge) const
void buildRoutes(RODFDetectorCon &det, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const
RODFNet(bool amInHighwayMode)
Constructor.
bool isDestination(const RODFDetector &det, const RODFDetectorCon &detectors) const
void buildDetectorDependencies(RODFDetectorCon &detectors)
void removeEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
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 * getDetectorEdge(const RODFDetector &det) const
double myMaxSpeedFactorLKW
bool hasSourceDetector(ROEdge *edge, const RODFDetectorCon &detectors) const
std::map< ROEdge *, ROEdgeVector > myApproachingEdges
Map of edge name->list of names of this edge approaching edges.
bool hasDetector(ROEdge *edge) const
const std::vector< std::string > & getDetectorList(ROEdge *edge) const
double getAbsPos(const RODFDetector &det) const
bool isSource(const RODFDetector &det, const RODFDetectorCon &detectors, bool strict) const
double myAvgSpeedFactorLKW
bool hasInBetweenDetectorsOnly(ROEdge *edge, const RODFDetectorCon &detectors) const
void reportEmptyDetectors(RODFDetectorCon &detectors, RODFDetectorFlows &flows)
std::map< ROEdge *, ROEdgeVector > myApproachedEdges
Map of edge name->list of names of edges approached by this edge.
A container for DFROUTER-routes.
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
bool removeRouteDesc(RODFRouteDesc &desc)
Removes the given route description from the container.
A basic edge for routing applications.
double getVClassMaxSpeed(SUMOVehicleClass vclass) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
double getSpeedLimit() const
Returns the speed allowed on this edge.
bool isInternal() const
return whether this edge is an internal edge
const RONode * getFromJunction() const
const ROEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
double getLength() const
Returns the length of the edge.
const RONode * getToJunction() const
The router's network representation.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition of the traffic during a certain time containing the flows and speeds.
comparator for maps using edges as key, used only in myDetectorsOnEdges to make tests comparable
A route within the DFROUTER.
ROEdgeVector edges2Pass
The edges the route is made of.
const ROEdge * lastDetectorEdge
const ROEdge * endDetectorEdge