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 /****************************************************************************/
16 // Calibrates the flow on an edge by removing an inserting vehicles
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <algorithm>
27 #include <cmath>
28 #include <microsim/MSNet.h>
29 #include <microsim/MSEdge.h>
30 #include <microsim/MSLane.h>
35 #include <utils/common/ToString.h>
38 #include <utils/xml/XMLSubSys.h>
44 #include "MSCalibrator.h"
45 
46 //#define MSCalibrator_DEBUG
47 
48 // ===========================================================================
49 // static members
50 // ===========================================================================
51 std::vector<MSMoveReminder*> MSCalibrator::LeftoverReminders;
52 std::vector<SUMOVehicleParameter*> MSCalibrator::LeftoverVehicleParameters;
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 MSCalibrator::MSCalibrator(const std::string& id,
58  const MSEdge* const edge,
59  MSLane* lane,
60  const double pos,
61  const std::string& aXMLFilename,
62  const std::string& outputFilename,
63  const SUMOTime freq, const double length,
64  const MSRouteProbe* probe,
65  const std::string& vTypes,
66  bool addLaneMeanData) :
67  MSTrigger(id),
68  MSRouteHandler(aXMLFilename, true),
69  MSDetectorFileOutput(id, vTypes, false), // detecting persons not yet supported
70  myEdge(edge),
71  myLane(lane),
72  myPos(pos), myProbe(probe),
73  myEdgeMeanData(nullptr, length, false, nullptr),
74  myMeanDataParent(id + "_dummyMeanData", 0, 0, false, false, false, false, false, false, 1, 0, 0, vTypes),
75  myCurrentStateInterval(myIntervals.begin()),
76  myOutput(nullptr), myFrequency(freq), myRemoved(0),
77  myInserted(0), myClearedInJam(0),
78  mySpeedIsDefault(true), myDidSpeedAdaption(false), myDidInit(false),
79  myDefaultSpeed(myLane == nullptr ? myEdge->getSpeedLimit() : myLane->getSpeedLimit()),
80  myHaveWarnedAboutClearingJam(false),
81  myAmActive(false),
82  myHaveInvalidJam(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)
290  // XXX could we miss vehicle movements if this is called less often than every DELTA_T (default) ?
291  updateMeanData();
292  const bool hadRemovals = removePending();
293  // check whether an adaptation value exists
294  if (isCurrentStateActive(currentTime)) {
295  myAmActive = true;
296  // all happens in isCurrentStateActive()
297  } else {
298  myAmActive = false;
299  reset();
300  if (!mySpeedIsDefault) {
301  // reset speed to default
302  if (myLane == nullptr) {
304  } else {
306  }
307  mySpeedIsDefault = true;
308  }
309  if (myCurrentStateInterval == myIntervals.end()) {
310  // keep calibrator alive for gui but do not call again
311  return TIME2STEPS(86400);
312  }
313  return myFrequency;
314  }
315  // we are active
316  if (!myDidSpeedAdaption && myCurrentStateInterval->v >= 0) {
317  if (myLane == nullptr) {
319  } else {
321  }
322  mySpeedIsDefault = false;
323  myDidSpeedAdaption = true;
324  }
325 
326  const bool calibrateFlow = myCurrentStateInterval->q >= 0;
327  const int totalWishedNum = totalWished();
328  int adaptedNum = passed() + myClearedInJam;
329 #ifdef MSCalibrator_DEBUG
330  std::cout << time2string(currentTime) << " " << getID()
331  << " q=" << myCurrentStateInterval->q
332  << " totalWished=" << totalWishedNum
333  << " adapted=" << adaptedNum
334  << " jam=" << myHaveInvalidJam
335  << " entered=" << myEdgeMeanData.nVehEntered
336  << " departed=" << myEdgeMeanData.nVehDeparted
337  << " arrived=" << myEdgeMeanData.nVehArrived
338  << " left=" << myEdgeMeanData.nVehLeft
339  << " waitSecs=" << myEdgeMeanData.waitSeconds
340  << " vaporized=" << myEdgeMeanData.nVehVaporized
341  << "\n";
342 #endif
343  if (calibrateFlow && adaptedNum < totalWishedNum && !hadRemovals) {
344  // we need to insert some vehicles
345  const double hourFraction = STEPS2TIME(currentTime - myCurrentStateInterval->begin + DELTA_T) / (double) 3600.;
346  const int wishedNum = (int)std::floor(myCurrentStateInterval->q * hourFraction + 0.5); // round to closest int
347  // only the difference between inflow and aspiredFlow should be added, thus
348  // we should not count vehicles vaporized from a jam here
349  // if we have enough time left we can add missing vehicles later
350  const int relaxedInsertion = (int)std::floor(STEPS2TIME(myCurrentStateInterval->end - currentTime) / 3);
351  const int insertionSlack = MAX2(0, adaptedNum + relaxedInsertion - totalWishedNum);
352  // increase number of vehicles
353 #ifdef MSCalibrator_DEBUG
354  std::cout
355  << " wished:" << wishedNum
356  << " slack:" << insertionSlack
357  << " before:" << adaptedNum
358  << "\n";
359 #endif
360  while (wishedNum > adaptedNum + insertionSlack) {
361  SUMOVehicleParameter* pars = myCurrentStateInterval->vehicleParameter;
362  const MSRoute* route = myProbe != nullptr ? myProbe->getRoute() : nullptr;
363  if (route == nullptr) {
364  route = MSRoute::dictionary(pars->routeid);
365  }
366  if (route == nullptr) {
367  WRITE_WARNING("No valid routes in calibrator '" + getID() + "'.");
368  break;
369  }
370  if (!route->contains(myEdge)) {
371  WRITE_WARNING("Route '" + route->getID() + "' in calibrator '" + getID() + "' does not contain edge '" + myEdge->getID() + "'.");
372  break;
373  }
374  const int routeIndex = (int)std::distance(route->begin(),
375  std::find(route->begin(), route->end(), myEdge));
377  assert(route != 0 && vtype != 0);
378  // build the vehicle
379  SUMOVehicleParameter* newPars = new SUMOVehicleParameter(*pars);
380  newPars->id = getNewVehicleID();
381  newPars->depart = currentTime;
382  newPars->routeid = route->getID();
383  newPars->departLaneProcedure = DEPART_LANE_FIRST_ALLOWED; // ensure successful vehicle creation
384  MSVehicle* vehicle;
385  try {
386  vehicle = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().buildVehicle(
387  newPars, route, vtype, true, false));
388  } catch (const ProcessError& e) {
390  WRITE_WARNING(e.what());
391  vehicle = nullptr;
392  break;
393  } else {
394  throw e;
395  }
396  }
397 #ifdef MSCalibrator_DEBUG
398  std::cout << " resetting route pos: " << routeIndex << "\n";
399 #endif
400  vehicle->resetRoutePosition(routeIndex, pars->departLaneProcedure);
401  if (myEdge->insertVehicle(*vehicle, currentTime)) {
402  if (!MSNet::getInstance()->getVehicleControl().addVehicle(vehicle->getID(), vehicle)) {
403  throw ProcessError("Emission of vehicle '" + vehicle->getID() + "' in calibrator '" + getID() + "'failed!");
404  }
405  myInserted++;
406  adaptedNum++;
407 #ifdef MSCalibrator_DEBUG
408  std::cout << "I ";
409 #endif
410  } else {
411  // could not insert vehicle
412 #ifdef MSCalibrator_DEBUG
413  std::cout << "F ";
414 #endif
416  break;
417  }
418  }
419  }
420  if (myCurrentStateInterval->end <= currentTime + myFrequency) {
421  intervalEnd();
422  }
423  return myFrequency;
424 }
425 
426 void
429  for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it = myLaneMeanData.begin(); it != myLaneMeanData.end(); ++it) {
430  (*it)->reset();
431  }
432 }
433 
434 
435 bool
436 MSCalibrator::invalidJam(int laneIndex) const {
437  if (laneIndex < 0) {
438  const int numLanes = (int)myEdge->getLanes().size();
439  for (int i = 0; i < numLanes; ++i) {
440  if (invalidJam(i)) {
441  return true;
442  }
443  }
444  return false;
445  }
446  assert(laneIndex < (int)myEdge->getLanes().size());
447  const MSLane* const lane = myEdge->getLanes()[laneIndex];
448  if (lane->getVehicleNumber() < 4) {
449  // cannot reliably detect invalid jams
450  return false;
451  }
452  // maxSpeed reflects the calibration target
453  const bool toSlow = lane->getMeanSpeed() < 0.5 * myEdge->getSpeedLimit();
454  return toSlow && remainingVehicleCapacity(laneIndex) < 1;
455 }
456 
457 
458 int
460  if (laneIndex < 0) {
461  const int numLanes = (int)myEdge->getLanes().size();
462  int result = 0;
463  for (int i = 0; i < numLanes; ++i) {
464  result = MAX2(result, remainingVehicleCapacity(i));
465  }
466  return result;
467  }
468  assert(laneIndex < (int)myEdge->getLanes().size());
469  MSLane* lane = myEdge->getLanes()[laneIndex];
470  MSVehicle* last = lane->getLastFullVehicle();
471  const SUMOVehicleParameter* pars = myCurrentStateInterval->vehicleParameter;
473  const double spacePerVehicle = vtype->getLengthWithGap() + myEdge->getSpeedLimit() * vtype->getCarFollowModel().getHeadwayTime();
474  int overallSpaceLeft = (int)ceil(lane->getLength() / spacePerVehicle) - lane->getVehicleNumber();
475  if (last != nullptr) {
476  int entrySpaceLeft = (int)(last->getPositionOnLane() / spacePerVehicle);
477  return MAX2(overallSpaceLeft, entrySpaceLeft);
478  } else {
479  return overallSpaceLeft;
480  }
481 }
482 
483 
484 void
486  for (std::vector<MSMoveReminder*>::iterator it = LeftoverReminders.begin(); it != LeftoverReminders.end(); ++it) {
487  delete *it;
488  }
489  LeftoverReminders.clear();
490  for (std::vector<SUMOVehicleParameter*>::iterator it = LeftoverVehicleParameters.begin();
491  it != LeftoverVehicleParameters.end(); ++it) {
492  delete *it;
493  }
495 }
496 
497 
498 void
501  for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it = myLaneMeanData.begin();
502  it != myLaneMeanData.end(); ++it) {
503  (*it)->addTo(myEdgeMeanData);
504  }
505 }
506 
507 
508 bool
510  if (myParent == nullptr) {
511  return false;
512  }
513  if (!myParent->vehicleApplies(veh)) {
514  return false;
515  }
516  if (myParent->isActive()) {
518  const bool calibrateFlow = myParent->myCurrentStateInterval->q >= 0;
519  const int totalWishedNum = myParent->totalWished();
520  int adaptedNum = myParent->passed() + myParent->myClearedInJam;
521  MSVehicle* vehicle = dynamic_cast<MSVehicle*>(&veh);
522  if (calibrateFlow && adaptedNum > totalWishedNum) {
523 #ifdef MSCalibrator_DEBUG
524  std::cout << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " " << myParent->getID()
525  << " vaporizing " << vehicle->getID() << " to reduce flow\n";
526 #endif
527  if (myParent->scheduleRemoval(vehicle)) {
528  myParent->myRemoved++;
529  }
530  } else if (myParent->myHaveInvalidJam) {
531 #ifdef MSCalibrator_DEBUG
532  std::cout << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " " << myParent->getID()
533  << " vaporizing " << vehicle->getID() << " to clear jam\n";
534 #endif
536  WRITE_WARNING("Clearing jam at calibrator '" + myParent->getID() + "' at time "
537  + time2string(MSNet::getInstance()->getCurrentTimeStep()));
539  }
540  if (myParent->scheduleRemoval(vehicle)) {
542  }
543  }
544  }
545  return true;
546 }
547 
548 
549 void
551  updateMeanData();
552  const int p = passed();
553  // meandata will be off if vehicles are removed on the next edge instead of this one
555  assert(discrepancy >= 0);
556  const std::string ds = (discrepancy > 0 ? "\" vaporizedOnNextEdge=\"" + toString(discrepancy) : "");
557  const double durationSeconds = STEPS2TIME(stopTime - startTime);
558  dev << " <interval begin=\"" << time2string(startTime) <<
559  "\" end=\"" << time2string(stopTime) <<
560  "\" id=\"" << getID() <<
561  "\" nVehContrib=\"" << p <<
562  "\" removed=\"" << myRemoved <<
563  "\" inserted=\"" << myInserted <<
564  "\" cleared=\"" << myClearedInJam <<
565  "\" flow=\"" << p * 3600.0 / durationSeconds <<
566  "\" aspiredFlow=\"" << myCurrentStateInterval->q <<
568  "\" aspiredSpeed=\"" << myCurrentStateInterval->v <<
569  ds << //optional
570  "\"/>\n";
571 }
572 
573 void
575  dev.writeXMLHeader("calibratorstats", "calibratorstats_file.xsd");
576 }
577 
578 std::string
580  // avoid name clash for subsecond interval spacing
581  const double beginS = STEPS2TIME(myCurrentStateInterval->begin);
582  const int precision = beginS == int(beginS) ? 0 : 2;
583  return getID() + "." + toString(beginS, precision) + "." + toString(myInserted);
584 }
585 
586 /****************************************************************************/
587 
MSCalibrator::myRemoved
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:287
MSCalibrator::myClearedInJam
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:291
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:240
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MSCalibrator::AspiredState::vehicleParameter
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:182
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
MSCalibrator::passed
virtual int passed() const
Definition: MSCalibrator.h:193
MSCalibrator::getID
const std::string & getID() const
Definition: MSCalibrator.h:90
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:112
MSCalibrator::myHaveWarnedAboutClearingJam
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:301
MSCalibrator::AspiredState::v
double v
Definition: MSCalibrator.h:181
MSEventControl::addEvent
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Definition: MSEventControl.cpp:52
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:877
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MSCalibrator::VehicleRemover
friend class VehicleRemover
Definition: MSCalibrator.h:167
MSNet.h
MSDetectorFileOutput
Base of value-generating classes (detectors)
Definition: MSDetectorFileOutput.h:63
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
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:353
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:63
MSCalibrator::myInserted
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:289
DELTA_T
SUMOTime DELTA_T
Definition: SUMOTime.cpp:36
MSRoute::end
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:75
MSCalibrator::myHaveInvalidJam
bool myHaveInvalidJam
whether the calibrator has registered an invalid jam in the last execution step
Definition: MSCalibrator.h:307
SUMOVehicleParserHelper.h
MSCalibrator::myFrequency
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:285
OptionsCont.h
MSCalibrator::myOutput
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:282
MSRouteProbe
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:60
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:57
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:474
MSCalibrator::myCurrentStateInterval
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:271
MSCalibrator.h
MSMeanData_Net::MSLaneMeanDataValues
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData_Net.h:66
MSCalibrator::AspiredState::end
SUMOTime end
Definition: MSCalibrator.h:179
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSMeanData_Net::MSLaneMeanDataValues::nVehArrived
int nVehArrived
The number of vehicles that finished on the lane.
Definition: MSMeanData_Net.h:155
MSMeanData_Net::MSLaneMeanDataValues::waitSeconds
double waitSeconds
The number of vehicle probes with small speed.
Definition: MSMeanData_Net.h:167
EmptyData
Definition: UtilExceptions.h:68
MSVehicle::onRemovalFromNet
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:1060
SUMO_ATTR_SPEED
@ SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:384
MSCalibrator::mySpeedIsDefault
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:293
MSMeanData_Net::MSLaneMeanDataValues::nVehLeft
int nVehLeft
The number of vehicles that left this lane within the sample interval.
Definition: MSMeanData_Net.h:161
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
MSEdge.h
MSCalibrator::myMeanDataParent
MSMeanData_Net myMeanDataParent
dummy parent to retrieve vType filter
Definition: MSCalibrator.h:266
MSLane::getLastFullVehicle
MSVehicle * getLastFullVehicle() const
returns the last vehicle for which this lane is responsible or 0
Definition: MSLane.cpp:2015
MSCalibrator::CalibratorCommand
Definition: MSCalibrator.h:101
MSVehicleControl::scheduleVehicleRemoval
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
Definition: MSVehicleControl.cpp:117
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:63
MSCalibrator::VehicleRemover::myParent
MSCalibrator * myParent
Definition: MSCalibrator.h:165
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:2155
MSRoute
Definition: MSRoute.h:66
MSBaseVehicle::resetRoutePosition
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
reset index of edge within route
Definition: MSBaseVehicle.cpp:397
SUMOVehicleParameter::depart
SUMOTime depart
Definition: SUMOVehicleParameter.h:482
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:73
MSCalibrator::myDefaultSpeed
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:299
MSMoveReminder::NOTIFICATION_VAPORIZED
@ NOTIFICATION_VAPORIZED
The vehicle got vaporized.
Definition: MSMoveReminder.h:109
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
@ SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:678
MSLane::getVehicleNumber
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition: MSLane.h:400
DEPART_LANE_ALLOWED_FREE
@ DEPART_LANE_ALLOWED_FREE
The least occupied lane from lanes which allow the continuation.
Definition: SUMOVehicleParameter.h:126
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
MSCalibrator::myLane
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:256
MSVehicleControl::buildVehicle
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.
Definition: MSVehicleControl.cpp:100
MSCalibrator::VehicleRemover
Definition: MSCalibrator.h:139
NumberFormatException
Definition: UtilExceptions.h:95
MSCalibrator::isActive
bool isActive() const
Definition: MSCalibrator.h:170
MSCalibrator::myDidInit
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:297
MSVehicleControl::getVehicle
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Definition: MSVehicleControl.cpp:240
RandomDistributor.h
SUMO_TAG_FLOW
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
Definition: SUMOXMLDefinitions.h:149
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:392
MSMeanData_Net::MSLaneMeanDataValues::nVehVaporized
int nVehVaporized
The number of vehicles that left this lane within the sample interval.
Definition: MSMeanData_Net.h:164
MSVehicleType::getCarFollowModel
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
Definition: MSVehicleType.h:140
MSCalibrator::myLaneMeanData
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:262
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
MSNet::getEndOfTimestepEvents
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:439
MSVehicleType::getLengthWithGap
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
Definition: MSVehicleType.h:117
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:295
MSCalibrator::reset
virtual void reset()
reset collected vehicle data
Definition: MSCalibrator.cpp:427
DEPART_LANE_GIVEN
@ DEPART_LANE_GIVEN
The lane is given.
Definition: SUMOVehicleParameter.h:120
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
SUMOVehicleParameter::id
std::string id
The vehicle's id.
Definition: SUMOVehicleParameter.h:468
MSLane::getLength
double getLength() const
Returns the lane's length.
Definition: MSLane.h:540
SUMORouteHandler::myEndElement
virtual void myEndElement(int element)
Called when a closing tag occurs.
Definition: SUMORouteHandler.cpp:215
MSCalibrator::updateMeanData
virtual void updateMeanData()
aggregate lane values
Definition: MSCalibrator.cpp:499
MSCalibrator::myAmActive
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:304
MSVehicleControl::deleteVehicle
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: MSVehicleControl.cpp:250
MSCalibrator::~MSCalibrator
virtual ~MSCalibrator()
Definition: MSCalibrator.cpp:127
ProcessError
Definition: UtilExceptions.h:39
MSCalibrator::invalidJam
bool invalidJam(int laneIndex) const
Definition: MSCalibrator.cpp:436
MSLane::getMeanSpeed
double getMeanSpeed() const
Returns the mean speed on this lane.
Definition: MSLane.cpp:2720
MSMeanData::MeanDataValues::getTravelledDistance
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:158
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:67
UtilExceptions.h
MSLane::removeVehicle
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:2180
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
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:518
MSGlobals::gCheckRoutes
static bool gCheckRoutes
Definition: MSGlobals.h:78
MSCalibrator::myEdgeMeanData
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
Definition: MSCalibrator.h:264
MSRouteProbe::getRoute
const MSRoute * getRoute() const
Definition: MSRouteProbe.cpp:124
MSCalibrator::myProbe
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:260
MSCalibrator::cleanup
static void cleanup()
cleanup remaining data structures
Definition: MSCalibrator.cpp:485
SUMOVehicleParameter::routeid
std::string routeid
The vehicle's route id.
Definition: SUMOVehicleParameter.h:471
MSCalibrator::myVehicleRemovers
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:273
MSTrigger
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:40
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
MSCalibrator::remainingVehicleCapacity
int remainingVehicleCapacity(int laneIndex) const
Definition: MSCalibrator.cpp:459
SUMOVehicleParameter::departLane
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
Definition: SUMOVehicleParameter.h:488
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:47
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:544
MSRouteHandler::myStartElement
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: MSRouteHandler.cpp:132
SUMOVehicleParameter::departLaneProcedure
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
Definition: SUMOVehicleParameter.h:491
MSMeanData::MeanDataValues::getSamples
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:277
MSCalibrator::writeXMLOutput
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
Definition: MSCalibrator.cpp:550
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:54
MSCalibrator::AspiredState
Definition: MSCalibrator.h:176
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
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:90
MSCalibrator::myToRemove
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:279
MSCFModel::getHeadwayTime
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition: MSCFModel.h:258
MSCalibrator::writeXMLDetectorProlog
void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
Definition: MSCalibrator.cpp:574
MSEdge::setMaxSpeed
void setMaxSpeed(double val) const
Sets a new maximum speed for all lanes (used by TraCI and MSCalibrator)
Definition: MSEdge.cpp:896
MSCalibrator::getNewVehicleID
std::string getNewVehicleID()
determine id of new vehicle from calibrator state
Definition: MSCalibrator.cpp:579
MSCalibrator::isCurrentStateActive
bool isCurrentStateActive(SUMOTime time)
Definition: MSCalibrator.cpp:227
MSRouteProbe.h
MSMoveReminder::setDescription
void setDescription(const std::string &description)
Definition: MSMoveReminder.h:226
MSRouteHandler
Parser and container for routes during their loading.
Definition: MSRouteHandler.h:53
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:138
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:167
DEPART_SPEED_MAX
@ DEPART_SPEED_MAX
The maximum safe speed is used.
Definition: SUMOVehicleParameter.h:200
DEPART_LANE_DEFAULT
@ DEPART_LANE_DEFAULT
No information given; use default.
Definition: SUMOVehicleParameter.h:118
MSRoute::begin
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
MSDetectorFileOutput::vehicleApplies
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
Definition: MSDetectorFileOutput.h:141
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:509
MSRoute::dictionary
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:113
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MSCalibrator::LeftoverReminders
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:311
DEPART_SPEED_DEFAULT
@ DEPART_SPEED_DEFAULT
No information given; use default.
Definition: SUMOVehicleParameter.h:194
MSCalibrator::LeftoverVehicleParameters
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:312
MSCalibrator::AspiredState::begin
SUMOTime begin
Definition: MSCalibrator.h:178
StringTokenizer.h
MSCalibrator::AspiredState::q
double q
Definition: MSCalibrator.h:180
SUMO_ATTR_END
@ SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:680
MSMeanData_Net::MSLaneMeanDataValues::nVehEntered
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
Definition: MSMeanData_Net.h:158
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:35
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:227
SUMO_ATTR_VEHSPERHOUR
@ SUMO_ATTR_VEHSPERHOUR
Definition: SUMOXMLDefinitions.h:786
MSMeanData_Net::MSLaneMeanDataValues::nVehDeparted
int nVehDeparted
Definition: MSMeanData_Net.h:152
MSCalibrator::intervalEnd
void intervalEnd()
Definition: MSCalibrator.cpp:213
MSCalibrator::myIntervals
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:269
MSRoute::contains
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:102
SUMO_TAG_CALIBRATOR
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
Definition: SUMOXMLDefinitions.h:91
MSCalibrator::myEdge
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:254
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
MSLane::getIndex
int getIndex() const
Returns the lane's index.
Definition: MSLane.h:563
DEPART_LANE_FIRST_ALLOWED
@ DEPART_LANE_FIRST_ALLOWED
The rightmost lane the vehicle may use.
Definition: SUMOVehicleParameter.h:130
SUMOXMLDefinitions.h
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
SUMOVehicleParameter::departSpeedProcedure
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
Definition: SUMOVehicleParameter.h:509
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:79