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