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>
45 #include <netload/NLBuilder.h>
47 #include "Simulation.h"
48 #include <libsumo/TraCIDefs.h>
49 
50 
51 namespace libsumo {
52 // ===========================================================================
53 // static member initializations
54 // ===========================================================================
57 
58 
59 // ===========================================================================
60 // static member definitions
61 // ===========================================================================
62 void
63 Simulation::load(const std::vector<std::string>& args) {
64  close();
66  OptionsIO::setArgs(args);
69 }
70 
71 
72 bool
74  return MSNet::hasInstance();
75 }
76 
77 
78 void
79 Simulation::step(const double time) {
81  const SUMOTime t = TIME2STEPS(time);
82  if (t == 0) {
84  } else {
85  while (MSNet::getInstance()->getCurrentTimeStep() < t) {
87  }
88  }
90 }
91 
92 
93 void
95  if (MSNet::hasInstance()) {
97  delete MSNet::getInstance();
100  }
101 }
102 
103 
105 
106 
107 void
108 Simulation::subscribe(const std::vector<int>& vars, double beginTime, double endTime) {
109  libsumo::Helper::subscribe(CMD_SUBSCRIBE_SIM_VARIABLE, "", vars, beginTime, endTime);
110 }
111 
112 
113 const TraCIResults
115  return mySubscriptionResults[""];
116 }
117 
118 
119 int
121  return (int)MSNet::getInstance()->getCurrentTimeStep();
122 }
123 
124 
125 double
127  return SIMTIME;
128 }
129 
130 
131 int
134 }
135 
136 
137 std::vector<std::string>
140 }
141 
142 
143 int
146 }
147 
148 
149 std::vector<std::string>
152 }
153 
154 
155 int
158 }
159 
160 
161 std::vector<std::string>
164 }
165 
166 
167 int
170 }
171 
172 
173 std::vector<std::string>
176 }
177 
178 
179 int
182 }
183 
184 
185 std::vector<std::string>
188 }
189 
190 
191 int
194 }
195 
196 
197 std::vector<std::string>
200 }
201 
202 
203 int
206 }
207 
208 
209 std::vector<std::string>
212 }
213 
214 
215 int
218 }
219 
220 
221 std::vector<std::string>
224 }
225 
226 
227 int
230 }
231 
232 
233 std::vector<std::string>
236 }
237 
238 
239 int
242 }
243 
244 
245 std::vector<std::string>
248 }
249 
250 
251 int
254 }
255 
256 
257 std::vector<std::string>
260 }
261 
262 
263 int
264 Simulation::getBusStopWaiting(const std::string& id) {
266  if (s == nullptr) {
267  throw TraCIException("Unknown bus stop '" + id + "'.");
268  }
269  return s->getTransportableNumber();
270 }
271 
272 
273 double
275  return TS;
276 }
277 
278 
283  tb[0].x = b.xmin();
284  tb[1].x = b.xmax();
285  tb[0].y = b.ymin();
286  tb[1].y = b.ymax();
287  tb[0].z = b.zmin();
288  tb[1].z = b.zmax();
289  return tb;
290 }
291 
292 
293 int
295  MSNet* net = MSNet::getInstance();
298  + (net->hasPersons() ? net->getPersonControl().getActiveCount() : 0)
299  + (net->hasContainers() ? net->getContainerControl().getActiveCount() : 0));
300 }
301 
302 
304 Simulation::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
305  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->getShape().positionAtOffset(pos);
306  if (toGeo) {
308  }
309  result.setz(0.);
310  return Helper::makeTraCIPosition(result);
311 }
312 
313 
315 Simulation::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) {
316  Position result = Helper::getLaneChecking(edgeID, laneIndex, pos)->getShape().positionAtOffset(pos);
317  if (toGeo) {
319  }
320  return Helper::makeTraCIPosition(result, true);
321 }
322 
323 
325 Simulation::convertRoad(double x, double y, bool isGeo) {
326  Position pos(x, y);
327  if (isGeo) {
329  }
330  std::pair<MSLane*, double> roadPos = libsumo::Helper::convertCartesianToRoadMap(pos);
331  if (roadPos.first == nullptr) {
332  throw TraCIException("Cannot convert position to road.");
333  }
334  TraCIRoadPosition result;
335  result.edgeID = roadPos.first->getEdge().getID();
336  result.laneIndex = roadPos.first->getIndex();
337  result.pos = roadPos.second;
338  return result;
339 }
340 
341 
343 Simulation::convertGeo(double x, double y, bool fromGeo) {
344  Position pos(x, y);
345  if (fromGeo) {
347  } else {
349  }
350  return Helper::makeTraCIPosition(pos);
351 }
352 
353 
354 double
355 Simulation::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
356  Position pos1(x1, y1);
357  Position pos2(x2, y2);
358  if (isGeo) {
361  }
362  if (isDriving) {
363  std::pair<const MSLane*, double> roadPos1 = libsumo::Helper::convertCartesianToRoadMap(pos1);
364  std::pair<const MSLane*, double> roadPos2 = libsumo::Helper::convertCartesianToRoadMap(pos2);
365  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
366  // same edge
367  return roadPos2.second - roadPos1.second;
368  } else {
369  double distance = 0.;
370  ConstMSEdgeVector newRoute;
371  if (roadPos2.first->isInternal()) {
372  distance = roadPos2.second;
373  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
374  roadPos2.second = roadPos2.first->getLength();
375  }
377  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), 0, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
378  MSRoute route("", newRoute, false, 0, std::vector<SUMOVehicleParameter::Stop>());
379  return distance + route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
380  }
381  } else {
382  return pos1.distanceTo(pos2);
383  }
384 }
385 
386 
387 double
388 Simulation::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
389  std::pair<const MSLane*, double> roadPos1 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID1, 0, pos1), pos1);
390  std::pair<const MSLane*, double> roadPos2 = std::make_pair(libsumo::Helper::getLaneChecking(edgeID2, 0, pos2), pos2);
391  if (isDriving) {
392  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
393  // same edge
394  return roadPos2.second - roadPos1.second;
395  } else {
396  double distance = 0.;
397  ConstMSEdgeVector newRoute;
398  if (roadPos2.first->isInternal()) {
399  distance = roadPos2.second;
400  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
401  roadPos2.second = roadPos2.first->getLength();
402  }
404  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), 0, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
405  MSRoute route("", newRoute, false, 0, std::vector<SUMOVehicleParameter::Stop>());
406  return distance + route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
407  }
408  } else {
409  Position pos1 = roadPos1.first->getShape().positionAtOffset(roadPos1.second);
410  Position pos2 = roadPos2.first->getShape().positionAtOffset(roadPos2.second);
411  return pos1.distanceTo(pos2);
412  }
413 }
414 
415 
417 Simulation::findRoute(const std::string& from, const std::string& to, const std::string& typeID, const double depart, const int routingMode) {
419  const MSEdge* const fromEdge = MSEdge::dictionary(from);
420  if (fromEdge == 0) {
421  throw TraCIException("Unknown from edge '" + from + "'.");
422  }
423  const MSEdge* const toEdge = MSEdge::dictionary(to);
424  if (toEdge == 0) {
425  throw TraCIException("Unknown to edge '" + from + "'.");
426  }
427  SUMOVehicle* vehicle = 0;
428  if (typeID != "") {
431  if (type == 0) {
432  throw TraCIException("The vehicle type '" + typeID + "' is not known.");
433  }
434  try {
435  const MSRoute* const routeDummy = new MSRoute("", ConstMSEdgeVector({ fromEdge }), false, 0, std::vector<SUMOVehicleParameter::Stop>());
436  vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(pars, routeDummy, type, false);
437  // we need to fix the speed factor here for deterministic results
438  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
439  } catch (ProcessError& e) {
440  throw TraCIException("Invalid departure edge for vehicle type '" + typeID + "' (" + e.what() + ")");
441  }
442  }
443  ConstMSEdgeVector edges;
444  const SUMOTime dep = depart < 0 ? MSNet::getInstance()->getCurrentTimeStep() : TIME2STEPS(depart);
446  router.compute(fromEdge, toEdge, vehicle, dep, edges);
447  for (const MSEdge* e : edges) {
448  result.edges.push_back(e->getID());
449  }
450  result.travelTime = result.cost = router.recomputeCosts(edges, vehicle, dep);
451  if (vehicle != 0) {
453  }
454  return result;
455 }
456 
457 
458 std::vector<TraCIStage>
459 Simulation::findIntermodalRoute(const std::string& from, const std::string& to,
460  const std::string& modes, double depart, const int routingMode, double speed, double walkFactor,
461  double departPos, double arrivalPos, const double departPosLat,
462  const std::string& pType, const std::string& vType, const std::string& destStop) {
463  UNUSED_PARAMETER(departPosLat);
464  std::vector<TraCIStage> result;
465  const MSEdge* const fromEdge = MSEdge::dictionary(from);
466  if (fromEdge == 0) {
467  throw TraCIException("Unknown from edge '" + from + "'.");
468  }
469  const MSEdge* const toEdge = MSEdge::dictionary(to);
470  if (toEdge == 0) {
471  throw TraCIException("Unknown to edge '" + to + "'.");
472  }
474  SVCPermissions modeSet = 0;
475  std::vector<SUMOVehicleParameter*> pars;
476  if (vType != "") {
477  pars.push_back(new SUMOVehicleParameter());
478  pars.back()->vtypeid = vType;
479  pars.back()->id = vType;
480  modeSet |= SVC_PASSENGER;
481  }
482  for (StringTokenizer st(modes); st.hasNext();) {
483  const std::string mode = st.next();
484  if (mode == "car") {
485  pars.push_back(new SUMOVehicleParameter());
486  pars.back()->vtypeid = DEFAULT_VTYPE_ID;
487  pars.back()->id = mode;
488  modeSet |= SVC_PASSENGER;
489  } else if (mode == "bicycle") {
490  pars.push_back(new SUMOVehicleParameter());
491  pars.back()->vtypeid = DEFAULT_BIKETYPE_ID;
492  pars.back()->id = mode;
493  modeSet |= SVC_BICYCLE;
494  } else if (mode == "public") {
495  pars.push_back(nullptr);
496  modeSet |= SVC_BUS;
497  } else {
498  throw TraCIException("Unknown person mode '" + mode + "'.");
499  }
500  }
501  if (pars.empty()) {
502  pars.push_back(nullptr);
503  }
504  // interpret default arguments
505  const MSVehicleType* pedType = vehControl.hasVType(pType) ? vehControl.getVType(pType) : vehControl.getVType(DEFAULT_PEDTYPE_ID);
506  SUMOTime departStep = TIME2STEPS(depart);
507  if (depart < 0) {
508  departStep = MSNet::getInstance()->getCurrentTimeStep();
509  }
510  if (speed < 0) {
511  speed = pedType->getMaxSpeed();
512  }
513  if (walkFactor < 0) {
514  walkFactor = OptionsCont::getOptions().getFloat("persontrip.walkfactor");
515  }
516  const double externalFactor = TplConvert::_str2double(pedType->getParameter().getParameter("externalEffortFactor", "1.0"));
517  if (departPos < 0) {
518  departPos += fromEdge->getLength();
519  }
520  if (arrivalPos == INVALID_DOUBLE_VALUE) {
521  arrivalPos = toEdge->getLength() / 2;
522  } else if (arrivalPos < 0) {
523  arrivalPos += toEdge->getLength();
524  }
525  if (departPos < 0 || departPos >= fromEdge->getLength()) {
526  throw TraCIException("Invalid depart position " + toString(departPos) + " for edge '" + to + "'.");
527  }
528  if (arrivalPos < 0 || arrivalPos >= toEdge->getLength()) {
529  throw TraCIException("Invalid arrival position " + toString(arrivalPos) + " for edge '" + to + "'.");
530  }
531  double minCost = std::numeric_limits<double>::max();
533  for (SUMOVehicleParameter* vehPar : pars) {
534  std::vector<TraCIStage> resultCand;
535  SUMOVehicle* vehicle = nullptr;
536  if (vehPar != nullptr) {
537  MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(vehPar->vtypeid);
538  if (type == 0) {
539  throw TraCIException("Unknown vehicle type '" + vehPar->vtypeid + "'.");
540  }
541  if (type->getVehicleClass() != SVC_IGNORING && (fromEdge->getPermissions() & type->getVehicleClass()) == 0) {
542  WRITE_WARNING("Ignoring vehicle type '" + type->getID() + "' when performing intermodal routing because it is not allowed on the start edge '" + from + "'.");
543  } else {
544  const MSRoute* const routeDummy = new MSRoute(vehPar->id, ConstMSEdgeVector({ fromEdge }), false, 0, std::vector<SUMOVehicleParameter::Stop>());
545  vehicle = vehControl.buildVehicle(vehPar, routeDummy, type, !MSGlobals::gCheckRoutes);
546  // we need to fix the speed factor here for deterministic results
547  vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
548  }
549  }
550  std::vector<MSNet::MSIntermodalRouter::TripItem> items;
551  if (router.compute(fromEdge, toEdge, departPos, arrivalPos, destStop,
552  speed * walkFactor, vehicle, modeSet, departStep, items, externalFactor)) {
553  double cost = 0;
554  for (std::vector<MSNet::MSIntermodalRouter::TripItem>::iterator it = items.begin(); it != items.end(); ++it) {
555  if (!it->edges.empty()) {
556  resultCand.push_back(TraCIStage(it->line == ""
559  resultCand.back().destStop = it->destStop;
560  resultCand.back().line = it->line;
561  for (const MSEdge* e : it->edges) {
562  resultCand.back().edges.push_back(e->getID());
563  }
564  resultCand.back().travelTime = resultCand.back().cost = it->cost;
565  resultCand.back().intended = it->intended;
566  resultCand.back().depart = it->depart;
567  }
568  cost += it->cost;
569  }
570  if (cost < minCost) {
571  minCost = cost;
572  result = resultCand;
573  }
574  }
575  if (vehicle != 0) {
576  vehControl.deleteVehicle(vehicle, true);
577  }
578  }
579  return result;
580 }
581 
582 
583 std::string
584 Simulation::getParameter(const std::string& objectID, const std::string& key) {
585  if (StringUtils::startsWith(key, "chargingStation.")) {
586  const std::string attrName = key.substr(16);
588  if (cs == 0) {
589  throw TraCIException("Invalid chargingStation '" + objectID + "'");
590  }
591  if (attrName == toString(SUMO_ATTR_TOTALENERGYCHARGED)) {
592  return toString(cs->getTotalCharged());
593  } else {
594  throw TraCIException("Invalid chargingStation parameter '" + attrName + "'");
595  }
596  } else if (StringUtils::startsWith(key, "parkingArea.")) {
597  const std::string attrName = key.substr(12);
599  if (pa == 0) {
600  throw TraCIException("Invalid parkingArea '" + objectID + "'");
601  }
602  if (attrName == "capacity") {
603  return toString(pa->getCapacity());
604  } else if (attrName == "occupancy") {
605  return toString(pa->getOccupancy());
606  } else {
607  throw TraCIException("Invalid parkingArea parameter '" + attrName + "'");
608  }
609  } else {
610  throw TraCIException("Parameter '" + key + "' is not supported.");
611  }
612 }
613 
614 
615 void
616 Simulation::clearPending(const std::string& routeID) {
618 }
619 
620 
621 void
622 Simulation::saveState(const std::string& fileName) {
623  MSStateHandler::saveState(fileName, MSNet::getInstance()->getCurrentTimeStep());
624 }
625 
626 
627 std::shared_ptr<VariableWrapper>
629  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
630 }
631 
632 
633 bool
634 Simulation::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
635  switch (variable) {
636  case VAR_TIME:
637  return wrapper->wrapDouble(objID, variable, getTime());
638  case VAR_TIME_STEP:
639  return wrapper->wrapInt(objID, variable, (int)getCurrentTime());
641  return wrapper->wrapInt(objID, variable, getLoadedNumber());
643  return wrapper->wrapStringList(objID, variable, getLoadedIDList());
645  return wrapper->wrapInt(objID, variable, getDepartedNumber());
647  return wrapper->wrapStringList(objID, variable, getDepartedIDList());
649  return wrapper->wrapInt(objID, variable, getStartingTeleportNumber());
651  return wrapper->wrapStringList(objID, variable, getStartingTeleportIDList());
653  return wrapper->wrapInt(objID, variable, getEndingTeleportNumber());
655  return wrapper->wrapStringList(objID, variable, getEndingTeleportIDList());
657  return wrapper->wrapInt(objID, variable, getArrivedNumber());
659  return wrapper->wrapStringList(objID, variable, getArrivedIDList());
661  return wrapper->wrapInt(objID, variable, getParkingStartingVehiclesNumber());
663  return wrapper->wrapStringList(objID, variable, getParkingStartingVehiclesIDList());
665  return wrapper->wrapInt(objID, variable, getParkingEndingVehiclesNumber());
667  return wrapper->wrapStringList(objID, variable, getParkingEndingVehiclesIDList());
669  return wrapper->wrapInt(objID, variable, getStopStartingVehiclesNumber());
671  return wrapper->wrapStringList(objID, variable, getStopStartingVehiclesIDList());
673  return wrapper->wrapInt(objID, variable, getStopEndingVehiclesNumber());
675  return wrapper->wrapStringList(objID, variable, getStopEndingVehiclesIDList());
677  return wrapper->wrapInt(objID, variable, getCollidingVehiclesNumber());
679  return wrapper->wrapStringList(objID, variable, getCollidingVehiclesIDList());
681  return wrapper->wrapInt(objID, variable, getEmergencyStoppingVehiclesNumber());
683  return wrapper->wrapStringList(objID, variable, getEmergencyStoppingVehiclesIDList());
684  case VAR_DELTA_T:
685  return wrapper->wrapDouble(objID, variable, getDeltaT());
687  return wrapper->wrapInt(objID, variable, getMinExpectedNumber());
689  return wrapper->wrapInt(objID, variable, getBusStopWaiting(objID));
690  default:
691  return false;
692  }
693 }
694 
695 
696 }
697 
698 
699 /****************************************************************************/
#define VAR_COLLIDING_VEHICLES_NUMBER
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:491
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:192
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:79
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:326
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:268
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:315
static std::vector< std::string > getParkingEndingVehiclesIDList()
Definition: Simulation.cpp:186
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:841
A lane area vehicles can halt at.
static void registerVehicleStateListener()
Definition: Helper.cpp:303
#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:459
static double getDeltaT()
Definition: Simulation.cpp:274
#define VAR_STOP_ENDING_VEHICLES_IDS
int getActiveCount()
return the number of active transportable objects
static int getDepartedNumber()
Definition: Simulation.cpp:144
#define VAR_PARKING_ENDING_VEHICLES_NUMBER
static std::vector< std::string > getEmergencyStoppingVehiclesIDList()
Definition: Simulation.cpp:234
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:225
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:63
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:916
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:274
static TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false)
Definition: Simulation.cpp:325
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:150
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
static std::string getParameter(const std::string &objectID, const std::string &key)
Definition: Simulation.cpp:584
static TraCIPosition convert2D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
Definition: Simulation.cpp:304
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:449
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:740
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:251
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:69
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
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:343
double getLength() const
return the length of the edge
Definition: MSEdge.h:563
const std::string DEFAULT_VTYPE_ID
static void close()
Closes all of an applications subsystems.
#define VAR_LOADED_VEHICLES_NUMBER
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:335
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:242
The simulated network and simulation perfomer.
Definition: MSNet.h:85
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
static double _str2double(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
Definition: TplConvert.h:357
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:756
The vehicles starts to stop.
Definition: MSNet.h:505
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:355
A road/street connecting two junctions.
Definition: MSEdge.h:75
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:417
static int getParkingStartingVehiclesNumber()
Definition: Simulation.cpp:168
#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:309
virtual void setChosenSpeedFactor(const double factor)=0
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:497
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
The vehicles starts to park.
Definition: MSNet.h:501
The vehicle is involved in a collision.
Definition: MSNet.h:509
static double getTime()
Definition: Simulation.cpp:126
static bool hasInstance()
Returns whether the network was already constructed.
Definition: MSNet.h:122
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:634
The vehicle had to brake harder than permitted.
Definition: MSNet.h:511
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:748
#define VAR_STOP_STARTING_VEHICLES_IDS
static std::vector< std::string > getLoadedIDList()
Definition: Simulation.cpp:138
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:363
static TraCIPositionVector getNetBoundary()
Definition: Simulation.cpp:280
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:331
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:108
static void close()
close simulation
Definition: Simulation.cpp:94
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:309
#define VAR_TELEPORT_STARTING_VEHICLES_NUMBER
bool hasContainers() const
Returns whether containers are simulated.
Definition: MSNet.h:342
int getCapacity() const
Returns the area capacity.
#define VAR_TELEPORT_ENDING_VEHICLES_IDS
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:256
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
static std::vector< std::string > getStopStartingVehiclesIDList()
Definition: Simulation.cpp:198
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:119
The vehicle started to teleport.
Definition: MSNet.h:493
static int getEndingTeleportNumber()
Definition: Simulation.cpp:252
static std::vector< std::string > getStopEndingVehiclesIDList()
Definition: Simulation.cpp:210
#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:388
static std::vector< std::string > getStartingTeleportIDList()
Definition: Simulation.cpp:246
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:52
The vehicle ends to park.
Definition: MSNet.h:503
static void saveState(const std::string &fileName)
Definition: Simulation.cpp:622
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:118
#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
#define INVALID_DOUBLE_VALUE
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:489
static std::vector< std::string > getParkingStartingVehiclesIDList()
Definition: Simulation.cpp:174
static int getCollidingVehiclesNumber()
Definition: Simulation.cpp:216
#define VAR_ARRIVED_VEHICLES_NUMBER
vehicle is a bus
static int getBusStopWaiting(const std::string &id)
Definition: Simulation.cpp:264
static int getStartingTeleportNumber()
Definition: Simulation.cpp:240
#define VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER
Structure representing possible vehicle parameter.
static const TraCIResults getSubscriptionResults()
Definition: Simulation.cpp:114
#define VAR_STOP_ENDING_VEHICLES_NUMBER
static std::vector< std::string > getEndingTeleportIDList()
Definition: Simulation.cpp:258
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:362
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:180
static bool isLoaded()
return whether a simulation (network) is present
Definition: Simulation.cpp:73
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
double travelTime
duration of the stage
Definition: TraCIDefs.h:333
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:228
The vehicle ends to stop.
Definition: MSNet.h:507
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:156
static int getMinExpectedNumber()
Definition: Simulation.cpp:294
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:233
double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime) const
static std::vector< std::string > getCollidingVehiclesIDList()
Definition: Simulation.cpp:222
#define VAR_PARKING_STARTING_VEHICLES_NUMBER
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:875
static void clearPending(const std::string &routeID="")
Definition: Simulation.cpp:616
The class responsible for building and deletion of vehicles.
SVCPermissions getPermissions() const
Definition: MSEdge.h:534
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:430
static void handleSubscriptions(const SUMOTime t)
Definition: Helper.cpp:130
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
#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:628
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:162
static int getLoadedNumber()
Definition: Simulation.cpp:132
static int getCurrentTime()
Definition: Simulation.cpp:120
const Distribution_Parameterized & getSpeedFactor() const
Returns this type&#39;s speed factor.
A list of positions.
The vehicle ended being teleported.
Definition: MSNet.h:495
vehicles ignoring classes
static TraCIPosition convert3D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
Definition: Simulation.cpp:315
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:204
void setz(double z)
set position z
Definition: Position.h:81