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,
55  const std::string& vTypes) :
56  MSDetectorFileOutput(id, vTypes), MSMoveReminder(id) {
57  myCurrentRouteDistribution = std::make_pair(distID, MSRoute::distDictionary(distID));
58  if (myCurrentRouteDistribution.second == 0) {
60  MSRoute::dictionary(distID, myCurrentRouteDistribution.second, false);
61  }
62  myLastRouteDistribution = std::make_pair(lastID, MSRoute::distDictionary(lastID));
65  while (seg != 0) {
66  seg->addDetector(this);
67  seg = seg->getNextSegment();
68  }
69  return;
70  }
71  for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) {
72  (*it)->addMoveReminder(this);
73  }
74 }
75 
76 
78 }
79 
80 
81 bool
84  if (myCurrentRouteDistribution.second->add(1., &veh.getRoute())) {
85  veh.getRoute().addReference();
86  }
87  }
88  return false;
89 }
90 
91 
92 void
94  SUMOTime startTime, SUMOTime stopTime) {
95  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
96  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\"";
97  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution.second->getVals();
98  const std::vector<SUMOReal>& probs = myCurrentRouteDistribution.second->getProbs();
99  for (int j = 0; j < (int)routes.size(); ++j) {
100  const MSRoute* r = routes[j];
101  dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\"";
102  for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
103  if (i != r->begin()) {
104  dev << " ";
105  }
106  dev << (*i)->getID();
107  }
108  dev << "\" probability=\"" << probs[j] << "\"";
109  dev.closeTag();
110  }
111  dev.closeTag();
112  if (myLastRouteDistribution.second != 0) {
114  }
116  myCurrentRouteDistribution.first = getID() + "_" + toString(stopTime);
119  }
120 }
121 
122 
123 void
125  dev.writeXMLHeader("route-probes");
126 }
127 
128 
129 const MSRoute*
131  if (myLastRouteDistribution.second == 0) {
132  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
133  return myCurrentRouteDistribution.second->get();
134  }
135  return 0;
136  }
137  return myLastRouteDistribution.second->get();
138 }
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:158
long long int SUMOTime
Definition: SUMOTime.h:43
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: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:165
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.
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
A road/street connecting two junctions.
Definition: MSEdge.h:80
The vehicle changes lanes (micro only) XXX: What if a vehicle changes lanes and passes a junction sim...
Representation of a vehicle.
Definition: SUMOVehicle.h:66
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:193
Something on a lane to be noticed about vehicle movement.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Returns whether the vehicle shall be aware of this entry.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
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:295
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:103
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:107
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
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:95
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:194
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:84
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:122