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-2015 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 #ifdef HAVE_INTERNAL
43 #include <mesosim/MELoop.h>
44 #include <mesosim/MESegment.h>
45 #endif
46 #include "MSRouteProbe.h"
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 MSRouteProbe::MSRouteProbe(const std::string& id, const MSEdge* edge, const std::string& distID, const std::string& lastID) :
58  myCurrentRouteDistribution = std::make_pair(distID, MSRoute::distDictionary(distID));
59  if (myCurrentRouteDistribution.second == 0) {
61  MSRoute::dictionary(distID, myCurrentRouteDistribution.second, false);
62  }
63  myLastRouteDistribution = std::make_pair(lastID, MSRoute::distDictionary(lastID));
64 #ifdef HAVE_INTERNAL
66  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(*edge);
67  while (seg != 0) {
68  seg->addDetector(this);
69  seg = seg->getNextSegment();
70  }
71  return;
72  }
73 #endif
74  for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) {
75  (*it)->addMoveReminder(this);
76  }
77 }
78 
79 
81 }
82 
83 
84 bool
87  if (myCurrentRouteDistribution.second->add(1., &veh.getRoute())) {
88  veh.getRoute().addReference();
89  }
90  }
91  return false;
92 }
93 
94 
95 void
97  SUMOTime startTime, SUMOTime stopTime) {
98  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
99  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\"";
100  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution.second->getVals();
101  const std::vector<SUMOReal>& probs = myCurrentRouteDistribution.second->getProbs();
102  for (unsigned int j = 0; j < routes.size(); ++j) {
103  const MSRoute* r = routes[j];
104  dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\"";
105  for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
106  if (i != r->begin()) {
107  dev << " ";
108  }
109  dev << (*i)->getID();
110  }
111  dev << "\" probability=\"" << probs[j] << "\"";
112  dev.closeTag();
113  }
114  dev.closeTag();
115  if (myLastRouteDistribution.second != 0) {
117  }
119  myCurrentRouteDistribution.first = getID() + "_" + toString(stopTime);
122  }
123 }
124 
125 
126 void
128  dev.writeXMLHeader("route-probes");
129 }
130 
131 
132 const MSRoute*
134  if (myLastRouteDistribution.second == 0) {
135  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
136  return myCurrentRouteDistribution.second->get();
137  }
138  return 0;
139  }
140  return myLastRouteDistribution.second->get();
141 }
virtual const MSRoute & getRoute() const =0
Returns the current route.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:186
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
The vehicle changes the segment (meso only)
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:150
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:60
A road/street connecting two junctions.
Definition: MSEdge.h:81
The vehicle changes lanes (micro only)
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:61
MSRouteProbe(const std::string &id, const MSEdge *edge, const std::string &distID, const std::string &lastID)
Constructor.
Something on a lane to be noticed about vehicle movement.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:100
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:81
int SUMOTime
Definition: SUMOTime.h:43
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
static const bool gUseMesoSim
Definition: MSGlobals.h:102
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:173
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:75
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:116