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.sourceforge.net/
12 // Copyright (C) 2001-2012 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)
56  : MSDetectorFileOutput(id), myCurrentRouteDistribution(0) {
57  const std::string distID = id + "_" + toString(begin);
59  if (myCurrentRouteDistribution == 0) {
62  }
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  veh.getRoute().addReference();
88  }
89  return false;
90 }
91 
92 
93 void
95  SUMOTime startTime, SUMOTime stopTime) {
97  dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\">\n";
98  const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution->getVals();
99  const std::vector<SUMOReal>& probs = myCurrentRouteDistribution->getProbs();
100  for (unsigned int j = 0; j < routes.size(); ++j) {
101  const MSRoute* r = routes[j];
102  dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\"";
103  for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
104  if (i != r->begin()) {
105  dev << " ";
106  }
107  dev << (*i)->getID();
108  }
109  dev << "\" probability=\"" << probs[j] << "\"";
110  dev.closeTag(true);
111  }
112  dev.closeTag();
115  }
116 }
117 
118 
119 void
121  dev.writeXMLHeader("route-probes");
122 }