64 :
Named(id), myLaneID(laneID), myPosition(pos), myType(type), myRoutes(0) {}
89 double distance = rd.
edges2Pass[0]->getFromJunction()->getPosition().distanceTo(rd.
edges2Pass.back()->getToJunction()->getPosition());
92 length += (*i)->getLength();
94 return (distance / length);
106 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
107 std::vector<RODFEdge*> nextDetEdges;
108 std::set<ROEdge*> preSplitEdges;
109 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
111 bool hadSplit =
false;
114 if (find(nextDetEdges.begin(), nextDetEdges.end(), *j) == nextDetEdges.end()) {
115 nextDetEdges.push_back(static_cast<RODFEdge*>(*j));
121 preSplitEdges.insert(*j);
123 if ((*j)->getNumSuccessors() > 1) {
128 std::map<ROEdge*, double> inFlows;
130 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
131 std::set<ROEdge*> seen(preSplitEdges);
133 pending.push_back(*i);
135 while (!pending.empty()) {
136 ROEdge* e = pending.back();
144 pending.push_back(e2);
154 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, ++index) {
156 double overallProb = 0;
158 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
159 double flow = detectors.
getAggFlowFor(*i, time, 60, flows) - inFlows[*i];
164 if (overallProb > 0) {
165 for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) {
184 std::vector<RODFRouteDesc>& descs =
myRoutes->
get();
186 for (
SUMOTime time = startTime; time < endTime; time += stepOffset) {
188 std::map<ROEdge*, double> flowMap;
191 for (std::vector<RODFRouteDesc>::iterator ri = descs.begin(); ri != descs.end(); ++ri, index++) {
193 for (ROEdgeVector::iterator j = (*ri).edges2Pass.begin(); j != (*ri).edges2Pass.end() && prob > 0;) {
200 if (probs.size() == 0) {
205 const std::map<RODFEdge*, double>& tprobs = probs[(int)((time - startTime) / stepOffset)];
207 for (std::map<RODFEdge*, double>::const_iterator k = tprobs.begin(); k != tprobs.end(); ++k) {
208 if (find(j, (*ri).edges2Pass.end(), (*k).first) != (*ri).edges2Pass.end()) {
210 splitEdge = (*k).first;
214 if (splitEdge != 0) {
215 j = find(j, (*ri).edges2Pass.end(), splitEdge);
220 into[time]->add(index, prob);
221 (*ri).overallProb = prob;
227 const std::vector<RODFRouteDesc>&
245 const std::set<const RODFDetector*>&
251 const std::set<const RODFDetector*>&
286 bool includeUnusedRoutes,
289 double defaultSpeed)
const {
297 const std::vector<RODFRouteDesc>& routes =
myRoutes->
get();
299 bool isEmptyDist =
true;
300 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
301 if ((*i).overallProb > 0) {
305 for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
306 if ((*i).overallProb > 0 || includeUnusedRoutes) {
319 if (insertionsOnly || flows.
knows(
myID)) {
324 for (
SUMOTime time = startTime; time < endTime; time += stepOffset, index++) {
326 assert(index < (
int)mflows.size());
327 const FlowDef& srcFD = mflows[index];
331 int carNo = (int)((srcFD.qPKW + srcFD.qLKW) * scale);
332 for (
int car = 0; car < carNo; ++car) {
336 int destIndex = destDist != 0 && destDist->
getOverallProb() > 0 ? (int) destDist->
get() : -1;
337 if (srcFD.isLKW >= 1) {
338 srcFD.isLKW = srcFD.isLKW - (double) 1.;
346 if (v <= 0 || v > 250) {
349 v = (double)(v / 3.6);
352 SUMOTime ctime = (
SUMOTime)(time + ((
double) stepOffset * (double) car / (
double) carNo));
365 if (oc.
isSet(
"departlane")) {
370 if (oc.
isSet(
"departpos")) {
371 std::string posDesc = oc.
getString(
"departpos");
372 if (posDesc.substr(0, 8) ==
"detector") {
374 if (posDesc.length() > 8) {
375 if (posDesc[8] ==
'+') {
377 }
else if (posDesc[8] ==
'-') {
390 if (oc.
isSet(
"departspeed")) {
395 if (oc.
isSet(
"arrivallane")) {
398 if (oc.
isSet(
"arrivalpos")) {
401 if (oc.
isSet(
"arrivalspeed")) {
404 if (destIndex >= 0) {
410 srcFD.isLKW += srcFD.fLKW;
435 SUMOTime stepOffset,
double defaultSpeed) {
440 for (
SUMOTime t = startTime; t < endTime; t += stepOffset, index++) {
441 assert(index < (
int)mflows.size());
442 const FlowDef& srcFD = mflows[index];
443 double speed =
MAX2(srcFD.vLKW, srcFD.vPKW);
444 if (speed <= 0 || speed > 250) {
445 speed = defaultSpeed;
447 speed = (double)(speed / 3.6);
467 for (std::vector<RODFDetector*>::iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
475 if (myDetectorMap.find(dfd->
getID()) != myDetectorMap.end()) {
478 myDetectorMap[dfd->
getID()] = dfd;
479 myDetectors.push_back(dfd);
481 if (myDetectorEdgeMap.find(edgeid) == myDetectorEdgeMap.end()) {
482 myDetectorEdgeMap[edgeid] = std::vector<RODFDetector*>();
484 myDetectorEdgeMap[edgeid].push_back(dfd);
491 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
502 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
503 if ((*i)->hasRoutes()) {
511 const std::vector< RODFDetector*>&
521 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
523 switch ((*i)->getType()) {
549 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
551 switch ((*i)->getType()) {
577 std::vector<std::string> saved;
579 bool lastWasSaved =
true;
580 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
588 lastWasSaved = (*i)->writeRoutes(saved, out);
597 return *(myDetectorMap.find(
id)->second);
603 return *(myDetectorMap.find(
id)->second);
609 return myDetectorMap.find(
id) != myDetectorMap.end();
618 bool writeCalibrators,
619 bool includeUnusedRoutes,
621 bool insertionsOnly) {
623 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
624 (*i)->computeSplitProbabilities(&net, *
this, flows, startTime, endTime, stepOffset);
632 if (separateVTypeOutput) {
642 pkwType.
write(vTypeOut);
646 lkwType.
write(vTypeOut);
652 type.
write(vTypeOut);
657 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
661 std::string defFileName;
673 std::map<SUMOTime, RandomDistributor<int>* > dists;
674 if (!insertionsOnly && flows.
knows(det->
getID())) {
678 if (!det->
writeEmitterDefinition(defFileName, dists, flows, startTime, endTime, stepOffset, includeUnusedRoutes, scale, insertionsOnly, defaultSpeed)) {
691 if (separateVTypeOutput) {
718 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
721 const unsigned char col =
static_cast<unsigned char>(128 * flow / flows.
getMaxDetectorFlow() + 128);
723 switch ((*i)->getType()) {
756 assert(myDetectorEdgeMap.find(edge->
getID()) != myDetectorEdgeMap.end());
757 const std::vector<FlowDef>& flows =
static_cast<const RODFEdge*
>(edge)->getFlows();
759 for (std::vector<FlowDef>::const_iterator i = flows.begin(); i != flows.end(); ++i) {
761 if (srcFD.
qLKW >= 0) {
764 if (srcFD.
qPKW >= 0) {
791 const std::string& file,
797 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
803 double defaultSpeed = net != 0 ? net->
getEdge(det->
getEdgeID())->getSpeedLimit() : (double) 200.;
815 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
830 bool singleFile,
bool friendly) {
833 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
837 double pos = det->
getPos();
861 std::map<std::string, RODFDetector*>::iterator ri1 = myDetectorMap.find(
id);
863 myDetectorMap.erase(ri1);
865 std::vector<RODFDetector*>::iterator ri2 =
866 find(myDetectors.begin(), myDetectors.end(), oldDet);
867 myDetectors.erase(ri2);
870 for (std::map<std::string, std::vector<RODFDetector*> >::iterator rr3 = myDetectorEdgeMap.begin(); !found && rr3 != myDetectorEdgeMap.end(); ++rr3) {
871 std::vector<RODFDetector*>& dets = (*rr3).second;
872 for (std::vector<RODFDetector*>::iterator ri3 = dets.begin(); !found && ri3 != dets.end();) {
873 if (*ri3 == oldDet) {
875 ri3 = dets.erase(ri3);
890 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
894 int noFollowerWithRoutes = 0;
895 int noPriorWithRoutes = 0;
897 std::set<const RODFDetector*>::const_iterator j;
898 for (j = prior.begin(); j != prior.end(); ++j) {
899 if (flows.
knows((*j)->getID())) {
903 for (j = follower.begin(); j != follower.end(); ++j) {
904 if (flows.
knows((*j)->getID())) {
905 ++noFollowerWithRoutes;
915 if (noPriorWithRoutes == (
int)prior.size()) {
921 if (noFollowerWithRoutes == (
int)follower.size()) {
932 for (std::vector<RODFDetector*>::const_iterator i = myDetectors.begin(); i != myDetectors.end(); ++i) {
933 if ((*i)->getEdgeID() == edge->
getID()) {
951 const std::vector<std::string>& oldids) {
953 const RODFDetector& first = getDetector(*(oldids.begin()));
957 for (std::vector<std::string>::const_iterator i = oldids.begin(); i != oldids.end(); ++i) {
double computeDistanceFactor(const RODFRouteDesc &rd) const
RODFDetector & getModifiableDetector(const std::string &id) const
bool knows(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.
void addRoute(RODFRouteDesc &nrd)
void removeDetector(const std::string &id)
RODFDetectorType
Numerical representation of different detector types.
void clearDists(std::map< SUMOTime, RandomDistributor< int > * > &dists) const
Clears the given distributions map, deleting the timed distributions.
Structure representing possible vehicle parameter.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool addDetector(RODFDetector *dfd)
void addRoutes(RODFRouteCont *routes)
std::vector< double > & getParameter()
Returns the parameters of this distribution.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::string time2string(SUMOTime t)
const std::vector< RODFRouteDesc > & getRouteVector() const
ROEdgeVector edges2Pass
The edges the route is made of.
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
void addPriorDetector(const RODFDetector *det)
const std::vector< RODFDetector * > & getDetectors() const
begin/end of the description of a polygon
void saveRoutes(const std::string &file) const
void writeSpeedTrigger(const RODFNet *const net, const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
const std::set< const RODFDetector * > & getFollowerDetectors() const
const std::string DEFAULT_VTYPE_ID
std::string getEdgeID() const
Returns the id of the edge this detector is placed on.
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)
bool hasDetector(ROEdge *edge) 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.
const RODFDetector & getAnyDetectorForEdge(const RODFEdge *const edge) const
vehicle is a large transport vehicle
RODFDetectorType getType() const
Returns the type of the detector.
A not yet defined detector.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
const std::string & getID() const
Returns the id.
bool writeRoutes(std::vector< std::string > &saved, OutputDevice &out)
double getFlowSumSecure(const std::string &id) const
const std::vector< std::map< RODFEdge *, double > > & getSplitProbabilities() const
double getMaxSpeedFactorPKW() const
static const RGBColor GREEN
void save(const std::string &file) const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::vector< std::map< RODFEdge *, double > > mySplitProbabilities
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 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.
std::vector< ROEdge * > ROEdgeVector
int getAggFlowFor(const ROEdge *edge, SUMOTime time, SUMOTime period, const RODFDetectorFlows &flows) const
T get(MTRand *which=0) const
Draw a sample of the distribution.
A detector which had to be discarded (!!!)
const ROEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of incoming edges.
void writeValidationDetectors(const std::string &file, bool includeSources, bool singleFile, bool friendly)
void setSpeedFactorAndDev(SUMOVTypeParameter &type, double maxFactor, double avgFactor, double dev, bool forceDev)
double getAvgSpeedFactorLKW() const
~RODFDetector()
Destructor.
bool knows(const std::string &det_id) const
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
double getMaxSpeedFactorLKW() 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.
void saveAsPOIs(const std::string &file) const
vehicle is a passenger car (a "normal" car)
A route within the DFROUTER.
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)
const std::set< const RODFDetector * > & getPriorDetectors() const
double getPos() const
Returns the position at which the detector lies.
void write(OutputDevice &dev) const
Writes the vtype.
int setParameter
Information for the router which parameter were set.
void writeSingleSpeedTrigger(const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, double defaultSpeed)
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.
trigger: the time of the step
static const RGBColor RED
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::map< std::string, RODFEdge * > myRoute2Edge
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
const RODFDetector & getDetector(const std::string &id) const
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 getAvgSpeedFactorPKW() const
std::string routename
The name of the route.
void writeEmitterPOIs(const std::string &file, const RODFDetectorFlows &flows)
double getMaxDetectorFlow() const
void setType(RODFDetectorType type)
std::set< const RODFDetector * > myPriorDetectors
const std::vector< FlowDef > & getFlowDefs(const std::string &id) const
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)
void buildDestinationDistribution(const RODFDetectorCon &detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, const RODFNet &net, std::map< SUMOTime, RandomDistributor< int > * > &into) const
void mesoJoin(const std::string &nid, const std::vector< std::string > &oldids)
void addRouteDesc(RODFRouteDesc &desc)
Adds a route to the container.
bool detectorsHaveRoutes() const
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...
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.
bool detectorsHaveCompleteTypes() const
trigger: a step description
const std::string & getLaneID() const
Returns the id of the lane this detector is placed on.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.