SUMO - Simulation of Urban MObility
TraCIAPI.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // C++ TraCI client API implementation
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef TraCIAPI_h
23 #define TraCIAPI_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <limits>
37 #include <string>
38 #include <sstream>
39 #include <iomanip>
40 #include <foreign/tcpip/socket.h>
42 #include <traci-server/TraCIDefs.h>
43 
44 // ===========================================================================
45 // global definitions
46 // ===========================================================================
47 #define DEFAULT_VIEW "View #0"
48 #define PRECISION 2
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
59 typedef long long int SUMOTime; // <utils/common/SUMOTime.h>
60 #define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
61 
62 
63 class TraCIAPI {
64 public:
67  TraCIAPI();
68 
69 
71  ~TraCIAPI();
72 
73 
76 
82  void connect(const std::string& host, int port);
83 
84 
86  void close();
88 
90  void simulationStep(SUMOTime time = 0);
91 
93  void load(const std::vector<std::string>& args);
94 
97 
98  SUMOTime getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
99  int getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
100  int getByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
101  int getInt(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
102  double getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
103  double getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
104  TraCIBoundary getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
105  TraCIPositionVector getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
106  TraCIPosition getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
107  std::string getString(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
108  std::vector<std::string> getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
109  TraCIColor getColor(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
111 
112 
119  public:
123  TraCIScopeWrapper(TraCIAPI& parent) : myParent(parent) {}
124 
126  virtual ~TraCIScopeWrapper() {}
127 
128 
129  protected:
132 
133 
134  private:
137 
140 
141  };
142 
143 
144 
145 
146 
150  class EdgeScope : public TraCIScopeWrapper {
151  public:
152  EdgeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
153  virtual ~EdgeScope() {}
154 
155  std::vector<std::string> getIDList() const;
156  int getIDCount() const;
157  double getAdaptedTraveltime(const std::string& edgeID, double time) const;
158  double getEffort(const std::string& edgeID, SUMOTime time) const;
159  double getCO2Emission(const std::string& edgeID) const;
160  double getCOEmission(const std::string& edgeID) const;
161  double getHCEmission(const std::string& edgeID) const;
162  double getPMxEmission(const std::string& edgeID) const;
163  double getNOxEmission(const std::string& edgeID) const;
164  double getFuelConsumption(const std::string& edgeID) const;
165  double getNoiseEmission(const std::string& edgeID) const;
166  double getElectricityConsumption(const std::string& edgeID) const;
167  double getLastStepMeanSpeed(const std::string& edgeID) const;
168  double getLastStepOccupancy(const std::string& edgeID) const;
169  double getLastStepLength(const std::string& edgeID) const;
170  double getTraveltime(const std::string& edgeID) const;
171  int getLastStepVehicleNumber(const std::string& edgeID) const;
172  double getLastStepHaltingNumber(const std::string& edgeID) const;
173  std::vector<std::string> getLastStepVehicleIDs(const std::string& edgeID) const;
174 
175  void adaptTraveltime(const std::string& edgeID, double time, double begin = 0, double end = SUMOTime_MAX / 1000.0) const;
176  void setEffort(const std::string& edgeID, double effort, SUMOTime begin = 0, SUMOTime end = SUMOTime_MAX) const;
177  void setMaxSpeed(const std::string& edgeID, double speed) const;
178 
179  private:
181  EdgeScope(const EdgeScope& src);
182 
184  EdgeScope& operator=(const EdgeScope& src);
185 
186  };
187 
188 
189 
190 
191 
195  class GUIScope : public TraCIScopeWrapper {
196  public:
197  GUIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
198  virtual ~GUIScope() {}
199 
200  std::vector<std::string> getIDList() const;
201  double getZoom(const std::string& viewID = DEFAULT_VIEW) const;
202  TraCIPosition getOffset(const std::string& viewID = DEFAULT_VIEW) const;
203  std::string getSchema(const std::string& viewID = DEFAULT_VIEW) const;
204  TraCIBoundary getBoundary(const std::string& viewID = DEFAULT_VIEW) const;
205  void setZoom(const std::string& viewID, double zoom) const;
206  void setOffset(const std::string& viewID, double x, double y) const;
207  void setSchema(const std::string& viewID, const std::string& schemeName) const;
208  void setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const;
209  void screenshot(const std::string& viewID, const std::string& filename) const;
210  void trackVehicle(const std::string& viewID, const std::string& vehID) const;
211 
212  private:
214  GUIScope(const GUIScope& src);
215 
217  GUIScope& operator=(const GUIScope& src);
218 
219  };
220 
221 
222 
223 
224 
229  public:
231  virtual ~InductionLoopScope() {}
232 
233  std::vector<std::string> getIDList() const;
234  double getPosition(const std::string& loopID) const;
235  std::string getLaneID(const std::string& loopID) const;
236  int getLastStepVehicleNumber(const std::string& loopID) const;
237  double getLastStepMeanSpeed(const std::string& loopID) const;
238  std::vector<std::string> getLastStepVehicleIDs(const std::string& loopID) const;
239  double getLastStepOccupancy(const std::string& loopID) const;
240  double getLastStepMeanLength(const std::string& loopID) const;
241  double getTimeSinceDetection(const std::string& loopID) const;
242  std::vector<TraCIVehicleData> getVehicleData(const std::string& loopID) const;
243 
244 
245  private:
248 
251 
252  };
253 
254 
255 
256 
257 
262  public:
264  virtual ~JunctionScope() {}
265 
266  std::vector<std::string> getIDList() const;
267  TraCIPosition getPosition(const std::string& junctionID) const;
268 
269  private:
271  JunctionScope(const JunctionScope& src);
272 
275 
276  };
277 
278 
279 
280 
281 
285  class LaneScope : public TraCIScopeWrapper {
286  public:
287  LaneScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
288  virtual ~LaneScope() {}
289 
290  std::vector<std::string> getIDList() const;
291  double getLength(const std::string& laneID) const;
292  double getMaxSpeed(const std::string& laneID) const;
293  double getWidth(const std::string& laneID) const;
294  std::vector<std::string> getAllowed(const std::string& laneID) const;
295  std::vector<std::string> getDisallowed(const std::string& laneID) const;
296  int getLinkNumber(const std::string& laneID) const;
297  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 
315  void setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const;
316  void setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const;
317  void setMaxSpeed(const std::string& laneID, double speed) const;
318  void setLength(const std::string& laneID, double length) const;
319 
320  private:
322  LaneScope(const LaneScope& src);
323 
325  LaneScope& operator=(const LaneScope& src);
326 
327  };
328 
329 
334  public:
336  virtual ~LaneAreaScope() {}
337 
338  std::vector<std::string> getIDList() const;
339 
340  private:
342  LaneAreaScope(const LaneAreaScope& src);
343 
346 
347  };
348 
349 
353  class MeMeScope : public TraCIScopeWrapper {
354  public:
355  MeMeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
356  virtual ~MeMeScope() {}
357 
358  std::vector<std::string> getIDList() const;
359  int getLastStepVehicleNumber(const std::string& detID) const;
360  double getLastStepMeanSpeed(const std::string& detID) const;
361  std::vector<std::string> getLastStepVehicleIDs(const std::string& detID) const;
362  int getLastStepHaltingNumber(const std::string& detID) const;
363 
364  private:
366  MeMeScope(const MeMeScope& src);
367 
369  MeMeScope& operator=(const MeMeScope& src);
370 
371  };
372 
373 
374 
375 
376 
380  class POIScope : public TraCIScopeWrapper {
381  public:
382  POIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
383  virtual ~POIScope() {}
384 
385  std::vector<std::string> getIDList() const;
386  std::string getType(const std::string& poiID) const;
387  TraCIPosition getPosition(const std::string& poiID) const;
388  TraCIColor getColor(const std::string& poiID) const;
389 
390  void setType(const std::string& poiID, const std::string& setType) const;
391  void setPosition(const std::string& poiID, double x, double y) const;
392  void setColor(const std::string& poiID, const TraCIColor& c) const;
393  void add(const std::string& poiID, double x, double y, const TraCIColor& c, const std::string& type, int layer) const;
394  void remove(const std::string& poiID, int layer = 0) const;
395 
396  private:
398  POIScope(const POIScope& src);
399 
401  POIScope& operator=(const POIScope& src);
402 
403  };
404 
405 
406 
407 
408 
413  public:
415  virtual ~PolygonScope() {}
416 
417  std::vector<std::string> getIDList() const;
418  std::string getType(const std::string& polygonID) const;
419  TraCIPositionVector getShape(const std::string& polygonID) const;
420  TraCIColor getColor(const std::string& polygonID) const;
421  void setType(const std::string& polygonID, const std::string& setType) const;
422  void setShape(const std::string& polygonID, const TraCIPositionVector& shape) const;
423  void setColor(const std::string& polygonID, const TraCIColor& c) const;
424  void add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) const;
425  void remove(const std::string& polygonID, int layer = 0) const;
426 
427  private:
429  PolygonScope(const PolygonScope& src);
430 
432  PolygonScope& operator=(const PolygonScope& src);
433 
434  };
435 
436 
437 
438 
439 
443  class RouteScope : public TraCIScopeWrapper {
444  public:
445  RouteScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
446  virtual ~RouteScope() {}
447 
448  std::vector<std::string> getIDList() const;
449  std::vector<std::string> getEdges(const std::string& routeID) const;
450 
451  void add(const std::string& routeID, const std::vector<std::string>& edges) const;
452 
453  private:
455  RouteScope(const RouteScope& src);
456 
458  RouteScope& operator=(const RouteScope& src);
459 
460  };
461 
462 
463 
465  typedef std::map<int, TraCIValue> TraCIValues;
466  typedef std::map<std::string, TraCIValues> SubscribedValues;
467  typedef std::map<std::string, SubscribedValues> SubscribedContextValues;
468 
469 
474  public:
476  virtual ~SimulationScope() {}
477 
478  SUMOTime getCurrentTime() const;
479  int getLoadedNumber() const;
480  std::vector<std::string> getLoadedIDList() const;
481  int getDepartedNumber() const;
482  std::vector<std::string> getDepartedIDList() const;
483  int getArrivedNumber() const;
484  std::vector<std::string> getArrivedIDList() const;
485  int getStartingTeleportNumber() const;
486  std::vector<std::string> getStartingTeleportIDList() const;
487  int getEndingTeleportNumber() const;
488  std::vector<std::string> getEndingTeleportIDList() const;
489  SUMOTime getDeltaT() const;
490  TraCIBoundary getNetBoundary() const;
491  int getMinExpectedNumber() const;
492 
493  void subscribe(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
494  void subscribeContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector<int>& vars) const;
495 
496  const SubscribedValues& getSubscriptionResults() const;
497  const TraCIValues& getSubscriptionResults(const std::string& objID) const;
498 
499  const SubscribedContextValues& getContextSubscriptionResults() const;
500  const SubscribedValues& getContextSubscriptionResults(const std::string& objID) const;
501 
502  private:
504  SimulationScope(const SimulationScope& src);
505 
508 
509  };
510 
511 
512 
513 
514 
519  public:
521  virtual ~TrafficLightScope() {}
522 
523  std::vector<std::string> getIDList() const;
524  std::string getRedYellowGreenState(const std::string& tlsID) const;
525  std::vector<TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) const;
526  std::vector<std::string> getControlledLanes(const std::string& tlsID) const;
527  std::vector<TraCILink> getControlledLinks(const std::string& tlsID) const;
528  std::string getProgram(const std::string& tlsID) const;
529  int getPhase(const std::string& tlsID) const;
530  int getNextSwitch(const std::string& tlsID) const;
531 
532  void setRedYellowGreenState(const std::string& tlsID, const std::string& state) const;
533  void setPhase(const std::string& tlsID, int index) const;
534  void setProgram(const std::string& tlsID, const std::string& programID) const;
535  void setPhaseDuration(const std::string& tlsID, int phaseDuration) const;
536  void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const TraCILogic& logic) const;
537 
538  private:
541 
544 
545  };
546 
547 
548 
549 
550 
555  public:
557  virtual ~VehicleTypeScope() {}
558 
559  std::vector<std::string> getIDList() const;
560  double getLength(const std::string& typeID) const;
561  double getMaxSpeed(const std::string& typeID) const;
562  double getSpeedFactor(const std::string& typeID) const;
563  double getSpeedDeviation(const std::string& typeID) const;
564  double getAccel(const std::string& typeID) const;
565  double getDecel(const std::string& typeID) const;
566  double getImperfection(const std::string& typeID) const;
567  double getTau(const std::string& typeID) const;
568  std::string getVehicleClass(const std::string& typeID) const;
569  std::string getEmissionClass(const std::string& typeID) const;
570  std::string getShapeClass(const std::string& typeID) const;
571  double getMinGap(const std::string& typeID) const;
572  double getWidth(const std::string& typeID) const;
573  double getHeight(const std::string& typeID) const;
574  TraCIColor getColor(const std::string& typeID) const;
575  double getMinGapLat(const std::string& typeID) const;
576  double getMaxSpeedLat(const std::string& typeID) const;
577  std::string getLateralAlignment(const std::string& typeID) const;
578 
579  void setLength(const std::string& typeID, double length) const;
580  void setMaxSpeed(const std::string& typeID, double speed) const;
581  void setVehicleClass(const std::string& typeID, const std::string& clazz) const;
582  void setSpeedFactor(const std::string& typeID, double factor) const;
583  void setSpeedDeviation(const std::string& typeID, double deviation) const;
584  void setEmissionClass(const std::string& typeID, const std::string& clazz) const;
585  void setShapeClass(const std::string& typeID, const std::string& shapeClass) const;
586  void setWidth(const std::string& typeID, double width) const;
587  void setHeight(const std::string& typeID, double height) const;
588  void setMinGap(const std::string& typeID, double minGap) const;
589  void setAccel(const std::string& typeID, double accel) const;
590  void setDecel(const std::string& typeID, double decel) const;
591  void setImperfection(const std::string& typeID, double imperfection) const;
592  void setTau(const std::string& typeID, double tau) const;
593  void setColor(const std::string& typeID, const TraCIColor& c) const;
594  void setMinGapLat(const std::string& typeID, double minGapLat) const;
595  void setMaxSpeedLat(const std::string& typeID, double speed) const;
596  void setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const;
597 
598  private:
601 
604 
605  };
606 
607 
608 
609 
610 
615  public:
617  virtual ~VehicleScope() {}
618 
619 
620  struct NextTLSData {
621  /* @brief Constructor */
624  std::string id;
626  int tlIndex;
628  double dist;
630  char state;
631  };
632 
633 
634  std::vector<std::string> getIDList() const;
635  int getIDCount() const;
636  double getSpeed(const std::string& vehicleID) const;
637  double getMaxSpeed(const std::string& vehicleID) const;
638  TraCIPosition getPosition(const std::string& vehicleID) const;
639  double getAngle(const std::string& vehicleID) const;
640  std::string getRoadID(const std::string& vehicleID) const;
641  std::string getLaneID(const std::string& vehicleID) const;
642  int getLaneIndex(const std::string& vehicleID) const;
643  std::string getTypeID(const std::string& vehicleID) const;
644  std::string getRouteID(const std::string& vehicleID) const;
645  int getRouteIndex(const std::string& vehicleID) const;
646  std::vector<std::string> getEdges(const std::string& vehicleID) const;
647  TraCIColor getColor(const std::string& vehicleID) const;
648  double getLanePosition(const std::string& vehicleID) const;
649  double getLateralLanePosition(const std::string& vehicleID) const;
650  double getCO2Emission(const std::string& vehicleID) const;
651  double getCOEmission(const std::string& vehicleID) const;
652  double getHCEmission(const std::string& vehicleID) const;
653  double getPMxEmission(const std::string& vehicleID) const;
654  double getNOxEmission(const std::string& vehicleID) const;
655  double getFuelConsumption(const std::string& vehicleID) const;
656  double getNoiseEmission(const std::string& vehicleID) const;
657  double getElectricityConsumption(const std::string& vehicleID) const;
658  int getSignalStates(const std::string& vehicleID) const;
659  double getWaitingTime(const std::string& vehicleID) const;
660  std::vector<NextTLSData> getNextTLS(const std::string& vehID) const;
661  int getSpeedMode(const std::string& vehicleID) const;
662  double getSlope(const std::string& vehicleID) const;
663  std::string getLine(const std::string& vehicleID) const;
664  std::vector<std::string> getVia(const std::string& vehicleID) const;
665  std::string getEmissionClass(const std::string& vehicleID) const;
666  std::string getShapeClass(const std::string& vehicleID) const;
667 
668  /* /// not yet implemented
669  int getBestLanes(const std::string& vehicleID) const;
670  int getStopState(const std::string& vehicleID) const;
671  double getLength(const std::string& vehicleID) const;
672  double getAccel(const std::string& vehicleID) const;
673  double getDecel(const std::string& vehicleID) const;
674  double getTau(const std::string& vehicleID) const;
675  double getImperfection(const std::string& vehicleID) const;
676  double getSpeedFactor(const std::string& vehicleID) const;
677  double getSpeedDeviation(const std::string& vehicleID) const;
678  std::string getVClass(const std::string& vehicleID) const;
679  double getMinGap(const std::string& vehicleID) const;
680  double getWidth(const std::string& vehicleID) const;
681  */
682 
683  void add(const std::string& vehicleID,
684  const std::string& routeID,
685  const std::string& typeID = "DEFAULT_VEHTYPE",
686  std::string depart = "-1",
687  const std::string& departLane = "first",
688  const std::string& departPos = "base",
689  const std::string& departSpeed = "0",
690  const std::string& arrivalLane = "current",
691  const std::string& arrivalPos = "max",
692  const std::string& arrivalSpeed = "current",
693  const std::string& fromTaz = "",
694  const std::string& toTaz = "",
695  const std::string& line = "",
696  int personCapacity = 0,
697  int personNumber = 0) const;
698 
699  void changeTarget(const std::string& vehicleID, const std::string& edgeID) const;
700  void moveTo(const std::string& vehicleID, const std::string& laneID, double position) const;
701  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;
702  void slowDown(const std::string& vehicleID, double speed, int duration) const;
703  void setSpeed(const std::string& vehicleID, double speed) const;
704  void setMaxSpeed(const std::string& vehicleID, double speed) const;
705  void remove(const std::string& vehicleID, char reason = REMOVE_VAPORIZED) const;
706  void setColor(const std::string& vehicleID, const TraCIColor& c) const;
707  void setLine(const std::string& vehicleID, const std::string& line) const;
708  void setVia(const std::string& vehicleID, const std::vector<std::string>& via) const;
709  void setShapeClass(const std::string& vehicleID, const std::string& clazz) const;
710  void setEmissionClass(const std::string& vehicleID, const std::string& clazz) const;
711 
712  private:
714  VehicleScope(const VehicleScope& src);
715 
717  VehicleScope& operator=(const VehicleScope& src);
718 
719  };
720 
725  public:
726  PersonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
727  virtual ~PersonScope() {}
728 
729  std::vector<std::string> getIDList() const;
730  int getIDCount() const;
731  double getSpeed(const std::string& personID) const;
732  TraCIPosition getPosition(const std::string& personID) const;
733  std::string getRoadID(const std::string& personID) const;
734  std::string getTypeID(const std::string& personID) const;
735  double getWaitingTime(const std::string& personID) const;
736  std::string getNextEdge(const std::string& personID) const;
737  std::string getVehicle(const std::string& personID) const;
738  int getRemainingStages(const std::string& personID) const;
739  int getStage(const std::string& personID, int nextStageIndex = 0) const;
740  std::vector<std::string> getEdges(const std::string& personID, int nextStageIndex = 0) const;
741 
742  void removeStages(const std::string& personID) const;
743  void add(const std::string& personID, const std::string& edgeID, double pos, double depart = DEPARTFLAG_NOW, const std::string typeID = "DEFAULT_PEDTYPE");
744  void appendWaitingStage(const std::string& personID, double duration, const std::string& description = "waiting", const std::string& stopID = "");
745  void appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration = -1, double speed = -1, const std::string& stopID = "");
746  void appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID = "");
747  void removeStage(const std::string& personID, int nextStageIndex) const;
748  void setSpeed(const std::string& personID, double speed) const;
749  void setType(const std::string& personID, const std::string& typeID) const;
750  void setLength(const std::string& personID, double length) const;
751  void setWidth(const std::string& personID, double width) const;
752  void setHeight(const std::string& personID, double height) const;
753  void setMinGap(const std::string& personID, double minGap) const;
754  void setColor(const std::string& personID, const TraCIColor& c) const;
755 
756  private:
758  PersonScope(const PersonScope& src);
759 
761  PersonScope& operator=(const PersonScope& src);
762  };
763 
764 
765 
766 public:
797 
798 
799 protected:
802 
805  void send_commandSimulationStep(SUMOTime time) const;
806 
807 
810  void send_commandClose() const;
811 
812 
819  void send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add = 0) const;
820 
821 
828  void send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const;
829 
830 
838  void send_commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
839 
840 
850  void send_commandSubscribeObjectContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
851  int domain, double range, const std::vector<int>& vars) const;
853 
854 
855  void send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane,
856  const double x, const double y, const double angle, const int keepRoute) const;
857 
858 
861 
868  void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
869 
873  int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
874 
875  void processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId = false) const;
877 
880  void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, SubscribedValues& into);
881 
882  template <class T>
883  static inline std::string toString(const T& t, std::streamsize accuracy = PRECISION) {
884  std::ostringstream oss;
885  oss.setf(std::ios::fixed , std::ios::floatfield);
886  oss << std::setprecision(accuracy);
887  oss << t;
888  return oss.str();
889  }
890 
892  void closeSocket();
893 
894 protected:
897 
898  SubscribedValues mySubscribedValues;
899  SubscribedContextValues mySubscribedContextValues;
900 };
901 
902 
903 #endif
904 
905 /****************************************************************************/
906 
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:768
#define DEPARTFLAG_NOW
char state
The current state of the tls.
Definition: TraCIAPI.h:630
LaneScope(TraCIAPI &parent)
Definition: TraCIAPI.h:287
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:151
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:896
C++ TraCI client API implementation.
Definition: TraCIAPI.h:63
void close()
ends the simulation and closes the connection
Definition: TraCIAPI.cpp:79
Scope for interaction with edges.
Definition: TraCIAPI.h:150
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:250
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:66
MeMeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:355
virtual ~PolygonScope()
Definition: TraCIAPI.h:415
std::map< int, TraCIValue > TraCIValues
{object->{variable->value}}
Definition: TraCIAPI.h:465
GUIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:197
TraCIScopeWrapper & operator=(const TraCIScopeWrapper &src)
invalidated assignment operator
JunctionScope junction
Scope for interaction with junctions.
Definition: TraCIAPI.h:774
PersonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:726
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:124
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:776
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:782
#define DEFAULT_VIEW
Definition: TraCIAPI.h:47
void load(const std::vector< std::string > &args)
Let sumo load a simulation using the given command line like options.
Definition: TraCIAPI.cpp:562
Scope for interaction with vehicles.
Definition: TraCIAPI.h:614
virtual ~RouteScope()
Definition: TraCIAPI.h:446
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:518
SubscribedContextValues mySubscribedContextValues
Definition: TraCIAPI.h:899
virtual ~LaneScope()
Definition: TraCIAPI.h:288
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:89
void simulationStep(SUMOTime time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:541
Scope for interaction with lane area detectors.
Definition: TraCIAPI.h:333
Scope for interaction with the gui.
Definition: TraCIAPI.h:195
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:792
void readVariableSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:520
std::map< std::string, SubscribedValues > SubscribedContextValues
Definition: TraCIAPI.h:467
Scope for interaction with routes.
Definition: TraCIAPI.h:443
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:772
TraCIPosition getPosition(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:410
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:228
POIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:382
virtual ~MeMeScope()
Definition: TraCIAPI.h:356
Scope for interaction with POIs.
Definition: TraCIAPI.h:380
Scope for interaction with the simulation.
Definition: TraCIAPI.h:473
Scope for interaction with multi entry/-exit detectors.
Definition: TraCIAPI.h:353
virtual ~EdgeScope()
Definition: TraCIAPI.h:153
SubscribedValues mySubscribedValues
Definition: TraCIAPI.h:898
InductionLoopScope(TraCIAPI &parent)
Definition: TraCIAPI.h:230
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition: TraCIAPI.h:780
std::map< std::string, TraCIValues > SubscribedValues
Definition: TraCIAPI.h:466
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:554
A 3D-position.
Definition: TraCIDefs.h:71
PolygonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:414
#define PRECISION
Definition: TraCIAPI.h:48
virtual ~JunctionScope()
Definition: TraCIAPI.h:264
double getFloat(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:358
~TraCIAPI()
Destructor.
Definition: TraCIAPI.cpp:60
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:172
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:788
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:100
Scope for interaction with polygons.
Definition: TraCIAPI.h:412
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:230
int getInt(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:349
int getByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:340
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition: TraCIAPI.h:883
int getUnsignedByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:331
double getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:367
Scope for interaction with vehicles.
Definition: TraCIAPI.h:724
Scope for interaction with junctions.
Definition: TraCIAPI.h:261
long long int SUMOTime
Definition: TraCIAPI.h:59
TrafficLightScope(TraCIAPI &parent)
Definition: TraCIAPI.h:520
virtual ~VehicleScope()
Definition: TraCIAPI.h:617
void readContextSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:527
TraCIPositionVector getPolygon(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:392
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, SubscribedValues &into)
Definition: TraCIAPI.cpp:459
virtual ~SimulationScope()
Definition: TraCIAPI.h:476
std::vector< std::string > getStringVector(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:432
EdgeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:152
POIScope poi
Scope for interaction with POIs.
Definition: TraCIAPI.h:784
virtual ~POIScope()
Definition: TraCIAPI.h:383
virtual ~PersonScope()
Definition: TraCIAPI.h:727
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:790
Scope for interaction with lanes.
Definition: TraCIAPI.h:285
TraCIScopeWrapper(TraCIAPI &parent)
Constructor.
Definition: TraCIAPI.h:123
RouteScope(TraCIAPI &parent)
Definition: TraCIAPI.h:445
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:794
SUMOTime getSUMOTime(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:322
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:313
A 3D-bounding box.
Definition: TraCIDefs.h:90
std::string id
The id of the next tls.
Definition: TraCIAPI.h:624
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:786
virtual ~TraCIScopeWrapper()
Destructor.
Definition: TraCIAPI.h:126
VehicleTypeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:556
virtual ~GUIScope()
Definition: TraCIAPI.h:198
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:113
TraCIAPI & myParent
The parent TraCI client which offers the connection.
Definition: TraCIAPI.h:131
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:289
TraCIBoundary getBoundingBox(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:376
#define REMOVE_VAPORIZED
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:770
#define SUMOTime_MAX
Definition: TraCIAPI.h:60
TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:446
long long int SUMOTime
Definition: TraCIDefs.h:52
std::string getString(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:423
VehicleScope(TraCIAPI &parent)
Definition: TraCIAPI.h:616
SimulationScope(TraCIAPI &parent)
Definition: TraCIAPI.h:475
double dist
The distance to the tls.
Definition: TraCIAPI.h:628
An abstract interface for accessing type-dependent values.
Definition: TraCIAPI.h:118
LaneAreaScope lanearea
Scope for interaction with lanes.
Definition: TraCIAPI.h:778
TraCIAPI()
Constructor.
Definition: TraCIAPI.cpp:48
virtual ~LaneAreaScope()
Definition: TraCIAPI.h:336
int tlIndex
The tls index of the controlled link.
Definition: TraCIAPI.h:626
LaneAreaScope(TraCIAPI &parent)
Definition: TraCIAPI.h:335
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:200
A list of positions.
JunctionScope(TraCIAPI &parent)
Definition: TraCIAPI.h:263
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:796