Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Simulation.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // C++ TraCI client API implementation
20 /****************************************************************************/
21 #include <config.h>
22 #ifdef HAVE_VERSION_H
23 #include <version.h>
24 #endif
27 #include <utils/common/StdDefs.h>
35 #include <utils/xml/XMLSubSys.h>
36 #include <microsim/MSNet.h>
37 #include <microsim/MSEdgeControl.h>
39 #include <microsim/MSEdge.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSVehicle.h>
47 #include <microsim/MSParkingArea.h>
51 #include <mesosim/MELoop.h>
52 #include <mesosim/MESegment.h>
53 #include <netload/NLBuilder.h>
54 #include <libsumo/TraCIConstants.h>
55 #include "Simulation.h"
56 #include <libsumo/TraCIDefs.h>
57 
58 
59 namespace libsumo {
60 // ===========================================================================
61 // static member initializations
62 // ===========================================================================
65 
66 
67 // ===========================================================================
68 // static member definitions
69 // ===========================================================================
70 void
71 Simulation::load(const std::vector<std::string>& args) {
72  close("Libsumo issued load command.");
73  try {
74  gSimulation = true;
76  OptionsIO::setArgs(args);
77  if (NLBuilder::init(true) != nullptr) {
78  const SUMOTime begin = string2time(OptionsCont::getOptions().getString("begin"));
79  MSNet::getInstance()->setCurrentTimeStep(begin); // needed for state loading
80  WRITE_MESSAGE("Simulation started via Libsumo with time: " + time2string(begin));
81  }
82  } catch (ProcessError& e) {
83  throw TraCIException(e.what());
84  }
85 }
86 
87 
88 bool
90  return MSNet::hasInstance();
91 }
92 
93 
94 void
95 Simulation::step(const double time) {
97  const SUMOTime t = TIME2STEPS(time);
98  if (t == 0) {
100  } else {
101  while (MSNet::getInstance()->getCurrentTimeStep() < t) {
103  }
104  }
106 }
107 
108 
109 void
110 Simulation::close(const std::string& reason) {
112  if (MSNet::hasInstance()) {
113  MSNet::getInstance()->closeSimulation(0, reason);
114  delete MSNet::getInstance();
117  }
118 }
119 
120 
121 void
122 Simulation::subscribe(const std::vector<int>& varIDs, double begin, double end) {
124 }
125 
126 
127 const TraCIResults
129  return mySubscriptionResults[""];
130 }
131 
132 
133 std::pair<int, std::string>
135  return std::make_pair(libsumo::TRACI_VERSION, "SUMO " VERSION_STRING);
136 }
137 
138 
139 int
141  return (int)MSNet::getInstance()->getCurrentTimeStep();
142 }
143 
144 
145 double
147  return SIMTIME;
148 }
149 
150 
151 int
154 }
155 
156 
157 std::vector<std::string>
160 }
161 
162 
163 int
166 }
167 
168 
169 std::vector<std::string>
172 }
173 
174 
175 int
178 }
179 
180 
181 std::vector<std::string>
184 }
185 
186 
187 int
190 }
191 
192 
193 std::vector<std::string>
196 }
197 
198 
199 int
202 }
203 
204 
205 std::vector<std::string>
208 }
209 
210 
211 int
214 }
215 
216 
217 std::vector<std::string>
220 }
221 
222 
223 int
226 }
227 
228 
229 std::vector<std::string>
232 }
233 
234 
235 int
238 }
239 
240 
241 std::vector<std::string>
244 }
245 
246 
247 int
250 }
251 
252 
253 std::vector<std::string>
256 }
257 
258 
259 int
262 }
263 
264 
265 std::vector<std::string>
268 }
269 
270 
271 int
274 }
275 
276 
277 std::vector<std::string>
280 }
281 
282 std::vector<std::string>
284  std::vector<std::string> result;
285  for (const auto pair : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_BUS_STOP)) {
286  result.push_back(pair.first);
287  }
288  return result;
289 }
290 
291 int
292 Simulation::getBusStopWaiting(const std::string& id) {
294  if (s == nullptr) {
295  throw TraCIException("Unknown bus stop '" + id + "'.");
296  }
297  return s->getTransportableNumber();
298 }
299 
300 std::vector<std::string>
301 Simulation::getBusStopWaitingIDList(const std::string& id) {
303  std::vector<MSTransportable*> transportables = s->getTransportables();
304  std::vector<std::string> result;
305  for (std::vector<MSTransportable*>::iterator it = transportables.begin(); it != transportables.end(); it++) {
306  result.push_back((*it)->getID());
307  }
308  return result;
309 }
310 
311 
312 double
314  return TS;
315 }
316 
317 
322  tb[0].x = b.xmin();
323  tb[1].x = b.xmax();
324  tb[0].y = b.ymin();
325  tb[1].y = b.ymax();
326  tb[0].z = b.zmin();
327  tb[1].z = b.zmax();
328  return tb;
329 }
330 
331 
332 int
334  MSNet* net = MSNet::getInstance();
337  + (net->hasPersons() ? net->getPersonControl().getActiveCount() : 0)
338  + (net->hasContainers() ? net->getContainerControl().getActiveCount() : 0));
339 }
340 
341 
343 Simulation::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
344  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->geometryPositionAtOffset(pos);
345  if (toGeo) {
347  }
348  result.setz(0.);
349  return Helper::makeTraCIPosition(result);
350 }
351 
352 
354 Simulation::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
355  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->geometryPositionAtOffset(pos);
356  if (toGeo) {
358  }
359  return Helper::makeTraCIPosition(result, true);
360 }
361 
362 
364 Simulation::convertRoad(double x, double y, bool isGeo, const std::string& vClass) {
365  Position pos(x, y);
366  if (isGeo) {
368  }
369  if (!SumoVehicleClassStrings.hasString(vClass)) {
370  throw TraCIException("Unknown vehicle class '" + vClass + "'.");
371  }
372  const SUMOVehicleClass vc = SumoVehicleClassStrings.get(vClass);
373  std::pair<MSLane*, double> roadPos = libsumo::Helper::convertCartesianToRoadMap(pos, vc);
374  if (roadPos.first == nullptr) {
375  throw TraCIException("Cannot convert position to road.");
376  }
377  TraCIRoadPosition result;
378  result.edgeID = roadPos.first->getEdge().getID();
379  result.laneIndex = roadPos.first->getIndex();
380  result.pos = roadPos.second;
381  return result;
382 }
383 
384 
386 Simulation::convertGeo(double x, double y, bool fromGeo) {
387  Position pos(x, y);
388  if (fromGeo) {
390  } else {
392  }
393  return Helper::makeTraCIPosition(pos);
394 }
395 
396 
397 double
398 Simulation::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
399  Position pos1(x1, y1);
400  Position pos2(x2, y2);
401  if (isGeo) {
404  }
405  if (isDriving) {
406  std::pair<const MSLane*, double> roadPos1 = libsumo::Helper::convertCartesianToRoadMap(pos1, SVC_IGNORING);
407  std::pair<const MSLane*, double> roadPos2 = libsumo::Helper::convertCartesianToRoadMap(pos2, SVC_IGNORING);
408  return Helper::getDrivingDistance(roadPos1, roadPos2);
409  } else {
410  return pos1.distanceTo(pos2);
411  }
412 }
413 
414 
415 double
416 Simulation::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
417  std::pair<const MSLane*, double> roadPos1 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID1, 0, pos1), pos1);
418  std::pair<const MSLane*, double> roadPos2 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID2, 0, pos2), pos2);
419  if (isDriving) {
420  return Helper::getDrivingDistance(roadPos1, roadPos2);
421  } else {
422  const Position p1 = roadPos1.first->geometryPositionAtOffset(roadPos1.second);
423  const Position p2 = roadPos2.first->geometryPositionAtOffset(roadPos2.second);
424  return p1.distanceTo(p2);
425  }
426 }
427 
428 
430 Simulation::findRoute(const std::string& from, const std::string& to, const std::string& typeID, const double depart, const int routingMode) {
431  TraCIStage result(STAGE_DRIVING);
432  const MSEdge* const fromEdge = MSEdge::dictionary(from);
433  if (fromEdge == nullptr) {
434  throw TraCIException("Unknown from edge '" + from + "'.");
435  }
436  const MSEdge* const toEdge = MSEdge::dictionary(to);
437  if (toEdge == nullptr) {
438  throw TraCIException("Unknown to edge '" + from + "'.");
439  }
440  SUMOVehicle* vehicle = nullptr;
441  MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(typeID == "" ? DEFAULT_VTYPE_ID : typeID);
442  if (type == nullptr) {
443  throw TraCIException("The vehicle type '" + typeID + "' is not known.");
444  }
446  pars->id = "simulation.findRoute";
447  try {
448  const MSRoute* const routeDummy = new MSRoute("", ConstMSEdgeVector({ fromEdge }), true, nullptr, std::vector<SUMOVehicleParameter::Stop>());
449  vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(pars, routeDummy, type, false);
450  std::string msg;
451  if (!vehicle->hasValidRouteStart(msg)) {
453  throw TraCIException("Invalid departure edge for vehicle type '" + type->getID() + "' (" + msg + ")");
454  }
455  // we need to fix the speed factor here for deterministic results
456  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
457  } catch (ProcessError& e) {
458  throw TraCIException("Invalid departure edge for vehicle type '" + type->getID() + "' (" + e.what() + ")");
459  }
460  ConstMSEdgeVector edges;
461  const SUMOTime dep = depart < 0 ? MSNet::getInstance()->getCurrentTimeStep() : TIME2STEPS(depart);
463  router.compute(fromEdge, toEdge, vehicle, dep, edges);
464  for (const MSEdge* e : edges) {
465  result.edges.push_back(e->getID());
466  }
467  result.travelTime = result.cost = router.recomputeCosts(edges, vehicle, dep, &result.length);
468  if (vehicle != nullptr) {
470  }
471  return result;
472 }
473 
474 
475 std::vector<TraCIStage>
476 Simulation::findIntermodalRoute(const std::string& from, const std::string& to,
477  const std::string& modes, double depart, const int routingMode, double speed, double walkFactor,
478  double departPos, double arrivalPos, const double departPosLat,
479  const std::string& pType, const std::string& vType, const std::string& destStop) {
480  UNUSED_PARAMETER(departPosLat);
481  std::vector<TraCIStage> result;
482  const MSEdge* const fromEdge = MSEdge::dictionary(from);
483  if (fromEdge == nullptr) {
484  throw TraCIException("Unknown from edge '" + from + "'.");
485  }
486  const MSEdge* const toEdge = MSEdge::dictionary(to);
487  if (toEdge == nullptr) {
488  throw TraCIException("Unknown to edge '" + to + "'.");
489  }
491  SVCPermissions modeSet = 0;
492  std::vector<SUMOVehicleParameter*> pars;
493  if (vType != "") {
494  pars.push_back(new SUMOVehicleParameter());
495  pars.back()->vtypeid = vType;
496  pars.back()->id = vType;
497  modeSet |= SVC_PASSENGER;
498  }
499  for (StringTokenizer st(modes); st.hasNext();) {
500  const std::string mode = st.next();
501  if (mode == toString(PersonMode::CAR)) {
502  pars.push_back(new SUMOVehicleParameter());
503  pars.back()->vtypeid = DEFAULT_VTYPE_ID;
504  pars.back()->id = mode;
505  modeSet |= SVC_PASSENGER;
506  } else if (mode == toString(PersonMode::BICYCLE)) {
507  pars.push_back(new SUMOVehicleParameter());
508  pars.back()->vtypeid = DEFAULT_BIKETYPE_ID;
509  pars.back()->id = mode;
510  modeSet |= SVC_BICYCLE;
511  } else if (mode == toString(PersonMode::PUBLIC)) {
512  pars.push_back(nullptr);
513  modeSet |= SVC_BUS;
514  } else if (mode == toString(PersonMode::WALK)) {
515  // do nothing
516  } else {
517  throw TraCIException("Unknown person mode '" + mode + "'.");
518  }
519  }
520  if (pars.empty()) {
521  pars.push_back(nullptr);
522  }
523  // interpret default arguments
524  const MSVehicleType* pedType = vehControl.hasVType(pType) ? vehControl.getVType(pType) : vehControl.getVType(DEFAULT_PEDTYPE_ID);
525  SUMOTime departStep = TIME2STEPS(depart);
526  if (depart < 0) {
527  departStep = MSNet::getInstance()->getCurrentTimeStep();
528  }
529  if (speed < 0) {
530  speed = pedType->getMaxSpeed();
531  }
532  if (walkFactor < 0) {
533  walkFactor = OptionsCont::getOptions().getFloat("persontrip.walkfactor");
534  }
535  const double externalFactor = StringUtils::toDouble(pedType->getParameter().getParameter("externalEffortFactor", "100"));
536  if (departPos < 0) {
537  departPos += fromEdge->getLength();
538  }
539  if (arrivalPos == INVALID_DOUBLE_VALUE) {
540  arrivalPos = toEdge->getLength() / 2;
541  } else if (arrivalPos < 0) {
542  arrivalPos += toEdge->getLength();
543  }
544  if (departPos < 0 || departPos >= fromEdge->getLength()) {
545  throw TraCIException("Invalid depart position " + toString(departPos) + " for edge '" + to + "'.");
546  }
547  if (arrivalPos < 0 || arrivalPos >= toEdge->getLength()) {
548  throw TraCIException("Invalid arrival position " + toString(arrivalPos) + " for edge '" + to + "'.");
549  }
550  double minCost = std::numeric_limits<double>::max();
552  for (SUMOVehicleParameter* vehPar : pars) {
553  std::vector<TraCIStage> resultCand;
554  SUMOVehicle* vehicle = nullptr;
555  if (vehPar != nullptr) {
556  MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(vehPar->vtypeid);
557  if (type == nullptr) {
558  throw TraCIException("Unknown vehicle type '" + vehPar->vtypeid + "'.");
559  }
560  if (type->getVehicleClass() != SVC_IGNORING && (fromEdge->getPermissions() & type->getVehicleClass()) == 0) {
561  WRITE_WARNING("Ignoring vehicle type '" + type->getID() + "' when performing intermodal routing because it is not allowed on the start edge '" + from + "'.");
562  } else {
563  const MSRoute* const routeDummy = new MSRoute(vehPar->id, ConstMSEdgeVector({ fromEdge }), true, nullptr, std::vector<SUMOVehicleParameter::Stop>());
564  vehicle = vehControl.buildVehicle(vehPar, routeDummy, type, !MSGlobals::gCheckRoutes);
565  // we need to fix the speed factor here for deterministic results
566  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
567  }
568  }
569  std::vector<MSNet::MSIntermodalRouter::TripItem> items;
570  if (router.compute(fromEdge, toEdge, departPos, arrivalPos, destStop,
571  speed * walkFactor, vehicle, modeSet, departStep, items, externalFactor)) {
572  double cost = 0;
573  for (std::vector<MSNet::MSIntermodalRouter::TripItem>::iterator it = items.begin(); it != items.end(); ++it) {
574  if (!it->edges.empty()) {
575  resultCand.push_back(TraCIStage((it->line == "" ? STAGE_WALKING : STAGE_DRIVING), it->vType, it->line, it->destStop));
576  for (const MSEdge* e : it->edges) {
577  resultCand.back().edges.push_back(e->getID());
578  }
579  resultCand.back().travelTime = it->traveltime;
580  resultCand.back().cost = it->cost;
581  resultCand.back().length = it->length;
582  resultCand.back().intended = it->intended;
583  resultCand.back().depart = it->depart;
584  resultCand.back().departPos = it->departPos;
585  resultCand.back().arrivalPos = it->arrivalPos;
586  resultCand.back().description = it->description;
587  }
588  cost += it->cost;
589  }
590  if (cost < minCost) {
591  minCost = cost;
592  result = resultCand;
593  }
594  }
595  if (vehicle != nullptr) {
596  vehControl.deleteVehicle(vehicle, true);
597  }
598  }
599  return result;
600 }
601 
602 
603 std::string
604 Simulation::getParameter(const std::string& objectID, const std::string& key) {
605  if (StringUtils::startsWith(key, "chargingStation.")) {
606  const std::string attrName = key.substr(16);
608  if (cs == nullptr) {
609  throw TraCIException("Invalid chargingStation '" + objectID + "'");
610  }
611  if (attrName == toString(SUMO_ATTR_TOTALENERGYCHARGED)) {
612  return toString(cs->getTotalCharged());
613  } else if (attrName == toString(SUMO_ATTR_NAME)) {
614  return toString(cs->getMyName());
615  } else if (attrName == "lane") {
616  return cs->getLane().getID();
617  } else if (cs->knowsParameter(attrName)) {
618  return cs->getParameter(attrName);
619  } else {
620  throw TraCIException("Invalid chargingStation parameter '" + attrName + "'");
621  }
622  } else if (StringUtils::startsWith(key, "overheadWire.")) {
623  const std::string attrName = key.substr(16);
625  if (cs == 0) {
626  throw TraCIException("Invalid overhead wire '" + objectID + "'");
627  }
628  if (attrName == toString(SUMO_ATTR_TOTALENERGYCHARGED)) {
629  return toString(cs->getTotalCharged());
630  } else if (attrName == toString(SUMO_ATTR_NAME)) {
631  return toString(cs->getMyName());
632  } else {
633  throw TraCIException("Invalid overhead wire parameter '" + attrName + "'");
634  }
635  } else if (StringUtils::startsWith(key, "parkingArea.")) {
636  const std::string attrName = key.substr(12);
638  if (pa == nullptr) {
639  throw TraCIException("Invalid parkingArea '" + objectID + "'");
640  }
641  if (attrName == "capacity") {
642  return toString(pa->getCapacity());
643  } else if (attrName == "occupancy") {
645  } else if (attrName == toString(SUMO_ATTR_NAME)) {
646  return toString(pa->getMyName());
647  } else if (attrName == "lane") {
648  return pa->getLane().getID();
649  } else if (pa->knowsParameter(attrName)) {
650  return pa->getParameter(attrName);
651  } else {
652  throw TraCIException("Invalid parkingArea parameter '" + attrName + "'");
653  }
654  } else if (StringUtils::startsWith(key, "busStop.")) {
655  const std::string attrName = key.substr(8);
657  if (bs == nullptr) {
658  throw TraCIException("Invalid busStop '" + objectID + "'");
659  }
660  if (attrName == toString(SUMO_ATTR_NAME)) {
661  return toString(bs->getMyName());
662  } else if (attrName == "lane") {
663  return bs->getLane().getID();
664  } else if (bs->knowsParameter(attrName)) {
665  return bs->getParameter(attrName);
666  } else {
667  throw TraCIException("Invalid busStop parameter '" + attrName + "'");
668  }
669  } else {
670  throw TraCIException("Parameter '" + key + "' is not supported.");
671  }
672 }
673 
674 
676 
677 
678 void
679 Simulation::clearPending(const std::string& routeID) {
681 }
682 
683 
684 void
685 Simulation::saveState(const std::string& fileName) {
686  MSStateHandler::saveState(fileName, MSNet::getInstance()->getCurrentTimeStep());
687 }
688 
689 double
690 Simulation::loadState(const std::string& fileName) {
691  long before = PROGRESS_BEGIN_TIME_MESSAGE("Loading state from '" + fileName + "'");
692  // XXX reset transportable state
693  // load time only
694  MSStateHandler hTime(fileName, 0, true);
695  XMLSubSys::runParser(hTime, fileName);
696  const SUMOTime newTime = hTime.getTime();
697  // clean up state
698  MSNet::getInstance()->clearState(newTime);
699  // load state
700  MSStateHandler h(fileName, 0);
701  XMLSubSys::runParser(h, fileName);
702  if (MsgHandler::getErrorInstance()->wasInformed()) {
703  throw TraCIException("Loading state from '" + fileName + "' failed.");
704  }
706  PROGRESS_TIME_MESSAGE(before);
707  return STEPS2TIME(newTime);
708 }
709 
710 void
711 Simulation::writeMessage(const std::string& msg) {
712  WRITE_MESSAGE(msg);
713 }
714 
715 
716 std::shared_ptr<VariableWrapper>
718  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
719 }
720 
721 
722 bool
723 Simulation::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
724  switch (variable) {
725  case VAR_TIME:
726  return wrapper->wrapDouble(objID, variable, getTime());
727  case VAR_TIME_STEP:
728  return wrapper->wrapInt(objID, variable, (int)getCurrentTime());
730  return wrapper->wrapInt(objID, variable, getLoadedNumber());
732  return wrapper->wrapStringList(objID, variable, getLoadedIDList());
734  return wrapper->wrapInt(objID, variable, getDepartedNumber());
736  return wrapper->wrapStringList(objID, variable, getDepartedIDList());
738  return wrapper->wrapInt(objID, variable, getStartingTeleportNumber());
740  return wrapper->wrapStringList(objID, variable, getStartingTeleportIDList());
742  return wrapper->wrapInt(objID, variable, getEndingTeleportNumber());
744  return wrapper->wrapStringList(objID, variable, getEndingTeleportIDList());
746  return wrapper->wrapInt(objID, variable, getArrivedNumber());
748  return wrapper->wrapStringList(objID, variable, getArrivedIDList());
750  return wrapper->wrapInt(objID, variable, getParkingStartingVehiclesNumber());
752  return wrapper->wrapStringList(objID, variable, getParkingStartingVehiclesIDList());
754  return wrapper->wrapInt(objID, variable, getParkingEndingVehiclesNumber());
756  return wrapper->wrapStringList(objID, variable, getParkingEndingVehiclesIDList());
758  return wrapper->wrapInt(objID, variable, getStopStartingVehiclesNumber());
760  return wrapper->wrapStringList(objID, variable, getStopStartingVehiclesIDList());
762  return wrapper->wrapInt(objID, variable, getStopEndingVehiclesNumber());
764  return wrapper->wrapStringList(objID, variable, getStopEndingVehiclesIDList());
766  return wrapper->wrapInt(objID, variable, getCollidingVehiclesNumber());
768  return wrapper->wrapStringList(objID, variable, getCollidingVehiclesIDList());
770  return wrapper->wrapInt(objID, variable, getEmergencyStoppingVehiclesNumber());
772  return wrapper->wrapStringList(objID, variable, getEmergencyStoppingVehiclesIDList());
773  case VAR_DELTA_T:
774  return wrapper->wrapDouble(objID, variable, getDeltaT());
776  return wrapper->wrapInt(objID, variable, getMinExpectedNumber());
778  return wrapper->wrapInt(objID, variable, getBusStopWaiting(objID));
779  default:
780  return false;
781  }
782 }
783 }
784 
785 
786 /****************************************************************************/
static std::pair< int, std::string > getVersion()
return TraCI API and SUMO version
Definition: Simulation.cpp:134
Definition of overhead wire segment.
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:568
A lane area vehicles can halt at.
Definition: MSParkingArea.h:57
TRACI_CONST int VAR_MIN_EXPECTED_VEHICLES
bool compute(const E *from, const E *to, const double departPos, const double arrivalPos, const std::string stopID, const double speed, const V *const vehicle, const SVCPermissions modeSet, const SUMOTime msTime, std::vector< TripItem > &into, const double externalFactor=0.)
Builds the route between the given edges using the minimum effort at the given time The definition of...
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_NUMBER
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:230
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:129
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:54
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:123
static SubscriptionResults mySubscriptionResults
Definition: Simulation.h:139
static int getStopStartingVehiclesNumber()
Definition: Simulation.cpp:212
SUMOTime getTime() const
get time
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
virtual bool wrapInt(const std::string &objID, const int variable, const int value)=0
long long int SUMOTime
Definition: SUMOTime.h:31
#define PROGRESS_BEGIN_TIME_MESSAGE(msg)
Definition: MsgHandler.h:281
static void step(const double time=0.)
Advances by one step (or up to the given time)
Definition: Simulation.cpp:95
TRACI_CONST int VAR_TIME
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:365
static void close()
Closes the xml-subsystem.
Definition: XMLSubSys.cpp:120
void clearPendingVehicles(const std::string &route)
clears out all pending vehicles from a route, "" for all routes
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1174
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:133
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:87
TRACI_CONST int VAR_TIME_STEP
const Boundary & getConvBoundary() const
Returns the converted boundary.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
static void clearVehicleStates()
Definition: Helper.cpp:542
static std::vector< std::string > getParkingEndingVehiclesIDList()
Definition: Simulation.cpp:206
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1073
A lane area vehicles can halt at.
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_NUMBER
Parser and output filter for routes and vehicles state saving and loading.
static std::vector< TraCIStage > findIntermodalRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &modes="", double depart=-1., const int routingMode=0, double speed=-1., double walkFactor=-1., double departPos=0, double arrivalPos=INVALID_DOUBLE_VALUE, const double departPosLat=0, const std::string &pType="", const std::string &vType="", const std::string &destStop="")
Definition: Simulation.cpp:476
static double getDeltaT()
Definition: Simulation.cpp:313
int getActiveCount()
return the number of active transportable objects
static int getDepartedNumber()
Definition: Simulation.cpp:164
static std::vector< std::string > getEmergencyStoppingVehiclesIDList()
Definition: Simulation.cpp:254
double length
length in m
Definition: TraCIDefs.h:472
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:378
TRACI_CONST int VAR_LOADED_VEHICLES_NUMBER
vehicle is a bicycle
static void load(const std::vector< std::string > &args)
load a simulation with the given arguments
Definition: Simulation.cpp:71
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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.
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:228
const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
double zmax() const
Returns maximum z-coordinate.
Definition: Boundary.cpp:147
static std::vector< std::string > getDepartedIDList()
Definition: Simulation.cpp:170
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
static std::string getParameter(const std::string &objectID, const std::string &key)
Definition: Simulation.cpp:604
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static TraCIPosition convert2D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
Definition: Simulation.cpp:343
void setCurrentTimeStep(const SUMOTime step)
Sets the current simulation step (used by state loading)
Definition: MSNet.h:298
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:793
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:404
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
const std::string DEFAULT_BIKETYPE_ID
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:231
virtual SUMOVehicleClass getVClass() const =0
Returns the object&#39;s access class.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
const std::string & getID() const
Returns the id.
Definition: Named.h:73
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
bool hasNext()
returns the information whether further substrings exist
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
#define TS
Definition: SUMOTime.h:40
TRACI_CONST int VAR_DEPARTED_VEHICLES_IDS
static TraCIPosition convertGeo(double x, double y, bool fromGeo=false)
Definition: Simulation.cpp:386
double getLength() const
return the length of the edge
Definition: MSEdge.h:627
const std::string DEFAULT_VTYPE_ID
static void close()
Closes all of an applications subsystems.
const std::string & getMyName() const
static double getDrivingDistance(std::pair< const MSLane *, double > &roadPos1, std::pair< const MSLane *, double > &roadPos2)
Definition: Helper.cpp:453
double zmin() const
Returns minimum z-coordinate.
Definition: Boundary.cpp:141
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
double cost
effort needed
Definition: TraCIDefs.h:470
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
The simulated network and simulation perfomer.
Definition: MSNet.h:89
TRACI_CONST int VAR_BUS_STOP_WAITING
The car-following model and parameter.
Definition: MSVehicleType.h:62
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:58
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
#define SIMTIME
Definition: SUMOTime.h:60
MSIntermodalRouter & getIntermodalRouter(const int rngIndex, const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1212
static double loadState(const std::string &fileName)
quick-load simulation state from file and return the state time
Definition: Simulation.cpp:690
bool gSimulation
Definition: StdDefs.cpp:28
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:970
The vehicles starts to stop.
Definition: MSNet.h:582
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
Definition: Simulation.cpp:398
TRACI_CONST int VAR_ARRIVED_VEHICLES_NUMBER
A road/street connecting two junctions.
Definition: MSEdge.h:77
static TraCIStage findRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &vType="", const double depart=-1., const int routingMode=0)
Definition: Simulation.cpp:430
static int getParkingStartingVehiclesNumber()
Definition: Simulation.cpp:188
#define PROGRESS_TIME_MESSAGE(before)
Definition: MsgHandler.h:282
virtual bool hasValidRouteStart(std::string &msg)=0
checks wether the vehicle can depart on the first edge
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static const std::vector< std::string > & getVehicleStateChanges(const MSNet::VehicleState state)
Definition: Helper.cpp:536
virtual void setChosenSpeedFactor(const double factor)=0
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:574
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:148
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
The vehicles starts to park.
Definition: MSNet.h:578
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
The vehicle is involved in a collision.
Definition: MSNet.h:586
static double getTime()
Definition: Simulation.cpp:146
TRACI_CONST int CMD_SUBSCRIBE_SIM_VARIABLE
static bool hasInstance()
Returns whether the network was already constructed.
Definition: MSNet.h:141
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_IDS
Representation of a vehicle.
Definition: SUMOVehicle.h:58
static bool gCheckRoutes
Definition: MSGlobals.h:76
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Simulation.cpp:723
The vehicle had to brake harder than permitted.
Definition: MSNet.h:588
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:961
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
static std::vector< std::string > getLoadedIDList()
Definition: Simulation.cpp:158
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
static TraCIPositionVector getNetBoundary()
Definition: Simulation.cpp:319
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:466
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:348
std::vector< MSTransportable * > getTransportables() const
Returns the tranportables waiting on this stop.
bool hasContainers() const
Returns whether containers are simulated.
Definition: MSNet.h:381
int getCapacity() const
Returns the area capacity.
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
TRACI_CONST int ROUTING_MODE_AGGREGATED
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:290
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
TRACI_CONST int VAR_DELTA_T
static std::vector< std::string > getStopStartingVehiclesIDList()
Definition: Simulation.cpp:218
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:117
The vehicle started to teleport.
Definition: MSNet.h:570
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_IDS
static void clearSubscriptions()
Definition: Helper.cpp:228
static int getEndingTeleportNumber()
Definition: Simulation.cpp:272
static std::vector< std::string > getStopEndingVehiclesIDList()
Definition: Simulation.cpp:230
#define VERSION_STRING
Definition: version.h:1
static double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
Definition: Simulation.cpp:416
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition: Helper.cpp:421
static std::vector< std::string > getStartingTeleportIDList()
Definition: Simulation.cpp:266
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
The vehicle ends to park.
Definition: MSNet.h:580
static void saveState(const std::string &fileName)
Definition: Simulation.cpp:685
static MSNet * init(const bool isLibsumo=false)
Definition: NLBuilder.cpp:250
static void subscribe(const int commandId, const std::string &id, const std::vector< int > &variables, const double beginTime, const double endTime, const int contextDomain=0, const double range=0.)
Definition: Helper.cpp:137
static std::vector< std::string > getBusStopIDList()
Definition: Simulation.cpp:283
TRACI_CONST int VAR_DEPARTED_VEHICLES_NUMBER
const SUMOVTypeParameter & getParameter() const
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
vehicle is a passenger car (a "normal" car)
TRACI_CONST int STAGE_WALKING
virtual bool wrapDouble(const std::string &objID, const int variable, const double value)=0
static void subscribe(const std::vector< int > &varIDs=std::vector< int >(), double begin=INVALID_DOUBLE_VALUE, double end=INVALID_DOUBLE_VALUE)
Definition: Simulation.cpp:122
TRACI_CONST int TRACI_VERSION
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_IDS
The vehicle was built, but has not yet departed.
Definition: MSNet.h:566
static std::vector< std::string > getParkingStartingVehiclesIDList()
Definition: Simulation.cpp:194
void clearState(const SUMOTime step)
Resets events when quick-loading state.
Definition: MSNet.cpp:743
TRACI_CONST int VAR_COLLIDING_VEHICLES_IDS
static int getCollidingVehiclesNumber()
Definition: Simulation.cpp:236
vehicle is a bus
static int getBusStopWaiting(const std::string &id)
Definition: Simulation.cpp:292
static int getStartingTeleportNumber()
Definition: Simulation.cpp:260
int getOccupancyIncludingBlocked() const
Returns the area occupancy.
static void close(const std::string &reason="Libsumo requested termination.")
close simulation
Definition: Simulation.cpp:110
Structure representing possible vehicle parameter.
static const TraCIResults getSubscriptionResults()
Definition: Simulation.cpp:128
static std::vector< std::string > getEndingTeleportIDList()
Definition: Simulation.cpp:278
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:401
const std::string DEFAULT_PEDTYPE_ID
static std::vector< std::string > getBusStopWaitingIDList(const std::string &id)
Returns the IDs of the transportables on a given bus stop.
Definition: Simulation.cpp:301
int getPendingFlowCount() const
Returns the number of flows that are still active.
TRACI_CONST int VAR_LOADED_VEHICLES_IDS
static int getParkingEndingVehiclesNumber()
Definition: Simulation.cpp:200
static bool isLoaded()
return whether a simulation (network) is present
Definition: Simulation.cpp:89
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS
TRACI_CONST int VAR_COLLIDING_VEHICLES_NUMBER
TRACI_CONST int STAGE_DRIVING
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:468
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_NUMBER
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:503
static int getEmergencyStoppingVehiclesNumber()
Definition: Simulation.cpp:248
The vehicle ends to stop.
Definition: MSNet.h:584
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
static ContextSubscriptionResults myContextSubscriptionResults
Definition: Simulation.h:140
static int getArrivedNumber()
Definition: Simulation.cpp:176
static int getMinExpectedNumber()
Definition: Simulation.cpp:333
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation. ...
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:231
static std::vector< std::string > getCollidingVehiclesIDList()
Definition: Simulation.cpp:242
static void writeMessage(const std::string &msg)
Definition: Simulation.cpp:711
static TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false, const std::string &vClass="ignoring")
Definition: Simulation.cpp:364
static LIBSUMO_GET_PARAMETER_WITH_KEY_API void clearPending(const std::string &routeID="")
Definition: Simulation.cpp:679
The class responsible for building and deletion of vehicles.
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
Definition: MSEdge.h:591
double getTotalCharged() const
TRACI_CONST int VAR_ARRIVED_VEHICLES_IDS
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.
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:515
static void handleSubscriptions(const SUMOTime t)
Definition: Helper.cpp:178
const MSLane & getLane() const
Returns the lane this stop is located at.
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_IDS
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:135
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:278
A 3D-position.
Definition: TraCIDefs.h:121
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Simulation.cpp:717
TRACI_CONST double INVALID_DOUBLE_VALUE
An overhead wire segment.
static std::vector< std::string > getArrivedIDList()
Definition: Simulation.cpp:182
static int getLoadedNumber()
Definition: Simulation.cpp:152
static int getCurrentTime()
Definition: Simulation.cpp:140
const Distribution_Parameterized & getSpeedFactor() const
Returns this type&#39;s speed factor.
A list of positions.
The vehicle ended being teleported.
Definition: MSNet.h:572
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_IDS
vehicles ignoring classes
static TraCIPosition convert3D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
Definition: Simulation.cpp:354
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_IDS
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_NUMBER
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
double getTotalCharged() const
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.
std::string id
The vehicle&#39;s id.
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_NUMBER
static int getStopEndingVehiclesNumber()
Definition: Simulation.cpp:224
void setz(double z)
set position z
Definition: Position.h:79
void closeSimulation(SUMOTime start, const std::string &reason="")
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:480