55 :
Named(id), myLaneID(laneID), myPosition(pos), myType(type), myRoutes(nullptr) {}
59 :
Named(id), myLaneID(f.myLaneID), myPosition(f.myPosition),
60 myType(f.myType), myRoutes(nullptr) {
80 double distance = rd.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(rd.
edges2Pass.back()->getToJunction()->getPosition());
83 length += (*i)->getLength();
85 return (distance / length);
97 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
98 std::vector<RODFEdge*> nextDetEdges;
99 std::set<ROEdge*> preSplitEdges;
100 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
102 bool hadSplit =
false;
105 if (find(nextDetEdges.begin(), nextDetEdges.end(), *j) == nextDetEdges.end()) {
106 nextDetEdges.push_back(
static_cast<RODFEdge*
>(*j));
112 preSplitEdges.insert(*j);
114 if ((*j)->getNumSuccessors() > 1) {
119 std::map<ROEdge*, double> inFlows;
121 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
122 std::set<ROEdge*> seen(preSplitEdges);
124 pending.push_back(*i);
126 while (!pending.empty()) {
127 ROEdge* e = pending.back();
135 pending.push_back(e2);
145 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, ++index) {
147 double overallProb = 0;
149 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
150 double flow = detectors.
getAggFlowFor(*i, time, 60, flows) - inFlows[*i];
155 if (overallProb > 0) {
156 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
175 std::vector<RODFRouteDesc>& descs =
myRoutes->
get();
177 for (
SUMOTime time = startTime; time < endTime; time += stepOffset) {
179 std::map<ROEdge*, double> flowMap;
182 for (std::vector<RODFRouteDesc>::iterator ri = descs.begin(); ri != descs.end(); ++ri, index++) {
184 for (ROEdgeVector::iterator j = (*ri).edges2Pass.begin(); j != (*ri).edges2Pass.end() && prob > 0;) {
191 if (probs.size() == 0) {
196 const std::map<RODFEdge*, double>& tprobs = probs[(int)((time - startTime) / stepOffset)];
198 for (std::map<RODFEdge*, double>::const_iterator k = tprobs.begin(); k != tprobs.end(); ++k) {
199 if (find(j, (*ri).edges2Pass.end(), (*k).first) != (*ri).edges2Pass.end()) {
201 splitEdge = (*k).first;
205 if (splitEdge !=
nullptr) {
206 j = std::find(j, (*ri).edges2Pass.end(), splitEdge);
211 into[time]->add(index, prob);
212 (*ri).overallProb = prob;
218 const std::vector<RODFRouteDesc>&
236 const std::set<const RODFDetector*>&
242 const std::set<const RODFDetector*>&
277 bool includeUnusedRoutes,
280 double defaultSpeed)
const {
288 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
290 bool isEmptyDist =
true;
291 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
292 if ((*i).overallProb > 0) {
296 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
299 }
else if ((*i).overallProb > 0 || includeUnusedRoutes) {
309 int vehicleIndex = 0;
310 if (insertionsOnly || flows.
knows(
myID)) {
315 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, index++) {
317 assert(index < (
int)mflows.size());
318 const FlowDef& srcFD = mflows[index];
322 const int numCars = (int)((srcFD.
qPKW + srcFD.
qLKW) * scale);
325 std::vector<SUMOTime> departures;
326 if (oc.
getBool(
"randomize-flows")) {
327 for (
int i = 0; i < numCars; ++i) {
330 std::sort(departures.begin(), departures.end());
332 for (
int i = 0; i < numCars; ++i) {
333 departures.push_back(time + (
SUMOTime)(stepOffset * i / (
double)numCars));
337 for (
int car = 0; car < numCars; ++car) {
342 if (destDist !=
nullptr) {
344 destIndex = destDist->
get();
350 if (srcFD.
isLKW >= 1) {
359 if (v <= 0 || v > 250) {
365 const SUMOTime ctime = departures[car];
374 if (oc.
isSet(
"departlane")) {
379 if (oc.
isSet(
"departpos")) {
380 std::string posDesc = oc.
getString(
"departpos");
381 if (posDesc.substr(0, 8) ==
"detector") {
383 if (posDesc.length() > 8) {
384 if (posDesc[8] ==
'+') {
386 }
else if (posDesc[8] ==
'-') {
399 if (oc.
isSet(
"departspeed")) {
404 if (oc.
isSet(
"arrivallane")) {
407 if (oc.
isSet(
"arrivalpos")) {
410 if (oc.
isSet(
"arrivalspeed")) {
413 if (destIndex >= 0) {
445 SUMOTime stepOffset,
double defaultSpeed) {
450 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
451 assert(index < (
int)mflows.size());
452 const FlowDef& srcFD = mflows[index];
454 if (speed <= 0 || speed > 250) {
455 speed = defaultSpeed;
457 speed = (double)(speed / 3.6);
513 if ((*i)->hasRoutes()) {
521 const std::vector< RODFDetector*>&
533 switch ((*i)->getType()) {
561 switch ((*i)->getType()) {
587 std::vector<std::string> saved;
589 bool lastWasSaved =
true;
598 lastWasSaved = (*i)->writeRoutes(saved, out);
628 bool writeCalibrators,
629 bool includeUnusedRoutes,
631 bool insertionsOnly) {
634 (*i)->computeSplitProbabilities(&net, *
this, flows, startTime, endTime, stepOffset);
642 if (separateVTypeOutput) {
652 pkwType.
write(vTypeOut);
656 lkwType.
write(vTypeOut);
662 type.
write(vTypeOut);
671 std::string defFileName;
683 std::map<SUMOTime, RandomDistributor<int>* > dists;
684 if (!insertionsOnly && flows.
knows(det->
getID())) {
688 if (!det->
writeEmitterDefinition(defFileName, dists, flows, startTime, endTime, stepOffset, includeUnusedRoutes, scale, insertionsOnly, defaultSpeed)) {
701 if (separateVTypeOutput) {
733 const unsigned char col =
static_cast<unsigned char>(128 * flow / flows.
getMaxDetectorFlow() + 128);
735 switch ((*i)->getType()) {
762 if (edge ==
nullptr) {
769 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(edge)->getFlows();
771 for (std::vector<FlowDef>::const_iterator i = flows.begin(); i != flows.end(); ++i) {
773 if (srcFD.
qLKW >= 0) {
776 if (srcFD.
qPKW >= 0) {
803 const std::string& file,
842 bool singleFile,
bool friendly) {
849 double pos = det->
getPos();
873 std::map<std::string, RODFDetector*>::iterator ri1 =
myDetectorMap.find(
id);
877 std::vector<RODFDetector*>::iterator ri2 =
883 std::vector<RODFDetector*>& dets = (*rr3).second;
884 for (std::vector<RODFDetector*>::iterator ri3 = dets.begin(); !found && ri3 != dets.end();) {
885 if (*ri3 == oldDet) {
887 ri3 = dets.erase(ri3);
906 int noFollowerWithRoutes = 0;
907 int noPriorWithRoutes = 0;
909 std::set<const RODFDetector*>::const_iterator j;
910 for (j = prior.begin(); j != prior.end(); ++j) {
911 if (flows.
knows((*j)->getID())) {
915 for (j = follower.begin(); j != follower.end(); ++j) {
916 if (flows.
knows((*j)->getID())) {
917 ++noFollowerWithRoutes;
927 if (noPriorWithRoutes == (
int)prior.size()) {
933 if (noFollowerWithRoutes == (
int)follower.size()) {
945 if ((*i)->getEdgeID() == edge->
getID()) {
963 const std::vector<std::string>& oldids) {
969 for (std::vector<std::string>::const_iterator i = oldids.begin(); i != oldids.end(); ++i) {
RODFDetectorType
Numerical representation of different detector types.
@ 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::string time2string(SUMOTime t)
convert SUMOTime to string
const int VTYPEPARS_VEHICLECLASS_SET
const int VTYPEPARS_SPEEDFACTOR_SET
@ SVC_TRUCK
vehicle is a large transport vehicle
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
const std::string DEFAULT_VTYPE_ID
@ SUMO_TAG_REROUTER
A rerouter.
@ SUMO_TAG_POI
begin/end of the description of a Point of interest
@ SUMO_TAG_STEP
trigger: a step description
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_E1DETECTOR
an e1 detector
@ SUMO_TAG_DETECTOR_DEFINITION
definition of a detector
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
@ SUMO_TAG_VSS
A variable speed sign.
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_TIME
trigger: the time of the step
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Base class for objects which have an id.
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
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.
Static storage of an output device and its base (abstract) implementation.
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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"
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
static const RGBColor BLUE
static const RGBColor GREEN
static const RGBColor RED
named colors
A container for RODFDetectors.
bool detectorsHaveRoutes() const
const RODFDetector & getAnyDetectorForEdge(const RODFEdge *const edge) const
void clearDists(std::map< SUMOTime, RandomDistributor< int > * > &dists) const
Clears the given distributions map, deleting the timed distributions.
std::map< std::string, std::vector< RODFDetector * > > myDetectorEdgeMap
void save(const std::string &file) const
void writeEmitterPOIs(const std::string &file, const RODFDetectorFlows &flows)
bool knows(const std::string &id) const
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
void removeDetector(const std::string &id)
bool addDetector(RODFDetector *dfd)
void writeValidationDetectors(const std::string &file, bool includeSources, bool singleFile, bool friendly)
const RODFDetector & getDetector(const std::string &id) const
std::map< std::string, RODFDetector * > myDetectorMap
void guessEmptyFlows(RODFDetectorFlows &flows)
bool detectorsHaveCompleteTypes() const
void saveRoutes(const std::string &file) const
std::vector< RODFDetector * > myDetectors
void writeSpeedTrigger(const RODFNet *const net, const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
void setSpeedFactorAndDev(SUMOVTypeParameter &type, double maxFactor, double avgFactor, double dev, bool forceDev)
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)
void saveAsPOIs(const std::string &file) const
RODFDetector & getModifiableDetector(const std::string &id) const
const std::vector< RODFDetector * > & getDetectors() const
void writeEndRerouterDetectors(const std::string &file)
int getAggFlowFor(const ROEdge *edge, SUMOTime time, SUMOTime period, const RODFDetectorFlows &flows) const
double getFlowSumSecure(const std::string &id) const
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
double getMaxDetectorFlow() const
bool knows(const std::string &det_id) const
Class representing a detector within the DFROUTER.
void computeSplitProbabilities(const RODFNet *net, const RODFDetectorCon &detectors, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
double getPos() const
Returns the position at which the detector lies.
void setType(RODFDetectorType type)
void addPriorDetector(const RODFDetector *det)
const std::vector< std::map< RODFEdge *, double > > & getSplitProbabilities() const
const std::vector< RODFRouteDesc > & getRouteVector() const
RODFDetector(const std::string &id, const std::string &laneID, double pos, const RODFDetectorType type)
Constructor.
void addRoute(RODFRouteDesc &nrd)
bool writeRoutes(std::vector< std::string > &saved, OutputDevice &out)
double computeDistanceFactor(const RODFRouteDesc &rd) const
void buildDestinationDistribution(const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, const RODFNet &net, std::map< SUMOTime, RandomDistributor< int > * > &into) const
const std::set< const RODFDetector * > & getPriorDetectors() const
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
void addRoutes(RODFRouteCont *routes)
RODFDetectorType getType() const
Returns the type of the detector.
std::vector< std::map< RODFEdge *, double > > mySplitProbabilities
void writeSingleSpeedTrigger(const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, double defaultSpeed)
std::map< std::string, RODFEdge * > myRoute2Edge
std::string getEdgeID() const
Returns the id of the edge this detector is placed on.
~RODFDetector()
Destructor.
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
std::set< const RODFDetector * > myPriorDetectors
void addFollowingDetector(const RODFDetector *det)
const std::set< const RODFDetector * > & getFollowerDetectors() const
std::set< const RODFDetector * > myFollowingDetectors
double getMaxSpeedFactorLKW() const
double getMaxSpeedFactorPKW() const
double getAvgSpeedFactorLKW() const
double getAvgSpeedFactorPKW() const
bool hasDetector(ROEdge *edge) const
A container for DFROUTER-routes.
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
bool save(std::vector< std::string > &saved, const std::string &prependix, OutputDevice &out)
Saves routes.
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
A basic edge for routing applications.
double getSpeedLimit() const
Returns the speed allowed on this edge.
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
const ROEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of incoming edges.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
T get(SumoRNG *which=nullptr) const
Draw a sample of the distribution.
Structure representing possible vehicle parameter.
void write(OutputDevice &dev) const
Writes the vtype.
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street.
int parametersSet
Information for the router which parameter were set.
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
static int getIndexFromLane(const std::string laneID)
return lane index when given the lane ID
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
Definition of the traffic during a certain time containing the flows and speeds.
A route within the DFROUTER.
std::string routename
The name of the route.
ROEdgeVector edges2Pass
The edges the route is made of.