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 /****************************************************************************/
10 // Writes route distributions at a certain edge
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2008-2014 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 }