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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // C++ TraCI client API implementation
20 /****************************************************************************/
21 #ifndef TraCIAPI_h
22 #define TraCIAPI_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <limits>
36 #include <string>
37 #include <sstream>
38 #include <iomanip>
39 #include <foreign/tcpip/socket.h>
41 #include <libsumo/TraCIDefs.h>
42 
43 // ===========================================================================
44 // global definitions
45 // ===========================================================================
46 #define DEFAULT_VIEW "View #0"
47 #define PRECISION 2
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
58 class TraCIAPI {
59 public:
62  TraCIAPI();
63 
64 
66  ~TraCIAPI();
67 
68 
71 
77  void connect(const std::string& host, int port);
78 
80  void setOrder(int order);
81 
83  void close();
85 
87  void simulationStep(SUMOTime time = 0);
88 
90  void load(const std::vector<std::string>& args);
91 
94 
95  SUMOTime getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
96  int getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
97  int getByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
98  int getInt(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
99  double getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
100  double getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
101  libsumo::TraCIBoundary getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
102  libsumo::TraCIPositionVector getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
103  libsumo::TraCIPosition getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
104  libsumo::TraCIPosition getPosition3D(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
105  std::string getString(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
106  std::vector<std::string> getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
107  libsumo::TraCIColor getColor(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
109 
110 
117  public:
121  TraCIScopeWrapper(TraCIAPI& parent) : myParent(parent) {}
122 
124  virtual ~TraCIScopeWrapper() {}
125 
126 
127  protected:
130 
131 
132  private:
135 
138 
139  };
140 
141 
142 
143 
144 
148  class EdgeScope : public TraCIScopeWrapper {
149  public:
150  EdgeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
151  virtual ~EdgeScope() {}
152 
153  std::vector<std::string> getIDList() const;
154  int getIDCount() const;
155  double getAdaptedTraveltime(const std::string& edgeID, double time) const;
156  double getEffort(const std::string& edgeID, SUMOTime time) const;
157  double getCO2Emission(const std::string& edgeID) const;
158  double getCOEmission(const std::string& edgeID) const;
159  double getHCEmission(const std::string& edgeID) const;
160  double getPMxEmission(const std::string& edgeID) const;
161  double getNOxEmission(const std::string& edgeID) const;
162  double getFuelConsumption(const std::string& edgeID) const;
163  double getNoiseEmission(const std::string& edgeID) const;
164  double getElectricityConsumption(const std::string& edgeID) const;
165  double getLastStepMeanSpeed(const std::string& edgeID) const;
166  double getLastStepOccupancy(const std::string& edgeID) const;
167  double getLastStepLength(const std::string& edgeID) const;
168  double getTraveltime(const std::string& edgeID) const;
169  int getLastStepVehicleNumber(const std::string& edgeID) const;
170  double getLastStepHaltingNumber(const std::string& edgeID) const;
171  std::vector<std::string> getLastStepVehicleIDs(const std::string& edgeID) const;
172 
173  void adaptTraveltime(const std::string& edgeID, double time, int beginSeconds = 0, int endSeconds = std::numeric_limits<int>::max()) const;
174  void setEffort(const std::string& edgeID, double effort, int beginSeconds = 0, int endSeconds = std::numeric_limits<int>::max()) const;
175  void setMaxSpeed(const std::string& edgeID, double speed) const;
176 
177  private:
179  EdgeScope(const EdgeScope& src);
180 
182  EdgeScope& operator=(const EdgeScope& src);
183 
184  };
185 
186 
187 
188 
189 
193  class GUIScope : public TraCIScopeWrapper {
194  public:
195  GUIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
196  virtual ~GUIScope() {}
197 
198  std::vector<std::string> getIDList() const;
199  double getZoom(const std::string& viewID = DEFAULT_VIEW) const;
200  libsumo::TraCIPosition getOffset(const std::string& viewID = DEFAULT_VIEW) const;
201  std::string getSchema(const std::string& viewID = DEFAULT_VIEW) const;
202  libsumo::TraCIBoundary getBoundary(const std::string& viewID = DEFAULT_VIEW) const;
203  void setZoom(const std::string& viewID, double zoom) const;
204  void setOffset(const std::string& viewID, double x, double y) const;
205  void setSchema(const std::string& viewID, const std::string& schemeName) const;
206  void setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const;
207  void screenshot(const std::string& viewID, const std::string& filename) const;
208  void trackVehicle(const std::string& viewID, const std::string& vehID) const;
209 
210  private:
212  GUIScope(const GUIScope& src);
213 
215  GUIScope& operator=(const GUIScope& src);
216 
217  };
218 
219 
220 
221 
222 
227  public:
229  virtual ~InductionLoopScope() {}
230 
231  std::vector<std::string> getIDList() const;
232  double getPosition(const std::string& loopID) const;
233  std::string getLaneID(const std::string& loopID) const;
234  int getLastStepVehicleNumber(const std::string& loopID) const;
235  double getLastStepMeanSpeed(const std::string& loopID) const;
236  std::vector<std::string> getLastStepVehicleIDs(const std::string& loopID) const;
237  double getLastStepOccupancy(const std::string& loopID) const;
238  double getLastStepMeanLength(const std::string& loopID) const;
239  double getTimeSinceDetection(const std::string& loopID) const;
240  std::vector<libsumo::TraCIVehicleData> getVehicleData(const std::string& loopID) const;
241 
242 
243  private:
246 
249 
250  };
251 
252 
253 
254 
255 
260  public:
262  virtual ~JunctionScope() {}
263 
264  std::vector<std::string> getIDList() const;
265  libsumo::TraCIPosition getPosition(const std::string& junctionID) const;
266 
267  private:
269  JunctionScope(const JunctionScope& src);
270 
273 
274  };
275 
276 
277 
278 
279 
283  class LaneScope : public TraCIScopeWrapper {
284  public:
285  LaneScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
286  virtual ~LaneScope() {}
287 
288  std::vector<std::string> getIDList() const;
289  int getIDCount() const;
290  double getLength(const std::string& laneID) const;
291  double getMaxSpeed(const std::string& laneID) const;
292  double getWidth(const std::string& laneID) const;
293  std::vector<std::string> getAllowed(const std::string& laneID) const;
294  std::vector<std::string> getDisallowed(const std::string& laneID) const;
295  int getLinkNumber(const std::string& laneID) const;
296  std::vector<libsumo::TraCIConnection> getLinks(const std::string& laneID) const;
297  libsumo::TraCIPositionVector getShape(const std::string& laneID) const;
298  std::string getEdgeID(const std::string& laneID) const;
299  double getCO2Emission(const std::string& laneID) const;
300  double getCOEmission(const std::string& laneID) const;
301  double getHCEmission(const std::string& laneID) const;
302  double getPMxEmission(const std::string& laneID) const;
303  double getNOxEmission(const std::string& laneID) const;
304  double getFuelConsumption(const std::string& laneID) const;
305  double getNoiseEmission(const std::string& laneID) const;
306  double getElectricityConsumption(const std::string& laneID) const;
307  double getLastStepMeanSpeed(const std::string& laneID) const;
308  double getLastStepOccupancy(const std::string& laneID) const;
309  double getLastStepLength(const std::string& laneID) const;
310  double getTraveltime(const std::string& laneID) const;
311  int getLastStepVehicleNumber(const std::string& laneID) const;
312  int getLastStepHaltingNumber(const std::string& laneID) const;
313  std::vector<std::string> getLastStepVehicleIDs(const std::string& laneID) const;
314  std::vector<std::string> getFoes(const std::string& laneID, const std::string& toLaneID) const;
315  std::vector<std::string> getInternalFoes(const std::string& laneID) const;
316 
317  void setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const;
318  void setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const;
319  void setMaxSpeed(const std::string& laneID, double speed) const;
320  void setLength(const std::string& laneID, double length) const;
321 
322  private:
324  LaneScope(const LaneScope& src);
325 
327  LaneScope& operator=(const LaneScope& src);
328 
329  };
330 
331 
336  public:
338  virtual ~LaneAreaScope() {}
339 
340  std::vector<std::string> getIDList() const;
341 
342  private:
344  LaneAreaScope(const LaneAreaScope& src);
345 
348 
349  };
350 
351 
355  class MeMeScope : public TraCIScopeWrapper {
356  public:
357  MeMeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
358  virtual ~MeMeScope() {}
359 
360  std::vector<std::string> getIDList() const;
361  int getLastStepVehicleNumber(const std::string& detID) const;
362  double getLastStepMeanSpeed(const std::string& detID) const;
363  std::vector<std::string> getLastStepVehicleIDs(const std::string& detID) const;
364  int getLastStepHaltingNumber(const std::string& detID) const;
365 
366  private:
368  MeMeScope(const MeMeScope& src);
369 
371  MeMeScope& operator=(const MeMeScope& src);
372 
373  };
374 
375 
376 
377 
378 
382  class POIScope : public TraCIScopeWrapper {
383  public:
384  POIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
385  virtual ~POIScope() {}
386 
387  std::vector<std::string> getIDList() const;
388  std::string getType(const std::string& poiID) const;
389  libsumo::TraCIPosition getPosition(const std::string& poiID) const;
390  libsumo::TraCIColor getColor(const std::string& poiID) const;
391 
392  void setType(const std::string& poiID, const std::string& setType) const;
393  void setPosition(const std::string& poiID, double x, double y) const;
394  void setColor(const std::string& poiID, const libsumo::TraCIColor& c) const;
395  void add(const std::string& poiID, double x, double y, const libsumo::TraCIColor& c, const std::string& type, int layer) const;
396  void remove(const std::string& poiID, int layer = 0) const;
397 
398  private:
400  POIScope(const POIScope& src);
401 
403  POIScope& operator=(const POIScope& src);
404 
405  };
406 
407 
408 
409 
410 
415  public:
417  virtual ~PolygonScope() {}
418 
419  std::vector<std::string> getIDList() const;
420  std::string getType(const std::string& polygonID) const;
421  libsumo::TraCIPositionVector getShape(const std::string& polygonID) const;
422  libsumo::TraCIColor getColor(const std::string& polygonID) const;
423  void setType(const std::string& polygonID, const std::string& setType) const;
424  void setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) const;
425  void setColor(const std::string& polygonID, const libsumo::TraCIColor& c) const;
426  void add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& c, bool fill, const std::string& type, int layer) const;
427  void remove(const std::string& polygonID, int layer = 0) const;
428 
429  private:
431  PolygonScope(const PolygonScope& src);
432 
434  PolygonScope& operator=(const PolygonScope& src);
435 
436  };
437 
438 
439 
440 
441 
445  class RouteScope : public TraCIScopeWrapper {
446  public:
447  RouteScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
448  virtual ~RouteScope() {}
449 
450  std::vector<std::string> getIDList() const;
451  std::vector<std::string> getEdges(const std::string& routeID) const;
452 
453  void add(const std::string& routeID, const std::vector<std::string>& edges) const;
454 
455  private:
457  RouteScope(const RouteScope& src);
458 
460  RouteScope& operator=(const RouteScope& src);
461 
462  };
463 
464 
465 
467  typedef std::map<int, libsumo::TraCIValue> TraCIValues;
468  typedef std::map<std::string, TraCIValues> SubscribedValues;
469  typedef std::map<std::string, SubscribedValues> SubscribedContextValues;
470 
471 
476  public:
478  virtual ~SimulationScope() {}
479 
480  SUMOTime getCurrentTime() const;
481  int getLoadedNumber() const;
482  std::vector<std::string> getLoadedIDList() const;
483  int getDepartedNumber() const;
484  std::vector<std::string> getDepartedIDList() const;
485  int getArrivedNumber() const;
486  std::vector<std::string> getArrivedIDList() const;
487  int getStartingTeleportNumber() const;
488  std::vector<std::string> getStartingTeleportIDList() const;
489  int getEndingTeleportNumber() const;
490  std::vector<std::string> getEndingTeleportIDList() const;
491  SUMOTime getDeltaT() const;
492  libsumo::TraCIBoundary getNetBoundary() const;
493  int getMinExpectedNumber() const;
494 
495  void subscribe(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
496  void subscribeContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector<int>& vars) const;
497 
498  const SubscribedValues& getSubscriptionResults() const;
499  const TraCIValues& getSubscriptionResults(const std::string& objID) const;
500 
501  const SubscribedContextValues& getContextSubscriptionResults() const;
502  const SubscribedValues& getContextSubscriptionResults(const std::string& objID) const;
503 
504  private:
506  SimulationScope(const SimulationScope& src);
507 
510 
511  };
512 
513 
514 
515 
516 
521  public:
523  virtual ~TrafficLightScope() {}
524 
525  std::vector<std::string> getIDList() const;
526  std::string getRedYellowGreenState(const std::string& tlsID) const;
527  std::vector<libsumo::TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) const;
528  std::vector<std::string> getControlledLanes(const std::string& tlsID) const;
529  std::vector<std::vector<libsumo::TraCILink> > getControlledLinks(const std::string& tlsID) const;
530  std::string getProgram(const std::string& tlsID) const;
531  int getPhase(const std::string& tlsID) const;
532  int getNextSwitch(const std::string& tlsID) const;
533 
534  void setRedYellowGreenState(const std::string& tlsID, const std::string& state) const;
535  void setPhase(const std::string& tlsID, int index) const;
536  void setProgram(const std::string& tlsID, const std::string& programID) const;
537  void setPhaseDuration(const std::string& tlsID, int phaseDuration) const;
538  void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const libsumo::TraCILogic& logic) const;
539 
540  private:
543 
546 
547  };
548 
549 
550 
551 
552 
557  public:
559  virtual ~VehicleTypeScope() {}
560 
561  std::vector<std::string> getIDList() const;
562  double getLength(const std::string& typeID) const;
563  double getMaxSpeed(const std::string& typeID) const;
564  double getSpeedFactor(const std::string& typeID) const;
565  double getSpeedDeviation(const std::string& typeID) const;
566  double getAccel(const std::string& typeID) const;
567  double getDecel(const std::string& typeID) const;
568  double getEmergencyDecel(const std::string& typeID) const;
569  double getApparentDecel(const std::string& typeID) const;
570  double getImperfection(const std::string& typeID) const;
571  double getTau(const std::string& typeID) const;
572  std::string getVehicleClass(const std::string& typeID) const;
573  std::string getEmissionClass(const std::string& typeID) const;
574  std::string getShapeClass(const std::string& typeID) const;
575  double getMinGap(const std::string& typeID) const;
576  double getWidth(const std::string& typeID) const;
577  double getHeight(const std::string& typeID) const;
578  libsumo::TraCIColor getColor(const std::string& typeID) const;
579  double getMinGapLat(const std::string& typeID) const;
580  double getMaxSpeedLat(const std::string& typeID) const;
581  std::string getLateralAlignment(const std::string& typeID) const;
582 
583  void setLength(const std::string& typeID, double length) const;
584  void setMaxSpeed(const std::string& typeID, double speed) const;
585  void setVehicleClass(const std::string& typeID, const std::string& clazz) const;
586  void setSpeedFactor(const std::string& typeID, double factor) const;
587  void setSpeedDeviation(const std::string& typeID, double deviation) const;
588  void setEmissionClass(const std::string& typeID, const std::string& clazz) const;
589  void setShapeClass(const std::string& typeID, const std::string& shapeClass) const;
590  void setWidth(const std::string& typeID, double width) const;
591  void setHeight(const std::string& typeID, double height) const;
592  void setMinGap(const std::string& typeID, double minGap) const;
593  void setAccel(const std::string& typeID, double accel) const;
594  void setDecel(const std::string& typeID, double decel) const;
595  void setEmergencyDecel(const std::string& typeID, double decel) const;
596  void setApparentDecel(const std::string& typeID, double decel) const;
597  void setImperfection(const std::string& typeID, double imperfection) const;
598  void setTau(const std::string& typeID, double tau) const;
599  void setColor(const std::string& typeID, const libsumo::TraCIColor& c) const;
600  void setMinGapLat(const std::string& typeID, double minGapLat) const;
601  void setMaxSpeedLat(const std::string& typeID, double speed) const;
602  void setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const;
603  void copy(const std::string& origTypeID, const std::string& newTypeID) const;
604 
605  private:
608 
611 
612  };
613 
614 
615 
616 
617 
622  public:
623  VehicleScope(TraCIAPI& parent) : TraCIScopeWrapper(parent), LAST_TRAVEL_TIME_UPDATE(-1) {}
624  virtual ~VehicleScope() {}
625 
628  std::vector<std::string> getIDList() const;
629  int getIDCount() const;
630  double getSpeed(const std::string& vehicleID) const;
631  libsumo::TraCIPosition getPosition(const std::string& vehicleID) const;
632  libsumo::TraCIPosition getPosition3D(const std::string& vehicleID) const;
633  double getAngle(const std::string& vehicleID) const;
634  std::string getRoadID(const std::string& vehicleID) const;
635  std::string getLaneID(const std::string& vehicleID) const;
636  int getLaneIndex(const std::string& vehicleID) const;
637  std::string getTypeID(const std::string& vehicleID) const;
638  std::string getRouteID(const std::string& vehicleID) const;
639  int getRouteIndex(const std::string& vehicleID) const;
640  std::vector<std::string> getEdges(const std::string& vehicleID) const; /*< deprecated in favour of getRoute */
641  std::vector<std::string> getRoute(const std::string& vehicleID) const;
642  libsumo::TraCIColor getColor(const std::string& vehicleID) const;
643  double getLanePosition(const std::string& vehicleID) const;
644  double getDistance(const std::string& vehicleID) const;
645  int getSignalStates(const std::string& vehicleID) const;
646  double getCO2Emission(const std::string& vehicleID) const;
647  double getCOEmission(const std::string& vehicleID) const;
648  double getHCEmission(const std::string& vehicleID) const;
649  double getPMxEmission(const std::string& vehicleID) const;
650  double getNOxEmission(const std::string& vehicleID) const;
651  double getFuelConsumption(const std::string& vehicleID) const;
652  double getNoiseEmission(const std::string& vehicleID) const;
653  double getElectricityConsumption(const std::string& vehicleID) const;
654  int getSpeedMode(const std::string& vehicleID) const;
655  int getStopState(const std::string& vehicleID) const;
656  double getWaitingTime(const std::string& vehicleID) const;
657  double getAccumulatedWaitingTime(const std::string& vehicleID) const;
658  double getSlope(const std::string& vehicleID) const;
659  double getAllowedSpeed(const std::string& vehicleID) const;
660  int getPersonNumber(const std::string& vehicleID) const;
661  double getSpeedWithoutTraCI(const std::string& vehicleID) const;
662  bool isRouteValid(const std::string& vehicleID) const;
663  double getLateralLanePosition(const std::string& vehicleID) const;
664  double getSpeedFactor(const std::string& vehicleID) const;
665  std::string getLine(const std::string& vehicleID) const;
666  std::vector<std::string> getVia(const std::string& vehicleID) const;
667  std::vector<libsumo::TraCINextTLSData> getNextTLS(const std::string& vehID) const;
668  std::vector<libsumo::TraCIBestLanesData> getBestLanes(const std::string& vehicleID) const;
669  std::pair<std::string, double> getLeader(const std::string& vehicleID, double dist) const;
671 
674  double getLength(const std::string& vehicleID) const;
675  double getMaxSpeed(const std::string& vehicleID) const;
676  double getAccel(const std::string& vehicleID) const;
677  double getDecel(const std::string& vehicleID) const;
678  double getEmergencyDecel(const std::string& vehicleID) const;
679  double getApparentDecel(const std::string& vehicleID) const;
680  double getTau(const std::string& vehicleID) const;
681  double getImperfection(const std::string& vehicleID) const;
682  double getSpeedDeviation(const std::string& vehicleID) const;
683  double getMinGap(const std::string& vehicleID) const;
684  double getWidth(const std::string& vehicleID) const;
685  double getHeight(const std::string& veihcleID) const;
686  double getMaxSpeedLat(const std::string& vehicleID) const;
687  double getMinGapLat(const std::string& vehicleID) const;
688  std::string getVehicleClass(const std::string& vehicleID) const;
689  std::string getEmissionClass(const std::string& vehicleID) const;
690  std::string getShapeClass(const std::string& vehicleID) const;
691  std::string getLateralAlignment(const std::string& vehicleID) const;
693 
696  void add(const std::string& vehicleID,
697  const std::string& routeID,
698  const std::string& typeID = "DEFAULT_VEHTYPE",
699  std::string depart = "-1",
700  const std::string& departLane = "first",
701  const std::string& departPos = "base",
702  const std::string& departSpeed = "0",
703  const std::string& arrivalLane = "current",
704  const std::string& arrivalPos = "max",
705  const std::string& arrivalSpeed = "current",
706  const std::string& fromTaz = "",
707  const std::string& toTaz = "",
708  const std::string& line = "",
709  int personCapacity = 0,
710  int personNumber = 0) const;
711 
712  void changeTarget(const std::string& vehicleID, const std::string& edgeID) const;
713  void setRouteID(const std::string& vehicleID, const std::string& routeID) const;
714  void setRoute(const std::string& vehicleID, const std::vector<std::string>& edge) const;
715  void rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes = true) const;
716  void moveTo(const std::string& vehicleID, const std::string& laneID, double position) const;
717  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;
718  void slowDown(const std::string& vehicleID, double speed, SUMOTime duration) const;
719  void setSpeed(const std::string& vehicleID, double speed) const;
720  void setType(const std::string& vehicleID, const std::string& typeID) const;
721  void remove(const std::string& vehicleID, char reason = REMOVE_VAPORIZED) const;
722  void setColor(const std::string& vehicleID, const libsumo::TraCIColor& c) const;
723  void setLine(const std::string& vehicleID, const std::string& line) const;
724  void setVia(const std::string& vehicleID, const std::vector<std::string>& via) const;
726 
729  void setShapeClass(const std::string& vehicleID, const std::string& clazz) const;
730  void setEmissionClass(const std::string& vehicleID, const std::string& clazz) const;
731  void setMaxSpeed(const std::string& vehicleID, double speed) const;
733 
734  private:
736 
738  VehicleScope(const VehicleScope& src);
739 
741  VehicleScope& operator=(const VehicleScope& src);
742 
743  };
744 
749  public:
750  PersonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
751  virtual ~PersonScope() {}
752 
753  std::vector<std::string> getIDList() const;
754  int getIDCount() const;
755  double getSpeed(const std::string& personID) const;
756  libsumo::TraCIPosition getPosition(const std::string& personID) const;
757  std::string getRoadID(const std::string& personID) const;
758  std::string getTypeID(const std::string& personID) const;
759  double getWaitingTime(const std::string& personID) const;
760  std::string getNextEdge(const std::string& personID) const;
761  std::string getVehicle(const std::string& personID) const;
762  int getRemainingStages(const std::string& personID) const;
763  int getStage(const std::string& personID, int nextStageIndex = 0) const;
764  std::vector<std::string> getEdges(const std::string& personID, int nextStageIndex = 0) const;
765  // TODO:
766  // double getAngle(const std::string& personID) const;
767  // double getLanePosition(const std::string& personID) const;
768  // libsumo::TraCIColor getColor(const std::string& personID) const;
769 
770 
771  void removeStages(const std::string& personID) const;
772  void add(const std::string& personID, const std::string& edgeID, double pos, double depart = DEPARTFLAG_NOW, const std::string typeID = "DEFAULT_PEDTYPE");
773  void appendWaitingStage(const std::string& personID, double duration, const std::string& description = "waiting", const std::string& stopID = "");
774  void appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration = -1, double speed = -1, const std::string& stopID = "");
775  void appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID = "");
776  void removeStage(const std::string& personID, int nextStageIndex) const;
777  void rerouteTraveltime(const std::string& personID) const;
778  void setSpeed(const std::string& personID, double speed) const;
779  void setType(const std::string& personID, const std::string& typeID) const;
780  void setLength(const std::string& personID, double length) const;
781  void setWidth(const std::string& personID, double width) const;
782  void setHeight(const std::string& personID, double height) const;
783  void setMinGap(const std::string& personID, double minGap) const;
784  void setColor(const std::string& personID, const libsumo::TraCIColor& c) const;
785 
786  private:
788  PersonScope(const PersonScope& src);
789 
791  PersonScope& operator=(const PersonScope& src);
792  };
793 
794 
795 
796 public:
827 
828 
829 protected:
832 
835  void send_commandSimulationStep(SUMOTime time) const;
836 
837 
840  void send_commandClose() const;
841 
842 
845  void send_commandSetOrder(int order) const;
846 
853  void send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add = 0) const;
854 
855 
862  void send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const;
863 
864 
872  void send_commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
873 
874 
884  void send_commandSubscribeObjectContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
885  int domain, double range, const std::vector<int>& vars) const;
887 
888 
889  void send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane,
890  const double x, const double y, const double angle, const int keepRoute) const;
891 
892 
895 
902  void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
903 
907  int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
908 
909  void processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId = false) const;
911 
914  void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, SubscribedValues& into);
915 
916  template <class T>
917  static inline std::string toString(const T& t, std::streamsize accuracy = PRECISION) {
918  std::ostringstream oss;
919  oss.setf(std::ios::fixed , std::ios::floatfield);
920  oss << std::setprecision(accuracy);
921  oss << t;
922  return oss.str();
923  }
924 
926  void closeSocket();
927 
928 protected:
931 
932  SubscribedValues mySubscribedValues;
933  SubscribedContextValues mySubscribedContextValues;
934 };
935 
936 
937 #endif
938 
939 /****************************************************************************/
940 
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:798
#define DEPARTFLAG_NOW
LaneScope(TraCIAPI &parent)
Definition: TraCIAPI.h:285
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:180
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:930
C++ TraCI client API implementation.
Definition: TraCIAPI.h:58
void close()
ends the simulation and closes the connection
Definition: TraCIAPI.cpp:95
Scope for interaction with edges.
Definition: TraCIAPI.h:148
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:279
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:67
MeMeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:357
void setOrder(int order)
set priority (execution order) for the client
Definition: TraCIAPI.cpp:80
virtual ~PolygonScope()
Definition: TraCIAPI.h:417
GUIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:195
TraCIScopeWrapper & operator=(const TraCIScopeWrapper &src)
invalidated assignment operator
JunctionScope junction
Scope for interaction with junctions.
Definition: TraCIAPI.h:804
PersonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:750
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:153
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:806
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:812
#define DEFAULT_VIEW
Definition: TraCIAPI.h:46
A 3D-bounding box.
Definition: TraCIDefs.h:90
void load(const std::vector< std::string > &args)
Let sumo load a simulation using the given command line like options.
Definition: TraCIAPI.cpp:604
Scope for interaction with vehicles.
Definition: TraCIAPI.h:621
virtual ~RouteScope()
Definition: TraCIAPI.h:448
void send_commandSetOrder(int order) const
Sends a SetOrder command.
Definition: TraCIAPI.cpp:140
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:520
SubscribedContextValues mySubscribedContextValues
Definition: TraCIAPI.h:933
virtual ~LaneScope()
Definition: TraCIAPI.h:286
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:105
void simulationStep(SUMOTime time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:583
Scope for interaction with lane area detectors.
Definition: TraCIAPI.h:335
Scope for interaction with the gui.
Definition: TraCIAPI.h:193
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:822
void readVariableSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:562
std::map< std::string, SubscribedValues > SubscribedContextValues
Definition: TraCIAPI.h:469
Scope for interaction with routes.
Definition: TraCIAPI.h:445
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:802
libsumo::TraCIPosition getPosition(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:439
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:226
POIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:384
virtual ~MeMeScope()
Definition: TraCIAPI.h:358
Scope for interaction with POIs.
Definition: TraCIAPI.h:382
Scope for interaction with the simulation.
Definition: TraCIAPI.h:475
Scope for interaction with multi entry/-exit detectors.
Definition: TraCIAPI.h:355
virtual ~EdgeScope()
Definition: TraCIAPI.h:151
SubscribedValues mySubscribedValues
Definition: TraCIAPI.h:932
InductionLoopScope(TraCIAPI &parent)
Definition: TraCIAPI.h:228
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition: TraCIAPI.h:810
std::map< std::string, TraCIValues > SubscribedValues
Definition: TraCIAPI.h:468
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:556
PolygonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:416
#define PRECISION
Definition: TraCIAPI.h:47
virtual ~JunctionScope()
Definition: TraCIAPI.h:262
double getFloat(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:387
~TraCIAPI()
Destructor.
Definition: TraCIAPI.cpp:61
void send_commandSubscribeObjectVariable(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, const std::vector< int > &vars) const
Sends a SubscribeVariable request.
Definition: TraCIAPI.cpp:201
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:818
std::map< int, libsumo::TraCIValue > TraCIValues
{object->{variable->value}}
Definition: TraCIAPI.h:467
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:116
Scope for interaction with polygons.
Definition: TraCIAPI.h:414
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:259
int getInt(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:378
int getByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:369
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition: TraCIAPI.h:917
int getUnsignedByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:360
double getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:396
Scope for interaction with vehicles.
Definition: TraCIAPI.h:748
Scope for interaction with junctions.
Definition: TraCIAPI.h:259
TrafficLightScope(TraCIAPI &parent)
Definition: TraCIAPI.h:522
virtual ~VehicleScope()
Definition: TraCIAPI.h:624
void readContextSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:569
libsumo::TraCIPositionVector getPolygon(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:421
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, SubscribedValues &into)
Definition: TraCIAPI.cpp:501
virtual ~SimulationScope()
Definition: TraCIAPI.h:478
std::vector< std::string > getStringVector(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:474
EdgeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:150
POIScope poi
Scope for interaction with POIs.
Definition: TraCIAPI.h:814
virtual ~POIScope()
Definition: TraCIAPI.h:385
virtual ~PersonScope()
Definition: TraCIAPI.h:751
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:820
Scope for interaction with lanes.
Definition: TraCIAPI.h:283
TraCIScopeWrapper(TraCIAPI &parent)
Constructor.
Definition: TraCIAPI.h:121
RouteScope(TraCIAPI &parent)
Definition: TraCIAPI.h:447
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:824
SUMOTime getSUMOTime(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:351
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:85
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:342
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:816
virtual ~TraCIScopeWrapper()
Destructor.
Definition: TraCIAPI.h:124
VehicleTypeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:558
virtual ~GUIScope()
Definition: TraCIAPI.h:196
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:129
TraCIAPI & myParent
The parent TraCI client which offers the connection.
Definition: TraCIAPI.h:129
libsumo::TraCIPosition getPosition3D(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:452
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:318
SUMOTime LAST_TRAVEL_TIME_UPDATE
Definition: TraCIAPI.h:735
libsumo::TraCIBoundary getBoundingBox(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:405
#define REMOVE_VAPORIZED
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:800
libsumo::TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:488
long long int SUMOTime
Definition: TraCIDefs.h:51
std::string getString(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:465
VehicleScope(TraCIAPI &parent)
Definition: TraCIAPI.h:623
SimulationScope(TraCIAPI &parent)
Definition: TraCIAPI.h:477
An abstract interface for accessing type-dependent values.
Definition: TraCIAPI.h:116
LaneAreaScope lanearea
Scope for interaction with lanes.
Definition: TraCIAPI.h:808
TraCIAPI()
Constructor.
Definition: TraCIAPI.cpp:49
virtual ~LaneAreaScope()
Definition: TraCIAPI.h:338
A 3D-position.
Definition: TraCIDefs.h:71
LaneAreaScope(TraCIAPI &parent)
Definition: TraCIAPI.h:337
void send_commandSubscribeObjectContext(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector< int > &vars) const
Sends a SubscribeContext request.
Definition: TraCIAPI.cpp:229
JunctionScope(TraCIAPI &parent)
Definition: TraCIAPI.h:261
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:826