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