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 
43 // ===========================================================================
44 // global definitions
45 // ===========================================================================
46 #define DEFAULT_VIEW "View #0"
47 #define PRECISION 2
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
58 typedef long long int SUMOTime; // <utils/common/SUMOTime.h>
59 #define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
60 
61 
62 class TraCIAPI {
63 public:
66 
70  struct TraCIPosition {
71  double x, y, z;
72  };
73 
77  struct TraCIColor {
78  int r, g, b, a;
79  };
80 
84  typedef std::vector<TraCIPosition> TraCIPositionVector;
85 
89  struct TraCIBoundary {
90  double xMin, yMin, zMin;
91  double xMax, yMax, zMax;
92  };
93 
94  struct TraCIValue {
95  union {
96  double scalar;
99  };
100  std::string string;
101  };
102 
103  class TraCIPhase {
104  public:
105  TraCIPhase(const SUMOTime _duration, const SUMOTime _duration1, const SUMOTime _duration2, const std::string& _phase)
106  : duration(_duration), duration1(_duration1), duration2(_duration2), phase(_phase) {}
108 
109  SUMOTime duration, duration1, duration2;
110  std::string phase;
111  };
112 
113 
114  class TraCILogic {
115  public:
116  TraCILogic(const std::string& _subID, int _type, const std::map<std::string, SUMOReal>& _subParameter, int _currentPhaseIndex, const std::vector<TraCIPhase>& _phases)
117  : subID(_subID), type(_type), subParameter(_subParameter), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
119 
120  std::string subID;
121  int type;
122  std::map<std::string, SUMOReal> subParameter;
124  std::vector<TraCIPhase> phases;
125  };
126 
127  class TraCILink {
128  public:
129  TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
130  : from(_from), via(_via), to(_to) {}
132 
133  std::string from;
134  std::string via;
135  std::string to;
136  };
137 
139 
140 
141 
144  TraCIAPI();
145 
146 
148  ~TraCIAPI();
149 
150 
153 
159  void connect(const std::string& host, int port);
160 
161 
163  void close();
165 
167  void simulationStep(SUMOTime time = 0);
168 
169 
172 
173  SUMOTime getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
174  int getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
175  int getByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
176  int getInt(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
177  SUMOReal getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
178  SUMOReal getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
179  TraCIBoundary getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
180  TraCIPositionVector getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
181  TraCIPosition getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
182  std::string getString(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
183  std::vector<std::string> getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
184  TraCIColor getColor(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
186 
187 
188  static const SUMOReal DEPART_NOW;
189 
196  public:
200  TraCIScopeWrapper(TraCIAPI& parent) : myParent(parent) {}
201 
203  virtual ~TraCIScopeWrapper() {}
204 
205 
206  protected:
209 
210 
211  private:
214 
216  TraCIScopeWrapper& operator=(const TraCIScopeWrapper& src);
217 
218  };
219 
220 
221 
222 
223 
227  class EdgeScope : public TraCIScopeWrapper {
228  public:
229  EdgeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
230  virtual ~EdgeScope() {}
231 
232  std::vector<std::string> getIDList() const;
233  int getIDCount() const;
234  SUMOReal getAdaptedTraveltime(const std::string& edgeID, SUMOReal time) const;
235  SUMOReal getEffort(const std::string& edgeID, SUMOTime time) const;
236  SUMOReal getCO2Emission(const std::string& edgeID) const;
237  SUMOReal getCOEmission(const std::string& edgeID) const;
238  SUMOReal getHCEmission(const std::string& edgeID) const;
239  SUMOReal getPMxEmission(const std::string& edgeID) const;
240  SUMOReal getNOxEmission(const std::string& edgeID) const;
241  SUMOReal getFuelConsumption(const std::string& edgeID) const;
242  SUMOReal getNoiseEmission(const std::string& edgeID) const;
243  SUMOReal getElectricityConsumption(const std::string& edgeID) const;
244  SUMOReal getLastStepMeanSpeed(const std::string& edgeID) const;
245  SUMOReal getLastStepOccupancy(const std::string& edgeID) const;
246  SUMOReal getLastStepLength(const std::string& edgeID) const;
247  SUMOReal getTraveltime(const std::string& edgeID) const;
248  int getLastStepVehicleNumber(const std::string& edgeID) const;
249  SUMOReal getLastStepHaltingNumber(const std::string& edgeID) const;
250  std::vector<std::string> getLastStepVehicleIDs(const std::string& edgeID) const;
251 
252  void adaptTraveltime(const std::string& edgeID, SUMOReal time, SUMOReal begin = 0, SUMOReal end = SUMOTime_MAX / 1000.0) const;
253  void setEffort(const std::string& edgeID, SUMOReal effort, SUMOTime begin = 0, SUMOTime end = SUMOTime_MAX) const;
254  void setMaxSpeed(const std::string& edgeID, SUMOReal speed) const;
255 
256  private:
258  EdgeScope(const EdgeScope& src);
259 
261  EdgeScope& operator=(const EdgeScope& src);
262 
263  };
264 
265 
266 
267 
268 
272  class GUIScope : public TraCIScopeWrapper {
273  public:
274  GUIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
275  virtual ~GUIScope() {}
276 
277  std::vector<std::string> getIDList() const;
278  SUMOReal getZoom(const std::string& viewID = DEFAULT_VIEW) const;
279  TraCIPosition getOffset(const std::string& viewID = DEFAULT_VIEW) const;
280  std::string getSchema(const std::string& viewID = DEFAULT_VIEW) const;
281  TraCIBoundary getBoundary(const std::string& viewID = DEFAULT_VIEW) const;
282  void setZoom(const std::string& viewID, SUMOReal zoom) const;
283  void setOffset(const std::string& viewID, SUMOReal x, SUMOReal y) const;
284  void setSchema(const std::string& viewID, const std::string& schemeName) const;
285  void setBoundary(const std::string& viewID, SUMOReal xmin, SUMOReal ymin, SUMOReal xmax, SUMOReal ymax) const;
286  void screenshot(const std::string& viewID, const std::string& filename) const;
287  void trackVehicle(const std::string& viewID, const std::string& vehID) const;
288 
289  private:
291  GUIScope(const GUIScope& src);
292 
294  GUIScope& operator=(const GUIScope& src);
295 
296  };
297 
298 
299 
300 
301 
306  public:
308  virtual ~InductionLoopScope() {}
309 
310  struct VehicleData {
311  /* @brief Constructor
312  (mirrors MSInductLoop::VehicleData) */
315  std::string id;
323  std::string typeID;
324  };
325 
326  std::vector<std::string> getIDList() const;
327  SUMOReal getPosition(const std::string& loopID) const;
328  std::string getLaneID(const std::string& loopID) const;
329  int getLastStepVehicleNumber(const std::string& loopID) const;
330  SUMOReal getLastStepMeanSpeed(const std::string& loopID) const;
331  std::vector<std::string> getLastStepVehicleIDs(const std::string& loopID) const;
332  SUMOReal getLastStepOccupancy(const std::string& loopID) const;
333  SUMOReal getLastStepMeanLength(const std::string& loopID) const;
334  SUMOReal getTimeSinceDetection(const std::string& loopID) const;
335  std::vector<VehicleData> getVehicleData(const std::string& loopID) const;
336 
337 
338  private:
341 
343  InductionLoopScope& operator=(const InductionLoopScope& src);
344 
345  };
346 
347 
348 
349 
350 
355  public:
357  virtual ~JunctionScope() {}
358 
359  std::vector<std::string> getIDList() const;
360  TraCIPosition getPosition(const std::string& junctionID) const;
361 
362  private:
364  JunctionScope(const JunctionScope& src);
365 
367  JunctionScope& operator=(const JunctionScope& src);
368 
369  };
370 
371 
372 
373 
374 
378  class LaneScope : public TraCIScopeWrapper {
379  public:
380  LaneScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
381  virtual ~LaneScope() {}
382 
383  std::vector<std::string> getIDList() const;
384  SUMOReal getLength(const std::string& laneID) const;
385  SUMOReal getMaxSpeed(const std::string& laneID) const;
386  SUMOReal getWidth(const std::string& laneID) const;
387  std::vector<std::string> getAllowed(const std::string& laneID) const;
388  std::vector<std::string> getDisallowed(const std::string& laneID) const;
389  int getLinkNumber(const std::string& laneID) const;
390  TraCIPositionVector getShape(const std::string& laneID) const;
391  std::string getEdgeID(const std::string& laneID) const;
392  SUMOReal getCO2Emission(const std::string& laneID) const;
393  SUMOReal getCOEmission(const std::string& laneID) const;
394  SUMOReal getHCEmission(const std::string& laneID) const;
395  SUMOReal getPMxEmission(const std::string& laneID) const;
396  SUMOReal getNOxEmission(const std::string& laneID) const;
397  SUMOReal getFuelConsumption(const std::string& laneID) const;
398  SUMOReal getNoiseEmission(const std::string& laneID) const;
399  SUMOReal getElectricityConsumption(const std::string& laneID) const;
400  SUMOReal getLastStepMeanSpeed(const std::string& laneID) const;
401  SUMOReal getLastStepOccupancy(const std::string& laneID) const;
402  SUMOReal getLastStepLength(const std::string& laneID) const;
403  SUMOReal getTraveltime(const std::string& laneID) const;
404  int getLastStepVehicleNumber(const std::string& laneID) const;
405  int getLastStepHaltingNumber(const std::string& laneID) const;
406  std::vector<std::string> getLastStepVehicleIDs(const std::string& laneID) const;
407 
408  void setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const;
409  void setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const;
410  void setMaxSpeed(const std::string& laneID, SUMOReal speed) const;
411  void setLength(const std::string& laneID, SUMOReal length) const;
412 
413  private:
415  LaneScope(const LaneScope& src);
416 
418  LaneScope& operator=(const LaneScope& src);
419 
420  };
421 
422 
426  class AreaScope : public TraCIScopeWrapper {
427  public:
428  AreaScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
429  virtual ~AreaScope() {}
430 
431  std::vector<std::string> getIDList() const;
432  int getJamLengthVehicle(const std::string& laneID) const;
433  SUMOReal getJamLengthMeters(const std::string& laneID) const;
434 
435  private:
437  AreaScope(const AreaScope& src);
438 
440  AreaScope& operator=(const AreaScope& src);
441 
442  };
443 
444 
448  class MeMeScope : public TraCIScopeWrapper {
449  public:
450  MeMeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
451  virtual ~MeMeScope() {}
452 
453  std::vector<std::string> getIDList() const;
454  int getLastStepVehicleNumber(const std::string& detID) const;
455  SUMOReal getLastStepMeanSpeed(const std::string& detID) const;
456  std::vector<std::string> getLastStepVehicleIDs(const std::string& detID) const;
457  int getLastStepHaltingNumber(const std::string& detID) const;
458 
459  private:
461  MeMeScope(const MeMeScope& src);
462 
464  MeMeScope& operator=(const MeMeScope& src);
465 
466  };
467 
468 
469 
470 
471 
475  class POIScope : public TraCIScopeWrapper {
476  public:
477  POIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
478  virtual ~POIScope() {}
479 
480  std::vector<std::string> getIDList() const;
481  std::string getType(const std::string& poiID) const;
482  TraCIPosition getPosition(const std::string& poiID) const;
483  TraCIColor getColor(const std::string& poiID) const;
484 
485  void setType(const std::string& poiID, const std::string& setType) const;
486  void setPosition(const std::string& poiID, SUMOReal x, SUMOReal y) const;
487  void setColor(const std::string& poiID, const TraCIColor& c) const;
488  void add(const std::string& poiID, SUMOReal x, SUMOReal y, const TraCIColor& c, const std::string& type, int layer) const;
489  void remove(const std::string& poiID, int layer = 0) const;
490 
491  private:
493  POIScope(const POIScope& src);
494 
496  POIScope& operator=(const POIScope& src);
497 
498  };
499 
500 
501 
502 
503 
508  public:
510  virtual ~PolygonScope() {}
511 
512  std::vector<std::string> getIDList() const;
513  std::string getType(const std::string& polygonID) const;
514  TraCIPositionVector getShape(const std::string& polygonID) const;
515  TraCIColor getColor(const std::string& polygonID) const;
516  void setType(const std::string& polygonID, const std::string& setType) const;
517  void setShape(const std::string& polygonID, const TraCIPositionVector& shape) const;
518  void setColor(const std::string& polygonID, const TraCIColor& c) const;
519  void add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) const;
520  void remove(const std::string& polygonID, int layer = 0) const;
521 
522  private:
524  PolygonScope(const PolygonScope& src);
525 
527  PolygonScope& operator=(const PolygonScope& src);
528 
529  };
530 
531 
532 
533 
534 
538  class RouteScope : public TraCIScopeWrapper {
539  public:
540  RouteScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
541  virtual ~RouteScope() {}
542 
543  std::vector<std::string> getIDList() const;
544  std::vector<std::string> getEdges(const std::string& routeID) const;
545 
546  void add(const std::string& routeID, const std::vector<std::string>& edges) const;
547 
548  private:
550  RouteScope(const RouteScope& src);
551 
553  RouteScope& operator=(const RouteScope& src);
554 
555  };
556 
557 
558 
560  typedef std::map<int, TraCIValue> TraCIValues;
561  typedef std::map<std::string, TraCIValues> SubscribedValues;
562  typedef std::map<std::string, SubscribedValues> SubscribedContextValues;
563 
564 
569  public:
571  virtual ~SimulationScope() {}
572 
573  SUMOTime getCurrentTime() const;
574  int getLoadedNumber() const;
575  std::vector<std::string> getLoadedIDList() const;
576  int getDepartedNumber() const;
577  std::vector<std::string> getDepartedIDList() const;
578  int getArrivedNumber() const;
579  std::vector<std::string> getArrivedIDList() const;
580  int getStartingTeleportNumber() const;
581  std::vector<std::string> getStartingTeleportIDList() const;
582  int getEndingTeleportNumber() const;
583  std::vector<std::string> getEndingTeleportIDList() const;
584  SUMOTime getDeltaT() const;
585  TraCIBoundary getNetBoundary() const;
586  int getMinExpectedNumber() const;
587 
588  void subscribe(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
589  void subscribeContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, SUMOReal range, const std::vector<int>& vars) const;
590 
591  SubscribedValues getSubscriptionResults();
592  TraCIValues getSubscriptionResults(const std::string& objID);
593 
594  SubscribedContextValues getContextSubscriptionResults();
595  SubscribedValues getContextSubscriptionResults(const std::string& objID);
596 
597  private:
599  SimulationScope(const SimulationScope& src);
600 
602  SimulationScope& operator=(const SimulationScope& src);
603 
604  };
605 
606 
607 
608 
609 
614  public:
616  virtual ~TrafficLightScope() {}
617 
618  std::vector<std::string> getIDList() const;
619  std::string getRedYellowGreenState(const std::string& tlsID) const;
620  std::vector<TraCIAPI::TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) const;
621  std::vector<std::string> getControlledLanes(const std::string& tlsID) const;
622  std::vector<TraCIAPI::TraCILink> getControlledLinks(const std::string& tlsID) const;
623  std::string getProgram(const std::string& tlsID) const;
624  int getPhase(const std::string& tlsID) const;
625  int getNextSwitch(const std::string& tlsID) const;
626 
627  void setRedYellowGreenState(const std::string& tlsID, const std::string& state) const;
628  void setPhase(const std::string& tlsID, int index) const;
629  void setProgram(const std::string& tlsID, const std::string& programID) const;
630  void setPhaseDuration(const std::string& tlsID, int phaseDuration) const;
631  void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const TraCIAPI::TraCILogic& logic) const;
632 
633  private:
636 
638  TrafficLightScope& operator=(const TrafficLightScope& src);
639 
640  };
641 
642 
643 
644 
645 
650  public:
652  virtual ~VehicleTypeScope() {}
653 
654  std::vector<std::string> getIDList() const;
655  SUMOReal getLength(const std::string& typeID) const;
656  SUMOReal getMaxSpeed(const std::string& typeID) const;
657  SUMOReal getSpeedFactor(const std::string& typeID) const;
658  SUMOReal getSpeedDeviation(const std::string& typeID) const;
659  SUMOReal getAccel(const std::string& typeID) const;
660  SUMOReal getDecel(const std::string& typeID) const;
661  SUMOReal getImperfection(const std::string& typeID) const;
662  SUMOReal getTau(const std::string& typeID) const;
663  std::string getVehicleClass(const std::string& typeID) const;
664  std::string getEmissionClass(const std::string& typeID) const;
665  std::string getShapeClass(const std::string& typeID) const;
666  SUMOReal getMinGap(const std::string& typeID) const;
667  SUMOReal getWidth(const std::string& typeID) const;
668  SUMOReal getHeight(const std::string& typeID) const;
669  TraCIColor getColor(const std::string& typeID) const;
670 
671  void setLength(const std::string& typeID, SUMOReal length) const;
672  void setMaxSpeed(const std::string& typeID, SUMOReal speed) const;
673  void setVehicleClass(const std::string& typeID, const std::string& clazz) const;
674  void setSpeedFactor(const std::string& typeID, SUMOReal factor) const;
675  void setSpeedDeviation(const std::string& typeID, SUMOReal deviation) const;
676  void setEmissionClass(const std::string& typeID, const std::string& clazz) const;
677  void setShapeClass(const std::string& typeID, const std::string& shapeClass) const;
678  void setWidth(const std::string& typeID, SUMOReal width) const;
679  void setHeight(const std::string& typeID, SUMOReal height) const;
680  void setMinGap(const std::string& typeID, SUMOReal minGap) const;
681  void setAccel(const std::string& typeID, SUMOReal accel) const;
682  void setDecel(const std::string& typeID, SUMOReal decel) const;
683  void setImperfection(const std::string& typeID, SUMOReal imperfection) const;
684  void setTau(const std::string& typeID, SUMOReal tau) const;
685  void setColor(const std::string& typeID, const TraCIColor& c) const;
686 
687  private:
690 
692  VehicleTypeScope& operator=(const VehicleTypeScope& src);
693 
694  };
695 
696 
697 
698 
699 
704  public:
706  virtual ~VehicleScope() {}
707 
708 
709  struct NextTLSData {
710  /* @brief Constructor */
713  std::string id;
715  int tlIndex;
719  char state;
720  };
721 
722 
723  std::vector<std::string> getIDList() const;
724  int getIDCount() const;
725  SUMOReal getSpeed(const std::string& vehicleID) const;
726  TraCIPosition getPosition(const std::string& vehicleID) const;
727  SUMOReal getAngle(const std::string& vehicleID) const;
728  std::string getRoadID(const std::string& vehicleID) const;
729  std::string getLaneID(const std::string& vehicleID) const;
730  int getLaneIndex(const std::string& vehicleID) const;
731  std::string getTypeID(const std::string& vehicleID) const;
732  std::string getRouteID(const std::string& vehicleID) const;
733  int getRouteIndex(const std::string& vehicleID) const;
734  std::vector<std::string> getEdges(const std::string& vehicleID) const;
735  TraCIColor getColor(const std::string& vehicleID) const;
736  SUMOReal getLanePosition(const std::string& vehicleID) const;
737  SUMOReal getCO2Emission(const std::string& vehicleID) const;
738  SUMOReal getCOEmission(const std::string& vehicleID) const;
739  SUMOReal getHCEmission(const std::string& vehicleID) const;
740  SUMOReal getPMxEmission(const std::string& vehicleID) const;
741  SUMOReal getNOxEmission(const std::string& vehicleID) const;
742  SUMOReal getFuelConsumption(const std::string& vehicleID) const;
743  SUMOReal getNoiseEmission(const std::string& vehicleID) const;
744  SUMOReal getElectricityConsumption(const std::string& vehicleID) const;
745  int getSignalStates(const std::string& vehicleID) const;
746  SUMOReal getWaitingTime(const std::string& vehicleID) const;
747  std::vector<NextTLSData> getNextTLS(const std::string& vehID) const;
748  int getSpeedMode(const std::string& vehicleID) const;
749  SUMOReal getSlope(const std::string& vehicleID) const;
750  std::string getLine(const std::string& vehicleID) const;
751  std::vector<std::string> getVia(const std::string& vehicleID) const;
752  std::string getEmissionClass(const std::string& vehicleID) const;
753  std::string getShapeClass(const std::string& vehicleID) const;
754 
755  /* /// not yet implemented
756  SUMOReal getCO2Emissions(const std::string& vehicleID) const;
757  SUMOReal getCOEmissions(const std::string& vehicleID) const;
758  SUMOReal getHCEmissions(const std::string& vehicleID) const;
759  SUMOReal getPMxEmissions(const std::string& vehicleID) const;
760  SUMOReal getNOxEmissions(const std::string& vehicleID) const;
761  SUMOReal getFuelConsumption(const std::string& vehicleID) const;
762  SUMOReal getNoiseEmission(const std::string& vehicleID) const;
763  int getBestLanes(const std::string& vehicleID) const;
764  int getStopState(const std::string& vehicleID) const;
765  SUMOReal getLength(const std::string& vehicleID) const;
766  SUMOReal getMaxSpeed(const std::string& vehicleID) const;
767  SUMOReal getAccel(const std::string& vehicleID) const;
768  SUMOReal getDecel(const std::string& vehicleID) const;
769  SUMOReal getTau(const std::string& vehicleID) const;
770  SUMOReal getImperfection(const std::string& vehicleID) const;
771  SUMOReal getSpeedFactor(const std::string& vehicleID) const;
772  SUMOReal getSpeedDeviation(const std::string& vehicleID) const;
773  std::string getVClass(const std::string& vehicleID) const;
774  SUMOReal getMinGap(const std::string& vehicleID) const;
775  SUMOReal getWidth(const std::string& vehicleID) const;
776  */
777 
778  void add(const std::string& vehicleID,
779  const std::string& routeID,
780  const std::string& typeID = "DEFAULT_VEHTYPE",
781  std::string depart = "-1",
782  const std::string& departLane = "first",
783  const std::string& departPos = "base",
784  const std::string& departSpeed = "0",
785  const std::string& arrivalLane = "current",
786  const std::string& arrivalPos = "max",
787  const std::string& arrivalSpeed = "current",
788  const std::string& fromTaz = "",
789  const std::string& toTaz = "",
790  const std::string& line = "",
791  int personCapacity = 0,
792  int personNumber = 0) const;
793 
794  void moveTo(const std::string& vehicleID, const std::string& laneID, SUMOReal position) const;
795  void moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const SUMOReal x, const SUMOReal y, const SUMOReal angle, const int keepRoute) const;
796  void slowDown(const std::string& vehicleID, SUMOReal speed, int duration) const;
797  void setSpeed(const std::string& vehicleID, SUMOReal speed) const;
798  void remove(const std::string& vehicleID, char reason = REMOVE_VAPORIZED) const;
799  void setColor(const std::string& vehicleID, const TraCIColor& c) const;
800  void setLine(const std::string& vehicleID, const std::string& line) const;
801  void setVia(const std::string& vehicleID, const std::vector<std::string>& via) const;
802  void setShapeClass(const std::string& vehicleID, const std::string& clazz) const;
803  void setEmissionClass(const std::string& vehicleID, const std::string& clazz) const;
804 
805  private:
807  VehicleScope(const VehicleScope& src);
808 
810  VehicleScope& operator=(const VehicleScope& src);
811 
812  };
813 
818  public:
819  PersonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
820  virtual ~PersonScope() {}
821 
822  std::vector<std::string> getIDList() const;
823  int getIDCount() const;
824  SUMOReal getSpeed(const std::string& personID) const;
825  TraCIPosition getPosition(const std::string& personID) const;
826  std::string getRoadID(const std::string& personID) const;
827  std::string getTypeID(const std::string& personID) const;
828  SUMOReal getWaitingTime(const std::string& personID) const;
829  std::string getNextEdge(const std::string& personID) const;
830  std::string getVehicle(const std::string& personID) const;
831  int getRemainingStages(const std::string& personID) const;
832  int getStage(const std::string& personID, int nextStageIndex = 0) const;
833  std::vector<std::string> getEdges(const std::string& personID, int nextStageIndex = 0) const;
834 
835  void removeStages(const std::string& personID) const;
836  void add(const std::string& personID, const std::string& edgeID, SUMOReal pos, SUMOReal depart = DEPART_NOW, const std::string typeID = "DEFAULT_PEDTYPE");
837  void appendWaitingStage(const std::string& personID, SUMOReal duration, const std::string& description = "waiting", const std::string& stopID = "");
838  void appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, SUMOReal arrivalPos, SUMOReal duration = -1, SUMOReal speed = -1, const std::string& stopID = "");
839  void appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID = "");
840  void removeStage(const std::string& personID, int nextStageIndex) const;
841  void setSpeed(const std::string& personID, SUMOReal speed) const;
842  void setType(const std::string& personID, const std::string& typeID) const;
843  void setLength(const std::string& personID, SUMOReal length) const;
844  void setWidth(const std::string& personID, SUMOReal width) const;
845  void setHeight(const std::string& personID, SUMOReal height) const;
846  void setMinGap(const std::string& personID, SUMOReal minGap) const;
847  void setColor(const std::string& personID, const TraCIColor& c) const;
848 
849  private:
851  PersonScope(const PersonScope& src);
852 
854  PersonScope& operator=(const PersonScope& src);
855  };
856 
857 
858 
859 public:
888 
889 
890 protected:
893 
896  void send_commandSimulationStep(SUMOTime time) const;
897 
898 
901  void send_commandClose() const;
902 
903 
910  void send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add = 0) const;
911 
912 
919  void send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const;
920 
921 
929  void send_commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
930 
931 
941  void send_commandSubscribeObjectContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
942  int domain, SUMOReal range, const std::vector<int>& vars) const;
944 
945 
946  void send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane,
947  const SUMOReal x, const SUMOReal y, const SUMOReal angle, const int keepRoute) const;
948 
949 
952 
959  void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
960 
964  int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
965 
966  void processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId = false) const;
968 
971  void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, SubscribedValues& into);
972 
973  template <class T>
974  static inline std::string toString(const T& t, std::streamsize accuracy = PRECISION) {
975  std::ostringstream oss;
976  oss.setf(std::ios::fixed , std::ios::floatfield);
977  oss << std::setprecision(accuracy);
978  oss << t;
979  return oss.str();
980  }
981 
983  void closeSocket();
984 
985 protected:
988 
989  SubscribedValues mySubscribedValues;
990  SubscribedContextValues mySubscribedContextValues;
991 };
992 
993 
994 #endif
995 
996 /****************************************************************************/
997 
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:861
TraCIPosition getPosition(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:414
SUMOReal entryTime
Entry-time of the vehicle in [s].
Definition: TraCIAPI.h:319
char state
The current state of the tls.
Definition: TraCIAPI.h:719
LaneScope(TraCIAPI &parent)
Definition: TraCIAPI.h:380
long long int SUMOTime
Definition: SUMOTime.h:43
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:987
C++ TraCI client API implementation.
Definition: TraCIAPI.h:62
void close()
ends the simulation and closes the connection
Definition: TraCIAPI.cpp:83
Scope for interaction with edges.
Definition: TraCIAPI.h:227
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:70
MeMeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:450
std::string typeID
Type of the vehicle in.
Definition: TraCIAPI.h:323
virtual ~PolygonScope()
Definition: TraCIAPI.h:510
std::map< int, TraCIValue > TraCIValues
{object->{variable->value}}
Definition: TraCIAPI.h:560
GUIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:274
std::string string
Definition: TraCIAPI.h:100
SUMOReal getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:371
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:117
JunctionScope junction
Scope for interaction with junctions.
Definition: TraCIAPI.h:867
PersonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:819
TraCIPhase(const SUMOTime _duration, const SUMOTime _duration1, const SUMOTime _duration2, const std::string &_phase)
Definition: TraCIAPI.h:105
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:869
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:887
#define DEFAULT_VIEW
Definition: TraCIAPI.h:46
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:317
Scope for interaction with vehicles.
Definition: TraCIAPI.h:703
virtual ~RouteScope()
Definition: TraCIAPI.h:541
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:613
SubscribedContextValues mySubscribedContextValues
Definition: TraCIAPI.h:990
virtual ~LaneScope()
Definition: TraCIAPI.h:381
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:93
void simulationStep(SUMOTime time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:538
Scope for interaction with the gui.
Definition: TraCIAPI.h:272
void send_commandMoveToXY(const std::string &vehicleID, const std::string &edgeID, const int lane, const SUMOReal x, const SUMOReal y, const SUMOReal angle, const int keepRoute) const
Definition: TraCIAPI.cpp:234
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:881
TraCIPositionVector getPolygon(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:396
void readVariableSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:517
std::map< std::string, SubscribedValues > SubscribedContextValues
Definition: TraCIAPI.h:562
Scope for interaction with routes.
Definition: TraCIAPI.h:538
TraCIColor color
Definition: TraCIAPI.h:98
SUMOTime duration2
Definition: TraCIAPI.h:109
TraCIBoundary getBoundingBox(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:380
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:865
SUMOReal leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIAPI.h:321
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:305
POIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:477
virtual ~MeMeScope()
Definition: TraCIAPI.h:451
AreaScope(TraCIAPI &parent)
Definition: TraCIAPI.h:428
Scope for interaction with POIs.
Definition: TraCIAPI.h:475
void send_commandSubscribeObjectContext(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, SUMOReal range, const std::vector< int > &vars) const
Sends a SubscribeContext request.
Definition: TraCIAPI.cpp:204
Scope for interaction with the simulation.
Definition: TraCIAPI.h:568
Scope for interaction with multi entry/-exit detectors.
Definition: TraCIAPI.h:448
virtual ~AreaScope()
Definition: TraCIAPI.h:429
virtual ~EdgeScope()
Definition: TraCIAPI.h:230
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:104
SubscribedValues mySubscribedValues
Definition: TraCIAPI.h:989
InductionLoopScope(TraCIAPI &parent)
Definition: TraCIAPI.h:307
SUMOReal length
Length of the vehicle.
Definition: TraCIAPI.h:317
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition: TraCIAPI.h:871
std::map< std::string, TraCIValues > SubscribedValues
Definition: TraCIAPI.h:561
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:649
TraCIPosition position
Definition: TraCIAPI.h:97
PolygonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:509
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:128
TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:450
#define PRECISION
Definition: TraCIAPI.h:47
virtual ~JunctionScope()
Definition: TraCIAPI.h:357
~TraCIAPI()
Destructor.
Definition: TraCIAPI.cpp:64
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:877
Scope for interaction with polygons.
Definition: TraCIAPI.h:507
A 3D-bounding box.
Definition: TraCIAPI.h:89
std::vector< TraCIPhase > phases
Definition: TraCIAPI.h:124
int getInt(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:353
int getByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:344
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition: TraCIAPI.h:974
int getUnsignedByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:335
Scope for interaction with vehicles.
Definition: TraCIAPI.h:817
Scope for interaction with junctions.
Definition: TraCIAPI.h:354
long long int SUMOTime
Definition: TraCIAPI.h:58
TrafficLightScope(TraCIAPI &parent)
Definition: TraCIAPI.h:615
virtual ~VehicleScope()
Definition: TraCIAPI.h:706
void readContextSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:524
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:293
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, SubscribedValues &into)
Definition: TraCIAPI.cpp:463
virtual ~SimulationScope()
Definition: TraCIAPI.h:571
std::vector< std::string > getStringVector(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:436
EdgeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:229
Scope for interaction with areal detectors.
Definition: TraCIAPI.h:426
POIScope poi
Scope for interaction with POIs.
Definition: TraCIAPI.h:873
virtual ~POIScope()
Definition: TraCIAPI.h:478
SUMOReal dist
The distance to the tls.
Definition: TraCIAPI.h:717
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:176
virtual ~PersonScope()
Definition: TraCIAPI.h:820
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:879
Scope for interaction with lanes.
Definition: TraCIAPI.h:378
TraCIScopeWrapper(TraCIAPI &parent)
Constructor.
Definition: TraCIAPI.h:200
RouteScope(TraCIAPI &parent)
Definition: TraCIAPI.h:540
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:885
SUMOTime getSUMOTime(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:326
static const SUMOReal DEPART_NOW
Definition: TraCIAPI.h:188
TraCILogic(const std::string &_subID, int _type, const std::map< std::string, SUMOReal > &_subParameter, int _currentPhaseIndex, const std::vector< TraCIPhase > &_phases)
Definition: TraCIAPI.h:116
std::string id
The id of the next tls.
Definition: TraCIAPI.h:713
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:875
virtual ~TraCIScopeWrapper()
Destructor.
Definition: TraCIAPI.h:203
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:254
VehicleTypeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:651
virtual ~GUIScope()
Definition: TraCIAPI.h:275
std::map< std::string, SUMOReal > subParameter
Definition: TraCIAPI.h:122
TraCIAPI & myParent
The parent TraCI client which offers the connection.
Definition: TraCIAPI.h:208
std::string subID
Definition: TraCIAPI.h:120
#define REMOVE_VAPORIZED
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:863
#define SUMOTime_MAX
Definition: TraCIAPI.h:59
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:155
#define SUMOReal
Definition: config.h:208
std::string getString(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:427
VehicleScope(TraCIAPI &parent)
Definition: TraCIAPI.h:705
SimulationScope(TraCIAPI &parent)
Definition: TraCIAPI.h:570
An abstract interface for accessing type-dependent values.
Definition: TraCIAPI.h:195
TraCIAPI()
Constructor.
Definition: TraCIAPI.cpp:53
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIAPI.h:84
int tlIndex
The tls index of the controlled link.
Definition: TraCIAPI.h:715
SUMOReal getFloat(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:362
std::string id
The id of the vehicle.
Definition: TraCIAPI.h:315
JunctionScope(TraCIAPI &parent)
Definition: TraCIAPI.h:356
A 3D-position.
Definition: TraCIAPI.h:70
std::string phase
Definition: TraCIAPI.h:110
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:883