Eclipse SUMO - Simulation of Urban MObility
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-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 // C++ TraCI client API implementation
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
25 #include <utils/common/StdDefs.h>
33 #include <utils/xml/XMLSubSys.h>
34 #include <microsim/MSNet.h>
35 #include <microsim/MSEdgeControl.h>
37 #include <microsim/MSEdge.h>
38 #include <microsim/MSLane.h>
39 #include <microsim/MSVehicle.h>
44 #include <microsim/MSParkingArea.h>
46 #include <netload/NLBuilder.h>
47 #include <libsumo/TraCIConstants.h>
48 #include "Simulation.h"
49 #include <libsumo/TraCIDefs.h>
50 
51 
52 namespace libsumo {
53 // ===========================================================================
54 // static member initializations
55 // ===========================================================================
58 
59 
60 // ===========================================================================
61 // static member definitions
62 // ===========================================================================
63 void
64 Simulation::load(const std::vector<std::string>& args) {
65  close();
67  OptionsIO::setArgs(args);
70 }
71 
72 
73 bool
75  return MSNet::hasInstance();
76 }
77 
78 
79 void
80 Simulation::step(const double time) {
82  const SUMOTime t = TIME2STEPS(time);
83  if (t == 0) {
85  } else {
86  while (MSNet::getInstance()->getCurrentTimeStep() < t) {
88  }
89  }
91 }
92 
93 
94 void
96  if (MSNet::hasInstance()) {
98  delete MSNet::getInstance();
101  }
102 }
103 
104 
106 
107 
108 void
109 Simulation::subscribe(const std::vector<int>& vars, double beginTime, double endTime) {
110  libsumo::Helper::subscribe(CMD_SUBSCRIBE_SIM_VARIABLE, "", vars, beginTime, endTime);
111 }
112 
113 
114 const TraCIResults
116  return mySubscriptionResults[""];
117 }
118 
119 
120 int
122  return (int)MSNet::getInstance()->getCurrentTimeStep();
123 }
124 
125 
126 double
128  return SIMTIME;
129 }
130 
131 
132 int
135 }
136 
137 
138 std::vector<std::string>
141 }
142 
143 
144 int
147 }
148 
149 
150 std::vector<std::string>
153 }
154 
155 
156 int
159 }
160 
161 
162 std::vector<std::string>
165 }
166 
167 
168 int
171 }
172 
173 
174 std::vector<std::string>
177 }
178 
179 
180 int
183 }
184 
185 
186 std::vector<std::string>
189 }
190 
191 
192 int
195 }
196 
197 
198 std::vector<std::string>
201 }
202 
203 
204 int
207 }
208 
209 
210 std::vector<std::string>
213 }
214 
215 
216 int
219 }
220 
221 
222 std::vector<std::string>
225 }
226 
227 
228 int
231 }
232 
233 
234 std::vector<std::string>
237 }
238 
239 
240 int
243 }
244 
245 
246 std::vector<std::string>
249 }
250 
251 
252 int
255 }
256 
257 
258 std::vector<std::string>
261 }
262 
263 std::vector<std::string>
265  std::vector<std::string> result;
266  for (const auto pair : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_BUS_STOP)) {
267  result.push_back(pair.first);
268  }
269  return result;
270 }
271 
272 int
273 Simulation::getBusStopWaiting(const std::string& id) {
275  if (s == nullptr) {
276  throw TraCIException("Unknown bus stop '" + id + "'.");
277  }
278  return s->getTransportableNumber();
279 }
280 
281 std::vector<std::string>
282 Simulation::getBusStopWaitingIDList(const std::string& id) {
284  std::vector<MSTransportable*> transportables = s->getTransportables();
285  std::vector<std::string> result;
286  for (std::vector<MSTransportable*>::iterator it = transportables.begin(); it != transportables.end(); it++) {
287  result.push_back((*it)->getID());
288  }
289  return result;
290 }
291 
292 
293 double
295  return TS;
296 }
297 
298 
303  tb[0].x = b.xmin();
304  tb[1].x = b.xmax();
305  tb[0].y = b.ymin();
306  tb[1].y = b.ymax();
307  tb[0].z = b.zmin();
308  tb[1].z = b.zmax();
309  return tb;
310 }
311 
312 
313 int
315  MSNet* net = MSNet::getInstance();
318  + (net->hasPersons() ? net->getPersonControl().getActiveCount() : 0)
319  + (net->hasContainers() ? net->getContainerControl().getActiveCount() : 0));
320 }
321 
322 
324 Simulation::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
325  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->geometryPositionAtOffset(pos);
326  if (toGeo) {
328  }
329  result.setz(0.);
330  return Helper::makeTraCIPosition(result);
331 }
332 
333 
335 Simulation::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
336  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->geometryPositionAtOffset(pos);
337  if (toGeo) {
339  }
340  return Helper::makeTraCIPosition(result, true);
341 }
342 
343 
345 Simulation::convertRoad(double x, double y, bool isGeo, const std::string& vClass) {
346  Position pos(x, y);
347  if (isGeo) {
349  }
350  if (!SumoVehicleClassStrings.hasString(vClass)) {
351  throw TraCIException("Unknown vehicle class '" + vClass + "'.");
352  }
353  const SUMOVehicleClass vc = SumoVehicleClassStrings.get(vClass);
354  std::pair<MSLane*, double> roadPos = libsumo::Helper::convertCartesianToRoadMap(pos, vc);
355  if (roadPos.first == nullptr) {
356  throw TraCIException("Cannot convert position to road.");
357  }
358  TraCIRoadPosition result;
359  result.edgeID = roadPos.first->getEdge().getID();
360  result.laneIndex = roadPos.first->getIndex();
361  result.pos = roadPos.second;
362  return result;
363 }
364 
365 
367 Simulation::convertGeo(double x, double y, bool fromGeo) {
368  Position pos(x, y);
369  if (fromGeo) {
371  } else {
373  }
374  return Helper::makeTraCIPosition(pos);
375 }
376 
377 
378 double
379 Simulation::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
380  Position pos1(x1, y1);
381  Position pos2(x2, y2);
382  if (isGeo) {
385  }
386  if (isDriving) {
387  std::pair<const MSLane*, double> roadPos1 = libsumo::Helper::convertCartesianToRoadMap(pos1, SVC_IGNORING);
388  std::pair<const MSLane*, double> roadPos2 = libsumo::Helper::convertCartesianToRoadMap(pos2, SVC_IGNORING);
389  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
390  // same edge
391  return roadPos2.second - roadPos1.second;
392  } else {
393  double distance = 0.;
394  ConstMSEdgeVector newRoute;
395  if (roadPos2.first->isInternal()) {
396  distance = roadPos2.second;
397  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
398  roadPos2.second = roadPos2.first->getLength();
399  }
401  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), nullptr, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
402  MSRoute route("", newRoute, false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
403  return distance + route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
404  }
405  } else {
406  return pos1.distanceTo(pos2);
407  }
408 }
409 
410 
411 double
412 Simulation::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
413  std::pair<const MSLane*, double> roadPos1 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID1, 0, pos1), pos1);
414  std::pair<const MSLane*, double> roadPos2 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID2, 0, pos2), pos2);
415  if (isDriving) {
416  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
417  // same edge
418  return roadPos2.second - roadPos1.second;
419  } else {
420  double distance = 0.;
421  ConstMSEdgeVector newRoute;
422  if (roadPos2.first->isInternal()) {
423  distance = roadPos2.second;
424  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
425  roadPos2.second = roadPos2.first->getLength();
426  }
428  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), nullptr, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
429  MSRoute route("", newRoute, false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
430  return distance + route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
431  }
432  } else {
433  const Position pos1 = roadPos1.first->geometryPositionAtOffset(roadPos1.second);
434  const Position pos2 = roadPos2.first->geometryPositionAtOffset(roadPos2.second);
435  return pos1.distanceTo(pos2);
436  }
437 }
438 
439 
441 Simulation::findRoute(const std::string& from, const std::string& to, const std::string& typeID, const double depart, const int routingMode) {
443  const MSEdge* const fromEdge = MSEdge::dictionary(from);
444  if (fromEdge == nullptr) {
445  throw TraCIException("Unknown from edge '" + from + "'.");
446  }
447  const MSEdge* const toEdge = MSEdge::dictionary(to);
448  if (toEdge == nullptr) {
449  throw TraCIException("Unknown to edge '" + from + "'.");
450  }
451  SUMOVehicle* vehicle = nullptr;
452  if (typeID != "") {
455  if (type == nullptr) {
456  throw TraCIException("The vehicle type '" + typeID + "' is not known.");
457  }
458  try {
459  const MSRoute* const routeDummy = new MSRoute("", ConstMSEdgeVector({ fromEdge }), false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
460  vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(pars, routeDummy, type, false);
461  // we need to fix the speed factor here for deterministic results
462  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
463  } catch (ProcessError& e) {
464  throw TraCIException("Invalid departure edge for vehicle type '" + typeID + "' (" + e.what() + ")");
465  }
466  }
467  ConstMSEdgeVector edges;
468  const SUMOTime dep = depart < 0 ? MSNet::getInstance()->getCurrentTimeStep() : TIME2STEPS(depart);
470  router.compute(fromEdge, toEdge, vehicle, dep, edges);
471  for (const MSEdge* e : edges) {
472  result.edges.push_back(e->getID());
473  }
474  result.travelTime = result.cost = router.recomputeCosts(edges, vehicle, dep, &result.length);
475  if (vehicle != nullptr) {
477  }
478  return result;
479 }
480 
481 
482 std::vector<TraCIStage>
483 Simulation::findIntermodalRoute(const std::string& from, const std::string& to,
484  const std::string& modes, double depart, const int routingMode, double speed, double walkFactor,
485  double departPos, double arrivalPos, const double departPosLat,
486  const std::string& pType, const std::string& vType, const std::string& destStop) {
487  UNUSED_PARAMETER(departPosLat);
488  std::vector<TraCIStage> result;
489  const MSEdge* const fromEdge = MSEdge::dictionary(from);
490  if (fromEdge == nullptr) {
491  throw TraCIException("Unknown from edge '" + from + "'.");
492  }
493  const MSEdge* const toEdge = MSEdge::dictionary(to);
494  if (toEdge == nullptr) {
495  throw TraCIException("Unknown to edge '" + to + "'.");
496  }
498  SVCPermissions modeSet = 0;
499  std::vector<SUMOVehicleParameter*> pars;
500  if (vType != "") {
501  pars.push_back(new SUMOVehicleParameter());
502  pars.back()->vtypeid = vType;
503  pars.back()->id = vType;
504  modeSet |= SVC_PASSENGER;
505  }
506  for (StringTokenizer st(modes); st.hasNext();) {
507  const std::string mode = st.next();
508  if (mode == toString(PERSONMODE_CAR)) {
509  pars.push_back(new SUMOVehicleParameter());
510  pars.back()->vtypeid = DEFAULT_VTYPE_ID;
511  pars.back()->id = mode;
512  modeSet |= SVC_PASSENGER;
513  } else if (mode == toString(PERSONMODE_BICYCLE)) {
514  pars.push_back(new SUMOVehicleParameter());
515  pars.back()->vtypeid = DEFAULT_BIKETYPE_ID;
516  pars.back()->id = mode;
517  modeSet |= SVC_BICYCLE;
518  } else if (mode == toString(PERSONMODE_PUBLIC)) {
519  pars.push_back(nullptr);
520  modeSet |= SVC_BUS;
521  } else if (mode == toString(PERSONMODE_WALK)) {
522  // do nothing
523  } else {
524  throw TraCIException("Unknown person mode '" + mode + "'.");
525  }
526  }
527  if (pars.empty()) {
528  pars.push_back(nullptr);
529  }
530  // interpret default arguments
531  const MSVehicleType* pedType = vehControl.hasVType(pType) ? vehControl.getVType(pType) : vehControl.getVType(DEFAULT_PEDTYPE_ID);
532  SUMOTime departStep = TIME2STEPS(depart);
533  if (depart < 0) {
534  departStep = MSNet::getInstance()->getCurrentTimeStep();
535  }
536  if (speed < 0) {
537  speed = pedType->getMaxSpeed();
538  }
539  if (walkFactor < 0) {
540  walkFactor = OptionsCont::getOptions().getFloat("persontrip.walkfactor");
541  }
542  const double externalFactor = StringUtils::toDouble(pedType->getParameter().getParameter("externalEffortFactor", "100"));
543  if (departPos < 0) {
544  departPos += fromEdge->getLength();
545  }
546  if (arrivalPos == INVALID_DOUBLE_VALUE) {
547  arrivalPos = toEdge->getLength() / 2;
548  } else if (arrivalPos < 0) {
549  arrivalPos += toEdge->getLength();
550  }
551  if (departPos < 0 || departPos >= fromEdge->getLength()) {
552  throw TraCIException("Invalid depart position " + toString(departPos) + " for edge '" + to + "'.");
553  }
554  if (arrivalPos < 0 || arrivalPos >= toEdge->getLength()) {
555  throw TraCIException("Invalid arrival position " + toString(arrivalPos) + " for edge '" + to + "'.");
556  }
557  double minCost = std::numeric_limits<double>::max();
559  for (SUMOVehicleParameter* vehPar : pars) {
560  std::vector<TraCIStage> resultCand;
561  SUMOVehicle* vehicle = nullptr;
562  if (vehPar != nullptr) {
563  MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(vehPar->vtypeid);
564  if (type == nullptr) {
565  throw TraCIException("Unknown vehicle type '" + vehPar->vtypeid + "'.");
566  }
567  if (type->getVehicleClass() != SVC_IGNORING && (fromEdge->getPermissions() & type->getVehicleClass()) == 0) {
568  WRITE_WARNING("Ignoring vehicle type '" + type->getID() + "' when performing intermodal routing because it is not allowed on the start edge '" + from + "'.");
569  } else {
570  const MSRoute* const routeDummy = new MSRoute(vehPar->id, ConstMSEdgeVector({ fromEdge }), false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
571  vehicle = vehControl.buildVehicle(vehPar, routeDummy, type, !MSGlobals::gCheckRoutes);
572  // we need to fix the speed factor here for deterministic results
573  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
574  }
575  }
576  std::vector<MSNet::MSIntermodalRouter::TripItem> items;
577  if (router.compute(fromEdge, toEdge, departPos, arrivalPos, destStop,
578  speed * walkFactor, vehicle, modeSet, departStep, items, externalFactor)) {
579  double cost = 0;
580  for (std::vector<MSNet::MSIntermodalRouter::TripItem>::iterator it = items.begin(); it != items.end(); ++it) {
581  if (!it->edges.empty()) {
582  resultCand.push_back(TraCIStage(it->line == ""
585  resultCand.back().vType = it->vType;
586  resultCand.back().line = it->line;
587  resultCand.back().destStop = it->destStop;
588  for (const MSEdge* e : it->edges) {
589  resultCand.back().edges.push_back(e->getID());
590  }
591  resultCand.back().travelTime = it->traveltime;
592  resultCand.back().cost = it->cost;
593  resultCand.back().length = it->length;
594  resultCand.back().intended = it->intended;
595  resultCand.back().depart = it->depart;
596  resultCand.back().departPos = it->departPos;
597  resultCand.back().arrivalPos = it->arrivalPos;
598  resultCand.back().description = it->description;
599  }
600  cost += it->cost;
601  }
602  if (cost < minCost) {
603  minCost = cost;
604  result = resultCand;
605  }
606  }
607  if (vehicle != nullptr) {
608  vehControl.deleteVehicle(vehicle, true);
609  }
610  }
611  return result;
612 }
613 
614 
615 std::string
616 Simulation::getParameter(const std::string& objectID, const std::string& key) {
617  if (StringUtils::startsWith(key, "chargingStation.")) {
618  const std::string attrName = key.substr(16);
620  if (cs == nullptr) {
621  throw TraCIException("Invalid chargingStation '" + objectID + "'");
622  }
623  if (attrName == toString(SUMO_ATTR_TOTALENERGYCHARGED)) {
624  return toString(cs->getTotalCharged());
625  } else if (attrName == toString(SUMO_ATTR_NAME)) {
626  return toString(cs->getMyName());
627  } else if (attrName == "lane") {
628  return cs->getLane().getID();
629  } else if (cs->knowsParameter(attrName)) {
630  return cs->getParameter(attrName);
631  } else {
632  throw TraCIException("Invalid chargingStation parameter '" + attrName + "'");
633  }
634  } else if (StringUtils::startsWith(key, "parkingArea.")) {
635  const std::string attrName = key.substr(12);
637  if (pa == nullptr) {
638  throw TraCIException("Invalid parkingArea '" + objectID + "'");
639  }
640  if (attrName == "capacity") {
641  return toString(pa->getCapacity());
642  } else if (attrName == "occupancy") {
644  } else if (attrName == toString(SUMO_ATTR_NAME)) {
645  return toString(pa->getMyName());
646  } else if (attrName == "lane") {
647  return pa->getLane().getID();
648  } else if (pa->knowsParameter(attrName)) {
649  return pa->getParameter(attrName);
650  } else {
651  throw TraCIException("Invalid parkingArea parameter '" + attrName + "'");
652  }
653  } else if (StringUtils::startsWith(key, "busStop.")) {
654  const std::string attrName = key.substr(8);
656  if (bs == nullptr) {
657  throw TraCIException("Invalid busStop '" + objectID + "'");
658  }
659  if (attrName == toString(SUMO_ATTR_NAME)) {
660  return toString(bs->getMyName());
661  } else if (attrName == "lane") {
662  return bs->getLane().getID();
663  } else if (bs->knowsParameter(attrName)) {
664  return bs->getParameter(attrName);
665  } else {
666  throw TraCIException("Invalid busStop parameter '" + attrName + "'");
667  }
668  } else {
669  throw TraCIException("Parameter '" + key + "' is not supported.");
670  }
671 }
672 
673 
674 void
675 Simulation::clearPending(const std::string& routeID) {
677 }
678 
679 
680 void
681 Simulation::saveState(const std::string& fileName) {
682  MSStateHandler::saveState(fileName, MSNet::getInstance()->getCurrentTimeStep());
683 }
684 
685 
686 std::shared_ptr<VariableWrapper>
688  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
689 }
690 
691 
692 bool
693 Simulation::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
694  switch (variable) {
695  case VAR_TIME:
696  return wrapper->wrapDouble(objID, variable, getTime());
697  case VAR_TIME_STEP:
698  return wrapper->wrapInt(objID, variable, (int)getCurrentTime());
700  return wrapper->wrapInt(objID, variable, getLoadedNumber());
702  return wrapper->wrapStringList(objID, variable, getLoadedIDList());
704  return wrapper->wrapInt(objID, variable, getDepartedNumber());
706  return wrapper->wrapStringList(objID, variable, getDepartedIDList());
708  return wrapper->wrapInt(objID, variable, getStartingTeleportNumber());
710  return wrapper->wrapStringList(objID, variable, getStartingTeleportIDList());
712  return wrapper->wrapInt(objID, variable, getEndingTeleportNumber());
714  return wrapper->wrapStringList(objID, variable, getEndingTeleportIDList());
716  return wrapper->wrapInt(objID, variable, getArrivedNumber());
718  return wrapper->wrapStringList(objID, variable, getArrivedIDList());
720  return wrapper->wrapInt(objID, variable, getParkingStartingVehiclesNumber());
722  return wrapper->wrapStringList(objID, variable, getParkingStartingVehiclesIDList());
724  return wrapper->wrapInt(objID, variable, getParkingEndingVehiclesNumber());
726  return wrapper->wrapStringList(objID, variable, getParkingEndingVehiclesIDList());
728  return wrapper->wrapInt(objID, variable, getStopStartingVehiclesNumber());
730  return wrapper->wrapStringList(objID, variable, getStopStartingVehiclesIDList());
732  return wrapper->wrapInt(objID, variable, getStopEndingVehiclesNumber());
734  return wrapper->wrapStringList(objID, variable, getStopEndingVehiclesIDList());
736  return wrapper->wrapInt(objID, variable, getCollidingVehiclesNumber());
738  return wrapper->wrapStringList(objID, variable, getCollidingVehiclesIDList());
740  return wrapper->wrapInt(objID, variable, getEmergencyStoppingVehiclesNumber());
742  return wrapper->wrapStringList(objID, variable, getEmergencyStoppingVehiclesIDList());
743  case VAR_DELTA_T:
744  return wrapper->wrapDouble(objID, variable, getDeltaT());
746  return wrapper->wrapInt(objID, variable, getMinExpectedNumber());
748  return wrapper->wrapInt(objID, variable, getBusStopWaiting(objID));
749  default:
750  return false;
751  }
752 }
753 
754 
755 }
756 
757 
758 /****************************************************************************/
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:540
A lane area vehicles can halt at.
Definition: MSParkingArea.h:59
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:204
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:131
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:125
static SubscriptionResults mySubscriptionResults
Definition: Simulation.h:136
static int getStopStartingVehiclesNumber()
Definition: Simulation.cpp:193
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:35
static void step(const double time=0.)
Advances by one step (or up to the given time)
Definition: Simulation.cpp:80
TRACI_CONST int VAR_TIME
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:354
static void close()
Closes the xml-subsystem.
Definition: XMLSubSys.cpp:91
void clearPendingVehicles(const std::string &route)
clears out all pending vehicles from a route, "" for all routes
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:122
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:384
static std::vector< std::string > getParkingEndingVehiclesIDList()
Definition: Simulation.cpp:187
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:899
A lane area vehicles can halt at.
static void registerVehicleStateListener()
Definition: Helper.cpp:370
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_NUMBER
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:483
static double getDeltaT()
Definition: Simulation.cpp:294
int getActiveCount()
return the number of active transportable objects
static int getDepartedNumber()
Definition: Simulation.cpp:145
static std::vector< std::string > getEmergencyStoppingVehiclesIDList()
Definition: Simulation.cpp:235
double length
length in m
Definition: TraCIDefs.h:364
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:264
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:64
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:202
MSIntermodalRouter & getIntermodalRouter(const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:995
double zmax() const
Returns maximum z-coordinate.
Definition: Boundary.cpp:149
static std::vector< std::string > getDepartedIDList()
Definition: Simulation.cpp:151
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
static std::string getParameter(const std::string &objectID, const std::string &key)
Definition: Simulation.cpp:616
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:324
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:804
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:290
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:205
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
const std::string & getID() const
Returns the id.
Definition: Named.h:77
#define TIME2STEPS(x)
Definition: SUMOTime.h:59
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
bool hasNext()
returns the information whether further substrings exist
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
#define TS
Definition: SUMOTime.h:44
TRACI_CONST int VAR_DEPARTED_VEHICLES_IDS
static TraCIPosition convertGeo(double x, double y, bool fromGeo=false)
Definition: Simulation.cpp:367
double getLength() const
return the length of the edge
Definition: MSEdge.h:582
const std::string DEFAULT_VTYPE_ID
static void close()
Closes all of an applications subsystems.
const std::string & getMyName() const
double zmin() const
Returns minimum z-coordinate.
Definition: Boundary.cpp:143
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
double cost
effort needed
Definition: TraCIDefs.h:362
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
The simulated network and simulation perfomer.
Definition: MSNet.h:92
TRACI_CONST int VAR_BUS_STOP_WAITING
The car-following model and parameter.
Definition: MSVehicleType.h:66
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
#define SIMTIME
Definition: SUMOTime.h:64
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:806
The vehicles starts to stop.
Definition: MSNet.h:554
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:379
TRACI_CONST int VAR_ARRIVED_VEHICLES_NUMBER
A road/street connecting two junctions.
Definition: MSEdge.h:76
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:441
static int getParkingStartingVehiclesNumber()
Definition: Simulation.cpp:169
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:378
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:546
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
The vehicles starts to park.
Definition: MSNet.h:550
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
The vehicle is involved in a collision.
Definition: MSNet.h:558
static double getTime()
Definition: Simulation.cpp:127
TRACI_CONST int CMD_SUBSCRIBE_SIM_VARIABLE
static bool hasInstance()
Returns whether the network was already constructed.
Definition: MSNet.h:144
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_IDS
Representation of a vehicle.
Definition: SUMOVehicle.h:61
static bool gCheckRoutes
Definition: MSGlobals.h:79
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Simulation.cpp:693
The vehicle had to brake harder than permitted.
Definition: MSNet.h:560
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:798
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:139
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:436
static TraCIPositionVector getNetBoundary()
Definition: Simulation.cpp:300
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:358
static LIBSUMO_SUBSCRIPTION_API void subscribe(const std::vector< int > &vars=std::vector< int >(), double beginTime=INVALID_DOUBLE_VALUE, double endTime=INVALID_DOUBLE_VALUE)
Definition: Simulation.cpp:109
static void close()
close simulation
Definition: Simulation.cpp:95
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
std::vector< MSTransportable * > getTransportables() const
Returns the tranportables waiting on this stop.
bool hasContainers() const
Returns whether containers are simulated.
Definition: MSNet.h:370
int getCapacity() const
Returns the area capacity.
TRACI_CONST int ROUTING_MODE_AGGREGATED
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:284
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...
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:199
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:119
The vehicle started to teleport.
Definition: MSNet.h:542
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_IDS
static int getEndingTeleportNumber()
Definition: Simulation.cpp:253
static std::vector< std::string > getStopEndingVehiclesIDList()
Definition: Simulation.cpp:211
static double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
Definition: Simulation.cpp:412
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition: Helper.cpp:307
static std::vector< std::string > getStartingTeleportIDList()
Definition: Simulation.cpp:247
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:51
The vehicle ends to park.
Definition: MSNet.h:552
static void saveState(const std::string &fileName)
Definition: Simulation.cpp:681
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:121
static std::vector< std::string > getBusStopIDList()
Definition: Simulation.cpp:264
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)
Definition: Edge.cpp:30
virtual bool wrapDouble(const std::string &objID, const int variable, const double value)=0
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_IDS
The vehicle was built, but has not yet departed.
Definition: MSNet.h:538
static std::vector< std::string > getParkingStartingVehiclesIDList()
Definition: Simulation.cpp:175
TRACI_CONST int VAR_COLLIDING_VEHICLES_IDS
static int getCollidingVehiclesNumber()
Definition: Simulation.cpp:217
vehicle is a bus
static int getBusStopWaiting(const std::string &id)
Definition: Simulation.cpp:273
static int getStartingTeleportNumber()
Definition: Simulation.cpp:241
int getOccupancyIncludingBlocked() const
Returns the area occupancy.
Structure representing possible vehicle parameter.
static const TraCIResults getSubscriptionResults()
Definition: Simulation.cpp:115
static std::vector< std::string > getEndingTeleportIDList()
Definition: Simulation.cpp:259
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:390
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:282
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:181
static bool isLoaded()
return whether a simulation (network) is present
Definition: Simulation.cpp:74
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS
TRACI_CONST int VAR_COLLIDING_VEHICLES_NUMBER
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:360
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_NUMBER
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
static int getEmergencyStoppingVehiclesNumber()
Definition: Simulation.cpp:229
The vehicle ends to stop.
Definition: MSNet.h:556
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
static ContextSubscriptionResults myContextSubscriptionResults
Definition: Simulation.h:137
static int getArrivedNumber()
Definition: Simulation.cpp:157
static int getMinExpectedNumber()
Definition: Simulation.cpp:314
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:234
static std::vector< std::string > getCollidingVehiclesIDList()
Definition: Simulation.cpp:223
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:954
static TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false, const std::string &vClass="ignoring")
Definition: Simulation.cpp:345
static void clearPending(const std::string &routeID="")
Definition: Simulation.cpp:675
The class responsible for building and deletion of vehicles.
SVCPermissions getPermissions() const
Definition: MSEdge.h:546
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:457
static void handleSubscriptions(const SUMOTime t)
Definition: Helper.cpp:133
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
static MSNet * init()
Definition: NLBuilder.cpp:220
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:137
A 3D-position.
Definition: TraCIDefs.h:110
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Simulation.cpp:687
TRACI_CONST double INVALID_DOUBLE_VALUE
static std::vector< std::string > getArrivedIDList()
Definition: Simulation.cpp:163
static int getLoadedNumber()
Definition: Simulation.cpp:133
static int getCurrentTime()
Definition: Simulation.cpp:121
const Distribution_Parameterized & getSpeedFactor() const
Returns this type&#39;s speed factor.
A list of positions.
The vehicle ended being teleported.
Definition: MSNet.h:544
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:335
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.
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_NUMBER
static int getStopEndingVehiclesNumber()
Definition: Simulation.cpp:205
void setz(double z)
set position z
Definition: Position.h:82
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:277