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