 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
57 :
Named(id), myLaneID(laneID), myPosition(pos), myType(type), myRoutes(nullptr) {}
61 :
Named(id), myLaneID(f.myLaneID), myPosition(f.myPosition),
62 myType(f.myType), myRoutes(nullptr) {
82 double distance = rd.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(rd.
edges2Pass.back()->getToJunction()->getPosition());
85 length += (*i)->getLength();
87 return (distance / length);
99 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
100 std::vector<RODFEdge*> nextDetEdges;
101 std::set<ROEdge*> preSplitEdges;
102 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
104 bool hadSplit =
false;
107 if (find(nextDetEdges.begin(), nextDetEdges.end(), *j) == nextDetEdges.end()) {
108 nextDetEdges.push_back(static_cast<RODFEdge*>(*j));
114 preSplitEdges.insert(*j);
116 if ((*j)->getNumSuccessors() > 1) {
121 std::map<ROEdge*, double> inFlows;
123 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
124 std::set<ROEdge*> seen(preSplitEdges);
126 pending.push_back(*i);
128 while (!pending.empty()) {
129 ROEdge* e = pending.back();
137 pending.push_back(e2);
147 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, ++index) {
149 double overallProb = 0;
151 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
152 double flow = detectors.
getAggFlowFor(*i, time, 60, flows) - inFlows[*i];
157 if (overallProb > 0) {
158 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
177 std::vector<RODFRouteDesc>& descs =
myRoutes->
get();
179 for (
SUMOTime time = startTime; time < endTime; time += stepOffset) {
181 std::map<ROEdge*, double> flowMap;
184 for (std::vector<RODFRouteDesc>::iterator ri = descs.begin(); ri != descs.end(); ++ri, index++) {
186 for (ROEdgeVector::iterator j = (*ri).edges2Pass.begin(); j != (*ri).edges2Pass.end() && prob > 0;) {
193 if (probs.size() == 0) {
198 const std::map<RODFEdge*, double>& tprobs = probs[(int)((time - startTime) / stepOffset)];
200 for (std::map<RODFEdge*, double>::const_iterator k = tprobs.begin(); k != tprobs.end(); ++k) {
201 if (find(j, (*ri).edges2Pass.end(), (*k).first) != (*ri).edges2Pass.end()) {
203 splitEdge = (*k).first;
207 if (splitEdge !=
nullptr) {
208 j = std::find(j, (*ri).edges2Pass.end(), splitEdge);
213 into[time]->add(index, prob);
214 (*ri).overallProb = prob;
220 const std::vector<RODFRouteDesc>&
238 const std::set<const RODFDetector*>&
244 const std::set<const RODFDetector*>&
279 bool includeUnusedRoutes,
282 double defaultSpeed)
const {
290 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
292 bool isEmptyDist =
true;
293 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
294 if ((*i).overallProb > 0) {
298 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
301 }
else if ((*i).overallProb > 0 || includeUnusedRoutes) {
311 int vehicleIndex = 0;
312 if (insertionsOnly || flows.
knows(
myID)) {
317 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, index++) {
319 assert(index < (
int)mflows.size());
320 const FlowDef& srcFD = mflows[index];
324 const int numCars = (int)((srcFD.qPKW + srcFD.qLKW) * scale);
327 std::vector<SUMOTime> departures;
328 if (oc.
getBool(
"randomize-flows")) {
329 for (
int i = 0; i < numCars; ++i) {
332 std::sort(departures.begin(), departures.end());
334 for (
int i = 0; i < numCars; ++i) {
335 departures.push_back(time + (
SUMOTime)(stepOffset * i / (
double)numCars));
339 for (
int car = 0; car < numCars; ++car) {
344 if (destDist !=
nullptr) {
346 destIndex = destDist->
get();
352 if (srcFD.isLKW >= 1) {
353 srcFD.isLKW = srcFD.isLKW - 1.;
361 if (v <= 0 || v > 250) {
367 const SUMOTime ctime = departures[car];
376 if (oc.
isSet(
"departlane")) {
381 if (oc.
isSet(
"departpos")) {
382 std::string posDesc = oc.
getString(
"departpos");
383 if (posDesc.substr(0, 8) ==
"detector") {
385 if (posDesc.length() > 8) {
386 if (posDesc[8] ==
'+') {
388 }
else if (posDesc[8] ==
'-') {
401 if (oc.
isSet(
"departspeed")) {
406 if (oc.
isSet(
"arrivallane")) {
409 if (oc.
isSet(
"arrivalpos")) {
412 if (oc.
isSet(
"arrivalspeed")) {
415 if (destIndex >= 0) {
421 srcFD.isLKW += srcFD.fLKW;
447 SUMOTime stepOffset,
double defaultSpeed) {
452 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
453 assert(index < (
int)mflows.size());
454 const FlowDef& srcFD = mflows[index];
455 double speed =
MAX2(srcFD.vLKW, srcFD.vPKW);
456 if (speed <= 0 || speed > 250) {
457 speed = defaultSpeed;
459 speed = (double)(speed / 3.6);
515 if ((*i)->hasRoutes()) {
523 const std::vector< RODFDetector*>&
535 switch ((*i)->getType()) {
563 switch ((*i)->getType()) {
589 std::vector<std::string> saved;
591 bool lastWasSaved =
true;
600 lastWasSaved = (*i)->writeRoutes(saved, out);
630 bool writeCalibrators,
631 bool includeUnusedRoutes,
633 bool insertionsOnly) {
636 (*i)->computeSplitProbabilities(&net, *
this, flows, startTime, endTime, stepOffset);
644 if (separateVTypeOutput) {
654 pkwType.
write(vTypeOut);
658 lkwType.
write(vTypeOut);
664 type.
write(vTypeOut);
673 std::string defFileName;
685 std::map<SUMOTime, RandomDistributor<int>* > dists;
686 if (!insertionsOnly && flows.
knows(det->
getID())) {
690 if (!det->
writeEmitterDefinition(defFileName, dists, flows, startTime, endTime, stepOffset, includeUnusedRoutes, scale, insertionsOnly, defaultSpeed)) {
703 if (separateVTypeOutput) {
735 const unsigned char col = static_cast<unsigned char>(128 * flow / flows.
getMaxDetectorFlow() + 128);
737 switch ((*i)->getType()) {
764 if (edge ==
nullptr) {
771 const std::vector<FlowDef>& flows = static_cast<const RODFEdge*>(edge)->getFlows();
773 for (std::vector<FlowDef>::const_iterator i = flows.begin(); i != flows.end(); ++i) {
775 if (srcFD.
qLKW >= 0) {
778 if (srcFD.
qPKW >= 0) {
805 const std::string& file,
817 double defaultSpeed = net !=
nullptr ? net->
getEdge(det->
getEdgeID())->getSpeedLimit() : (double) 200.;
844 bool singleFile,
bool friendly) {
851 double pos = det->
getPos();
875 std::map<std::string, RODFDetector*>::iterator ri1 =
myDetectorMap.find(
id);
879 std::vector<RODFDetector*>::iterator ri2 =
885 std::vector<RODFDetector*>& dets = (*rr3).second;
886 for (std::vector<RODFDetector*>::iterator ri3 = dets.begin(); !found && ri3 != dets.end();) {
887 if (*ri3 == oldDet) {
889 ri3 = dets.erase(ri3);
908 int noFollowerWithRoutes = 0;
909 int noPriorWithRoutes = 0;
911 std::set<const RODFDetector*>::const_iterator j;
912 for (j = prior.begin(); j != prior.end(); ++j) {
913 if (flows.
knows((*j)->getID())) {
917 for (j = follower.begin(); j != follower.end(); ++j) {
918 if (flows.
knows((*j)->getID())) {
919 ++noFollowerWithRoutes;
929 if (noPriorWithRoutes == (
int)prior.size()) {
935 if (noFollowerWithRoutes == (
int)follower.size()) {
947 if ((*i)->getEdgeID() == edge->
getID()) {
965 const std::vector<std::string>& oldids) {
971 for (std::vector<std::string>::const_iterator i = oldids.begin(); i != oldids.end(); ++i) {
void addRoutes(RODFRouteCont *routes)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool detectorsHaveRoutes() const
#define UNUSED_PARAMETER(x)
std::set< const RODFDetector * > myFollowingDetectors
void addRoute(RODFRouteDesc &nrd)
std::string getEdgeID() const
Returns the id of the edge this detector is placed on.
int getAggFlowFor(const ROEdge *edge, SUMOTime time, SUMOTime period, const RODFDetectorFlows &flows) const
Class representing a detector within the DFROUTER.
std::map< std::string, RODFDetector * > myDetectorMap
bool knows(const std::string &id) const
Base class for objects which have an id.
void addPriorDetector(const RODFDetector *det)
Static storage of an output device and its base (abstract) implementation.
bool writeEmitterDefinition(const std::string &file, const std::map< SUMOTime, RandomDistributor< int > * > &dists, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, bool includeUnusedRoutes, double scale, bool insertionsOnly, double defaultSpeed) const
void removeDetector(const std::string &id)
void writeSpeedTrigger(const RODFNet *const net, const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
void saveRoutes(const std::string &file) const
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
double getFlowSumSecure(const std::string &id) const
const RODFDetector & getAnyDetectorForEdge(const RODFEdge *const edge) const
const std::set< const RODFDetector * > & getFollowerDetectors() const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
std::vector< RODFDetector * > myDetectors
begin/end of the description of a Point of interest
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
const std::vector< RODFRouteDesc > & getRouteVector() const
double getMaxDetectorFlow() const
bool knows(const std::string &det_id) const
A container for RODFDetectors.
RODFDetector(const std::string &id, const std::string &laneID, double pos, const RODFDetectorType type)
Constructor.
void close()
Closes the device and removes it from the dictionary.
void writeEmitters(const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, const RODFNet &net, bool writeCalibrators, bool includeUnusedRoutes, double scale, bool insertionsOnly)
std::vector< std::map< RODFEdge *, double > > mySplitProbabilities
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
RODFDetectorType getType() const
Returns the type of the detector.
const ROEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of incoming edges.
int parametersSet
Information for the router which parameter were set.
const RODFDetector & getDetector(const std::string &id) const
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
T get(std::mt19937 *which=0) const
Draw a sample of the distribution.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
std::vector< double > & getParameter()
Returns the parameters of this distribution.
Definition of the traffic during a certain time containing the flows and speeds.
vehicle is a large transport vehicle
~RODFDetector()
Destructor.
bool hasDetector(ROEdge *edge) const
void writeEmitterPOIs(const std::string &file, const RODFDetectorFlows &flows)
const std::set< const RODFDetector * > & getPriorDetectors() const
double getMaxSpeedFactorPKW() const
Structure representing possible vehicle parameter.
A route within the DFROUTER.
const std::string DEFAULT_VTYPE_ID
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
vehicle is a passenger car (a "normal" car)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
void computeSplitProbabilities(const RODFNet *net, const RODFDetectorCon &detectors, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
static const RGBColor BLUE
trigger: a step description
const std::vector< std::map< RODFEdge *, double > > & getSplitProbabilities() const
bool save(std::vector< std::string > &saved, const std::string &prependix, OutputDevice &out)
Saves routes.
std::string time2string(SUMOTime t)
void writeSingleSpeedTrigger(const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, double defaultSpeed)
bool detectorsHaveCompleteTypes() const
static const RGBColor RED
named colors
A storage for options typed value containers)
double computeDistanceFactor(const RODFRouteDesc &rd) const
bool writeRoutes(std::vector< std::string > &saved, OutputDevice &out)
std::vector< ROEdge * > ROEdgeVector
const int VTYPEPARS_SPEEDFACTOR_SET
void write(OutputDevice &dev) const
Writes the vtype.
trigger: the time of the step
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
OutputDevice & writeNonEmptyAttr(const SumoXMLAttr attr, const std::string &val)
writes a string attribute only if it is not the empty string and not the string "default"
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street.
std::string routename
The name of the route.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
ROEdgeVector edges2Pass
The edges the route is made of.
const std::vector< RODFDetector * > & getDetectors() const
void buildDestinationDistribution(const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, const RODFNet &net, std::map< SUMOTime, RandomDistributor< int > * > &into) const
std::set< const RODFDetector * > myPriorDetectors
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
std::map< std::string, RODFEdge * > myRoute2Edge
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
RODFDetectorType
Numerical representation of different detector types.
double getAvgSpeedFactorPKW() const
void clearDists(std::map< SUMOTime, RandomDistributor< int > * > &dists) const
Clears the given distributions map, deleting the timed distributions.
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
A basic edge for routing applications.
double getAvgSpeedFactorLKW() const
void guessEmptyFlows(RODFDetectorFlows &flows)
double getPos() const
Returns the position at which the detector lies.
A not yet defined detector.
begin/end of the description of a route
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
void saveAsPOIs(const std::string &file) const
static const RGBColor GREEN
A container for DFROUTER-routes.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
void setType(RODFDetectorType type)
A detector which had to be discarded (!!!)
void addFollowingDetector(const RODFDetector *det)
double getMaxSpeedFactorLKW() const
A calibrator placed over edge.
void setSpeedFactorAndDev(SUMOVTypeParameter &type, double maxFactor, double avgFactor, double dev, bool forceDev)
std::string myID
The name of the object.
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
void writeEndRerouterDetectors(const std::string &file)
void save(const std::string &file) const
bool addDetector(RODFDetector *dfd)
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
const std::string & getID() const
Returns the id.
void writeValidationDetectors(const std::string &file, bool includeSources, bool singleFile, bool friendly)
const int VTYPEPARS_VEHICLECLASS_SET
RODFDetector & getModifiableDetector(const std::string &id) const
std::map< std::string, std::vector< RODFDetector * > > myDetectorEdgeMap