SUMO - Simulation of Urban MObility
MSRouteProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Writes route distributions at a certain edge
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <microsim/MSEdge.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSGlobals.h>
37 #include <microsim/MSRoute.h>
38 #include <microsim/MSVehicle.h>
39 #include <utils/common/ToString.h>
41 #include <mesosim/MELoop.h>
42 #include <mesosim/MESegment.h>
43 #include "MSRouteProbe.h"
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 MSRouteProbe::MSRouteProbe(const std::string& id, const MSEdge* edge, const std::string& distID, const std::string& lastID,
50  const std::string& vTypes) :
51  MSDetectorFileOutput(id, vTypes), MSMoveReminder(id) {
52  myCurrentRouteDistribution = std::make_pair(distID, MSRoute::distDictionary(distID));
53  if (myCurrentRouteDistribution.second == 0) {
55  MSRoute::dictionary(distID, myCurrentRouteDistribution.second, false);
56  }
57  myLastRouteDistribution = std::make_pair(lastID, MSRoute::distDictionary(lastID));
60  while (seg != 0) {
61  seg->addDetector(this);
62  seg = seg->getNextSegment();
63  }
64  return;
65  }
66  for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) {
67  (*it)->addMoveReminder(this);
68  }
69 }
70 
71 
73 }
74 
75 
76 bool
79  if (myCurrentRouteDistribution.second->add(&veh.getRoute(), 1.)) {
80  veh.getRoute().addReference();
81  }
82  }
83  return false;
84 }
85 
86 
87 void
89  SUMOTime startTime, SUMOTime stopTime) {
90  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
91  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\"";
92  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution.second->getVals();
93  const std::vector<double>& probs = myCurrentRouteDistribution.second->getProbs();
94  for (int j = 0; j < (int)routes.size(); ++j) {
95  const MSRoute* r = routes[j];
96  dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\"";
97  for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
98  if (i != r->begin()) {
99  dev << " ";
100  }
101  dev << (*i)->getID();
102  }
103  dev << "\" probability=\"" << probs[j] << "\"";
104  dev.closeTag();
105  }
106  dev.closeTag();
107  if (myLastRouteDistribution.second != 0) {
109  }
111  myCurrentRouteDistribution.first = getID() + "_" + toString(stopTime);
114  }
115 }
116 
117 
118 void
120  dev.writeXMLHeader("routes", "routes_file.xsd");
121 }
122 
123 
124 const MSRoute*
126  if (myLastRouteDistribution.second == 0) {
127  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
128  return myCurrentRouteDistribution.second->get();
129  }
130  return 0;
131  }
132  return myLastRouteDistribution.second->get();
133 }
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:156
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:289
const MSRoute * getRoute() const
virtual const MSRoute & getRoute() const =0
Returns the current route.
Represents a generic random distribution.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
The vehicle changes the segment (meso only)
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:160
const std::string & getID() const
Returns the id.
Definition: Named.h:65
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes values into the given stream.
std::pair< std::string, RandomDistributor< const MSRoute * > * > myLastRouteDistribution
The previous distribution of routes (probability->route)
Definition: MSRouteProbe.h:137
virtual ~MSRouteProbe()
Destructor.
A road/street connecting two junctions.
Definition: MSEdge.h:80
The vehicle changes lanes (micro only)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
Representation of a vehicle.
Definition: SUMOVehicle.h:66
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::pair< std::string, RandomDistributor< const MSRoute * > * > myCurrentRouteDistribution
The current distribution of routes (probability->route)
Definition: MSRouteProbe.h:140
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:64
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:204
Something on a lane to be noticed about vehicle movement.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
A single mesoscopic segment (cell)
Definition: MESegment.h:56
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:98
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:112
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Returns whether the vehicle shall be aware of this entry.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:51
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:73
MSRouteProbe(const std::string &id, const MSEdge *edge, const std::string &distID, const std::string &lastID, const std::string &vTypes)
Constructor.
static bool gUseMesoSim
Definition: MSGlobals.h:97
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:189
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:79
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Base of value-generating classes (detectors)
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:117