SUMO - Simulation of Urban MObility
MSCalibrator.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2005-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Calibrates the flow on an edge by removing an inserting vehicles
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <algorithm>
28 #include <cmath>
29 #include <microsim/MSNet.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSLane.h>
36 #include <utils/common/ToString.h>
39 #include <utils/xml/XMLSubSys.h>
45 #include "MSCalibrator.h"
46 
47 //#define MSCalibrator_DEBUG
48 
49 // ===========================================================================
50 // static members
51 // ===========================================================================
52 std::vector<MSMoveReminder*> MSCalibrator::LeftoverReminders;
53 std::vector<SUMOVehicleParameter*> MSCalibrator::LeftoverVehicleParameters;
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 MSCalibrator::MSCalibrator(const std::string& id,
59  const MSEdge* const edge,
60  MSLane* lane,
61  const double pos,
62  const std::string& aXMLFilename,
63  const std::string& outputFilename,
64  const SUMOTime freq, const double length,
65  const MSRouteProbe* probe,
66  bool addLaneMeanData) :
67  MSTrigger(id),
68  MSRouteHandler(aXMLFilename, true),
69  myEdge(edge),
70  myLane(lane),
71  myPos(pos), myProbe(probe),
72  myEdgeMeanData(nullptr, length, false, nullptr),
73  myCurrentStateInterval(myIntervals.begin()),
74  myOutput(nullptr), myFrequency(freq), myRemoved(0),
75  myInserted(0), myClearedInJam(0),
76  mySpeedIsDefault(true), myDidSpeedAdaption(false), myDidInit(false),
77  myDefaultSpeed(myLane == nullptr ? myEdge->getSpeedLimit() : myLane->getSpeedLimit()),
78  myHaveWarnedAboutClearingJam(false),
79  myAmActive(false) {
80  if (outputFilename != "") {
81  myOutput = &OutputDevice::getDevice(outputFilename);
82  myOutput->writeXMLHeader("calibratorstats", "calibratorstats_file.xsd");
83  }
84  if (aXMLFilename != "") {
85  XMLSubSys::runParser(*this, aXMLFilename);
86  if (!myDidInit) {
87  init();
88  }
89  }
90  if (addLaneMeanData) {
91  // disabled for METriggeredCalibrator
92  for (int i = 0; i < (int)myEdge->getLanes().size(); ++i) {
93  MSLane* lane = myEdge->getLanes()[i];
94  if (myLane == nullptr || myLane == lane) {
95  //std::cout << " cali=" << getID() << " myLane=" << Named::getIDSecure(myLane) << " checkLane=" << i << "\n";
96  MSMeanData_Net::MSLaneMeanDataValues* laneData = new MSMeanData_Net::MSLaneMeanDataValues(lane, lane->getLength(), true, nullptr);
97  laneData->setDescription("meandata_calibrator_" + lane->getID());
98  LeftoverReminders.push_back(laneData);
99  myLaneMeanData.push_back(laneData);
100  VehicleRemover* remover = new VehicleRemover(lane, (int)i, this);
101  LeftoverReminders.push_back(remover);
102  myVehicleRemovers.push_back(remover);
103  }
104  }
105  }
106 }
107 
108 
109 void
111  if (myIntervals.size() > 0) {
112  if (myIntervals.back().end == -1) {
113  myIntervals.back().end = SUMOTime_MAX;
114  }
115  // calibration should happen after regular insertions have taken place
117  } else {
118  WRITE_WARNING("No flow intervals in calibrator '" + myID + "'.");
119  }
120  myDidInit = true;
121 }
122 
123 
125  if (myCurrentStateInterval != myIntervals.end()) {
126  writeXMLOutput();
127  }
128  for (std::vector<VehicleRemover*>::iterator it = myVehicleRemovers.begin(); it != myVehicleRemovers.end(); ++it) {
129  (*it)->disable();
130  }
131 }
132 
133 
134 void
136  const SUMOSAXAttributes& attrs) {
137  if (element == SUMO_TAG_FLOW) {
138  AspiredState state;
139  SUMOTime lastEnd = -1;
140  if (myIntervals.size() > 0) {
141  lastEnd = myIntervals.back().end;
142  if (lastEnd == -1) {
143  lastEnd = myIntervals.back().begin;
144  }
145  }
146  try {
147  bool ok = true;
148  state.q = attrs.getOpt<double>(SUMO_ATTR_VEHSPERHOUR, nullptr, ok, -1.);
149  state.v = attrs.getOpt<double>(SUMO_ATTR_SPEED, nullptr, ok, -1.);
150  state.begin = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, myID.c_str(), ok);
151  if (state.begin < lastEnd) {
152  WRITE_ERROR("Overlapping or unsorted intervals in calibrator '" + myID + "'.");
153  }
154  state.end = attrs.getOptSUMOTimeReporting(SUMO_ATTR_END, myID.c_str(), ok, -1);
157  // vehicles should be inserted with max speed unless stated otherwise
160  }
161  // vehicles should be inserted on any lane unless stated otherwise
163  if (myLane == nullptr) {
165  } else {
168  }
169  } else if (myLane != nullptr && (
171  || state.vehicleParameter->departLane != myLane->getIndex())) {
172  WRITE_WARNING("Insertion lane may differ from calibrator lane for calibrator '" + getID() + "'.");
173  }
174  if (state.vehicleParameter->vtypeid != DEFAULT_VTYPE_ID &&
176  WRITE_ERROR("Unknown vehicle type '" + state.vehicleParameter->vtypeid + "' in calibrator '" + myID + "'.");
177  }
178  } catch (EmptyData&) {
179  WRITE_ERROR("Mandatory attribute missing in definition of calibrator '" + myID + "'.");
180  } catch (NumberFormatException&) {
181  WRITE_ERROR("Non-numeric value for numeric attribute in definition of calibrator '" + myID + "'.");
182  }
183  if (state.q < 0 && state.v < 0) {
184  WRITE_ERROR("Either 'vehsPerHour' or 'speed' has to be given in flow definition of calibrator '" + myID + "'.");
185  }
186  if (myIntervals.size() > 0 && myIntervals.back().end == -1) {
187  myIntervals.back().end = state.begin;
188  }
189  myIntervals.push_back(state);
191  } else {
192  MSRouteHandler::myStartElement(element, attrs);
193  }
194 }
195 
196 
197 void
199  if (element == SUMO_TAG_CALIBRATOR) {
200  if (!myDidInit) {
201  init();
202  }
203  } else if (element != SUMO_TAG_FLOW) {
205  }
206 }
207 
208 
209 void
211  if (myOutput != nullptr) {
212  updateMeanData();
213  const int p = passed();
214  // meandata will be off if vehicles are removed on the next edge instead of this one
216  assert(discrepancy >= 0);
217  const std::string ds = (discrepancy > 0 ? "\" vaporizedOnNextEdge=\"" + toString(discrepancy) : "");
218  const double durationSeconds = STEPS2TIME(myCurrentStateInterval->end - myCurrentStateInterval->begin);
219  (*myOutput) << " <interval begin=\"" << time2string(myCurrentStateInterval->begin) <<
220  "\" end=\"" << time2string(myCurrentStateInterval->end) <<
221  "\" id=\"" << myID <<
222  "\" nVehContrib=\"" << p <<
223  "\" removed=\"" << myRemoved <<
224  "\" inserted=\"" << myInserted <<
225  "\" cleared=\"" << myClearedInJam <<
226  "\" flow=\"" << p * 3600.0 / durationSeconds <<
227  "\" aspiredFlow=\"" << myCurrentStateInterval->q <<
229  "\" aspiredSpeed=\"" << myCurrentStateInterval->v <<
230  ds << //optional
231  "\"/>\n";
232  }
233  myDidSpeedAdaption = false;
234  myInserted = 0;
235  myRemoved = 0;
236  myClearedInJam = 0;
238  reset();
239 }
240 
241 
242 bool
244  while (myCurrentStateInterval != myIntervals.end() && myCurrentStateInterval->end <= time) {
245  // XXX what about skipped intervals?
247  }
248  return myCurrentStateInterval != myIntervals.end() &&
249  myCurrentStateInterval->begin <= time && myCurrentStateInterval->end > time;
250 }
251 
252 int
254  if (myCurrentStateInterval != myIntervals.end()) {
255  const double totalHourFraction = STEPS2TIME(myCurrentStateInterval->end - myCurrentStateInterval->begin) / (double) 3600.;
256  return (int)std::floor(myCurrentStateInterval->q * totalHourFraction + 0.5); // round to closest int
257  } else {
258  return -1;
259  }
260 }
261 
262 
263 double
265  const double totalHourFraction = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - myCurrentStateInterval->begin) / (double) 3600.;
266  return passed() / totalHourFraction;
267 }
268 
269 double
271  if (myEdgeMeanData.getSamples() > 0) {
273  } else {
274  return -1;
275  }
276 }
277 
278 
279 bool
281  if (myToRemove.size() > 0) {
283  // it is not save to remove the vehicles inside
284  // VehicleRemover::notifyEnter so we do it here
285  for (std::set<std::string>::iterator it = myToRemove.begin(); it != myToRemove.end(); ++it) {
286  MSVehicle* vehicle = dynamic_cast<MSVehicle*>(vc.getVehicle(*it));
287  if (vehicle != nullptr) {
290  vc.scheduleVehicleRemoval(vehicle);
291  } else {
292  WRITE_WARNING("Calibrator '" + getID() + "' could not remove vehicle '" + *it + "'.");
293  }
294  }
295  myToRemove.clear();
296  return true;
297  }
298  return false;
299 }
300 
301 
302 SUMOTime
304  // get current simulation values (valid for the last simulation second)
305  // XXX could we miss vehicle movements if this is called less often than every DELTA_T (default) ?
306  updateMeanData();
307  const bool hadRemovals = removePending();
308  // check whether an adaptation value exists
309  if (isCurrentStateActive(currentTime)) {
310  myAmActive = true;
311  // all happens in isCurrentStateActive()
312  } else {
313  myAmActive = false;
314  reset();
315  if (!mySpeedIsDefault) {
316  // reset speed to default
317  if (myLane == nullptr) {
319  } else {
321  }
322  mySpeedIsDefault = true;
323  }
324  if (myCurrentStateInterval == myIntervals.end()) {
325  // keep calibrator alive for gui but do not call again
326  return TIME2STEPS(86400);
327  }
328  return myFrequency;
329  }
330  // we are active
331  if (!myDidSpeedAdaption && myCurrentStateInterval->v >= 0) {
332  if (myLane == nullptr) {
334  } else {
336  }
337  mySpeedIsDefault = false;
338  myDidSpeedAdaption = true;
339  }
340 
341  const bool calibrateFlow = myCurrentStateInterval->q >= 0;
342  const int totalWishedNum = totalWished();
343  int adaptedNum = passed() + myClearedInJam;
344 #ifdef MSCalibrator_DEBUG
345  std::cout << time2string(currentTime) << " " << myID
346  << " q=" << myCurrentStateInterval->q
347  << " totalWished=" << totalWishedNum
348  << " adapted=" << adaptedNum
349  << " jam=" << invalidJam(myLane == 0 ? -1 : myLane->getIndex())
350  << " entered=" << myEdgeMeanData.nVehEntered
351  << " departed=" << myEdgeMeanData.nVehDeparted
352  << " arrived=" << myEdgeMeanData.nVehArrived
353  << " left=" << myEdgeMeanData.nVehLeft
354  << " waitSecs=" << myEdgeMeanData.waitSeconds
355  << " vaporized=" << myEdgeMeanData.nVehVaporized
356  << "\n";
357 #endif
358  if (calibrateFlow && adaptedNum < totalWishedNum && !hadRemovals) {
359  // we need to insert some vehicles
360  const double hourFraction = STEPS2TIME(currentTime - myCurrentStateInterval->begin + DELTA_T) / (double) 3600.;
361  const int wishedNum = (int)std::floor(myCurrentStateInterval->q * hourFraction + 0.5); // round to closest int
362  // only the difference between inflow and aspiredFlow should be added, thus
363  // we should not count vehicles vaporized from a jam here
364  // if we have enough time left we can add missing vehicles later
365  const int relaxedInsertion = (int)std::floor(STEPS2TIME(myCurrentStateInterval->end - currentTime) / 3);
366  const int insertionSlack = MAX2(0, adaptedNum + relaxedInsertion - totalWishedNum);
367  // increase number of vehicles
368 #ifdef MSCalibrator_DEBUG
369  std::cout
370  << " wished:" << wishedNum
371  << " slack:" << insertionSlack
372  << " before:" << adaptedNum
373  << "\n";
374 #endif
375  while (wishedNum > adaptedNum + insertionSlack) {
376  SUMOVehicleParameter* pars = myCurrentStateInterval->vehicleParameter;
377  const MSRoute* route = myProbe != nullptr ? myProbe->getRoute() : nullptr;
378  if (route == nullptr) {
379  route = MSRoute::dictionary(pars->routeid);
380  }
381  if (route == nullptr) {
382  WRITE_WARNING("No valid routes in calibrator '" + myID + "'.");
383  break;
384  }
385  if (!route->contains(myEdge)) {
386  WRITE_WARNING("Route '" + route->getID() + "' in calibrator '" + myID + "' does not contain edge '" + myEdge->getID() + "'.");
387  break;
388  }
389  const int routeIndex = (int)std::distance(route->begin(),
390  std::find(route->begin(), route->end(), myEdge));
392  assert(route != 0 && vtype != 0);
393  // build the vehicle
394  SUMOVehicleParameter* newPars = new SUMOVehicleParameter(*pars);
395  newPars->id = myID + "." + toString((int)STEPS2TIME(myCurrentStateInterval->begin)) + "." + toString(myInserted);
396  newPars->depart = currentTime;
397  newPars->routeid = route->getID();
398  MSVehicle* vehicle;
399  try {
400  vehicle = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().buildVehicle(
401  newPars, route, vtype, true, false));
402  } catch (const ProcessError& e) {
404  WRITE_WARNING(e.what());
405  vehicle = nullptr;
406  break;
407  } else {
408  throw e;
409  }
410  }
411 #ifdef MSCalibrator_DEBUG
412  std::cout << " resetting route pos: " << routeIndex << "\n";
413 #endif
414  vehicle->resetRoutePosition(routeIndex);
415  if (myEdge->insertVehicle(*vehicle, currentTime)) {
416  if (!MSNet::getInstance()->getVehicleControl().addVehicle(vehicle->getID(), vehicle)) {
417  throw ProcessError("Emission of vehicle '" + vehicle->getID() + "' in calibrator '" + getID() + "'failed!");
418  }
419  myInserted++;
420  adaptedNum++;
421 #ifdef MSCalibrator_DEBUG
422  std::cout << "I ";
423 #endif
424  } else {
425  // could not insert vehicle
426 #ifdef MSCalibrator_DEBUG
427  std::cout << "F ";
428 #endif
430  break;
431  }
432  }
433  }
434  if (myCurrentStateInterval->end <= currentTime + myFrequency) {
435  writeXMLOutput();
436  }
437  return myFrequency;
438 }
439 
440 void
443  for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it = myLaneMeanData.begin(); it != myLaneMeanData.end(); ++it) {
444  (*it)->reset();
445  }
446 }
447 
448 
449 bool
450 MSCalibrator::invalidJam(int laneIndex) const {
451  if (laneIndex < 0) {
452  const int numLanes = (int)myEdge->getLanes().size();
453  for (int i = 0; i < numLanes; ++i) {
454  if (invalidJam(i)) {
455  return true;
456  }
457  }
458  return false;
459  }
460  assert(laneIndex < (int)myEdge->getLanes().size());
461  const MSLane* const lane = myEdge->getLanes()[laneIndex];
462  if (lane->getVehicleNumber() < 4) {
463  // cannot reliably detect invalid jams
464  return false;
465  }
466  // maxSpeed reflects the calibration target
467  const bool toSlow = lane->getMeanSpeed() < 0.5 * myEdge->getSpeedLimit();
468  return toSlow && remainingVehicleCapacity(laneIndex) < 1;
469 }
470 
471 
472 int
474  if (laneIndex < 0) {
475  const int numLanes = (int)myEdge->getLanes().size();
476  int result = 0;
477  for (int i = 0; i < numLanes; ++i) {
478  result = MAX2(result, remainingVehicleCapacity(i));
479  }
480  return result;
481  }
482  assert(laneIndex < (int)myEdge->getLanes().size());
483  MSLane* lane = myEdge->getLanes()[laneIndex];
484  MSVehicle* last = lane->getLastFullVehicle();
485  const SUMOVehicleParameter* pars = myCurrentStateInterval->vehicleParameter;
487  const double spacePerVehicle = vtype->getLengthWithGap() + myEdge->getSpeedLimit() * vtype->getCarFollowModel().getHeadwayTime();
488  if (last == nullptr) {
489  // ensure vehicles can be inserted on short edges
490  return MAX2(1, (int)(myEdge->getLength() / spacePerVehicle));
491  } else {
492  return (int)(last->getPositionOnLane() / spacePerVehicle);
493  }
494 }
495 
496 
497 void
499  for (std::vector<MSMoveReminder*>::iterator it = LeftoverReminders.begin(); it != LeftoverReminders.end(); ++it) {
500  delete *it;
501  }
502  LeftoverReminders.clear();
503  for (std::vector<SUMOVehicleParameter*>::iterator it = LeftoverVehicleParameters.begin();
504  it != LeftoverVehicleParameters.end(); ++it) {
505  delete *it;
506  }
508 }
509 
510 
511 void
514  for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it = myLaneMeanData.begin();
515  it != myLaneMeanData.end(); ++it) {
516  (*it)->addTo(myEdgeMeanData);
517  }
518 }
519 
520 bool MSCalibrator::VehicleRemover::notifyEnter(SUMOVehicle& veh, Notification /* reason */, const MSLane* /* enteredLane */) {
521  if (myParent == nullptr) {
522  return false;
523  }
524  if (myParent->isActive()) {
525  myParent->updateMeanData();
526  const bool calibrateFlow = myParent->myCurrentStateInterval->q >= 0;
527  const int totalWishedNum = myParent->totalWished();
528  int adaptedNum = myParent->passed() + myParent->myClearedInJam;
529  MSVehicle* vehicle = dynamic_cast<MSVehicle*>(&veh);
530  if (calibrateFlow && adaptedNum > totalWishedNum) {
531 #ifdef MSCalibrator_DEBUG
532  std::cout << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " " << myParent->getID()
533  << " vaporizing " << vehicle->getID() << " to reduce flow\n";
534 #endif
535  if (myParent->scheduleRemoval(vehicle)) {
536  myParent->myRemoved++;
537  }
538  } else if (myParent->invalidJam(myLaneIndex)) {
539 #ifdef MSCalibrator_DEBUG
540  std::cout << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " " << myParent->getID()
541  << " vaporizing " << vehicle->getID() << " to clear jam\n";
542 #endif
543  if (!myParent->myHaveWarnedAboutClearingJam) {
544  WRITE_WARNING("Clearing jam at calibrator '" + myParent->myID + "' at time "
545  + time2string(MSNet::getInstance()->getCurrentTimeStep()));
546  myParent->myHaveWarnedAboutClearingJam = true;
547  }
548  if (myParent->scheduleRemoval(vehicle)) {
549  myParent->myClearedInJam++;
550  }
551  }
552  }
553  return true;
554 }
555 
556 
557 
558 /****************************************************************************/
559 
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
double getLengthWithGap() const
Get vehicle&#39;s length including the minimum gap [m].
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false, const bool forceCheck=false) const
Tries to insert the given vehicle into the network.
Definition: MSEdge.cpp:575
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
long long int SUMOTime
Definition: SUMOTime.h:36
std::string vtypeid
The vehicle&#39;s type id.
int nVehVaporized
The number of vehicles that left this lane within the sample interval.
const MSRoute * getRoute() const
a flow definition (used by router)
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:565
A calibrator placed over edge.
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:279
void setMaxSpeed(double val)
Sets a new maximum speed for the lane (used by TraCI and MSCalibrator)
Definition: MSLane.cpp:2020
virtual int passed() const
Definition: MSCalibrator.h:169
virtual void myEndElement(int element)
Called on the closing of a tag;.
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:61
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:265
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:403
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, const bool optionalID=false, const bool skipDepart=false, const bool isPerson=false)
Parses a vehicle&#39;s attributes.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:274
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:2045
weights: time range begin
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:162
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:267
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
T MAX2(T a, T b)
Definition: StdDefs.h:76
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:514
The vehicle got vaporized.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
const std::string & getID() const
Returns the id.
Definition: Named.h:78
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:255
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:257
friend class VehicleRemover
Definition: MSCalibrator.h:143
double getLength() const
return the length of the edge
Definition: MSEdge.h:568
double currentSpeed() const
measured speed in the current interval
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:113
const std::string DEFAULT_VTYPE_ID
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:261
double getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
Definition: MSEdge.cpp:899
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:227
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Data structure for mean (aggregated) edge/lane values.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
The car-following model and parameter.
Definition: MSVehicleType.h:66
The lane is given.
int totalWished() const
number of vehicles expected to pass this interval
A road/street connecting two junctions.
Definition: MSEdge.h:75
int getIndex() const
Returns the lane&#39;s index.
Definition: MSLane.h:537
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:241
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:41
std::string routeid
The vehicle&#39;s route id.
void writeXMLOutput()
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static bool gCheckRoutes
Definition: MSGlobals.h:79
The least occupied lane from lanes which allow the continuation.
Encapsulated SAX-Attributes.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
SUMOTime depart
The vehicle&#39;s departure time.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
void resetRoutePosition(int index)
Definition: MSVehicle.cpp:1033
The maximum speed is used.
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:269
No information given; use default.
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:263
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:934
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:239
virtual void reset()
reset collected vehicle data
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:271
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
void setDescription(const std::string &description)
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:419
double waitSeconds
The number of vehicle probes with small speed.
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:159
int nVehLeft
The number of vehicles that left this lane within the sample interval.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:229
int nVehArrived
The number of vehicles that finished on the lane.
bool invalidJam(int laneIndex) const
No information given; use default.
virtual void myEndElement(int element)
Called when a closing tag occurs.
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:235
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:278
std::string myID
The name of the object.
Definition: Named.h:130
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
Structure representing possible vehicle parameter.
#define SUMOTime_MAX
Definition: SUMOTime.h:37
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:259
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
weights: time range end
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:158
void setMaxSpeed(double val) const
Sets a new maximum speed for all lanes (used by TraCI and MSCalibrator)
Definition: MSEdge.cpp:918
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:233
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:252
virtual void updateMeanData()
aggregate lane values
virtual ~MSCalibrator()
virtual SUMOTime execute(SUMOTime currentTime)
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:275
bool removePending()
remove any vehicles which are scheduled for removal. return true if removals took place ...
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
Definition: MSCalibrator.h:237
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
The class responsible for building and deletion of vehicles.
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:243
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
int remainingVehicleCapacity(int laneIndex) const
MSCalibrator(const std::string &id, const MSEdge *const edge, MSLane *lane, const double pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const double length, const MSRouteProbe *probe, bool addLaneMeanData=true)
const std::string & getID() const
Returns the name of the vehicle.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:249
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:76
Parser and container for routes during their loading.
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:103
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:259
double currentFlow() const
flow in the current interval in veh/h
std::string id
The vehicle&#39;s id.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:114