63 :
Named(id), myLaneID(laneID), myPosition(pos), myType(type), myRoutes(0) {}
88 double distance = rd.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(rd.
edges2Pass.back()->getToJunction()->getPosition());
91 length += (*i)->getLength();
93 return (distance / length);
105 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
106 std::vector<RODFEdge*> nextDetEdges;
107 std::set<ROEdge*> preSplitEdges;
108 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
110 bool hadSplit =
false;
113 if (find(nextDetEdges.begin(), nextDetEdges.end(), *j) == nextDetEdges.end()) {
114 nextDetEdges.push_back(static_cast<RODFEdge*>(*j));
120 preSplitEdges.insert(*j);
122 if ((*j)->getNumSuccessors() > 1) {
127 std::map<ROEdge*, double> inFlows;
129 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
130 std::set<ROEdge*> seen(preSplitEdges);
132 pending.push_back(*i);
134 while (!pending.empty()) {
135 ROEdge* e = pending.back();
143 pending.push_back(e2);
153 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, ++index) {
155 double overallProb = 0;
157 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
158 double flow = detectors.
getAggFlowFor(*i, time, 60, flows) - inFlows[*i];
163 if (overallProb > 0) {
164 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
183 std::vector<RODFRouteDesc>& descs =
myRoutes->
get();
185 for (
SUMOTime time = startTime; time < endTime; time += stepOffset) {
187 std::map<ROEdge*, double> flowMap;
190 for (std::vector<RODFRouteDesc>::iterator ri = descs.begin(); ri != descs.end(); ++ri, index++) {
192 for (ROEdgeVector::iterator j = (*ri).edges2Pass.begin(); j != (*ri).edges2Pass.end() && prob > 0;) {
199 if (probs.size() == 0) {
204 const std::map<RODFEdge*, double>& tprobs = probs[(int)((time - startTime) / stepOffset)];
206 for (std::map<RODFEdge*, double>::const_iterator k = tprobs.begin(); k != tprobs.end(); ++k) {
207 if (find(j, (*ri).edges2Pass.end(), (*k).first) != (*ri).edges2Pass.end()) {
209 splitEdge = (*k).first;
213 if (splitEdge != 0) {
214 j = find(j, (*ri).edges2Pass.end(), splitEdge);
219 into[time]->add(index, prob);
220 (*ri).overallProb = prob;
226 const std::vector<RODFRouteDesc>&
244 const std::set<const RODFDetector*>&
250 const std::set<const RODFDetector*>&
285 bool includeUnusedRoutes,
288 double defaultSpeed)
const {
296 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
298 bool isEmptyDist =
true;
299 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
300 if ((*i).overallProb > 0) {
304 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
305 if ((*i).overallProb > 0 || includeUnusedRoutes) {
318 if (insertionsOnly || flows.
knows(
myID)) {
323 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, index++) {
325 assert(index < (
int)mflows.size());
326 const FlowDef& srcFD = mflows[index];
330 const int numCars = (int)((srcFD.qPKW + srcFD.qLKW) * scale);
333 std::vector<SUMOTime> departures;
334 if (oc.
getBool(
"randomize-flows")) {
335 for (
int i = 0; i < numCars; ++i) {
338 std::sort(departures.begin(), departures.end());
340 for (
int i = 0; i < numCars; ++i) {
341 departures.push_back(time + (
SUMOTime)(stepOffset * i / (
double)numCars));
345 for (
int car = 0; car < numCars; ++car) {
349 int destIndex = destDist != 0 && destDist->
getOverallProb() > 0 ? (int) destDist->
get() : -1;
350 if (srcFD.isLKW >= 1) {
351 srcFD.isLKW = srcFD.isLKW - 1.;
359 if (v <= 0 || v > 250) {
365 const SUMOTime ctime = departures[car];
378 if (oc.
isSet(
"departlane")) {
383 if (oc.
isSet(
"departpos")) {
384 std::string posDesc = oc.
getString(
"departpos");
385 if (posDesc.substr(0, 8) ==
"detector") {
387 if (posDesc.length() > 8) {
388 if (posDesc[8] ==
'+') {
390 }
else if (posDesc[8] ==
'-') {
403 if (oc.
isSet(
"departspeed")) {
408 if (oc.
isSet(
"arrivallane")) {
411 if (oc.
isSet(
"arrivalpos")) {
414 if (oc.
isSet(
"arrivalspeed")) {
417 if (destIndex >= 0) {
423 srcFD.isLKW += srcFD.fLKW;
448 SUMOTime stepOffset,
double defaultSpeed) {
453 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
454 assert(index < (
int)mflows.size());
455 const FlowDef& srcFD = mflows[index];
456 double speed =
MAX2(srcFD.vLKW, srcFD.vPKW);
457 if (speed <= 0 || speed > 250) {
458 speed = defaultSpeed;
460 speed = (double)(speed / 3.6);
480 for (std::vector<RODFDetector*>::iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
488 if (myDetectorMap.find(dfd->
getID()) != myDetectorMap.end()) {
491 myDetectorMap[dfd->
getID()] = dfd;
492 myDetectors.push_back(dfd);
494 if (myDetectorEdgeMap.find(edgeid) == myDetectorEdgeMap.end()) {
495 myDetectorEdgeMap[edgeid] = std::vector<RODFDetector*>();
497 myDetectorEdgeMap[edgeid].push_back(dfd);
504 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
515 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
516 if ((*i)->hasRoutes()) {
524 const std::vector< RODFDetector*>&
534 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
536 switch ((*i)->getType()) {
562 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
564 switch ((*i)->getType()) {
590 std::vector<std::string> saved;
592 bool lastWasSaved =
true;
593 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
601 lastWasSaved = (*i)->writeRoutes(saved, out);
610 return *(myDetectorMap.find(
id)->second);
616 return *(myDetectorMap.find(
id)->second);
622 return myDetectorMap.find(
id) != myDetectorMap.end();
631 bool writeCalibrators,
632 bool includeUnusedRoutes,
634 bool insertionsOnly) {
636 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
637 (*i)->computeSplitProbabilities(&net, *
this, flows, startTime, endTime, stepOffset);
645 if (separateVTypeOutput) {
655 pkwType.
write(vTypeOut);
659 lkwType.
write(vTypeOut);
665 type.
write(vTypeOut);
670 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
674 std::string defFileName;
686 std::map<SUMOTime, RandomDistributor<int>* > dists;
687 if (!insertionsOnly && flows.
knows(det->
getID())) {
691 if (!det->
writeEmitterDefinition(defFileName, dists, flows, startTime, endTime, stepOffset, includeUnusedRoutes, scale, insertionsOnly, defaultSpeed)) {
704 if (separateVTypeOutput) {
731 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
734 const unsigned char col =
static_cast<unsigned char>(128 * flow / flows.
getMaxDetectorFlow() + 128);
736 switch ((*i)->getType()) {
769 assert(myDetectorEdgeMap.find(edge->
getID()) != myDetectorEdgeMap.end());
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,
810 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
816 double defaultSpeed = net != 0 ? net->
getEdge(det->
getEdgeID())->getSpeedLimit() : (double) 200.;
828 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
843 bool singleFile,
bool friendly) {
846 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
850 double pos = det->
getPos();
874 std::map<std::string, RODFDetector*>::iterator ri1 = myDetectorMap.find(
id);
876 myDetectorMap.erase(ri1);
878 std::vector<RODFDetector*>::iterator ri2 =
879 find(myDetectors.begin(), myDetectors.end(), oldDet);
880 myDetectors.erase(ri2);
883 for (std::map<std::string, std::vector<RODFDetector*> >::iterator rr3 = myDetectorEdgeMap.begin(); !found && rr3 != myDetectorEdgeMap.end(); ++rr3) {
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);
903 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
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()) {
945 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
946 if ((*i)->getEdgeID() == edge->
getID()) {
964 const std::vector<std::string>& oldids) {
966 const RODFDetector& first = getDetector(*(oldids.begin()));
970 for (std::vector<std::string>::const_iterator i = oldids.begin(); i != oldids.end(); ++i) {
double getFlowSumSecure(const std::string &id) const
RODFDetector & getModifiableDetector(const std::string &id) const
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
static const RGBColor BLUE
void close()
Closes the device and removes it from the dictionary.
const ROEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of incoming edges.
bool detectorsHaveRoutes() const
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 addRoute(RODFRouteDesc &nrd)
std::string getEdgeID() const
Returns the id of the edge this detector is placed on.
void removeDetector(const std::string &id)
void saveRoutes(const std::string &file) const
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
RODFDetectorType
Numerical representation of different detector types.
void save(const std::string &file) const
A calibrator placed over edge.
Structure representing possible vehicle parameter.
bool addDetector(RODFDetector *dfd)
double getAvgSpeedFactorPKW() const
void addRoutes(RODFRouteCont *routes)
const RODFDetector & getDetector(const std::string &id) const
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
std::string time2string(SUMOTime t)
ROEdgeVector edges2Pass
The edges the route is made of.
double getMaxSpeedFactorPKW() const
int getAggFlowFor(const ROEdge *edge, SUMOTime time, SUMOTime period, const RODFDetectorFlows &flows) const
void addPriorDetector(const RODFDetector *det)
bool hasDetector(ROEdge *edge) const
begin/end of the description of a Point of interest
const std::vector< RODFDetector * > & getDetectors() const
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
void writeSpeedTrigger(const RODFNet *const net, const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
RODFDetectorType getType() const
Returns the type of the detector.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
const std::vector< RODFRouteDesc > & getRouteVector() const
bool knows(const std::string &det_id) const
const std::string DEFAULT_VTYPE_ID
RODFDetector(const std::string &id, const std::string &laneID, double pos, const RODFDetectorType type)
Constructor.
std::vector< RODFRouteDesc > & get()
Returns the container of stored routes.
A container for RODFDetectors.
#define UNUSED_PARAMETER(x)
const std::set< const RODFDetector * > & getFollowerDetectors() const
begin/end of the description of a route
void computeSplitProbabilities(const RODFNet *net, const RODFDetectorCon &detectors, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
static OptionsCont & getOptions()
Retrieves the options.
vehicle is a large transport vehicle
A not yet defined detector.
double getMaxDetectorFlow() const
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool writeRoutes(std::vector< std::string > &saved, OutputDevice &out)
double getMaxSpeedFactorLKW() const
static const RGBColor GREEN
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::vector< std::map< RODFEdge *, double > > mySplitProbabilities
const std::vector< std::map< RODFEdge *, double > > & getSplitProbabilities() const
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 knows(const std::string &id) const
T get(std::mt19937 *which=0) const
Draw a sample of the distribution.
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.
const std::set< const RODFDetector * > & getPriorDetectors() const
std::vector< ROEdge * > ROEdgeVector
double computeDistanceFactor(const RODFRouteDesc &rd) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
A detector which had to be discarded (!!!)
const RODFDetector & getAnyDetectorForEdge(const RODFEdge *const edge) const
void writeValidationDetectors(const std::string &file, bool includeSources, bool singleFile, bool friendly)
void setSpeedFactorAndDev(SUMOVTypeParameter &type, double maxFactor, double avgFactor, double dev, bool forceDev)
~RODFDetector()
Destructor.
void clearDists(std::map< SUMOTime, RandomDistributor< int > * > &dists) const
Clears the given distributions map, deleting the timed distributions.
void saveAsPOIs(const std::string &file) const
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.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
vehicle is a passenger car (a "normal" car)
A route within the DFROUTER.
double getAvgSpeedFactorLKW() const
A basic edge for routing applications.
Base class for objects which have an id.
const int VTYPEPARS_SPEEDFACTOR_SET
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)
int parametersSet
Information for the router which parameter were set.
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
void writeSingleSpeedTrigger(const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, double defaultSpeed)
bool detectorsHaveCompleteTypes() const
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
std::string myID
The name of the object.
void write(OutputDevice &dev) const
Writes the vtype.
trigger: the time of the step
static const RGBColor RED
named colors
std::map< std::string, RODFEdge * > myRoute2Edge
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
void guessEmptyFlows(RODFDetectorFlows &flows)
Class representing a detector within the DFROUTER.
A storage for options typed value containers)
static double _2double(const E *const data)
converts a char-type array into the double value described by it
A container for DFROUTER-routes.
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
std::string routename
The name of the route.
void buildDestinationDistribution(const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, const RODFNet &net, std::map< SUMOTime, RandomDistributor< int > * > &into) const
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
void writeEmitterPOIs(const std::string &file, const RODFDetectorFlows &flows)
void setType(RODFDetectorType type)
std::set< const RODFDetector * > myPriorDetectors
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
std::set< const RODFDetector * > myFollowingDetectors
void writeEndRerouterDetectors(const std::string &file)
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
const int VTYPEPARS_VEHICLECLASS_SET
void addFollowingDetector(const RODFDetector *det)
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
double getPos() const
Returns the position at which the detector lies.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool save(std::vector< std::string > &saved, const std::string &prependix, OutputDevice &out)
Saves routes.
trigger: a step description