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-2016 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 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 MSRouteProbe::MSRouteProbe(const std::string& id, const MSEdge* edge, const std::string& distID, const std::string& lastID) :
56  myCurrentRouteDistribution = std::make_pair(distID, MSRoute::distDictionary(distID));
57  if (myCurrentRouteDistribution.second == 0) {
59  MSRoute::dictionary(distID, myCurrentRouteDistribution.second, false);
60  }
61  myLastRouteDistribution = std::make_pair(lastID, MSRoute::distDictionary(lastID));
64  while (seg != 0) {
65  seg->addDetector(this);
66  seg = seg->getNextSegment();
67  }
68  return;
69  }
70  for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) {
71  (*it)->addMoveReminder(this);
72  }
73 }
74 
75 
77 }
78 
79 
80 bool
83  if (myCurrentRouteDistribution.second->add(1., &veh.getRoute())) {
84  veh.getRoute().addReference();
85  }
86  }
87  return false;
88 }
89 
90 
91 void
93  SUMOTime startTime, SUMOTime stopTime) {
94  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
95  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\"";
96  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution.second->getVals();
97  const std::vector<SUMOReal>& probs = myCurrentRouteDistribution.second->getProbs();
98  for (unsigned int j = 0; j < routes.size(); ++j) {
99  const MSRoute* r = routes[j];
100  dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\"";
101  for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
102  if (i != r->begin()) {
103  dev << " ";
104  }
105  dev << (*i)->getID();
106  }
107  dev << "\" probability=\"" << probs[j] << "\"";
108  dev.closeTag();
109  }
110  dev.closeTag();
111  if (myLastRouteDistribution.second != 0) {
113  }
115  myCurrentRouteDistribution.first = getID() + "_" + toString(stopTime);
118  }
119 }
120 
121 
122 void
124  dev.writeXMLHeader("route-probes");
125 }
126 
127 
128 const MSRoute*
130  if (myLastRouteDistribution.second == 0) {
131  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
132  return myCurrentRouteDistribution.second->get();
133  }
134  return 0;
135  }
136  return myLastRouteDistribution.second->get();
137 }
long long int SUMOTime
Definition: SUMOTime.h:43
virtual const MSRoute & getRoute() const =0
Returns the current route.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:185
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
The vehicle changes the segment (meso only)
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:165
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.
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A road/street connecting two junctions.
Definition: MSEdge.h:80
The vehicle changes lanes (micro only)
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:158
Representation of a vehicle.
Definition: SUMOVehicle.h:65
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
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:65
MSRouteProbe(const std::string &id, const MSEdge *edge, const std::string &distID, const std::string &lastID)
Constructor.
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:159
Something on a lane to be noticed about vehicle movement.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:103
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Returns whether the vehicle shall be aware of this entry.
const MSRoute * getRoute() const
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:84
A single mesoscopic segment (cell)
Definition: MESegment.h:57
MESegment * getSegmentForEdge(const MSEdge &e, SUMOReal pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:288
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:99
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
static bool gUseMesoSim
Definition: MSGlobals.h:87
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:194
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Base of value-generating classes (detectors)
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:122