SUMO - Simulation of Urban MObility
MSRouteProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Writes route distributions at a certain edge
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2008-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <microsim/MSEdge.h>
36 #include <microsim/MSLane.h>
37 #include <microsim/MSGlobals.h>
38 #include <microsim/MSRoute.h>
39 #include <microsim/MSVehicle.h>
40 #include <utils/common/ToString.h>
42 #include <mesosim/MELoop.h>
43 #include <mesosim/MESegment.h>
44 #include "MSRouteProbe.h"
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 MSRouteProbe::MSRouteProbe(const std::string& id, const MSEdge* edge, const std::string& distID, const std::string& lastID,
51  const std::string& vTypes) :
52  MSDetectorFileOutput(id, vTypes), MSMoveReminder(id) {
53  myCurrentRouteDistribution = std::make_pair(distID, MSRoute::distDictionary(distID));
54  if (myCurrentRouteDistribution.second == 0) {
56  MSRoute::dictionary(distID, myCurrentRouteDistribution.second, false);
57  }
58  myLastRouteDistribution = std::make_pair(lastID, MSRoute::distDictionary(lastID));
61  while (seg != 0) {
62  seg->addDetector(this);
63  seg = seg->getNextSegment();
64  }
65  return;
66  }
67  for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) {
68  (*it)->addMoveReminder(this);
69  }
70 }
71 
72 
74 }
75 
76 
77 bool
80  if (myCurrentRouteDistribution.second->add(&veh.getRoute(), 1.)) {
81  veh.getRoute().addReference();
82  }
83  }
84  return false;
85 }
86 
87 
88 void
90  SUMOTime startTime, SUMOTime stopTime) {
91  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
92  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\"";
93  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution.second->getVals();
94  const std::vector<double>& probs = myCurrentRouteDistribution.second->getProbs();
95  for (int j = 0; j < (int)routes.size(); ++j) {
96  const MSRoute* r = routes[j];
97  dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\"";
98  for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
99  if (i != r->begin()) {
100  dev << " ";
101  }
102  dev << (*i)->getID();
103  }
104  dev << "\" probability=\"" << probs[j] << "\"";
105  dev.closeTag();
106  }
107  dev.closeTag();
108  if (myLastRouteDistribution.second != 0) {
110  }
112  myCurrentRouteDistribution.first = getID() + "_" + toString(stopTime);
115  }
116 }
117 
118 
119 void
121  dev.writeXMLHeader("routes", "routes_file.xsd");
122 }
123 
124 
125 const MSRoute*
127  if (myLastRouteDistribution.second == 0) {
128  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
129  return myCurrentRouteDistribution.second->get();
130  }
131  return 0;
132  }
133  return myLastRouteDistribution.second->get();
134 }
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:157
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:60
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
The vehicle changes the segment (meso only)
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:161
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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:138
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:56
Representation of a vehicle.
Definition: SUMOVehicle.h:67
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:141
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:205
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:57
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:99
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:113
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:71
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:52
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
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:98
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:190
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
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:118