SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSRouteProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Writes route distributions at a certain edge
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
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 #ifdef HAVE_INTERNAL
42 #include <mesosim/MELoop.h>
43 #include <mesosim/MESegment.h>
44 #endif
45 #include "MSRouteProbe.h"
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 MSRouteProbe::MSRouteProbe(const std::string& id, const MSEdge* edge, const std::string& distID, const std::string& lastID) :
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));
63 #ifdef HAVE_INTERNAL
65  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(*edge);
66  while (seg != 0) {
67  seg->addDetector(this);
68  seg = seg->getNextSegment();
69  }
70  return;
71  }
72 #endif
73  for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) {
74  (*it)->addMoveReminder(this);
75  }
76 }
77 
78 
80 }
81 
82 
83 bool
86  if (myCurrentRouteDistribution.second->add(1., &veh.getRoute())) {
87  veh.getRoute().addReference();
88  }
89  }
90  return false;
91 }
92 
93 
94 void
96  SUMOTime startTime, SUMOTime stopTime) {
97  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
98  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\"";
99  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution.second->getVals();
100  const std::vector<SUMOReal>& probs = myCurrentRouteDistribution.second->getProbs();
101  for (unsigned int j = 0; j < routes.size(); ++j) {
102  const MSRoute* r = routes[j];
103  dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\"";
104  for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
105  if (i != r->begin()) {
106  dev << " ";
107  }
108  dev << (*i)->getID();
109  }
110  dev << "\" probability=\"" << probs[j] << "\"";
111  dev.closeTag();
112  }
113  dev.closeTag();
114  if (myLastRouteDistribution.second != 0) {
116  }
118  myCurrentRouteDistribution.first = getID() + "_" + toString(stopTime);
121  }
122 }
123 
124 
125 void
127  dev.writeXMLHeader("route-probes");
128 }
129 
130 
131 const MSRoute*
133  if (myLastRouteDistribution.second == 0) {
134  if (myCurrentRouteDistribution.second->getOverallProb() > 0) {
135  return myCurrentRouteDistribution.second->get();
136  }
137  return 0;
138  }
139  return myLastRouteDistribution.second->get();
140 }
virtual const MSRoute & getRoute() const =0
Returns the current route.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
MSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:59
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:149
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:73
The vehicle changes lanes (micro only)
Representation of a vehicle.
Definition: SUMOVehicle.h:63
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
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:52
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:99
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:80
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
static const bool gUseMesoSim
Definition: MSGlobals.h:98
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:172
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:74
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:115