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()) {
513  myParent->updateMeanData();
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
531  if (!myParent->myHaveWarnedAboutClearingJam) {
532  WRITE_WARNING("Clearing jam at calibrator '" + myParent->getID() + "' at time "
533  + time2string(MSNet::getInstance()->getCurrentTimeStep()));
534  myParent->myHaveWarnedAboutClearingJam = true;
535  }
536  if (myParent->scheduleRemoval(vehicle)) {
537  myParent->myClearedInJam++;
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 
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:583
virtual void myEndElement(int element)
Called when a closing tag occurs.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
long long int SUMOTime
Definition: SUMOTime.h:35
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 definitio nusing a from-to edges instead of a route (used by router)
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
A calibrator placed over edge.
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:307
void setMaxSpeed(double val)
Sets a new maximum speed for the lane (used by TraCI and MSCalibrator)
Definition: MSLane.cpp:2144
virtual int passed() const
Definition: MSCalibrator.h:194
virtual void myEndElement(int element)
Called on the closing of a tag;.
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:61
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:293
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.
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:397
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false, const bool isPerson=false)
Parses a vehicle&#39;s attributes.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:302
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:2169
weights: time range begin
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:165
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:295
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
T MAX2(T a, T b)
Definition: StdDefs.h:80
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:541
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:77
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:283
#define TIME2STEPS(x)
Definition: SUMOTime.h:59
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:285
friend class VehicleRemover
Definition: MSCalibrator.h:168
double getLength() const
return the length of the edge
Definition: MSEdge.h:582
double currentSpeed() const
measured speed in the current interval
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:113
const std::string DEFAULT_VTYPE_ID
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:289
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:916
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:252
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:239
The car-following model and parameter.
Definition: MSVehicleType.h:66
const std::string & getID() const
Definition: MSCalibrator.h:91
The lane is given.
int totalWished() const
number of vehicles expected to pass this interval
A road/street connecting two junctions.
Definition: MSEdge.h:76
int getIndex() const
Returns the lane&#39;s index.
Definition: MSLane.h:564
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
Definition: MSVehicle.cpp:1186
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:48
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:269
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:41
std::string routeid
The vehicle&#39;s route id.
static bool gCheckRoutes
Definition: MSGlobals.h:79
The least occupied lane from lanes which allow the continuation.
Encapsulated SAX-Attributes.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
The maximum safe speed is used.
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:297
No information given; use default.
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:291
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:1055
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:267
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:299
The rightmost lane the vehicle may use.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
void setDescription(const std::string &description)
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:440
double waitSeconds
The number of vehicle probes with small speed.
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:159
int nVehLeft
The number of vehicles that left this lane within the sample interval.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
MSMeanData_Net myMeanDataParent
dummy parent to retrieve vType filter
Definition: MSCalibrator.h:264
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:254
int nVehArrived
The number of vehicles that finished on the lane.
bool invalidJam(int laneIndex) const
No information given; use default.
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:260
void intervalEnd()
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:306
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.
Structure representing possible vehicle parameter.
Representation of a vehicle or person.
#define SUMOTime_MAX
Definition: SUMOTime.h:36
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:259
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
weights: time range end
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:183
void setMaxSpeed(double val) const
Sets a new maximum speed for all lanes (used by TraCI and MSCalibrator)
Definition: MSEdge.cpp:935
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:258
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:280
virtual void updateMeanData()
aggregate lane values
virtual ~MSCalibrator()
virtual SUMOTime execute(SUMOTime currentTime)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:275
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)
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:262
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
The class responsible for building and deletion of vehicles.
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:271
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
const std::string & getID() const
Returns the name of the vehicle.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:277
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:76
Parser and container for routes during their loading.
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:103
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:287
Base of value-generating classes (detectors)
double currentFlow() const
flow in the current interval in veh/h
std::string id
The vehicle&#39;s id.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:114