 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
56 :
Named(id), myLaneID(laneID), myPosition(pos), myType(type), myRoutes(nullptr) {}
60 :
Named(id), myLaneID(f.myLaneID), myPosition(f.myPosition),
61 myType(f.myType), myRoutes(nullptr) {
81 double distance = rd.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(rd.
edges2Pass.back()->getToJunction()->getPosition());
84 length += (*i)->getLength();
86 return (distance / length);
98 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
99 std::vector<RODFEdge*> nextDetEdges;
100 std::set<ROEdge*> preSplitEdges;
101 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
103 bool hadSplit =
false;
106 if (find(nextDetEdges.begin(), nextDetEdges.end(), *j) == nextDetEdges.end()) {
107 nextDetEdges.push_back(
static_cast<RODFEdge*
>(*j));
113 preSplitEdges.insert(*j);
115 if ((*j)->getNumSuccessors() > 1) {
120 std::map<ROEdge*, double> inFlows;
122 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
123 std::set<ROEdge*> seen(preSplitEdges);
125 pending.push_back(*i);
127 while (!pending.empty()) {
128 ROEdge* e = pending.back();
136 pending.push_back(e2);
146 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, ++index) {
148 double overallProb = 0;
150 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
151 double flow = detectors.
getAggFlowFor(*i, time, 60, flows) - inFlows[*i];
156 if (overallProb > 0) {
157 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
176 std::vector<RODFRouteDesc>& descs =
myRoutes->
get();
178 for (
SUMOTime time = startTime; time < endTime; time += stepOffset) {
180 std::map<ROEdge*, double> flowMap;
183 for (std::vector<RODFRouteDesc>::iterator ri = descs.begin(); ri != descs.end(); ++ri, index++) {
185 for (ROEdgeVector::iterator j = (*ri).edges2Pass.begin(); j != (*ri).edges2Pass.end() && prob > 0;) {
192 if (probs.size() == 0) {
197 const std::map<RODFEdge*, double>& tprobs = probs[(int)((time - startTime) / stepOffset)];
199 for (std::map<RODFEdge*, double>::const_iterator k = tprobs.begin(); k != tprobs.end(); ++k) {
200 if (find(j, (*ri).edges2Pass.end(), (*k).first) != (*ri).edges2Pass.end()) {
202 splitEdge = (*k).first;
206 if (splitEdge !=
nullptr) {
207 j = std::find(j, (*ri).edges2Pass.end(), splitEdge);
212 into[time]->add(index, prob);
213 (*ri).overallProb = prob;
219 const std::vector<RODFRouteDesc>&
237 const std::set<const RODFDetector*>&
243 const std::set<const RODFDetector*>&
278 bool includeUnusedRoutes,
281 double defaultSpeed)
const {
289 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
291 bool isEmptyDist =
true;
292 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
293 if ((*i).overallProb > 0) {
297 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
300 }
else if ((*i).overallProb > 0 || includeUnusedRoutes) {
310 int vehicleIndex = 0;
311 if (insertionsOnly || flows.
knows(
myID)) {
316 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, index++) {
318 assert(index < (
int)mflows.size());
319 const FlowDef& srcFD = mflows[index];
323 const int numCars = (int)((srcFD.
qPKW + srcFD.
qLKW) * scale);
326 std::vector<SUMOTime> departures;
327 if (oc.
getBool(
"randomize-flows")) {
328 for (
int i = 0; i < numCars; ++i) {
331 std::sort(departures.begin(), departures.end());
333 for (
int i = 0; i < numCars; ++i) {
334 departures.push_back(time + (
SUMOTime)(stepOffset * i / (
double)numCars));
338 for (
int car = 0; car < numCars; ++car) {
343 if (destDist !=
nullptr) {
345 destIndex = destDist->
get();
351 if (srcFD.
isLKW >= 1) {
360 if (v <= 0 || v > 250) {
366 const SUMOTime ctime = departures[car];
375 if (oc.
isSet(
"departlane")) {
380 if (oc.
isSet(
"departpos")) {
381 std::string posDesc = oc.
getString(
"departpos");
382 if (posDesc.substr(0, 8) ==
"detector") {
384 if (posDesc.length() > 8) {
385 if (posDesc[8] ==
'+') {
387 }
else if (posDesc[8] ==
'-') {
400 if (oc.
isSet(
"departspeed")) {
405 if (oc.
isSet(
"arrivallane")) {
408 if (oc.
isSet(
"arrivalpos")) {
411 if (oc.
isSet(
"arrivalspeed")) {
414 if (destIndex >= 0) {
446 SUMOTime stepOffset,
double defaultSpeed) {
451 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
452 assert(index < (
int)mflows.size());
453 const FlowDef& srcFD = mflows[index];
455 if (speed <= 0 || speed > 250) {
456 speed = defaultSpeed;
458 speed = (double)(speed / 3.6);
514 if ((*i)->hasRoutes()) {
522 const std::vector< RODFDetector*>&
534 switch ((*i)->getType()) {
562 switch ((*i)->getType()) {
588 std::vector<std::string> saved;
590 bool lastWasSaved =
true;
599 lastWasSaved = (*i)->writeRoutes(saved, out);
629 bool writeCalibrators,
630 bool includeUnusedRoutes,
632 bool insertionsOnly) {
635 (*i)->computeSplitProbabilities(&net, *
this, flows, startTime, endTime, stepOffset);
643 if (separateVTypeOutput) {
653 pkwType.
write(vTypeOut);
657 lkwType.
write(vTypeOut);
663 type.
write(vTypeOut);
672 std::string defFileName;
684 std::map<SUMOTime, RandomDistributor<int>* > dists;
685 if (!insertionsOnly && flows.
knows(det->
getID())) {
689 if (!det->
writeEmitterDefinition(defFileName, dists, flows, startTime, endTime, stepOffset, includeUnusedRoutes, scale, insertionsOnly, defaultSpeed)) {
702 if (separateVTypeOutput) {
734 const unsigned char col =
static_cast<unsigned char>(128 * flow / flows.
getMaxDetectorFlow() + 128);
736 switch ((*i)->getType()) {
763 if (edge ==
nullptr) {
770 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(edge)->getFlows();
772 for (std::vector<FlowDef>::const_iterator i = flows.begin(); i != flows.end(); ++i) {
774 if (srcFD.
qLKW >= 0) {
777 if (srcFD.
qPKW >= 0) {
804 const std::string& file,
843 bool singleFile,
bool friendly) {
850 double pos = det->
getPos();
874 std::map<std::string, RODFDetector*>::iterator ri1 =
myDetectorMap.find(
id);
878 std::vector<RODFDetector*>::iterator ri2 =
884 std::vector<RODFDetector*>& dets = (*rr3).second;
885 for (std::vector<RODFDetector*>::iterator ri3 = dets.begin(); !found && ri3 != dets.end();) {
886 if (*ri3 == oldDet) {
888 ri3 = dets.erase(ri3);
907 int noFollowerWithRoutes = 0;
908 int noPriorWithRoutes = 0;
910 std::set<const RODFDetector*>::const_iterator j;
911 for (j = prior.begin(); j != prior.end(); ++j) {
912 if (flows.
knows((*j)->getID())) {
916 for (j = follower.begin(); j != follower.end(); ++j) {
917 if (flows.
knows((*j)->getID())) {
918 ++noFollowerWithRoutes;
928 if (noPriorWithRoutes == (
int)prior.size()) {
934 if (noFollowerWithRoutes == (
int)follower.size()) {
946 if ((*i)->getEdgeID() == edge->
getID()) {
964 const std::vector<std::string>& oldids) {
970 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)
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
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)
@ SUMO_ATTR_COLOR
A color information.
static OptionsCont & getOptions()
Retrieves the options.
std::vector< RODFDetector * > myDetectors
@ SUMO_TAG_POI
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.
@ SUMO_TAG_DETECTOR_DEFINITION
definition of a detector
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.
@ SVC_TRUCK
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
@ SUMO_TAG_VSS
A variable speed sign.
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)
@ SVC_PASSENGER
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.
@ SUMO_ATTR_EDGES
the edges of a route
void computeSplitProbabilities(const RODFNet *net, const RODFDetectorCon &detectors, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
static const RGBColor BLUE
@ SUMO_TAG_STEP
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)
@ SUMO_TAG_REROUTER
A rerouter.
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.
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_ATTR_TIME
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.
@ TYPE_NOT_DEFINED
A not yet defined detector.
@ SOURCE_DETECTOR
A source detector.
@ SUMO_TAG_ROUTE
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
double getSpeedLimit() const
Returns the speed allowed on this edge.
static const RGBColor GREEN
@ BETWEEN_DETECTOR
An in-between detector.
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)
@ DISCARDED_DETECTOR
A detector which had to be discarded (!!!)
void addFollowingDetector(const RODFDetector *det)
double getMaxSpeedFactorLKW() const
@ SUMO_TAG_CALIBRATOR
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
@ SUMO_TAG_E1DETECTOR
an e1 detector
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