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-2018 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>
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 
264 int
265 Simulation::getBusStopWaiting(const std::string& id) {
267  if (s == nullptr) {
268  throw TraCIException("Unknown bus stop '" + id + "'.");
269  }
270  return s->getTransportableNumber();
271 }
272 
273 
274 double
276  return TS;
277 }
278 
279 
284  tb[0].x = b.xmin();
285  tb[1].x = b.xmax();
286  tb[0].y = b.ymin();
287  tb[1].y = b.ymax();
288  tb[0].z = b.zmin();
289  tb[1].z = b.zmax();
290  return tb;
291 }
292 
293 
294 int
296  MSNet* net = MSNet::getInstance();
299  + (net->hasPersons() ? net->getPersonControl().getActiveCount() : 0)
300  + (net->hasContainers() ? net->getContainerControl().getActiveCount() : 0));
301 }
302 
303 
305 Simulation::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
306  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->getShape().positionAtOffset(pos);
307  if (toGeo) {
309  }
310  result.setz(0.);
311  return Helper::makeTraCIPosition(result);
312 }
313 
314 
316 Simulation::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
317  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->getShape().positionAtOffset(pos);
318  if (toGeo) {
320  }
321  return Helper::makeTraCIPosition(result, true);
322 }
323 
324 
326 Simulation::convertRoad(double x, double y, bool isGeo) {
327  Position pos(x, y);
328  if (isGeo) {
330  }
331  std::pair<MSLane*, double> roadPos = libsumo::Helper::convertCartesianToRoadMap(pos);
332  if (roadPos.first == nullptr) {
333  throw TraCIException("Cannot convert position to road.");
334  }
335  TraCIRoadPosition result;
336  result.edgeID = roadPos.first->getEdge().getID();
337  result.laneIndex = roadPos.first->getIndex();
338  result.pos = roadPos.second;
339  return result;
340 }
341 
342 
344 Simulation::convertGeo(double x, double y, bool fromGeo) {
345  Position pos(x, y);
346  if (fromGeo) {
348  } else {
350  }
351  return Helper::makeTraCIPosition(pos);
352 }
353 
354 
355 double
356 Simulation::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
357  Position pos1(x1, y1);
358  Position pos2(x2, y2);
359  if (isGeo) {
362  }
363  if (isDriving) {
364  std::pair<const MSLane*, double> roadPos1 = libsumo::Helper::convertCartesianToRoadMap(pos1);
365  std::pair<const MSLane*, double> roadPos2 = libsumo::Helper::convertCartesianToRoadMap(pos2);
366  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
367  // same edge
368  return roadPos2.second - roadPos1.second;
369  } else {
370  double distance = 0.;
371  ConstMSEdgeVector newRoute;
372  if (roadPos2.first->isInternal()) {
373  distance = roadPos2.second;
374  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
375  roadPos2.second = roadPos2.first->getLength();
376  }
378  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), nullptr, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
379  MSRoute route("", newRoute, false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
380  return distance + route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
381  }
382  } else {
383  return pos1.distanceTo(pos2);
384  }
385 }
386 
387 
388 double
389 Simulation::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
390  std::pair<const MSLane*, double> roadPos1 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID1, 0, pos1), pos1);
391  std::pair<const MSLane*, double> roadPos2 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID2, 0, pos2), pos2);
392  if (isDriving) {
393  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
394  // same edge
395  return roadPos2.second - roadPos1.second;
396  } else {
397  double distance = 0.;
398  ConstMSEdgeVector newRoute;
399  if (roadPos2.first->isInternal()) {
400  distance = roadPos2.second;
401  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
402  roadPos2.second = roadPos2.first->getLength();
403  }
405  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), nullptr, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
406  MSRoute route("", newRoute, false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
407  return distance + route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
408  }
409  } else {
410  Position pos1 = roadPos1.first->getShape().positionAtOffset(roadPos1.second);
411  Position pos2 = roadPos2.first->getShape().positionAtOffset(roadPos2.second);
412  return pos1.distanceTo(pos2);
413  }
414 }
415 
416 
418 Simulation::findRoute(const std::string& from, const std::string& to, const std::string& typeID, const double depart, const int routingMode) {
420  const MSEdge* const fromEdge = MSEdge::dictionary(from);
421  if (fromEdge == nullptr) {
422  throw TraCIException("Unknown from edge '" + from + "'.");
423  }
424  const MSEdge* const toEdge = MSEdge::dictionary(to);
425  if (toEdge == nullptr) {
426  throw TraCIException("Unknown to edge '" + from + "'.");
427  }
428  SUMOVehicle* vehicle = nullptr;
429  if (typeID != "") {
432  if (type == nullptr) {
433  throw TraCIException("The vehicle type '" + typeID + "' is not known.");
434  }
435  try {
436  const MSRoute* const routeDummy = new MSRoute("", ConstMSEdgeVector({ fromEdge }), false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
437  vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(pars, routeDummy, type, false);
438  // we need to fix the speed factor here for deterministic results
439  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
440  } catch (ProcessError& e) {
441  throw TraCIException("Invalid departure edge for vehicle type '" + typeID + "' (" + e.what() + ")");
442  }
443  }
444  ConstMSEdgeVector edges;
445  const SUMOTime dep = depart < 0 ? MSNet::getInstance()->getCurrentTimeStep() : TIME2STEPS(depart);
447  router.compute(fromEdge, toEdge, vehicle, dep, edges);
448  for (const MSEdge* e : edges) {
449  result.edges.push_back(e->getID());
450  }
451  result.travelTime = result.cost = router.recomputeCosts(edges, vehicle, dep);
452  if (vehicle != nullptr) {
454  }
455  return result;
456 }
457 
458 
459 std::vector<TraCIStage>
460 Simulation::findIntermodalRoute(const std::string& from, const std::string& to,
461  const std::string& modes, double depart, const int routingMode, double speed, double walkFactor,
462  double departPos, double arrivalPos, const double departPosLat,
463  const std::string& pType, const std::string& vType, const std::string& destStop) {
464  UNUSED_PARAMETER(departPosLat);
465  std::vector<TraCIStage> result;
466  const MSEdge* const fromEdge = MSEdge::dictionary(from);
467  if (fromEdge == nullptr) {
468  throw TraCIException("Unknown from edge '" + from + "'.");
469  }
470  const MSEdge* const toEdge = MSEdge::dictionary(to);
471  if (toEdge == nullptr) {
472  throw TraCIException("Unknown to edge '" + to + "'.");
473  }
475  SVCPermissions modeSet = 0;
476  std::vector<SUMOVehicleParameter*> pars;
477  if (vType != "") {
478  pars.push_back(new SUMOVehicleParameter());
479  pars.back()->vtypeid = vType;
480  pars.back()->id = vType;
481  modeSet |= SVC_PASSENGER;
482  }
483  for (StringTokenizer st(modes); st.hasNext();) {
484  const std::string mode = st.next();
485  if (mode == "car") {
486  pars.push_back(new SUMOVehicleParameter());
487  pars.back()->vtypeid = DEFAULT_VTYPE_ID;
488  pars.back()->id = mode;
489  modeSet |= SVC_PASSENGER;
490  } else if (mode == "bicycle") {
491  pars.push_back(new SUMOVehicleParameter());
492  pars.back()->vtypeid = DEFAULT_BIKETYPE_ID;
493  pars.back()->id = mode;
494  modeSet |= SVC_BICYCLE;
495  } else if (mode == "public") {
496  pars.push_back(nullptr);
497  modeSet |= SVC_BUS;
498  } else {
499  throw TraCIException("Unknown person mode '" + mode + "'.");
500  }
501  }
502  if (pars.empty()) {
503  pars.push_back(nullptr);
504  }
505  // interpret default arguments
506  const MSVehicleType* pedType = vehControl.hasVType(pType) ? vehControl.getVType(pType) : vehControl.getVType(DEFAULT_PEDTYPE_ID);
507  SUMOTime departStep = TIME2STEPS(depart);
508  if (depart < 0) {
509  departStep = MSNet::getInstance()->getCurrentTimeStep();
510  }
511  if (speed < 0) {
512  speed = pedType->getMaxSpeed();
513  }
514  if (walkFactor < 0) {
515  walkFactor = OptionsCont::getOptions().getFloat("persontrip.walkfactor");
516  }
517  const double externalFactor = StringUtils::toDouble(pedType->getParameter().getParameter("externalEffortFactor", "1.0"));
518  if (departPos < 0) {
519  departPos += fromEdge->getLength();
520  }
521  if (arrivalPos == INVALID_DOUBLE_VALUE) {
522  arrivalPos = toEdge->getLength() / 2;
523  } else if (arrivalPos < 0) {
524  arrivalPos += toEdge->getLength();
525  }
526  if (departPos < 0 || departPos >= fromEdge->getLength()) {
527  throw TraCIException("Invalid depart position " + toString(departPos) + " for edge '" + to + "'.");
528  }
529  if (arrivalPos < 0 || arrivalPos >= toEdge->getLength()) {
530  throw TraCIException("Invalid arrival position " + toString(arrivalPos) + " for edge '" + to + "'.");
531  }
532  double minCost = std::numeric_limits<double>::max();
534  for (SUMOVehicleParameter* vehPar : pars) {
535  std::vector<TraCIStage> resultCand;
536  SUMOVehicle* vehicle = nullptr;
537  if (vehPar != nullptr) {
538  MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(vehPar->vtypeid);
539  if (type == nullptr) {
540  throw TraCIException("Unknown vehicle type '" + vehPar->vtypeid + "'.");
541  }
542  if (type->getVehicleClass() != SVC_IGNORING && (fromEdge->getPermissions() & type->getVehicleClass()) == 0) {
543  WRITE_WARNING("Ignoring vehicle type '" + type->getID() + "' when performing intermodal routing because it is not allowed on the start edge '" + from + "'.");
544  } else {
545  const MSRoute* const routeDummy = new MSRoute(vehPar->id, ConstMSEdgeVector({ fromEdge }), false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
546  vehicle = vehControl.buildVehicle(vehPar, routeDummy, type, !MSGlobals::gCheckRoutes);
547  // we need to fix the speed factor here for deterministic results
548  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
549  }
550  }
551  std::vector<MSNet::MSIntermodalRouter::TripItem> items;
552  if (router.compute(fromEdge, toEdge, departPos, arrivalPos, destStop,
553  speed * walkFactor, vehicle, modeSet, departStep, items, externalFactor)) {
554  double cost = 0;
555  for (std::vector<MSNet::MSIntermodalRouter::TripItem>::iterator it = items.begin(); it != items.end(); ++it) {
556  if (!it->edges.empty()) {
557  resultCand.push_back(TraCIStage(it->line == ""
560  resultCand.back().vType = it->vType;
561  resultCand.back().line = it->line;
562  resultCand.back().destStop = it->destStop;
563  for (const MSEdge* e : it->edges) {
564  resultCand.back().edges.push_back(e->getID());
565  }
566  resultCand.back().travelTime = it->traveltime;
567  resultCand.back().cost = it->cost;
568  resultCand.back().length = it->length;
569  resultCand.back().intended = it->intended;
570  resultCand.back().depart = it->depart;
571  resultCand.back().departPos = it->departPos;
572  resultCand.back().arrivalPos = it->arrivalPos;
573  resultCand.back().description = it->description;
574  }
575  cost += it->cost;
576  }
577  if (cost < minCost) {
578  minCost = cost;
579  result = resultCand;
580  }
581  }
582  if (vehicle != nullptr) {
583  vehControl.deleteVehicle(vehicle, true);
584  }
585  }
586  return result;
587 }
588 
589 
590 std::string
591 Simulation::getParameter(const std::string& objectID, const std::string& key) {
592  if (StringUtils::startsWith(key, "chargingStation.")) {
593  const std::string attrName = key.substr(16);
595  if (cs == nullptr) {
596  throw TraCIException("Invalid chargingStation '" + objectID + "'");
597  }
598  if (attrName == toString(SUMO_ATTR_TOTALENERGYCHARGED)) {
599  return toString(cs->getTotalCharged());
600  } else if (attrName == toString(SUMO_ATTR_NAME)) {
601  return toString(cs->getMyName());
602  } else {
603  throw TraCIException("Invalid chargingStation parameter '" + attrName + "'");
604  }
605  } else if (StringUtils::startsWith(key, "parkingArea.")) {
606  const std::string attrName = key.substr(12);
608  if (pa == nullptr) {
609  throw TraCIException("Invalid parkingArea '" + objectID + "'");
610  }
611  if (attrName == "capacity") {
612  return toString(pa->getCapacity());
613  } else if (attrName == "occupancy") {
614  return toString(pa->getOccupancy());
615  } else if (attrName == toString(SUMO_ATTR_NAME)) {
616  return toString(pa->getMyName());
617  } else {
618  throw TraCIException("Invalid parkingArea parameter '" + attrName + "'");
619  }
620  } else if (StringUtils::startsWith(key, "busStop.")) {
621  const std::string attrName = key.substr(8);
623  if (bs == nullptr) {
624  throw TraCIException("Invalid busStop '" + objectID + "'");
625  }
626  if (attrName == toString(SUMO_ATTR_NAME)) {
627  return toString(bs->getMyName());
628  } else {
629  throw TraCIException("Invalid busStop parameter '" + attrName + "'");
630  }
631  } else {
632  throw TraCIException("Parameter '" + key + "' is not supported.");
633  }
634 }
635 
636 
637 void
638 Simulation::clearPending(const std::string& routeID) {
640 }
641 
642 
643 void
644 Simulation::saveState(const std::string& fileName) {
645  MSStateHandler::saveState(fileName, MSNet::getInstance()->getCurrentTimeStep());
646 }
647 
648 
649 std::shared_ptr<VariableWrapper>
651  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
652 }
653 
654 
655 bool
656 Simulation::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
657  switch (variable) {
658  case VAR_TIME:
659  return wrapper->wrapDouble(objID, variable, getTime());
660  case VAR_TIME_STEP:
661  return wrapper->wrapInt(objID, variable, (int)getCurrentTime());
663  return wrapper->wrapInt(objID, variable, getLoadedNumber());
665  return wrapper->wrapStringList(objID, variable, getLoadedIDList());
667  return wrapper->wrapInt(objID, variable, getDepartedNumber());
669  return wrapper->wrapStringList(objID, variable, getDepartedIDList());
671  return wrapper->wrapInt(objID, variable, getStartingTeleportNumber());
673  return wrapper->wrapStringList(objID, variable, getStartingTeleportIDList());
675  return wrapper->wrapInt(objID, variable, getEndingTeleportNumber());
677  return wrapper->wrapStringList(objID, variable, getEndingTeleportIDList());
679  return wrapper->wrapInt(objID, variable, getArrivedNumber());
681  return wrapper->wrapStringList(objID, variable, getArrivedIDList());
683  return wrapper->wrapInt(objID, variable, getParkingStartingVehiclesNumber());
685  return wrapper->wrapStringList(objID, variable, getParkingStartingVehiclesIDList());
687  return wrapper->wrapInt(objID, variable, getParkingEndingVehiclesNumber());
689  return wrapper->wrapStringList(objID, variable, getParkingEndingVehiclesIDList());
691  return wrapper->wrapInt(objID, variable, getStopStartingVehiclesNumber());
693  return wrapper->wrapStringList(objID, variable, getStopStartingVehiclesIDList());
695  return wrapper->wrapInt(objID, variable, getStopEndingVehiclesNumber());
697  return wrapper->wrapStringList(objID, variable, getStopEndingVehiclesIDList());
699  return wrapper->wrapInt(objID, variable, getCollidingVehiclesNumber());
701  return wrapper->wrapStringList(objID, variable, getCollidingVehiclesIDList());
703  return wrapper->wrapInt(objID, variable, getEmergencyStoppingVehiclesNumber());
705  return wrapper->wrapStringList(objID, variable, getEmergencyStoppingVehiclesIDList());
706  case VAR_DELTA_T:
707  return wrapper->wrapDouble(objID, variable, getDeltaT());
709  return wrapper->wrapInt(objID, variable, getMinExpectedNumber());
711  return wrapper->wrapInt(objID, variable, getBusStopWaiting(objID));
712  default:
713  return false;
714  }
715 }
716 
717 
718 }
719 
720 
721 /****************************************************************************/
#define VAR_COLLIDING_VEHICLES_NUMBER
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:498
A lane area vehicles can halt at.
Definition: MSParkingArea.h:59
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...
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:131
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
#define VAR_TIME_STEP
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:125
static SubscriptionResults mySubscriptionResults
Definition: Simulation.h:130
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:36
static void step(const double time=0.)
Advances by one step (or up to the given time)
Definition: Simulation.cpp:80
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:333
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
static std::pair< MSLane *, double > convertCartesianToRoadMap(Position pos)
Definition: Helper.cpp:290
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:119
#define VAR_TIME
const Boundary & getConvBoundary() const
Returns the converted boundary.
static void clearVehicleStates()
Definition: Helper.cpp:337
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:869
A lane area vehicles can halt at.
static void registerVehicleStateListener()
Definition: Helper.cpp:325
#define VAR_PARKING_STARTING_VEHICLES_IDS
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:460
static double getDeltaT()
Definition: Simulation.cpp:275
#define VAR_STOP_ENDING_VEHICLES_IDS
int getActiveCount()
return the number of active transportable objects
static int getDepartedNumber()
Definition: Simulation.cpp:145
#define VAR_PARKING_ENDING_VEHICLES_NUMBER
static std::vector< std::string > getEmergencyStoppingVehiclesIDList()
Definition: Simulation.cpp:235
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:247
std::vector< double > & getParameter()
Returns the parameters of this distribution.
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
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:197
MSIntermodalRouter & getIntermodalRouter(const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:944
static TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false)
Definition: Simulation.cpp:326
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
#define VAR_LOADED_VEHICLES_IDS
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:165
static std::string getParameter(const std::string &objectID, const std::string &key)
Definition: Simulation.cpp:591
static TraCIPosition convert2D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
Definition: Simulation.cpp:305
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
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:788
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:273
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:200
#define VAR_TELEPORT_STARTING_VEHICLES_IDS
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
const std::string & getID() const
Returns the id.
Definition: Named.h:78
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
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:45
static TraCIPosition convertGeo(double x, double y, bool fromGeo=false)
Definition: Simulation.cpp:344
double getLength() const
return the length of the edge
Definition: MSEdge.h:568
const std::string DEFAULT_VTYPE_ID
static void close()
Closes all of an applications subsystems.
#define VAR_LOADED_VEHICLES_NUMBER
const std::string & getMyName() const
double zmin() const
Returns minimum z-coordinate.
Definition: Boundary.cpp:143
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
double cost
effort needed
Definition: TraCIDefs.h:347
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
#define VAR_STOP_STARTING_VEHICLES_NUMBER
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
The simulated network and simulation perfomer.
Definition: MSNet.h:84
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
#define VAR_EMERGENCYSTOPPING_VEHICLES_IDS
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
#define SIMTIME
Definition: SUMOTime.h:65
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:784
The vehicles starts to stop.
Definition: MSNet.h:512
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
#define CMD_SUBSCRIBE_SIM_VARIABLE
static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
Definition: Simulation.cpp:356
A road/street connecting two junctions.
Definition: MSEdge.h:75
#define INVALID_DOUBLE_VALUE
Definition: TraCIDefs.h:42
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:418
static int getParkingStartingVehiclesNumber()
Definition: Simulation.cpp:169
#define VAR_DEPARTED_VEHICLES_NUMBER
#define VAR_MIN_EXPECTED_VEHICLES
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:331
virtual void setChosenSpeedFactor(const double factor)=0
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:504
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
The vehicles starts to park.
Definition: MSNet.h:508
The vehicle is involved in a collision.
Definition: MSNet.h:516
static double getTime()
Definition: Simulation.cpp:127
static bool hasInstance()
Returns whether the network was already constructed.
Definition: MSNet.h:123
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static bool gCheckRoutes
Definition: MSGlobals.h:79
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Simulation.cpp:656
The vehicle had to brake harder than permitted.
Definition: MSNet.h:518
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:776
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
#define VAR_STOP_STARTING_VEHICLES_IDS
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:423
static TraCIPositionVector getNetBoundary()
Definition: Simulation.cpp:281
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:343
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:316
#define VAR_TELEPORT_STARTING_VEHICLES_NUMBER
bool hasContainers() const
Returns whether containers are simulated.
Definition: MSNet.h:349
int getCapacity() const
Returns the area capacity.
#define VAR_TELEPORT_ENDING_VEHICLES_IDS
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:263
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
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:500
static int getEndingTeleportNumber()
Definition: Simulation.cpp:253
static std::vector< std::string > getStopEndingVehiclesIDList()
Definition: Simulation.cpp:211
#define VAR_DEPARTED_VEHICLES_IDS
static double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
Definition: Simulation.cpp:389
static std::vector< std::string > getStartingTeleportIDList()
Definition: Simulation.cpp:247
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:52
The vehicle ends to park.
Definition: MSNet.h:510
static void saveState(const std::string &fileName)
Definition: Simulation.cpp:644
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:119
#define VAR_DELTA_T
const SUMOVTypeParameter & getParameter() const
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getOccupancy() const
Returns the area occupancy.
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
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
The vehicle was built, but has not yet departed.
Definition: MSNet.h:496
static std::vector< std::string > getParkingStartingVehiclesIDList()
Definition: Simulation.cpp:175
static int getCollidingVehiclesNumber()
Definition: Simulation.cpp:217
#define VAR_ARRIVED_VEHICLES_NUMBER
vehicle is a bus
static int getBusStopWaiting(const std::string &id)
Definition: Simulation.cpp:265
static int getStartingTeleportNumber()
Definition: Simulation.cpp:241
#define VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER
Structure representing possible vehicle parameter.
static const TraCIResults getSubscriptionResults()
Definition: Simulation.cpp:115
#define VAR_STOP_ENDING_VEHICLES_NUMBER
static std::vector< std::string > getEndingTeleportIDList()
Definition: Simulation.cpp:259
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:369
const std::string DEFAULT_PEDTYPE_ID
#define ROUTING_MODE_AGGREGATED
int getPendingFlowCount() const
Returns the number of flows that are still active.
static int getParkingEndingVehiclesNumber()
Definition: Simulation.cpp:181
static bool isLoaded()
return whether a simulation (network) is present
Definition: Simulation.cpp:74
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:345
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
#define VAR_PARKING_ENDING_VEHICLES_IDS
static int getEmergencyStoppingVehiclesNumber()
Definition: Simulation.cpp:229
The vehicle ends to stop.
Definition: MSNet.h:514
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
#define VAR_TELEPORT_ENDING_VEHICLES_NUMBER
static ContextSubscriptionResults myContextSubscriptionResults
Definition: Simulation.h:131
static int getArrivedNumber()
Definition: Simulation.cpp:157
static int getMinExpectedNumber()
Definition: Simulation.cpp:295
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
double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime) const
static std::vector< std::string > getCollidingVehiclesIDList()
Definition: Simulation.cpp:223
#define VAR_PARKING_STARTING_VEHICLES_NUMBER
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:903
static void clearPending(const std::string &routeID="")
Definition: Simulation.cpp:638
The class responsible for building and deletion of vehicles.
SVCPermissions getPermissions() const
Definition: MSEdge.h:532
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:441
static void handleSubscriptions(const SUMOTime t)
Definition: Helper.cpp:131
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
#define VAR_COLLIDING_VEHICLES_IDS
static MSNet * init()
Definition: NLBuilder.cpp:220
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:137
A 3D-position.
Definition: TraCIDefs.h:107
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Simulation.cpp:650
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
#define VAR_ARRIVED_VEHICLES_IDS
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:502
vehicles ignoring classes
static TraCIPosition convert3D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
Definition: Simulation.cpp:316
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
#define VAR_BUS_STOP_WAITING
double getTotalCharged() const
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.
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