SUMO - Simulation of Urban MObility
TraCIAPI.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-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 /****************************************************************************/
17 // C++ TraCI client API implementation
18 /****************************************************************************/
19 #ifndef TraCIAPI_h
20 #define TraCIAPI_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <limits>
30 #include <string>
31 #include <sstream>
32 #include <iomanip>
33 #include <foreign/tcpip/socket.h>
35 #include <libsumo/TraCIDefs.h>
36 
37 // ===========================================================================
38 // global definitions
39 // ===========================================================================
40 #define DEFAULT_VIEW "View #0"
41 #define PRECISION 2
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
52 class TraCIAPI {
53 public:
56  TraCIAPI();
57 
58 
60  ~TraCIAPI();
61 
62 
65 
71  void connect(const std::string& host, int port);
72 
74  void setOrder(int order);
75 
77  void close();
79 
81  void simulationStep(double time = 0);
82 
84  void load(const std::vector<std::string>& args);
85 
88  int getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
89  int getByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
90  int getInt(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
91  double getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
92  libsumo::TraCIPositionVector getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
93  libsumo::TraCIPosition getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
94  libsumo::TraCIPosition getPosition3D(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
95  std::string getString(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
96  std::vector<std::string> getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
97  libsumo::TraCIColor getColor(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
99 
100 
107  public:
111  TraCIScopeWrapper(TraCIAPI& parent, int cmdGetID, int cmdSetID, int subscribeID, int contextSubscribeID) :
112  myParent(parent),
113  myCmdGetID(cmdGetID),
114  myCmdSetID(cmdSetID),
115  mySubscribeID(subscribeID),
116  myContextSubscribeID(contextSubscribeID) {
117  }
118 
120  virtual ~TraCIScopeWrapper() {}
121 
123  std::string getParameter(const std::string& objectID, const std::string& key) const;
124 
126  void setParameter(const std::string& objectID, const std::string& key, const std::string& value) const;
127 
128  void subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) const;
129  void subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) const;
130 
132  const libsumo::TraCIResults getSubscriptionResults(const std::string& objID) const;
133 
135  const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string& objID) const;
136 
137  // the following are only for internal use
141 
142 
143  protected:
152 
153 
154  private:
157 
160 
161  };
162 
163 
164 
165 
166 
170  class EdgeScope : public TraCIScopeWrapper {
171  public:
173  virtual ~EdgeScope() {}
174 
175  std::vector<std::string> getIDList() const;
176  int getIDCount() const;
177  double getAdaptedTraveltime(const std::string& edgeID, double time) const;
178  double getEffort(const std::string& edgeID, double time) const;
179  double getCO2Emission(const std::string& edgeID) const;
180  double getCOEmission(const std::string& edgeID) const;
181  double getHCEmission(const std::string& edgeID) const;
182  double getPMxEmission(const std::string& edgeID) const;
183  double getNOxEmission(const std::string& edgeID) const;
184  double getFuelConsumption(const std::string& edgeID) const;
185  double getNoiseEmission(const std::string& edgeID) const;
186  double getElectricityConsumption(const std::string& edgeID) const;
187  double getLastStepMeanSpeed(const std::string& edgeID) const;
188  double getLastStepOccupancy(const std::string& edgeID) const;
189  double getLastStepLength(const std::string& edgeID) const;
190  double getTraveltime(const std::string& edgeID) const;
191  int getLastStepVehicleNumber(const std::string& edgeID) const;
192  double getLastStepHaltingNumber(const std::string& edgeID) const;
193  std::vector<std::string> getLastStepVehicleIDs(const std::string& edgeID) const;
194  int getLaneNumber(const std::string& edgeID) const;
195  std::string getStreetName(const std::string& id) const;
196 
197  void adaptTraveltime(const std::string& edgeID, double time, double beginSeconds = 0., double endSeconds = std::numeric_limits<double>::max()) const;
198  void setEffort(const std::string& edgeID, double effort, double beginSeconds = 0., double endSeconds = std::numeric_limits<double>::max()) const;
199  void setMaxSpeed(const std::string& edgeID, double speed) const;
200 
201  private:
203  EdgeScope(const EdgeScope& src);
204 
206  EdgeScope& operator=(const EdgeScope& src);
207 
208  };
209 
210 
211 
212 
213 
217  class GUIScope : public TraCIScopeWrapper {
218  public:
220  virtual ~GUIScope() {}
221 
222  std::vector<std::string> getIDList() const;
223  double getZoom(const std::string& viewID = DEFAULT_VIEW) const;
224  libsumo::TraCIPosition getOffset(const std::string& viewID = DEFAULT_VIEW) const;
225  std::string getSchema(const std::string& viewID = DEFAULT_VIEW) const;
226  libsumo::TraCIPositionVector getBoundary(const std::string& viewID = DEFAULT_VIEW) const;
227  void setZoom(const std::string& viewID, double zoom) const;
228  void setOffset(const std::string& viewID, double x, double y) const;
229  void setSchema(const std::string& viewID, const std::string& schemeName) const;
230  void setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const;
231  void screenshot(const std::string& viewID, const std::string& filename, const int width = -1, const int height = -1) const;
232  void trackVehicle(const std::string& viewID, const std::string& vehID) const;
233 
234  private:
236  GUIScope(const GUIScope& src);
237 
239  GUIScope& operator=(const GUIScope& src);
240 
241  };
242 
243 
244 
245 
246 
251  public:
253  virtual ~InductionLoopScope() {}
254 
255  std::vector<std::string> getIDList() const;
256  double getPosition(const std::string& loopID) const;
257  std::string getLaneID(const std::string& loopID) const;
258  int getLastStepVehicleNumber(const std::string& loopID) const;
259  double getLastStepMeanSpeed(const std::string& loopID) const;
260  std::vector<std::string> getLastStepVehicleIDs(const std::string& loopID) const;
261  double getLastStepOccupancy(const std::string& loopID) const;
262  double getLastStepMeanLength(const std::string& loopID) const;
263  double getTimeSinceDetection(const std::string& loopID) const;
264  std::vector<libsumo::TraCIVehicleData> getVehicleData(const std::string& loopID) const;
265 
266 
267  private:
270 
273 
274  };
275 
276 
277 
278 
279 
284  public:
286  virtual ~JunctionScope() {}
287 
288  std::vector<std::string> getIDList() const;
289  libsumo::TraCIPosition getPosition(const std::string& junctionID) const;
290 
291  private:
293  JunctionScope(const JunctionScope& src);
294 
297 
298  };
299 
300 
301 
302 
303 
307  class LaneScope : public TraCIScopeWrapper {
308  public:
310  virtual ~LaneScope() {}
311 
312  std::vector<std::string> getIDList() const;
313  int getIDCount() const;
314  double getLength(const std::string& laneID) const;
315  double getMaxSpeed(const std::string& laneID) const;
316  double getWidth(const std::string& laneID) const;
317  std::vector<std::string> getAllowed(const std::string& laneID) const;
318  std::vector<std::string> getDisallowed(const std::string& laneID) const;
319  int getLinkNumber(const std::string& laneID) const;
320  std::vector<libsumo::TraCIConnection> getLinks(const std::string& laneID) const;
321  libsumo::TraCIPositionVector getShape(const std::string& laneID) const;
322  std::string getEdgeID(const std::string& laneID) const;
323  double getCO2Emission(const std::string& laneID) const;
324  double getCOEmission(const std::string& laneID) const;
325  double getHCEmission(const std::string& laneID) const;
326  double getPMxEmission(const std::string& laneID) const;
327  double getNOxEmission(const std::string& laneID) const;
328  double getFuelConsumption(const std::string& laneID) const;
329  double getNoiseEmission(const std::string& laneID) const;
330  double getElectricityConsumption(const std::string& laneID) const;
331  double getLastStepMeanSpeed(const std::string& laneID) const;
332  double getLastStepOccupancy(const std::string& laneID) const;
333  double getLastStepLength(const std::string& laneID) const;
334  double getTraveltime(const std::string& laneID) const;
335  int getLastStepVehicleNumber(const std::string& laneID) const;
336  int getLastStepHaltingNumber(const std::string& laneID) const;
337  std::vector<std::string> getLastStepVehicleIDs(const std::string& laneID) const;
338  std::vector<std::string> getFoes(const std::string& laneID, const std::string& toLaneID) const;
339  std::vector<std::string> getInternalFoes(const std::string& laneID) const;
340 
341  void setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const;
342  void setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const;
343  void setMaxSpeed(const std::string& laneID, double speed) const;
344  void setLength(const std::string& laneID, double length) const;
345 
346  private:
348  LaneScope(const LaneScope& src);
349 
351  LaneScope& operator=(const LaneScope& src);
352 
353  };
354 
355 
360  public:
362  virtual ~LaneAreaScope() {}
363 
364  std::vector<std::string> getIDList() const;
365 
366  private:
368  LaneAreaScope(const LaneAreaScope& src);
369 
372 
373  };
374 
375 
379  class MeMeScope : public TraCIScopeWrapper {
380  public:
382  virtual ~MeMeScope() {}
383 
384  std::vector<std::string> getIDList() const;
385  int getLastStepVehicleNumber(const std::string& detID) const;
386  double getLastStepMeanSpeed(const std::string& detID) const;
387  std::vector<std::string> getLastStepVehicleIDs(const std::string& detID) const;
388  int getLastStepHaltingNumber(const std::string& detID) const;
389 
390  private:
392  MeMeScope(const MeMeScope& src);
393 
395  MeMeScope& operator=(const MeMeScope& src);
396 
397  };
398 
399 
400 
401 
402 
406  class POIScope : public TraCIScopeWrapper {
407  public:
409  virtual ~POIScope() {}
410 
411  std::vector<std::string> getIDList() const;
412  int getIDCount() const;
413  std::string getType(const std::string& poiID) const;
414  libsumo::TraCIPosition getPosition(const std::string& poiID) const;
415  libsumo::TraCIColor getColor(const std::string& poiID) const;
416 
417  void setType(const std::string& poiID, const std::string& setType) const;
418  void setPosition(const std::string& poiID, double x, double y) const;
419  void setColor(const std::string& poiID, const libsumo::TraCIColor& c) const;
420  void add(const std::string& poiID, double x, double y, const libsumo::TraCIColor& c, const std::string& type, int layer) const;
421  void remove(const std::string& poiID, int layer = 0) const;
422 
423  private:
425  POIScope(const POIScope& src);
426 
428  POIScope& operator=(const POIScope& src);
429 
430  };
431 
432 
433 
434 
435 
440  public:
442  virtual ~PolygonScope() {}
443 
444  std::vector<std::string> getIDList() const;
445  int getIDCount() const;
446  double getLineWidth(const std::string& polygonID) const;
447  std::string getType(const std::string& polygonID) const;
448  libsumo::TraCIPositionVector getShape(const std::string& polygonID) const;
449  libsumo::TraCIColor getColor(const std::string& polygonID) const;
450  void setType(const std::string& polygonID, const std::string& setType) const;
451  void setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) const;
452  void setColor(const std::string& polygonID, const libsumo::TraCIColor& c) const;
453  void setLineWidth(const std::string& polygonID, const double lineWidth) const;
454  void add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& c, bool fill, const std::string& type, int layer) const;
455  void remove(const std::string& polygonID, int layer = 0) const;
456 
457  private:
459  PolygonScope(const PolygonScope& src);
460 
462  PolygonScope& operator=(const PolygonScope& src);
463 
464  };
465 
466 
467 
468 
469 
473  class RouteScope : public TraCIScopeWrapper {
474  public:
476  virtual ~RouteScope() {}
477 
478  std::vector<std::string> getIDList() const;
479  std::vector<std::string> getEdges(const std::string& routeID) const;
480 
481  void add(const std::string& routeID, const std::vector<std::string>& edges) const;
482 
483  private:
485  RouteScope(const RouteScope& src);
486 
488  RouteScope& operator=(const RouteScope& src);
489 
490  };
491 
492 
493 
498  public:
500  virtual ~SimulationScope() {}
501 
502  int getCurrentTime() const;
503  double getTime() const;
504  int getLoadedNumber() const;
505  std::vector<std::string> getLoadedIDList() const;
506  int getDepartedNumber() const;
507  std::vector<std::string> getDepartedIDList() const;
508  int getArrivedNumber() const;
509  std::vector<std::string> getArrivedIDList() const;
510  int getStartingTeleportNumber() const;
511  std::vector<std::string> getStartingTeleportIDList() const;
512  int getEndingTeleportNumber() const;
513  std::vector<std::string> getEndingTeleportIDList() const;
514  double getDeltaT() const;
515  libsumo::TraCIPositionVector getNetBoundary() const;
516  int getMinExpectedNumber() const;
517  double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false);
518  double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false);
519 
520 
521  private:
523  SimulationScope(const SimulationScope& src);
524 
527 
528  };
529 
530 
531 
532 
533 
538  public:
540  virtual ~TrafficLightScope() {}
541 
542  std::vector<std::string> getIDList() const;
543  int getIDCount() const;
544  std::string getRedYellowGreenState(const std::string& tlsID) const;
545  std::vector<libsumo::TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) const;
546  std::vector<std::string> getControlledLanes(const std::string& tlsID) const;
547  std::vector<std::vector<libsumo::TraCILink> > getControlledLinks(const std::string& tlsID) const;
548  std::string getProgram(const std::string& tlsID) const;
549  int getPhase(const std::string& tlsID) const;
550  double getPhaseDuration(const std::string& tlsID) const;
551  double getNextSwitch(const std::string& tlsID) const;
552 
553  void setRedYellowGreenState(const std::string& tlsID, const std::string& state) const;
554  void setPhase(const std::string& tlsID, int index) const;
555  void setProgram(const std::string& tlsID, const std::string& programID) const;
556  void setPhaseDuration(const std::string& tlsID, double phaseDuration) const;
557  void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const libsumo::TraCILogic& logic) const;
558 
559  private:
562 
565 
566  };
567 
568 
569 
570 
571 
576  public:
578  virtual ~VehicleTypeScope() {}
579 
580  std::vector<std::string> getIDList() const;
581  double getLength(const std::string& typeID) const;
582  double getMaxSpeed(const std::string& typeID) const;
583  double getSpeedFactor(const std::string& typeID) const;
584  double getSpeedDeviation(const std::string& typeID) const;
585  double getAccel(const std::string& typeID) const;
586  double getDecel(const std::string& typeID) const;
587  double getEmergencyDecel(const std::string& typeID) const;
588  double getApparentDecel(const std::string& typeID) const;
589  double getImperfection(const std::string& typeID) const;
590  double getTau(const std::string& typeID) const;
591  std::string getVehicleClass(const std::string& typeID) const;
592  std::string getEmissionClass(const std::string& typeID) const;
593  std::string getShapeClass(const std::string& typeID) const;
594  double getMinGap(const std::string& typeID) const;
595  double getWidth(const std::string& typeID) const;
596  double getHeight(const std::string& typeID) const;
597  libsumo::TraCIColor getColor(const std::string& typeID) const;
598  double getMinGapLat(const std::string& typeID) const;
599  double getMaxSpeedLat(const std::string& typeID) const;
600  std::string getLateralAlignment(const std::string& typeID) const;
601 
602  void setLength(const std::string& typeID, double length) const;
603  void setMaxSpeed(const std::string& typeID, double speed) const;
604  void setVehicleClass(const std::string& typeID, const std::string& clazz) const;
605  void setSpeedFactor(const std::string& typeID, double factor) const;
606  void setSpeedDeviation(const std::string& typeID, double deviation) const;
607  void setEmissionClass(const std::string& typeID, const std::string& clazz) const;
608  void setShapeClass(const std::string& typeID, const std::string& shapeClass) const;
609  void setWidth(const std::string& typeID, double width) const;
610  void setHeight(const std::string& typeID, double height) const;
611  void setMinGap(const std::string& typeID, double minGap) const;
612  void setAccel(const std::string& typeID, double accel) const;
613  void setDecel(const std::string& typeID, double decel) const;
614  void setEmergencyDecel(const std::string& typeID, double decel) const;
615  void setApparentDecel(const std::string& typeID, double decel) const;
616  void setImperfection(const std::string& typeID, double imperfection) const;
617  void setTau(const std::string& typeID, double tau) const;
618  void setColor(const std::string& typeID, const libsumo::TraCIColor& c) const;
619  void setMinGapLat(const std::string& typeID, double minGapLat) const;
620  void setMaxSpeedLat(const std::string& typeID, double speed) const;
621  void setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const;
622  void copy(const std::string& origTypeID, const std::string& newTypeID) const;
623 
624  private:
627 
630 
631  };
632 
633 
634 
635 
636 
641  public:
643  virtual ~VehicleScope() {}
644 
646  SIGNAL_BLINKER_RIGHT = 1,
647  SIGNAL_BLINKER_LEFT = 2,
648  SIGNAL_BLINKER_EMERGENCY = 4,
649  SIGNAL_BRAKELIGHT = 8,
650  SIGNAL_FRONTLIGHT = 16,
651  SIGNAL_FOGLIGHT = 32,
652  SIGNAL_HIGHBEAM = 64,
653  SIGNAL_BACKDRIVE = 128,
654  SIGNAL_WIPER = 256,
655  SIGNAL_DOOR_OPEN_LEFT = 512,
656  SIGNAL_DOOR_OPEN_RIGHT = 1024,
657  SIGNAL_EMERGENCY_BLUE = 2048,
658  SIGNAL_EMERGENCY_RED = 4096,
659  SIGNAL_EMERGENCY_YELLOW = 8192,
660  SIGNAL_RESET = -1, /*< sending a negative signal resets all signals to their computed values immediately */
661  };
662 
665  std::vector<std::string> getIDList() const;
666  int getIDCount() const;
667  double getSpeed(const std::string& vehicleID) const;
668  double getAcceleration(const std::string& vehicleID) const;
669  libsumo::TraCIPosition getPosition(const std::string& vehicleID) const;
670  libsumo::TraCIPosition getPosition3D(const std::string& vehicleID) const;
671  double getAngle(const std::string& vehicleID) const;
672  std::string getRoadID(const std::string& vehicleID) const;
673  std::string getLaneID(const std::string& vehicleID) const;
674  int getLaneIndex(const std::string& vehicleID) const;
675  std::string getTypeID(const std::string& vehicleID) const;
676  std::string getRouteID(const std::string& vehicleID) const;
677  int getRouteIndex(const std::string& vehicleID) const;
678  std::vector<std::string> getRoute(const std::string& vehicleID) const;
679  libsumo::TraCIColor getColor(const std::string& vehicleID) const;
680  double getLanePosition(const std::string& vehicleID) const;
681  double getDistance(const std::string& vehicleID) const;
682  int getSignals(const std::string& vehicleID) const;
683  double getCO2Emission(const std::string& vehicleID) const;
684  double getCOEmission(const std::string& vehicleID) const;
685  double getHCEmission(const std::string& vehicleID) const;
686  double getPMxEmission(const std::string& vehicleID) const;
687  double getNOxEmission(const std::string& vehicleID) const;
688  double getFuelConsumption(const std::string& vehicleID) const;
689  double getNoiseEmission(const std::string& vehicleID) const;
690  double getElectricityConsumption(const std::string& vehicleID) const;
691  int getSpeedMode(const std::string& vehicleID) const;
692  int getStopState(const std::string& vehicleID) const;
693  double getWaitingTime(const std::string& vehicleID) const;
694  double getAccumulatedWaitingTime(const std::string& vehicleID) const;
695  double getSlope(const std::string& vehicleID) const;
696  double getAllowedSpeed(const std::string& vehicleID) const;
697  int getPersonNumber(const std::string& vehicleID) const;
698  std::vector<std::string> getPersonIDList(const std::string& vehicleID) const;
699  double getSpeedWithoutTraCI(const std::string& vehicleID) const;
700  bool isRouteValid(const std::string& vehicleID) const;
701  double getLateralLanePosition(const std::string& vehicleID) const;
702  double getSpeedFactor(const std::string& vehicleID) const;
703  std::string getLine(const std::string& vehicleID) const;
704  std::vector<std::string> getVia(const std::string& vehicleID) const;
705  std::vector<libsumo::TraCINextTLSData> getNextTLS(const std::string& vehID) const;
706  std::vector<libsumo::TraCIBestLanesData> getBestLanes(const std::string& vehicleID) const;
707  std::pair<std::string, double> getLeader(const std::string& vehicleID, double dist) const;
708  int getRoutingMode(const std::string& vehicleID) const;
709  std::pair<int, int> getLaneChangeState(const std::string& vehicleID, int direction) const;
711 
714  double getLength(const std::string& vehicleID) const;
715  double getMaxSpeed(const std::string& vehicleID) const;
716  double getAccel(const std::string& vehicleID) const;
717  double getDecel(const std::string& vehicleID) const;
718  double getEmergencyDecel(const std::string& vehicleID) const;
719  double getApparentDecel(const std::string& vehicleID) const;
720  double getTau(const std::string& vehicleID) const;
721  double getImperfection(const std::string& vehicleID) const;
722  double getSpeedDeviation(const std::string& vehicleID) const;
723  double getMinGap(const std::string& vehicleID) const;
724  double getWidth(const std::string& vehicleID) const;
725  double getHeight(const std::string& veihcleID) const;
726  double getMaxSpeedLat(const std::string& vehicleID) const;
727  double getMinGapLat(const std::string& vehicleID) const;
728  std::string getVehicleClass(const std::string& vehicleID) const;
729  std::string getEmissionClass(const std::string& vehicleID) const;
730  std::string getShapeClass(const std::string& vehicleID) const;
731  std::string getLateralAlignment(const std::string& vehicleID) const;
733 
736  void add(const std::string& vehicleID,
737  const std::string& routeID,
738  const std::string& typeID = "DEFAULT_VEHTYPE",
739  std::string depart = "-1",
740  const std::string& departLane = "first",
741  const std::string& departPos = "base",
742  const std::string& departSpeed = "0",
743  const std::string& arrivalLane = "current",
744  const std::string& arrivalPos = "max",
745  const std::string& arrivalSpeed = "current",
746  const std::string& fromTaz = "",
747  const std::string& toTaz = "",
748  const std::string& line = "",
749  int personCapacity = 0,
750  int personNumber = 0) const;
751 
752  void changeTarget(const std::string& vehicleID, const std::string& edgeID) const;
753  void changeLane(const std::string& vehicleID, int laneIndex, double duration) const;
754  void changeLaneRelative(const std::string& vehicleID, int laneChange, double duration) const;
755  void changeSublane(const std::string& vehicleID, double latDist) const;
756  void setRouteID(const std::string& vehicleID, const std::string& routeID) const;
757  void setRoute(const std::string& vehicleID, const std::vector<std::string>& edge) const;
758  void rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes = true) const;
759  void moveTo(const std::string& vehicleID, const std::string& laneID, double position) const;
760  void moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const;
761  void slowDown(const std::string& vehicleID, double speed, double duration) const;
762  void openGap(const std::string& vehicleID, double newTau, double duration, double changeRate, double maxDecel) const;
763  void setSpeed(const std::string& vehicleID, double speed) const;
764  void setSpeedMode(const std::string& vehicleID, int mode) const;
765  void setStop(const std::string vehicleID, const std::string edgeID, const double endPos = 1.,
766  const int laneIndex = 0, const double duration = std::numeric_limits<double>::max(),
767  const int flags = 0, const double startPos = std::numeric_limits<int>::min(),
768  const double until = -1) const;
769  void setType(const std::string& vehicleID, const std::string& typeID) const;
770  void remove(const std::string& vehicleID, char reason = REMOVE_VAPORIZED) const;
771  void setColor(const std::string& vehicleID, const libsumo::TraCIColor& c) const;
772  void setLine(const std::string& vehicleID, const std::string& line) const;
773  void setVia(const std::string& vehicleID, const std::vector<std::string>& via) const;
774  void setSignals(const std::string& vehicleID, int signals) const;
775  void setRoutingMode(const std::string& vehicleID, int routingMode) const;
777 
780  void setShapeClass(const std::string& vehicleID, const std::string& clazz) const;
781  void setEmissionClass(const std::string& vehicleID, const std::string& clazz) const;
782  void setSpeedFactor(const std::string& vehicleID, double factor) const;
783  void setMaxSpeed(const std::string& vehicleID, double speed) const;
785 
786  private:
788  VehicleScope(const VehicleScope& src);
789 
791  VehicleScope& operator=(const VehicleScope& src);
792 
793  };
794 
799  public:
801  virtual ~PersonScope() {}
802 
803  std::vector<std::string> getIDList() const;
804  int getIDCount() const;
805  double getSpeed(const std::string& personID) const;
806  libsumo::TraCIPosition getPosition(const std::string& personID) const;
807  libsumo::TraCIPosition getPosition3D(const std::string& personID) const;
808  std::string getRoadID(const std::string& personID) const;
809  std::string getTypeID(const std::string& personID) const;
810  double getWaitingTime(const std::string& personID) const;
811  std::string getNextEdge(const std::string& personID) const;
812  std::string getVehicle(const std::string& personID) const;
813  int getRemainingStages(const std::string& personID) const;
814  int getStage(const std::string& personID, int nextStageIndex = 0) const;
815  std::vector<std::string> getEdges(const std::string& personID, int nextStageIndex = 0) const;
816  double getAngle(const std::string& personID) const;
817  double getLanePosition(const std::string& personID) const;
818  libsumo::TraCIColor getColor(const std::string& personID) const;
819 
822  double getLength(const std::string& personID) const;
824 
825 
826  void removeStages(const std::string& personID) const;
827  void add(const std::string& personID, const std::string& edgeID, double pos, double depart = DEPARTFLAG_NOW, const std::string typeID = "DEFAULT_PEDTYPE");
828  void appendWaitingStage(const std::string& personID, double duration, const std::string& description = "waiting", const std::string& stopID = "");
829  void appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration = -1, double speed = -1, const std::string& stopID = "");
830  void appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID = "");
831  void removeStage(const std::string& personID, int nextStageIndex) const;
832  void rerouteTraveltime(const std::string& personID) const;
833  void setSpeed(const std::string& personID, double speed) const;
834  void setType(const std::string& personID, const std::string& typeID) const;
835  void setLength(const std::string& personID, double length) const;
836  void setWidth(const std::string& personID, double width) const;
837  void setHeight(const std::string& personID, double height) const;
838  void setMinGap(const std::string& personID, double minGap) const;
839  void setColor(const std::string& personID, const libsumo::TraCIColor& c) const;
840 
841  private:
843  PersonScope(const PersonScope& src);
844 
846  PersonScope& operator=(const PersonScope& src);
847  };
848 
849 
850 
851 public:
882 
883 
884 protected:
887 
890  void send_commandSimulationStep(double time) const;
891 
892 
895  void send_commandClose() const;
896 
897 
900  void send_commandSetOrder(int order) const;
901 
908  void send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add = 0) const;
909 
910 
917  void send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const;
918 
919 
927  void send_commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime, const std::vector<int>& vars) const;
928 
929 
939  void send_commandSubscribeObjectContext(int domID, const std::string& objID, double beginTime, double endTime,
940  int domain, double range, const std::vector<int>& vars) const;
942 
943 
944  void send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane,
945  const double x, const double y, const double angle, const int keepRoute) const;
946 
947 
950 
957  void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
958 
962  int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
963 
964  void processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId = false) const;
966 
967  void readVariableSubscription(int cmdId, tcpip::Storage& inMsg);
968  void readContextSubscription(int cmdId, tcpip::Storage& inMsg);
969  void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, libsumo::SubscriptionResults& into);
970 
971  template <class T>
972  static inline std::string toString(const T& t, std::streamsize accuracy = PRECISION) {
973  std::ostringstream oss;
974  oss.setf(std::ios::fixed , std::ios::floatfield);
975  oss << std::setprecision(accuracy);
976  oss << t;
977  return oss.str();
978  }
979 
981  void closeSocket();
982 
983 protected:
984  std::map<int, TraCIScopeWrapper*> myDomains;
987 };
988 
989 
990 #endif
991 
992 /****************************************************************************/
993 
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:853
#define DEPARTFLAG_NOW
LaneScope(TraCIAPI &parent)
Definition: TraCIAPI.h:309
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
std::string getParameter(const std::string &objectID, const std::string &key) const
retrieve generic paramter
Definition: TraCIAPI.cpp:3235
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:187
#define CMD_SUBSCRIBE_VEHICLE_CONTEXT
#define CMD_SUBSCRIBE_LANE_VARIABLE
libsumo::SubscriptionResults & getModifiableSubscriptionResults()
Definition: TraCIAPI.cpp:3320
libsumo::SubscriptionResults & getModifiableContextSubscriptionResults(const std::string &objID)
Definition: TraCIAPI.cpp:3326
#define CMD_SUBSCRIBE_LANEAREA_VARIABLE
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:986
C++ TraCI client API implementation.
Definition: TraCIAPI.h:52
void close()
ends the simulation and closes the connection
Definition: TraCIAPI.cpp:102
Scope for interaction with edges.
Definition: TraCIAPI.h:170
void check_resultState(tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const
Validates the result state of a command.
Definition: TraCIAPI.cpp:286
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:74
#define CMD_GET_TL_VARIABLE
#define CMD_SUBSCRIBE_JUNCTION_CONTEXT
MeMeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:381
void setOrder(int order)
set priority (execution order) for the client
Definition: TraCIAPI.cpp:87
#define CMD_GET_VEHICLE_VARIABLE
#define CMD_SUBSCRIBE_SIM_CONTEXT
#define CMD_SUBSCRIBE_VEHICLETYPE_CONTEXT
virtual ~PolygonScope()
Definition: TraCIAPI.h:442
#define CMD_GET_INDUCTIONLOOP_VARIABLE
void setParameter(const std::string &objectID, const std::string &key, const std::string &value) const
set generic paramter
Definition: TraCIAPI.cpp:3244
GUIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:219
libsumo::TraCIPositionVector getPolygon(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:392
TraCIScopeWrapper & operator=(const TraCIScopeWrapper &src)
invalidated assignment operator
JunctionScope junction
Scope for interaction with junctions.
Definition: TraCIAPI.h:859
#define CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
PersonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:800
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:160
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:197
#define CMD_GET_LANEAREA_VARIABLE
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:861
#define CMD_GET_PERSON_VARIABLE
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:867
#define DEFAULT_VIEW
Definition: TraCIAPI.h:40
void load(const std::vector< std::string > &args)
Let sumo load a simulation using the given command line like options.
Definition: TraCIAPI.cpp:589
Scope for interaction with vehicles.
Definition: TraCIAPI.h:640
virtual ~RouteScope()
Definition: TraCIAPI.h:476
TraCIScopeWrapper(TraCIAPI &parent, int cmdGetID, int cmdSetID, int subscribeID, int contextSubscribeID)
Constructor.
Definition: TraCIAPI.h:111
#define CMD_SUBSCRIBE_POLYGON_CONTEXT
void send_commandSetOrder(int order) const
Sends a SetOrder command.
Definition: TraCIAPI.cpp:147
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:537
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:200
virtual ~LaneScope()
Definition: TraCIAPI.h:310
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:112
#define CMD_GET_POLYGON_VARIABLE
#define CMD_SUBSCRIBE_JUNCTION_VARIABLE
Scope for interaction with lane area detectors.
Definition: TraCIAPI.h:359
#define CMD_SUBSCRIBE_ROUTE_CONTEXT
libsumo::TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:462
Scope for interaction with the gui.
Definition: TraCIAPI.h:217
#define CMD_SET_EDGE_VARIABLE
#define CMD_SET_GUI_VARIABLE
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:877
const libsumo::SubscriptionResults getAllSubscriptionResults() const
Definition: TraCIAPI.cpp:3281
Scope for interaction with routes.
Definition: TraCIAPI.h:473
#define CMD_SUBSCRIBE_EDGE_VARIABLE
#define CMD_GET_ROUTE_VARIABLE
#define CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:857
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:250
#define CMD_SET_JUNCTION_VARIABLE
#define CMD_SUBSCRIBE_POI_VARIABLE
POIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:408
std::map< int, TraCIScopeWrapper * > myDomains
Definition: TraCIAPI.h:984
virtual ~MeMeScope()
Definition: TraCIAPI.h:382
#define CMD_SET_TL_VARIABLE
Scope for interaction with POIs.
Definition: TraCIAPI.h:406
#define CMD_SUBSCRIBE_LANE_CONTEXT
libsumo::TraCIPosition getPosition3D(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:426
#define CMD_SUBSCRIBE_SIM_VARIABLE
#define CMD_GET_VEHICLETYPE_VARIABLE
Scope for interaction with the simulation.
Definition: TraCIAPI.h:497
Scope for interaction with multi entry/-exit detectors.
Definition: TraCIAPI.h:379
const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string &objID) const
Definition: TraCIAPI.cpp:3303
virtual ~EdgeScope()
Definition: TraCIAPI.h:173
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, libsumo::SubscriptionResults &into)
Definition: TraCIAPI.cpp:476
#define CMD_SET_ROUTE_VARIABLE
InductionLoopScope(TraCIAPI &parent)
Definition: TraCIAPI.h:252
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition: TraCIAPI.h:865
#define CMD_SUBSCRIBE_GUI_CONTEXT
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:575
PolygonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:441
#define PRECISION
Definition: TraCIAPI.h:41
#define CMD_GET_POI_VARIABLE
virtual ~JunctionScope()
Definition: TraCIAPI.h:286
#define CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE
libsumo::ContextSubscriptionResults myContextSubscriptionResults
Definition: TraCIAPI.h:151
~TraCIAPI()
Destructor.
Definition: TraCIAPI.cpp:68
#define CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT
#define CMD_SET_VEHICLETYPE_VARIABLE
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:873
Scope for interaction with polygons.
Definition: TraCIAPI.h:439
void simulationStep(double time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:567
void send_commandMoveToXY(const std::string &vehicleID, const std::string &edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const
Definition: TraCIAPI.cpp:266
void send_commandSubscribeObjectVariable(int domID, const std::string &objID, double beginTime, double endTime, const std::vector< int > &vars) const
Sends a SubscribeVariable request.
Definition: TraCIAPI.cpp:208
#define CMD_SUBSCRIBE_GUI_VARIABLE
#define CMD_GET_LANE_VARIABLE
void send_commandSubscribeObjectContext(int domID, const std::string &objID, double beginTime, double endTime, int domain, double range, const std::vector< int > &vars) const
Sends a SubscribeContext request.
Definition: TraCIAPI.cpp:236
int getInt(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:374
#define CMD_SUBSCRIBE_LANEAREA_CONTEXT
libsumo::SubscriptionResults mySubscriptionResults
Definition: TraCIAPI.h:150
#define CMD_SET_VEHICLE_VARIABLE
void subscribe(const std::string &objID, const std::vector< int > &vars, double beginTime, double endTime) const
Definition: TraCIAPI.cpp:3259
#define CMD_GET_SIM_VARIABLE
#define CMD_GET_EDGE_VARIABLE
int getByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:365
void subscribeContext(const std::string &objID, int domain, double range, const std::vector< int > &vars, double beginTime, double endTime) const
Definition: TraCIAPI.cpp:3271
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition: TraCIAPI.h:972
#define CMD_GET_GUI_VARIABLE
#define CMD_SET_POI_VARIABLE
int getUnsignedByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:356
double getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:383
#define CMD_SUBSCRIBE_POLYGON_VARIABLE
Scope for interaction with vehicles.
Definition: TraCIAPI.h:798
#define CMD_SUBSCRIBE_TL_CONTEXT
#define CMD_SUBSCRIBE_EDGE_CONTEXT
#define CMD_GET_JUNCTION_VARIABLE
Scope for interaction with junctions.
Definition: TraCIAPI.h:283
#define CMD_SUBSCRIBE_PERSON_VARIABLE
TrafficLightScope(TraCIAPI &parent)
Definition: TraCIAPI.h:539
virtual ~VehicleScope()
Definition: TraCIAPI.h:643
#define CMD_SET_SIM_VARIABLE
const libsumo::TraCIResults getSubscriptionResults(const std::string &objID) const
Definition: TraCIAPI.cpp:3287
virtual ~SimulationScope()
Definition: TraCIAPI.h:500
std::vector< std::string > getStringVector(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:448
#define CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE
EdgeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:172
POIScope poi
Scope for interaction with POIs.
Definition: TraCIAPI.h:869
virtual ~POIScope()
Definition: TraCIAPI.h:409
virtual ~PersonScope()
Definition: TraCIAPI.h:801
#define CMD_SET_POLYGON_VARIABLE
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:875
Scope for interaction with lanes.
Definition: TraCIAPI.h:307
RouteScope(TraCIAPI &parent)
Definition: TraCIAPI.h:475
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:879
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:145
#define CMD_SUBSCRIBE_VEHICLE_VARIABLE
#define CMD_SUBSCRIBE_PERSON_CONTEXT
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:349
void readVariableSubscription(int cmdId, tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:544
#define CMD_SET_LANE_VARIABLE
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:871
#define CMD_GET_MULTIENTRYEXIT_VARIABLE
virtual ~TraCIScopeWrapper()
Destructor.
Definition: TraCIAPI.h:120
VehicleTypeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:577
virtual ~GUIScope()
Definition: TraCIAPI.h:220
void send_commandSimulationStep(double time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:123
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:136
TraCIAPI & myParent
The parent TraCI client which offers the connection.
Definition: TraCIAPI.h:145
int check_commandGetResult(tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const
Validates the result state of a command.
Definition: TraCIAPI.cpp:325
libsumo::TraCIPosition getPosition(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:413
#define REMOVE_VAPORIZED
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:855
#define CMD_SUBSCRIBE_TL_VARIABLE
std::string getString(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:439
VehicleScope(TraCIAPI &parent)
Definition: TraCIAPI.h:642
SimulationScope(TraCIAPI &parent)
Definition: TraCIAPI.h:499
An abstract interface for accessing type-dependent values.
Definition: TraCIAPI.h:106
#define CMD_SET_PERSON_VARIABLE
LaneAreaScope lanearea
Scope for interaction with lanes.
Definition: TraCIAPI.h:863
TraCIAPI()
Constructor.
Definition: TraCIAPI.cpp:41
virtual ~LaneAreaScope()
Definition: TraCIAPI.h:362
A 3D-position.
Definition: TraCIDefs.h:107
#define CMD_SUBSCRIBE_POI_CONTEXT
const libsumo::ContextSubscriptionResults getAllContextSubscriptionResults() const
Definition: TraCIAPI.cpp:3297
LaneAreaScope(TraCIAPI &parent)
Definition: TraCIAPI.h:361
JunctionScope(TraCIAPI &parent)
Definition: TraCIAPI.h:285
void readContextSubscription(int cmdId, tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:552
#define CMD_SUBSCRIBE_ROUTE_VARIABLE
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:881