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, 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 }