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 <string>
37 #include <sstream>
38 #include <iomanip>
39 #include <foreign/tcpip/socket.h>
41 
42 
43 // ===========================================================================
44 // global definitions
45 // ===========================================================================
46 #define DEFAULT_VIEW "View #0"
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
58 typedef long long int SUMOTime; // <utils/common/SUMOTime.h>
59 
60 
61 class TraCIAPI {
62 public:
65 
69  struct TraCIPosition {
70  double x, y, z;
71  };
72 
76  struct TraCIColor {
77  int r, g, b, a;
78  };
79 
83  typedef std::vector<TraCIPosition> TraCIPositionVector;
84 
88  struct TraCIBoundary {
89  double xMin, yMin, zMin;
90  double xMax, yMax, zMax;
91  };
92 
93  struct TraCIValue {
94  union {
95  double scalar;
98  };
99  std::string string;
100  };
101 
102  class TraCIPhase {
103  public:
104  TraCIPhase(const SUMOTime _duration, const SUMOTime _duration1, const SUMOTime _duration2, const std::string& _phase)
105  : duration(_duration), duration1(_duration1), duration2(_duration2), phase(_phase) {}
107 
108  SUMOTime duration, duration1, duration2;
109  std::string phase;
110  };
111 
112 
113  class TraCILogic {
114  public:
115  TraCILogic(const std::string& _subID, int _type, const std::map<std::string, SUMOReal>& _subParameter, int _currentPhaseIndex, const std::vector<TraCIPhase>& _phases)
116  : subID(_subID), type(_type), subParameter(_subParameter), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
118 
119  std::string subID;
120  int type;
121  std::map<std::string, SUMOReal> subParameter;
123  std::vector<TraCIPhase> phases;
124  };
125 
126  class TraCILink {
127  public:
128  TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
129  : from(_from), via(_via), to(_to) {}
131 
132  std::string from;
133  std::string via;
134  std::string to;
135  };
136 
138 
139 
140 
143  TraCIAPI();
144 
145 
147  ~TraCIAPI();
148 
149 
152 
158  void connect(const std::string& host, int port);
159 
160 
162  void close();
164 
166  void simulationStep(SUMOTime time = 0);
167 
168 
171 
172  SUMOTime getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
173  int getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
174  int getByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
175  int getInt(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
176  SUMOReal getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
177  SUMOReal getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
178  TraCIBoundary getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
179  TraCIPositionVector getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
180  TraCIPosition getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
181  std::string getString(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
182  std::vector<std::string> getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
183  TraCIColor getColor(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
185 
186 
187 
194  public:
198  TraCIScopeWrapper(TraCIAPI& parent) : myParent(parent) {}
199 
201  virtual ~TraCIScopeWrapper() {}
202 
203 
204  protected:
207 
208 
209  private:
212 
214  TraCIScopeWrapper& operator=(const TraCIScopeWrapper& src);
215 
216  };
217 
218 
219 
220 
221 
225  class EdgeScope : public TraCIScopeWrapper {
226  public:
227  EdgeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
228  virtual ~EdgeScope() {}
229 
230  std::vector<std::string> getIDList() const;
231  int getIDCount() const;
232  SUMOReal getAdaptedTraveltime(const std::string& edgeID, SUMOTime time) const;
233  SUMOReal getEffort(const std::string& edgeID, SUMOTime time) const;
234  SUMOReal getCO2Emission(const std::string& edgeID) const;
235  SUMOReal getCOEmission(const std::string& edgeID) const;
236  SUMOReal getHCEmission(const std::string& edgeID) const;
237  SUMOReal getPMxEmission(const std::string& edgeID) const;
238  SUMOReal getNOxEmission(const std::string& edgeID) const;
239  SUMOReal getFuelConsumption(const std::string& edgeID) const;
240  SUMOReal getNoiseEmission(const std::string& edgeID) const;
241  SUMOReal getElectricityConsumption(const std::string& edgeID) const;
242  SUMOReal getLastStepMeanSpeed(const std::string& edgeID) const;
243  SUMOReal getLastStepOccupancy(const std::string& edgeID) const;
244  SUMOReal getLastStepLength(const std::string& edgeID) const;
245  SUMOReal getTraveltime(const std::string& edgeID) const;
246  int getLastStepVehicleNumber(const std::string& edgeID) const;
247  SUMOReal getLastStepHaltingNumber(const std::string& edgeID) const;
248  std::vector<std::string> getLastStepVehicleIDs(const std::string& edgeID) const;
249 
250  void adaptTraveltime(const std::string& edgeID, SUMOReal time) const;
251  void setEffort(const std::string& edgeID, SUMOReal effort) const;
252  void setMaxSpeed(const std::string& edgeID, SUMOReal speed) const;
253 
254  private:
256  EdgeScope(const EdgeScope& src);
257 
259  EdgeScope& operator=(const EdgeScope& src);
260 
261  };
262 
263 
264 
265 
266 
270  class GUIScope : public TraCIScopeWrapper {
271  public:
272  GUIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
273  virtual ~GUIScope() {}
274 
275  std::vector<std::string> getIDList() const;
276  SUMOReal getZoom(const std::string& viewID = DEFAULT_VIEW) const;
277  TraCIPosition getOffset(const std::string& viewID = DEFAULT_VIEW) const;
278  std::string getSchema(const std::string& viewID = DEFAULT_VIEW) const;
279  TraCIBoundary getBoundary(const std::string& viewID = DEFAULT_VIEW) const;
280  void setZoom(const std::string& viewID, SUMOReal zoom) const;
281  void setOffset(const std::string& viewID, SUMOReal x, SUMOReal y) const;
282  void setSchema(const std::string& viewID, const std::string& schemeName) const;
283  void setBoundary(const std::string& viewID, SUMOReal xmin, SUMOReal ymin, SUMOReal xmax, SUMOReal ymax) const;
284  void screenshot(const std::string& viewID, const std::string& filename) const;
285  void trackVehicle(const std::string& viewID, const std::string& vehID) const;
286 
287  private:
289  GUIScope(const GUIScope& src);
290 
292  GUIScope& operator=(const GUIScope& src);
293 
294  };
295 
296 
297 
298 
299 
304  public:
306  virtual ~InductionLoopScope() {}
307 
308  struct VehicleData {
309  /* @brief Constructor
310  (mirrors MSInductLoop::VehicleData) */
313  std::string id;
321  std::string typeID;
322  };
323 
324  std::vector<std::string> getIDList() const;
325  SUMOReal getPosition(const std::string& loopID) const;
326  std::string getLaneID(const std::string& loopID) const;
327  int getLastStepVehicleNumber(const std::string& loopID) const;
328  SUMOReal getLastStepMeanSpeed(const std::string& loopID) const;
329  std::vector<std::string> getLastStepVehicleIDs(const std::string& loopID) const;
330  SUMOReal getLastStepOccupancy(const std::string& loopID) const;
331  SUMOReal getLastStepMeanLength(const std::string& loopID) const;
332  SUMOReal getTimeSinceDetection(const std::string& loopID) const;
333  std::vector<VehicleData> getVehicleData(const std::string& loopID) const;
334 
335 
336  private:
339 
341  InductionLoopScope& operator=(const InductionLoopScope& src);
342 
343  };
344 
345 
346 
347 
348 
353  public:
355  virtual ~JunctionScope() {}
356 
357  std::vector<std::string> getIDList() const;
358  TraCIPosition getPosition(const std::string& junctionID) const;
359 
360  private:
362  JunctionScope(const JunctionScope& src);
363 
365  JunctionScope& operator=(const JunctionScope& src);
366 
367  };
368 
369 
370 
371 
372 
376  class LaneScope : public TraCIScopeWrapper {
377  public:
378  LaneScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
379  virtual ~LaneScope() {}
380 
381  std::vector<std::string> getIDList() const;
382  SUMOReal getLength(const std::string& laneID) const;
383  SUMOReal getMaxSpeed(const std::string& laneID) const;
384  SUMOReal getWidth(const std::string& laneID) const;
385  std::vector<std::string> getAllowed(const std::string& laneID) const;
386  std::vector<std::string> getDisallowed(const std::string& laneID) const;
387  int getLinkNumber(const std::string& laneID) const;
388  TraCIPositionVector getShape(const std::string& laneID) const;
389  std::string getEdgeID(const std::string& laneID) const;
390  SUMOReal getCO2Emission(const std::string& laneID) const;
391  SUMOReal getCOEmission(const std::string& laneID) const;
392  SUMOReal getHCEmission(const std::string& laneID) const;
393  SUMOReal getPMxEmission(const std::string& laneID) const;
394  SUMOReal getNOxEmission(const std::string& laneID) const;
395  SUMOReal getFuelConsumption(const std::string& laneID) const;
396  SUMOReal getNoiseEmission(const std::string& laneID) const;
397  SUMOReal getElectricityConsumption(const std::string& laneID) const;
398  SUMOReal getLastStepMeanSpeed(const std::string& laneID) const;
399  SUMOReal getLastStepOccupancy(const std::string& laneID) const;
400  SUMOReal getLastStepLength(const std::string& laneID) const;
401  SUMOReal getTraveltime(const std::string& laneID) const;
402  int getLastStepVehicleNumber(const std::string& laneID) const;
403  int getLastStepHaltingNumber(const std::string& laneID) const;
404  std::vector<std::string> getLastStepVehicleIDs(const std::string& laneID) const;
405 
406  void setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const;
407  void setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const;
408  void setMaxSpeed(const std::string& laneID, SUMOReal speed) const;
409  void setLength(const std::string& laneID, SUMOReal length) const;
410 
411  private:
413  LaneScope(const LaneScope& src);
414 
416  LaneScope& operator=(const LaneScope& src);
417 
418  };
419 
420 
424  class AreaScope : public TraCIScopeWrapper {
425  public:
426  AreaScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
427  virtual ~AreaScope() {}
428 
429  std::vector<std::string> getIDList() const;
430  int getJamLengthVehicle(const std::string& laneID) const;
431  SUMOReal getJamLengthMeters(const std::string& laneID) const;
432 
433  private:
435  AreaScope(const AreaScope& src);
436 
438  AreaScope& operator=(const AreaScope& src);
439 
440  };
441 
442 
446  class MeMeScope : public TraCIScopeWrapper {
447  public:
448  MeMeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
449  virtual ~MeMeScope() {}
450 
451  std::vector<std::string> getIDList() const;
452  int getLastStepVehicleNumber(const std::string& detID) const;
453  SUMOReal getLastStepMeanSpeed(const std::string& detID) const;
454  std::vector<std::string> getLastStepVehicleIDs(const std::string& detID) const;
455  int getLastStepHaltingNumber(const std::string& detID) const;
456 
457  private:
459  MeMeScope(const MeMeScope& src);
460 
462  MeMeScope& operator=(const MeMeScope& src);
463 
464  };
465 
466 
467 
468 
469 
473  class POIScope : public TraCIScopeWrapper {
474  public:
475  POIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
476  virtual ~POIScope() {}
477 
478  std::vector<std::string> getIDList() const;
479  std::string getType(const std::string& poiID) const;
480  TraCIPosition getPosition(const std::string& poiID) const;
481  TraCIColor getColor(const std::string& poiID) const;
482 
483  void setType(const std::string& poiID, const std::string& setType) const;
484  void setPosition(const std::string& poiID, SUMOReal x, SUMOReal y) const;
485  void setColor(const std::string& poiID, const TraCIColor& c) const;
486  void add(const std::string& poiID, SUMOReal x, SUMOReal y, const TraCIColor& c, const std::string& type, int layer) const;
487  void remove(const std::string& poiID, int layer = 0) const;
488 
489  private:
491  POIScope(const POIScope& src);
492 
494  POIScope& operator=(const POIScope& src);
495 
496  };
497 
498 
499 
500 
501 
506  public:
508  virtual ~PolygonScope() {}
509 
510  std::vector<std::string> getIDList() const;
511  std::string getType(const std::string& polygonID) const;
512  TraCIPositionVector getShape(const std::string& polygonID) const;
513  TraCIColor getColor(const std::string& polygonID) const;
514  void setType(const std::string& polygonID, const std::string& setType) const;
515  void setShape(const std::string& polygonID, const TraCIPositionVector& shape) const;
516  void setColor(const std::string& polygonID, const TraCIColor& c) const;
517  void add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) const;
518  void remove(const std::string& polygonID, int layer = 0) const;
519 
520  private:
522  PolygonScope(const PolygonScope& src);
523 
525  PolygonScope& operator=(const PolygonScope& src);
526 
527  };
528 
529 
530 
531 
532 
536  class RouteScope : public TraCIScopeWrapper {
537  public:
538  RouteScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
539  virtual ~RouteScope() {}
540 
541  std::vector<std::string> getIDList() const;
542  std::vector<std::string> getEdges(const std::string& routeID) const;
543 
544  void add(const std::string& routeID, const std::vector<std::string>& edges) const;
545 
546  private:
548  RouteScope(const RouteScope& src);
549 
551  RouteScope& operator=(const RouteScope& src);
552 
553  };
554 
555 
556 
558  typedef std::map<int, TraCIValue> TraCIValues;
559  typedef std::map<std::string, TraCIValues> SubscribedValues;
560  typedef std::map<std::string, SubscribedValues> SubscribedContextValues;
561 
562 
567  public:
569  virtual ~SimulationScope() {}
570 
571  SUMOTime getCurrentTime() const;
572  int getLoadedNumber() const;
573  std::vector<std::string> getLoadedIDList() const;
574  int getDepartedNumber() const;
575  std::vector<std::string> getDepartedIDList() const;
576  int getArrivedNumber() const;
577  std::vector<std::string> getArrivedIDList() const;
578  int getStartingTeleportNumber() const;
579  std::vector<std::string> getStartingTeleportIDList() const;
580  int getEndingTeleportNumber() const;
581  std::vector<std::string> getEndingTeleportIDList() const;
582  SUMOTime getDeltaT() const;
583  TraCIBoundary getNetBoundary() const;
584  int getMinExpectedNumber() const;
585 
586  void subscribe(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
587  void subscribeContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, SUMOReal range, const std::vector<int>& vars) const;
588 
589  SubscribedValues getSubscriptionResults();
590  TraCIValues getSubscriptionResults(const std::string& objID);
591 
592  SubscribedContextValues getContextSubscriptionResults();
593  SubscribedValues getContextSubscriptionResults(const std::string& objID);
594 
595  private:
597  SimulationScope(const SimulationScope& src);
598 
600  SimulationScope& operator=(const SimulationScope& src);
601 
602  };
603 
604 
605 
606 
607 
612  public:
614  virtual ~TrafficLightScope() {}
615 
616  std::vector<std::string> getIDList() const;
617  std::string getRedYellowGreenState(const std::string& tlsID) const;
618  std::vector<TraCIAPI::TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) const;
619  std::vector<std::string> getControlledLanes(const std::string& tlsID) const;
620  std::vector<TraCIAPI::TraCILink> getControlledLinks(const std::string& tlsID) const;
621  std::string getProgram(const std::string& tlsID) const;
622  int getPhase(const std::string& tlsID) const;
623  int getNextSwitch(const std::string& tlsID) const;
624 
625  void setRedYellowGreenState(const std::string& tlsID, const std::string& state) const;
626  void setPhase(const std::string& tlsID, int index) const;
627  void setProgram(const std::string& tlsID, const std::string& programID) const;
628  void setPhaseDuration(const std::string& tlsID, int phaseDuration) const;
629  void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const TraCIAPI::TraCILogic& logic) const;
630 
631  private:
634 
636  TrafficLightScope& operator=(const TrafficLightScope& src);
637 
638  };
639 
640 
641 
642 
643 
648  public:
650  virtual ~VehicleTypeScope() {}
651 
652  std::vector<std::string> getIDList() const;
653  SUMOReal getLength(const std::string& typeID) const;
654  SUMOReal getMaxSpeed(const std::string& typeID) const;
655  SUMOReal getSpeedFactor(const std::string& typeID) const;
656  SUMOReal getSpeedDeviation(const std::string& typeID) const;
657  SUMOReal getAccel(const std::string& typeID) const;
658  SUMOReal getDecel(const std::string& typeID) const;
659  SUMOReal getImperfection(const std::string& typeID) const;
660  SUMOReal getTau(const std::string& typeID) const;
661  std::string getVehicleClass(const std::string& typeID) const;
662  std::string getEmissionClass(const std::string& typeID) const;
663  std::string getShapeClass(const std::string& typeID) const;
664  SUMOReal getMinGap(const std::string& typeID) const;
665  SUMOReal getWidth(const std::string& typeID) const;
666  TraCIColor getColor(const std::string& typeID) const;
667 
668  void setLength(const std::string& typeID, SUMOReal length) const;
669  void setMaxSpeed(const std::string& typeID, SUMOReal speed) const;
670  void setVehicleClass(const std::string& typeID, const std::string& clazz) const;
671  void setSpeedFactor(const std::string& typeID, SUMOReal factor) const;
672  void setSpeedDeviation(const std::string& typeID, SUMOReal deviation) const;
673  void setEmissionClass(const std::string& typeID, const std::string& clazz) const;
674  void setWidth(const std::string& typeID, SUMOReal width) const;
675  void setMinGap(const std::string& typeID, SUMOReal minGap) const;
676  void setShapeClass(const std::string& typeID, const std::string& clazz) const;
677  void setAccel(const std::string& typeID, SUMOReal accel) const;
678  void setDecel(const std::string& typeID, SUMOReal decel) const;
679  void setImperfection(const std::string& typeID, SUMOReal imperfection) const;
680  void setTau(const std::string& typeID, SUMOReal tau) const;
681  void setColor(const std::string& typeID, const TraCIColor& c) const;
682 
683  private:
686 
688  VehicleTypeScope& operator=(const VehicleTypeScope& src);
689 
690  };
691 
692 
693 
694 
695 
700  public:
702  virtual ~VehicleScope() {}
703 
704 
705  struct NextTLSData {
706  /* @brief Constructor */
709  std::string id;
711  int tlIndex;
715  char state;
716  };
717 
718 
719  std::vector<std::string> getIDList() const;
720  int getIDCount() const;
721  SUMOReal getSpeed(const std::string& vehicleID) const;
722  TraCIPosition getPosition(const std::string& vehicleID) const;
723  SUMOReal getAngle(const std::string& vehicleID) const;
724  std::string getRoadID(const std::string& vehicleID) const;
725  std::string getLaneID(const std::string& vehicleID) const;
726  int getLaneIndex(const std::string& vehicleID) const;
727  std::string getTypeID(const std::string& vehicleID) const;
728  std::string getRouteID(const std::string& vehicleID) const;
729  int getRouteIndex(const std::string& vehicleID) const;
730  std::vector<std::string> getEdges(const std::string& vehicleID) const;
731  TraCIColor getColor(const std::string& vehicleID) const;
732  SUMOReal getLanePosition(const std::string& vehicleID) const;
733  SUMOReal getCO2Emission(const std::string& vehicleID) const;
734  SUMOReal getCOEmission(const std::string& vehicleID) const;
735  SUMOReal getHCEmission(const std::string& vehicleID) const;
736  SUMOReal getPMxEmission(const std::string& vehicleID) const;
737  SUMOReal getNOxEmission(const std::string& vehicleID) const;
738  SUMOReal getFuelConsumption(const std::string& vehicleID) const;
739  SUMOReal getNoiseEmission(const std::string& vehicleID) const;
740  SUMOReal getElectricityConsumption(const std::string& vehicleID) const;
741  int getSignalStates(const std::string& vehicleID) const;
742  SUMOReal getWaitingTime(const std::string& vehicleID) const;
743  std::vector<NextTLSData> getNextTLS(const std::string& vehID) const;
744  int getSpeedMode(const std::string& vehicleID) const;
745  SUMOReal getSlope(const std::string& vehicleID) const;
746 
747  /* /// not yet implemented
748  SUMOReal getCO2Emissions(const std::string& vehicleID) const;
749  SUMOReal getCOEmissions(const std::string& vehicleID) const;
750  SUMOReal getHCEmissions(const std::string& vehicleID) const;
751  SUMOReal getPMxEmissions(const std::string& vehicleID) const;
752  SUMOReal getNOxEmissions(const std::string& vehicleID) const;
753  SUMOReal getFuelConsumption(const std::string& vehicleID) const;
754  SUMOReal getNoiseEmission(const std::string& vehicleID) const;
755  int getBestLanes(const std::string& vehicleID) const;
756  int getStopState(const std::string& vehicleID) const;
757  SUMOReal getLength(const std::string& vehicleID) const;
758  SUMOReal getMaxSpeed(const std::string& vehicleID) const;
759  SUMOReal getAccel(const std::string& vehicleID) const;
760  SUMOReal getDecel(const std::string& vehicleID) const;
761  SUMOReal getTau(const std::string& vehicleID) const;
762  SUMOReal getImperfection(const std::string& vehicleID) const;
763  SUMOReal getSpeedFactor(const std::string& vehicleID) const;
764  SUMOReal getSpeedDeviation(const std::string& vehicleID) const;
765  std::string getVClass(const std::string& vehicleID) const;
766  std::string getEmissionClass(const std::string& vehicleID) const;
767  std::string getShapeClass(const std::string& vehicleID) const;
768  SUMOReal getMinGap(const std::string& vehicleID) const;
769  SUMOReal getWidth(const std::string& vehicleID) const;
770  */
771 
772  void add(const std::string& vehicleID,
773  const std::string& routeID,
774  const std::string& typeID = "DEFAULT_VEHTYPE",
775  std::string depart = "-1",
776  const std::string& departLane = "first",
777  const std::string& departPos = "base",
778  const std::string& departSpeed = "0",
779  const std::string& arrivalLane = "current",
780  const std::string& arrivalPos = "max",
781  const std::string& arrivalSpeed = "current",
782  const std::string& fromTaz = "",
783  const std::string& toTaz = "",
784  const std::string& line = "",
785  int personCapacity = 0,
786  int personNumber = 0) const;
787 
788  void moveTo(const std::string& vehicleID, const std::string& laneID, SUMOReal position) const;
789  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;
790  void slowDown(const std::string& vehicleID, SUMOReal speed, int duration) const;
791  void setSpeed(const std::string& vehicleID, SUMOReal speed) const;
792  void remove(const std::string& vehicleID, char reason = REMOVE_VAPORIZED) const;
793 
794  private:
796  VehicleScope(const VehicleScope& src);
797 
799  VehicleScope& operator=(const VehicleScope& src);
800 
801  };
802 
807  public:
808  PersonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
809  virtual ~PersonScope() {}
810 
811  std::vector<std::string> getIDList() const;
812  int getIDCount() const;
813  SUMOReal getSpeed(const std::string& typeID) const;
814  TraCIPosition getPosition(const std::string& typeID) const;
815  std::string getRoadID(const std::string& typeID) const;
816  std::string getTypeID(const std::string& typeID) const;
817  SUMOReal getWaitingTime(const std::string& typeID) const;
818  std::string getNextEdge(const std::string& typeID) const;
819 
820  private:
822  PersonScope(const PersonScope& src);
823 
825  PersonScope& operator=(const PersonScope& src);
826  };
827 
828 
829 
830 public:
859 
860 
861 protected:
864 
867  void send_commandSimulationStep(SUMOTime time) const;
868 
869 
872  void send_commandClose() const;
873 
874 
881  void send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add = 0) const;
882 
883 
890  void send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const;
891 
892 
900  void send_commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
901 
902 
912  void send_commandSubscribeObjectContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
913  int domain, SUMOReal range, const std::vector<int>& vars) const;
915 
916 
917  void send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane,
918  const SUMOReal x, const SUMOReal y, const SUMOReal angle, const int keepRoute) const;
919 
920 
923 
930  void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
931 
935  int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
936 
937  void processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId = false) const;
939 
942  void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, SubscribedValues& into);
943 
944  template <class T>
945  static inline std::string toString(const T& t, std::streamsize accuracy = OUTPUT_ACCURACY) {
946  std::ostringstream oss;
947  oss.setf(std::ios::fixed , std::ios::floatfield);
948  oss << std::setprecision(accuracy);
949  oss << t;
950  return oss.str();
951  }
952 
953 protected:
956 
957  SubscribedValues mySubscribedValues;
958  SubscribedContextValues mySubscribedContextValues;
959 };
960 
961 
962 #endif
963 
964 /****************************************************************************/
965 
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:832
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:317
char state
The current state of the tls.
Definition: TraCIAPI.h:715
LaneScope(TraCIAPI &parent)
Definition: TraCIAPI.h:378
long long int SUMOTime
Definition: SUMOTime.h:43
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:955
C++ TraCI client API implementation.
Definition: TraCIAPI.h:61
void close()
Closes the connection.
Definition: TraCIAPI.cpp:80
Scope for interaction with edges.
Definition: TraCIAPI.h:225
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:67
MeMeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:448
std::string typeID
Type of the vehicle in.
Definition: TraCIAPI.h:321
virtual ~PolygonScope()
Definition: TraCIAPI.h:508
std::map< int, TraCIValue > TraCIValues
{object->{variable->value}}
Definition: TraCIAPI.h:558
GUIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:272
std::string string
Definition: TraCIAPI.h:99
SUMOReal getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:358
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:104
JunctionScope junction
Scope for interaction with junctions.
Definition: TraCIAPI.h:838
PersonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:808
TraCIPhase(const SUMOTime _duration, const SUMOTime _duration1, const SUMOTime _duration2, const std::string &_phase)
Definition: TraCIAPI.h:104
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:840
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:858
#define DEFAULT_VIEW
Definition: TraCIAPI.h:46
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:304
Scope for interaction with vehicles.
Definition: TraCIAPI.h:699
virtual ~RouteScope()
Definition: TraCIAPI.h:539
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:611
SubscribedContextValues mySubscribedContextValues
Definition: TraCIAPI.h:958
virtual ~LaneScope()
Definition: TraCIAPI.h:379
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:270
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
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:852
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:560
Scope for interaction with routes.
Definition: TraCIAPI.h:536
TraCIColor color
Definition: TraCIAPI.h:97
SUMOTime duration2
Definition: TraCIAPI.h:108
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:836
SUMOReal leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIAPI.h:319
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:303
#define OUTPUT_ACCURACY
Definition: config.h:163
POIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:475
virtual ~MeMeScope()
Definition: TraCIAPI.h:449
AreaScope(TraCIAPI &parent)
Definition: TraCIAPI.h:426
Scope for interaction with POIs.
Definition: TraCIAPI.h:473
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
Scope for interaction with the simulation.
Definition: TraCIAPI.h:566
Scope for interaction with multi entry/-exit detectors.
Definition: TraCIAPI.h:446
virtual ~AreaScope()
Definition: TraCIAPI.h:427
virtual ~EdgeScope()
Definition: TraCIAPI.h:228
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:91
SubscribedValues mySubscribedValues
Definition: TraCIAPI.h:957
InductionLoopScope(TraCIAPI &parent)
Definition: TraCIAPI.h:305
SUMOReal length
Length of the vehicle.
Definition: TraCIAPI.h:315
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition: TraCIAPI.h:842
std::map< std::string, TraCIValues > SubscribedValues
Definition: TraCIAPI.h:559
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:647
TraCIPosition position
Definition: TraCIAPI.h:96
PolygonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:507
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:115
TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:437
virtual ~JunctionScope()
Definition: TraCIAPI.h:355
~TraCIAPI()
Destructor.
Definition: TraCIAPI.cpp:61
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:848
Scope for interaction with polygons.
Definition: TraCIAPI.h:505
A 3D-bounding box.
Definition: TraCIAPI.h:88
static std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: TraCIAPI.h:945
std::vector< TraCIPhase > phases
Definition: TraCIAPI.h:123
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:806
Scope for interaction with junctions.
Definition: TraCIAPI.h:352
long long int SUMOTime
Definition: TraCIAPI.h:58
TrafficLightScope(TraCIAPI &parent)
Definition: TraCIAPI.h:613
virtual ~VehicleScope()
Definition: TraCIAPI.h:702
void readContextSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:506
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
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, SubscribedValues &into)
Definition: TraCIAPI.cpp:450
virtual ~SimulationScope()
Definition: TraCIAPI.h:569
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:227
Scope for interaction with areal detectors.
Definition: TraCIAPI.h:424
POIScope poi
Scope for interaction with POIs.
Definition: TraCIAPI.h:844
virtual ~POIScope()
Definition: TraCIAPI.h:476
SUMOReal dist
The distance to the tls.
Definition: TraCIAPI.h:713
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
virtual ~PersonScope()
Definition: TraCIAPI.h:809
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:850
Scope for interaction with lanes.
Definition: TraCIAPI.h:376
TraCIScopeWrapper(TraCIAPI &parent)
Constructor.
Definition: TraCIAPI.h:198
RouteScope(TraCIAPI &parent)
Definition: TraCIAPI.h:538
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:856
SUMOTime getSUMOTime(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:313
TraCILogic(const std::string &_subID, int _type, const std::map< std::string, SUMOReal > &_subParameter, int _currentPhaseIndex, const std::vector< TraCIPhase > &_phases)
Definition: TraCIAPI.h:115
std::string id
The id of the next tls.
Definition: TraCIAPI.h:709
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:846
virtual ~TraCIScopeWrapper()
Destructor.
Definition: TraCIAPI.h:201
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
VehicleTypeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:649
virtual ~GUIScope()
Definition: TraCIAPI.h:273
std::map< std::string, SUMOReal > subParameter
Definition: TraCIAPI.h:121
TraCIAPI & myParent
The parent TraCI client which offers the connection.
Definition: TraCIAPI.h:206
std::string subID
Definition: TraCIAPI.h:119
#define REMOVE_VAPORIZED
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:834
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:142
#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:701
SimulationScope(TraCIAPI &parent)
Definition: TraCIAPI.h:568
An abstract interface for accessing type-dependent values.
Definition: TraCIAPI.h:193
TraCIAPI()
Constructor.
Definition: TraCIAPI.cpp:50
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIAPI.h:83
int tlIndex
The tls index of the controlled link.
Definition: TraCIAPI.h:711
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:313
JunctionScope(TraCIAPI &parent)
Definition: TraCIAPI.h:354
A 3D-position.
Definition: TraCIAPI.h:69
std::string phase
Definition: TraCIAPI.h:109
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:854