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