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-2013 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, SUMOTime begin) :
57  MSMoveReminder(id),
58  myCurrentRouteDistribution(0) {
59  const std::string distID = id + "_" + toString(begin);
61  if (myCurrentRouteDistribution == 0) {
64  }
65 #ifdef HAVE_INTERNAL
67  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(*edge);
68  while (seg != 0) {
69  seg->addDetector(this);
70  seg = seg->getNextSegment();
71  }
72  return;
73  }
74 #endif
75  for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) {
76  (*it)->addMoveReminder(this);
77  }
78 }
79 
80 
82 }
83 
84 
85 bool
88  veh.getRoute().addReference();
90  }
91  return false;
92 }
93 
94 
95 void
97  SUMOTime startTime, SUMOTime stopTime) {
99  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\"";
100  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution->getVals();
101  const std::vector<SUMOReal>& probs = myCurrentRouteDistribution->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();
117  }
118 }
119 
120 
121 void
123  dev.writeXMLHeader("route-probes");
124 }
const std::vector< SUMOReal > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
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:167
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:150
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes values into the given stream.
static void releaseRoute(const MSRoute *route)
release the route (to be used as function pointer with RandomDistributor)
Definition: MSRoute.h:192
virtual ~MSRouteProbe()
Destructor.
const std::vector< T > & getVals() const
Returns the members of the distribution.
static unsigned int getMaxRouteDistSize()
Definition: MSRoute.h:200
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 &quot;detector&quot; as root element.
MSRouteProbe(const std::string &id, const MSEdge *edge, SUMOTime begin)
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:51
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.
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:81
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:95
RandomDistributor< const MSRoute * > * myCurrentRouteDistribution
The current distribution of routes (probability-&gt;route)
Definition: MSRouteProbe.h:135
void add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
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