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-2016 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 // ===========================================================================
45 // global definitions
46 // ===========================================================================
47 #define DEFAULT_VIEW "View #0"
48 
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 
71  struct TraCIPosition {
72  double x, y, z;
73  };
74 
78  struct TraCIColor {
79  int r, g, b, a;
80  };
81 
85  typedef std::vector<TraCIPosition> TraCIPositionVector;
86 
90  struct TraCIBoundary {
91  double xMin, yMin, zMin;
92  double xMax, yMax, zMax;
93  };
94 
95  struct TraCIValue {
96  union {
97  double scalar;
100  };
101  std::string string;
102  };
103 
104  class TraCIPhase {
105  public:
106  TraCIPhase(const SUMOTime _duration, const SUMOTime _duration1, const SUMOTime _duration2, const std::string& _phase)
107  : duration(_duration), duration1(_duration1), duration2(_duration2), phase(_phase) {}
109 
110  SUMOTime duration, duration1, duration2;
111  std::string phase;
112  };
113 
114 
115  class TraCILogic {
116  public:
117  TraCILogic(const std::string& _subID, int _type, const std::map<std::string, SUMOReal>& _subParameter, int _currentPhaseIndex, const std::vector<TraCIPhase>& _phases)
118  : subID(_subID), type(_type), subParameter(_subParameter), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
120 
121  std::string subID;
122  int type;
123  std::map<std::string, SUMOReal> subParameter;
125  std::vector<TraCIPhase> phases;
126  };
127 
128  class TraCILink {
129  public:
130  TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
131  : from(_from), via(_via), to(_to) {}
133 
134  std::string from;
135  std::string via;
136  std::string to;
137  };
138 
140 
141 
142 
145  TraCIAPI();
146 
147 
149  ~TraCIAPI();
150 
151 
154 
160  void connect(const std::string& host, int port);
161 
162 
164  void close();
166 
168  void simulationStep(SUMOTime time = 0);
169 
170 
173 
174  SUMOTime getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
175  int getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
176  int getByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
177  int getInt(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
178  SUMOReal getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
179  SUMOReal getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
180  TraCIBoundary getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
181  TraCIPositionVector getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
182  TraCIPosition getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
183  std::string getString(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
184  std::vector<std::string> getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
185  TraCIColor getColor(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
187 
188 
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, SUMOTime 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, SUMOTime begin = 0, SUMOTime end = SUMOTime_MAX) 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 setWidth(const std::string& typeID, SUMOReal width) const;
678  void setHeight(const std::string& typeID, SUMOReal height) const;
679  void setMinGap(const std::string& typeID, SUMOReal minGap) const;
680  void setShapeClass(const std::string& typeID, const std::string& clazz) 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 
751  /* /// not yet implemented
752  SUMOReal getCO2Emissions(const std::string& vehicleID) const;
753  SUMOReal getCOEmissions(const std::string& vehicleID) const;
754  SUMOReal getHCEmissions(const std::string& vehicleID) const;
755  SUMOReal getPMxEmissions(const std::string& vehicleID) const;
756  SUMOReal getNOxEmissions(const std::string& vehicleID) const;
757  SUMOReal getFuelConsumption(const std::string& vehicleID) const;
758  SUMOReal getNoiseEmission(const std::string& vehicleID) const;
759  int getBestLanes(const std::string& vehicleID) const;
760  int getStopState(const std::string& vehicleID) const;
761  SUMOReal getLength(const std::string& vehicleID) const;
762  SUMOReal getMaxSpeed(const std::string& vehicleID) const;
763  SUMOReal getAccel(const std::string& vehicleID) const;
764  SUMOReal getDecel(const std::string& vehicleID) const;
765  SUMOReal getTau(const std::string& vehicleID) const;
766  SUMOReal getImperfection(const std::string& vehicleID) const;
767  SUMOReal getSpeedFactor(const std::string& vehicleID) const;
768  SUMOReal getSpeedDeviation(const std::string& vehicleID) const;
769  std::string getVClass(const std::string& vehicleID) const;
770  std::string getEmissionClass(const std::string& vehicleID) const;
771  std::string getShapeClass(const std::string& vehicleID) const;
772  SUMOReal getMinGap(const std::string& vehicleID) const;
773  SUMOReal getWidth(const std::string& vehicleID) const;
774  */
775 
776  void add(const std::string& vehicleID,
777  const std::string& routeID,
778  const std::string& typeID = "DEFAULT_VEHTYPE",
779  std::string depart = "-1",
780  const std::string& departLane = "first",
781  const std::string& departPos = "base",
782  const std::string& departSpeed = "0",
783  const std::string& arrivalLane = "current",
784  const std::string& arrivalPos = "max",
785  const std::string& arrivalSpeed = "current",
786  const std::string& fromTaz = "",
787  const std::string& toTaz = "",
788  const std::string& line = "",
789  int personCapacity = 0,
790  int personNumber = 0) const;
791 
792  void moveTo(const std::string& vehicleID, const std::string& laneID, SUMOReal position) const;
793  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;
794  void slowDown(const std::string& vehicleID, SUMOReal speed, int duration) const;
795  void setSpeed(const std::string& vehicleID, SUMOReal speed) const;
796  void remove(const std::string& vehicleID, char reason = REMOVE_VAPORIZED) const;
797  void setColor(const std::string& vehicleID, const TraCIColor& c) const;
798 
799  private:
801  VehicleScope(const VehicleScope& src);
802 
804  VehicleScope& operator=(const VehicleScope& src);
805 
806  };
807 
812  public:
813  PersonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
814  virtual ~PersonScope() {}
815 
816  std::vector<std::string> getIDList() const;
817  int getIDCount() const;
818  SUMOReal getSpeed(const std::string& typeID) const;
819  TraCIPosition getPosition(const std::string& typeID) const;
820  std::string getRoadID(const std::string& typeID) const;
821  std::string getTypeID(const std::string& typeID) const;
822  SUMOReal getWaitingTime(const std::string& typeID) const;
823  std::string getNextEdge(const std::string& typeID) const;
824 
825  private:
827  PersonScope(const PersonScope& src);
828 
830  PersonScope& operator=(const PersonScope& src);
831  };
832 
833 
834 
835 public:
864 
865 
866 protected:
869 
872  void send_commandSimulationStep(SUMOTime time) const;
873 
874 
877  void send_commandClose() const;
878 
879 
886  void send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add = 0) const;
887 
888 
895  void send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const;
896 
897 
905  void send_commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
906 
907 
917  void send_commandSubscribeObjectContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
918  int domain, SUMOReal range, const std::vector<int>& vars) const;
920 
921 
922  void send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane,
923  const SUMOReal x, const SUMOReal y, const SUMOReal angle, const int keepRoute) const;
924 
925 
928 
935  void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
936 
940  int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
941 
942  void processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId = false) const;
944 
947  void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, SubscribedValues& into);
948 
949  template <class T>
950  static inline std::string toString(const T& t, std::streamsize accuracy = OUTPUT_ACCURACY) {
951  std::ostringstream oss;
952  oss.setf(std::ios::fixed , std::ios::floatfield);
953  oss << std::setprecision(accuracy);
954  oss << t;
955  return oss.str();
956  }
957 
958 protected:
961 
962  SubscribedValues mySubscribedValues;
963  SubscribedContextValues mySubscribedContextValues;
964 };
965 
966 
967 #endif
968 
969 /****************************************************************************/
970 
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:837
TraCIPosition getPosition(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:401
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
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:142
long long int SUMOTime
Definition: SUMOTime.h:43
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:960
C++ TraCI client API implementation.
Definition: TraCIAPI.h:63
void close()
Closes the connection.
Definition: TraCIAPI.cpp:80
Scope for interaction with edges.
Definition: TraCIAPI.h:227
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:241
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:67
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:101
SUMOReal getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:358
JunctionScope junction
Scope for interaction with junctions.
Definition: TraCIAPI.h:843
PersonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:813
TraCIPhase(const SUMOTime _duration, const SUMOTime _duration1, const SUMOTime _duration2, const std::string &_phase)
Definition: TraCIAPI.h:106
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:115
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:845
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:863
#define DEFAULT_VIEW
Definition: TraCIAPI.h:47
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:963
virtual ~LaneScope()
Definition: TraCIAPI.h:381
void simulationStep(SUMOTime time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:520
Scope for interaction with the gui.
Definition: TraCIAPI.h:272
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:857
TraCIPositionVector getPolygon(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:383
void readVariableSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:499
std::map< std::string, SubscribedValues > SubscribedContextValues
Definition: TraCIAPI.h:562
Scope for interaction with routes.
Definition: TraCIAPI.h:538
TraCIColor color
Definition: TraCIAPI.h:99
SUMOTime duration2
Definition: TraCIAPI.h:110
TraCIBoundary getBoundingBox(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:367
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:841
SUMOReal leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIAPI.h:321
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:305
#define OUTPUT_ACCURACY
Definition: config.h:163
POIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:477
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:221
virtual ~MeMeScope()
Definition: TraCIAPI.h:451
AreaScope(TraCIAPI &parent)
Definition: TraCIAPI.h:428
Scope for interaction with POIs.
Definition: TraCIAPI.h:475
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
SubscribedValues mySubscribedValues
Definition: TraCIAPI.h:962
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:847
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:98
PolygonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:509
TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:437
virtual ~JunctionScope()
Definition: TraCIAPI.h:357
~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:163
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:853
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:91
Scope for interaction with polygons.
Definition: TraCIAPI.h:507
A 3D-bounding box.
Definition: TraCIAPI.h:90
static std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: TraCIAPI.h:950
std::vector< TraCIPhase > phases
Definition: TraCIAPI.h:125
int getInt(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:340
int getByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:331
int getUnsignedByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:322
Scope for interaction with vehicles.
Definition: TraCIAPI.h:811
Scope for interaction with junctions.
Definition: TraCIAPI.h:354
long long int SUMOTime
Definition: TraCIAPI.h:59
TrafficLightScope(TraCIAPI &parent)
Definition: TraCIAPI.h:615
virtual ~VehicleScope()
Definition: TraCIAPI.h:706
void readContextSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:506
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, SubscribedValues &into)
Definition: TraCIAPI.cpp:450
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:423
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:849
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:191
virtual ~POIScope()
Definition: TraCIAPI.h:478
SUMOReal dist
The distance to the tls.
Definition: TraCIAPI.h:717
virtual ~PersonScope()
Definition: TraCIAPI.h:814
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:855
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:861
SUMOTime getSUMOTime(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:313
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:304
TraCILogic(const std::string &_subID, int _type, const std::map< std::string, SUMOReal > &_subParameter, int _currentPhaseIndex, const std::vector< TraCIPhase > &_phases)
Definition: TraCIAPI.h:117
std::string id
The id of the next tls.
Definition: TraCIAPI.h:713
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:851
virtual ~TraCIScopeWrapper()
Destructor.
Definition: TraCIAPI.h:203
VehicleTypeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:651
virtual ~GUIScope()
Definition: TraCIAPI.h:275
std::map< std::string, SUMOReal > subParameter
Definition: TraCIAPI.h:123
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:104
TraCIAPI & myParent
The parent TraCI client which offers the connection.
Definition: TraCIAPI.h:208
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:280
std::string subID
Definition: TraCIAPI.h:121
#define REMOVE_VAPORIZED
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:839
#define SUMOTime_MAX
Definition: TraCIAPI.h:60
#define SUMOReal
Definition: config.h:213
std::string getString(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:414
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:50
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIAPI.h:85
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:349
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:71
std::string phase
Definition: TraCIAPI.h:111
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:859