SUMO - Simulation of Urban MObility
TraCIAPI.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // C++ TraCI client API implementation
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef TraCIAPI_h
23 #define TraCIAPI_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <limits>
37 #include <string>
38 #include <sstream>
39 #include <iomanip>
40 #include <foreign/tcpip/socket.h>
42 #include <traci-server/TraCIDefs.h>
43 
44 // ===========================================================================
45 // global definitions
46 // ===========================================================================
47 #define DEFAULT_VIEW "View #0"
48 #define PRECISION 2
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
59 typedef long long int SUMOTime; // <utils/common/SUMOTime.h>
60 #define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
61 
62 
63 class TraCIAPI {
64 public:
67  TraCIAPI();
68 
69 
71  ~TraCIAPI();
72 
73 
76 
82  void connect(const std::string& host, int port);
83 
85  void setOrder(int order);
86 
88  void close();
90 
92  void simulationStep(SUMOTime time = 0);
93 
95  void load(const std::vector<std::string>& args);
96 
99 
100  SUMOTime getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
101  int getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
102  int getByte(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
103  int getInt(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
104  double getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
105  double getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
106  TraCIBoundary getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
107  TraCIPositionVector getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
108  TraCIPosition getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
109  TraCIPosition getPosition3D(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
110  std::string getString(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
111  std::vector<std::string> getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
112  TraCIColor getColor(int cmd, int var, const std::string& id, tcpip::Storage* add = 0);
114 
115 
122  public:
126  TraCIScopeWrapper(TraCIAPI& parent) : myParent(parent) {}
127 
129  virtual ~TraCIScopeWrapper() {}
130 
131 
132  protected:
135 
136 
137  private:
140 
143 
144  };
145 
146 
147 
148 
149 
153  class EdgeScope : public TraCIScopeWrapper {
154  public:
155  EdgeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
156  virtual ~EdgeScope() {}
157 
158  std::vector<std::string> getIDList() const;
159  int getIDCount() const;
160  double getAdaptedTraveltime(const std::string& edgeID, double time) const;
161  double getEffort(const std::string& edgeID, SUMOTime time) const;
162  double getCO2Emission(const std::string& edgeID) const;
163  double getCOEmission(const std::string& edgeID) const;
164  double getHCEmission(const std::string& edgeID) const;
165  double getPMxEmission(const std::string& edgeID) const;
166  double getNOxEmission(const std::string& edgeID) const;
167  double getFuelConsumption(const std::string& edgeID) const;
168  double getNoiseEmission(const std::string& edgeID) const;
169  double getElectricityConsumption(const std::string& edgeID) const;
170  double getLastStepMeanSpeed(const std::string& edgeID) const;
171  double getLastStepOccupancy(const std::string& edgeID) const;
172  double getLastStepLength(const std::string& edgeID) const;
173  double getTraveltime(const std::string& edgeID) const;
174  int getLastStepVehicleNumber(const std::string& edgeID) const;
175  double getLastStepHaltingNumber(const std::string& edgeID) const;
176  std::vector<std::string> getLastStepVehicleIDs(const std::string& edgeID) const;
177 
178  void adaptTraveltime(const std::string& edgeID, double time, double begin = 0, double end = SUMOTime_MAX / 1000.0) const;
179  void setEffort(const std::string& edgeID, double effort, SUMOTime begin = 0, SUMOTime end = SUMOTime_MAX) const;
180  void setMaxSpeed(const std::string& edgeID, double speed) const;
181 
182  private:
184  EdgeScope(const EdgeScope& src);
185 
187  EdgeScope& operator=(const EdgeScope& src);
188 
189  };
190 
191 
192 
193 
194 
198  class GUIScope : public TraCIScopeWrapper {
199  public:
200  GUIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
201  virtual ~GUIScope() {}
202 
203  std::vector<std::string> getIDList() const;
204  double getZoom(const std::string& viewID = DEFAULT_VIEW) const;
205  TraCIPosition getOffset(const std::string& viewID = DEFAULT_VIEW) const;
206  std::string getSchema(const std::string& viewID = DEFAULT_VIEW) const;
207  TraCIBoundary getBoundary(const std::string& viewID = DEFAULT_VIEW) const;
208  void setZoom(const std::string& viewID, double zoom) const;
209  void setOffset(const std::string& viewID, double x, double y) const;
210  void setSchema(const std::string& viewID, const std::string& schemeName) const;
211  void setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const;
212  void screenshot(const std::string& viewID, const std::string& filename) const;
213  void trackVehicle(const std::string& viewID, const std::string& vehID) const;
214 
215  private:
217  GUIScope(const GUIScope& src);
218 
220  GUIScope& operator=(const GUIScope& src);
221 
222  };
223 
224 
225 
226 
227 
232  public:
234  virtual ~InductionLoopScope() {}
235 
236  std::vector<std::string> getIDList() const;
237  double getPosition(const std::string& loopID) const;
238  std::string getLaneID(const std::string& loopID) const;
239  int getLastStepVehicleNumber(const std::string& loopID) const;
240  double getLastStepMeanSpeed(const std::string& loopID) const;
241  std::vector<std::string> getLastStepVehicleIDs(const std::string& loopID) const;
242  double getLastStepOccupancy(const std::string& loopID) const;
243  double getLastStepMeanLength(const std::string& loopID) const;
244  double getTimeSinceDetection(const std::string& loopID) const;
245  std::vector<TraCIVehicleData> getVehicleData(const std::string& loopID) const;
246 
247 
248  private:
251 
254 
255  };
256 
257 
258 
259 
260 
265  public:
267  virtual ~JunctionScope() {}
268 
269  std::vector<std::string> getIDList() const;
270  TraCIPosition getPosition(const std::string& junctionID) const;
271 
272  private:
274  JunctionScope(const JunctionScope& src);
275 
278 
279  };
280 
281 
282 
283 
284 
288  class LaneScope : public TraCIScopeWrapper {
289  public:
290  LaneScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
291  virtual ~LaneScope() {}
292 
293  std::vector<std::string> getIDList() const;
294  int getIDCount() const;
295  double getLength(const std::string& laneID) const;
296  double getMaxSpeed(const std::string& laneID) const;
297  double getWidth(const std::string& laneID) const;
298  std::vector<std::string> getAllowed(const std::string& laneID) const;
299  std::vector<std::string> getDisallowed(const std::string& laneID) const;
300  int getLinkNumber(const std::string& laneID) const;
301  std::vector<TraCIConnection> getLinks(const std::string& laneID) const;
302  TraCIPositionVector getShape(const std::string& laneID) const;
303  std::string getEdgeID(const std::string& laneID) const;
304  double getCO2Emission(const std::string& laneID) const;
305  double getCOEmission(const std::string& laneID) const;
306  double getHCEmission(const std::string& laneID) const;
307  double getPMxEmission(const std::string& laneID) const;
308  double getNOxEmission(const std::string& laneID) const;
309  double getFuelConsumption(const std::string& laneID) const;
310  double getNoiseEmission(const std::string& laneID) const;
311  double getElectricityConsumption(const std::string& laneID) const;
312  double getLastStepMeanSpeed(const std::string& laneID) const;
313  double getLastStepOccupancy(const std::string& laneID) const;
314  double getLastStepLength(const std::string& laneID) const;
315  double getTraveltime(const std::string& laneID) const;
316  int getLastStepVehicleNumber(const std::string& laneID) const;
317  int getLastStepHaltingNumber(const std::string& laneID) const;
318  std::vector<std::string> getLastStepVehicleIDs(const std::string& laneID) const;
319 
320  void setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const;
321  void setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const;
322  void setMaxSpeed(const std::string& laneID, double speed) const;
323  void setLength(const std::string& laneID, double length) const;
324 
325  private:
327  LaneScope(const LaneScope& src);
328 
330  LaneScope& operator=(const LaneScope& src);
331 
332  };
333 
334 
339  public:
341  virtual ~LaneAreaScope() {}
342 
343  std::vector<std::string> getIDList() const;
344 
345  private:
347  LaneAreaScope(const LaneAreaScope& src);
348 
351 
352  };
353 
354 
358  class MeMeScope : public TraCIScopeWrapper {
359  public:
360  MeMeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
361  virtual ~MeMeScope() {}
362 
363  std::vector<std::string> getIDList() const;
364  int getLastStepVehicleNumber(const std::string& detID) const;
365  double getLastStepMeanSpeed(const std::string& detID) const;
366  std::vector<std::string> getLastStepVehicleIDs(const std::string& detID) const;
367  int getLastStepHaltingNumber(const std::string& detID) const;
368 
369  private:
371  MeMeScope(const MeMeScope& src);
372 
374  MeMeScope& operator=(const MeMeScope& src);
375 
376  };
377 
378 
379 
380 
381 
385  class POIScope : public TraCIScopeWrapper {
386  public:
387  POIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
388  virtual ~POIScope() {}
389 
390  std::vector<std::string> getIDList() const;
391  std::string getType(const std::string& poiID) const;
392  TraCIPosition getPosition(const std::string& poiID) const;
393  TraCIColor getColor(const std::string& poiID) const;
394 
395  void setType(const std::string& poiID, const std::string& setType) const;
396  void setPosition(const std::string& poiID, double x, double y) const;
397  void setColor(const std::string& poiID, const TraCIColor& c) const;
398  void add(const std::string& poiID, double x, double y, const TraCIColor& c, const std::string& type, int layer) const;
399  void remove(const std::string& poiID, int layer = 0) const;
400 
401  private:
403  POIScope(const POIScope& src);
404 
406  POIScope& operator=(const POIScope& src);
407 
408  };
409 
410 
411 
412 
413 
418  public:
420  virtual ~PolygonScope() {}
421 
422  std::vector<std::string> getIDList() const;
423  std::string getType(const std::string& polygonID) const;
424  TraCIPositionVector getShape(const std::string& polygonID) const;
425  TraCIColor getColor(const std::string& polygonID) const;
426  void setType(const std::string& polygonID, const std::string& setType) const;
427  void setShape(const std::string& polygonID, const TraCIPositionVector& shape) const;
428  void setColor(const std::string& polygonID, const TraCIColor& c) const;
429  void add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) const;
430  void remove(const std::string& polygonID, int layer = 0) const;
431 
432  private:
434  PolygonScope(const PolygonScope& src);
435 
437  PolygonScope& operator=(const PolygonScope& src);
438 
439  };
440 
441 
442 
443 
444 
448  class RouteScope : public TraCIScopeWrapper {
449  public:
450  RouteScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
451  virtual ~RouteScope() {}
452 
453  std::vector<std::string> getIDList() const;
454  std::vector<std::string> getEdges(const std::string& routeID) const;
455 
456  void add(const std::string& routeID, const std::vector<std::string>& edges) const;
457 
458  private:
460  RouteScope(const RouteScope& src);
461 
463  RouteScope& operator=(const RouteScope& src);
464 
465  };
466 
467 
468 
470  typedef std::map<int, TraCIValue> TraCIValues;
471  typedef std::map<std::string, TraCIValues> SubscribedValues;
472  typedef std::map<std::string, SubscribedValues> SubscribedContextValues;
473 
474 
479  public:
481  virtual ~SimulationScope() {}
482 
483  SUMOTime getCurrentTime() const;
484  int getLoadedNumber() const;
485  std::vector<std::string> getLoadedIDList() const;
486  int getDepartedNumber() const;
487  std::vector<std::string> getDepartedIDList() const;
488  int getArrivedNumber() const;
489  std::vector<std::string> getArrivedIDList() const;
490  int getStartingTeleportNumber() const;
491  std::vector<std::string> getStartingTeleportIDList() const;
492  int getEndingTeleportNumber() const;
493  std::vector<std::string> getEndingTeleportIDList() const;
494  SUMOTime getDeltaT() const;
495  TraCIBoundary getNetBoundary() const;
496  int getMinExpectedNumber() const;
497 
498  void subscribe(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
499  void subscribeContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector<int>& vars) const;
500 
501  const SubscribedValues& getSubscriptionResults() const;
502  const TraCIValues& getSubscriptionResults(const std::string& objID) const;
503 
504  const SubscribedContextValues& getContextSubscriptionResults() const;
505  const SubscribedValues& getContextSubscriptionResults(const std::string& objID) const;
506 
507  private:
509  SimulationScope(const SimulationScope& src);
510 
513 
514  };
515 
516 
517 
518 
519 
524  public:
526  virtual ~TrafficLightScope() {}
527 
528  std::vector<std::string> getIDList() const;
529  std::string getRedYellowGreenState(const std::string& tlsID) const;
530  std::vector<TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) const;
531  std::vector<std::string> getControlledLanes(const std::string& tlsID) const;
532  std::vector<TraCILink> getControlledLinks(const std::string& tlsID) const;
533  std::string getProgram(const std::string& tlsID) const;
534  int getPhase(const std::string& tlsID) const;
535  int getNextSwitch(const std::string& tlsID) const;
536 
537  void setRedYellowGreenState(const std::string& tlsID, const std::string& state) const;
538  void setPhase(const std::string& tlsID, int index) const;
539  void setProgram(const std::string& tlsID, const std::string& programID) const;
540  void setPhaseDuration(const std::string& tlsID, int phaseDuration) const;
541  void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const TraCILogic& logic) const;
542 
543  private:
546 
549 
550  };
551 
552 
553 
554 
555 
560  public:
562  virtual ~VehicleTypeScope() {}
563 
564  std::vector<std::string> getIDList() const;
565  double getLength(const std::string& typeID) const;
566  double getMaxSpeed(const std::string& typeID) const;
567  double getSpeedFactor(const std::string& typeID) const;
568  double getSpeedDeviation(const std::string& typeID) const;
569  double getAccel(const std::string& typeID) const;
570  double getDecel(const std::string& typeID) const;
571  double getEmergencyDecel(const std::string& typeID) const;
572  double getApparentDecel(const std::string& typeID) const;
573  double getImperfection(const std::string& typeID) const;
574  double getTau(const std::string& typeID) const;
575  std::string getVehicleClass(const std::string& typeID) const;
576  std::string getEmissionClass(const std::string& typeID) const;
577  std::string getShapeClass(const std::string& typeID) const;
578  double getMinGap(const std::string& typeID) const;
579  double getWidth(const std::string& typeID) const;
580  double getHeight(const std::string& typeID) const;
581  TraCIColor getColor(const std::string& typeID) const;
582  double getMinGapLat(const std::string& typeID) const;
583  double getMaxSpeedLat(const std::string& typeID) const;
584  std::string getLateralAlignment(const std::string& typeID) const;
585 
586  void setLength(const std::string& typeID, double length) const;
587  void setMaxSpeed(const std::string& typeID, double speed) const;
588  void setVehicleClass(const std::string& typeID, const std::string& clazz) const;
589  void setSpeedFactor(const std::string& typeID, double factor) const;
590  void setSpeedDeviation(const std::string& typeID, double deviation) const;
591  void setEmissionClass(const std::string& typeID, const std::string& clazz) const;
592  void setShapeClass(const std::string& typeID, const std::string& shapeClass) const;
593  void setWidth(const std::string& typeID, double width) const;
594  void setHeight(const std::string& typeID, double height) const;
595  void setMinGap(const std::string& typeID, double minGap) const;
596  void setAccel(const std::string& typeID, double accel) const;
597  void setDecel(const std::string& typeID, double decel) const;
598  void setEmergencyDecel(const std::string& typeID, double decel) const;
599  void setApparentDecel(const std::string& typeID, double decel) const;
600  void setImperfection(const std::string& typeID, double imperfection) const;
601  void setTau(const std::string& typeID, double tau) const;
602  void setColor(const std::string& typeID, const TraCIColor& c) const;
603  void setMinGapLat(const std::string& typeID, double minGapLat) const;
604  void setMaxSpeedLat(const std::string& typeID, double speed) const;
605  void setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const;
606  void copy(const std::string& origTypeID, const std::string& newTypeID) const;
607 
608  private:
611 
614 
615  };
616 
617 
618 
619 
620 
625  public:
626  VehicleScope(TraCIAPI& parent) : TraCIScopeWrapper(parent), LAST_TRAVEL_TIME_UPDATE(-1) {}
627  virtual ~VehicleScope() {}
628 
631  std::vector<std::string> getIDList() const;
632  int getIDCount() const;
633  double getSpeed(const std::string& vehicleID) const;
634  TraCIPosition getPosition(const std::string& vehicleID) const;
635  TraCIPosition getPosition3D(const std::string& vehicleID) const;
636  double getAngle(const std::string& vehicleID) const;
637  std::string getRoadID(const std::string& vehicleID) const;
638  std::string getLaneID(const std::string& vehicleID) const;
639  int getLaneIndex(const std::string& vehicleID) const;
640  std::string getTypeID(const std::string& vehicleID) const;
641  std::string getRouteID(const std::string& vehicleID) const;
642  int getRouteIndex(const std::string& vehicleID) const;
643  std::vector<std::string> getEdges(const std::string& vehicleID) const; /*< deprecated in favour of getRoute */
644  std::vector<std::string> getRoute(const std::string& vehicleID) const;
645  TraCIColor getColor(const std::string& vehicleID) const;
646  double getLanePosition(const std::string& vehicleID) const;
647  double getDistance(const std::string& vehicleID) const;
648  int getSignalStates(const std::string& vehicleID) const;
649  double getCO2Emission(const std::string& vehicleID) const;
650  double getCOEmission(const std::string& vehicleID) const;
651  double getHCEmission(const std::string& vehicleID) const;
652  double getPMxEmission(const std::string& vehicleID) const;
653  double getNOxEmission(const std::string& vehicleID) const;
654  double getFuelConsumption(const std::string& vehicleID) const;
655  double getNoiseEmission(const std::string& vehicleID) const;
656  double getElectricityConsumption(const std::string& vehicleID) const;
657  int getSpeedMode(const std::string& vehicleID) const;
658  int getStopState(const std::string& vehicleID) const;
659  double getWaitingTime(const std::string& vehicleID) const;
660  double getAccumulatedWaitingTime(const std::string& vehicleID) const;
661  double getSlope(const std::string& vehicleID) const;
662  double getAllowedSpeed(const std::string& vehicleID) const;
663  int getPersonNumber(const std::string& vehicleID) const;
664  double getSpeedWithoutTraCI(const std::string& vehicleID) const;
665  bool isRouteValid(const std::string& vehicleID) const;
666  double getLateralLanePosition(const std::string& vehicleID) const;
667  double getSpeedFactor(const std::string& vehicleID) const;
668  std::string getLine(const std::string& vehicleID) const;
669  std::vector<std::string> getVia(const std::string& vehicleID) const;
670  std::vector<TraCINextTLSData> getNextTLS(const std::string& vehID) const;
671  std::vector<TraCIBestLanesData> getBestLanes(const std::string& vehicleID) const;
672  std::pair<std::string, double> getLeader(const std::string& vehicleID, double dist) const;
674 
677  double getLength(const std::string& vehicleID) const;
678  double getMaxSpeed(const std::string& vehicleID) const;
679  double getAccel(const std::string& vehicleID) const;
680  double getDecel(const std::string& vehicleID) const;
681  double getEmergencyDecel(const std::string& vehicleID) const;
682  double getApparentDecel(const std::string& vehicleID) const;
683  double getTau(const std::string& vehicleID) const;
684  double getImperfection(const std::string& vehicleID) const;
685  double getSpeedDeviation(const std::string& vehicleID) const;
686  double getMinGap(const std::string& vehicleID) const;
687  double getWidth(const std::string& vehicleID) const;
688  double getHeight(const std::string& veihcleID) const;
689  double getMaxSpeedLat(const std::string& vehicleID) const;
690  double getMinGapLat(const std::string& vehicleID) const;
691  std::string getVehicleClass(const std::string& vehicleID) const;
692  std::string getEmissionClass(const std::string& vehicleID) const;
693  std::string getShapeClass(const std::string& vehicleID) const;
694  std::string getLateralAlignment(const std::string& vehicleID) const;
696 
699  void add(const std::string& vehicleID,
700  const std::string& routeID,
701  const std::string& typeID = "DEFAULT_VEHTYPE",
702  std::string depart = "-1",
703  const std::string& departLane = "first",
704  const std::string& departPos = "base",
705  const std::string& departSpeed = "0",
706  const std::string& arrivalLane = "current",
707  const std::string& arrivalPos = "max",
708  const std::string& arrivalSpeed = "current",
709  const std::string& fromTaz = "",
710  const std::string& toTaz = "",
711  const std::string& line = "",
712  int personCapacity = 0,
713  int personNumber = 0) const;
714 
715  void changeTarget(const std::string& vehicleID, const std::string& edgeID) const;
716  void setRouteID(const std::string& vehicleID, const std::string& routeID) const;
717  void setRoute(const std::string& vehicleID, const std::vector<std::string>& edge) const;
718  void rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes = true) const;
719  void moveTo(const std::string& vehicleID, const std::string& laneID, double position) const;
720  void moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const;
721  void slowDown(const std::string& vehicleID, double speed, int duration) const;
722  void setSpeed(const std::string& vehicleID, double speed) const;
723  void remove(const std::string& vehicleID, char reason = REMOVE_VAPORIZED) const;
724  void setColor(const std::string& vehicleID, const TraCIColor& c) const;
725  void setLine(const std::string& vehicleID, const std::string& line) const;
726  void setVia(const std::string& vehicleID, const std::vector<std::string>& via) const;
728 
731  void setShapeClass(const std::string& vehicleID, const std::string& clazz) const;
732  void setEmissionClass(const std::string& vehicleID, const std::string& clazz) const;
733  void setMaxSpeed(const std::string& vehicleID, double speed) const;
735 
736  private:
738 
740  VehicleScope(const VehicleScope& src);
741 
743  VehicleScope& operator=(const VehicleScope& src);
744 
745  };
746 
751  public:
752  PersonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent) {}
753  virtual ~PersonScope() {}
754 
755  std::vector<std::string> getIDList() const;
756  int getIDCount() const;
757  double getSpeed(const std::string& personID) const;
758  TraCIPosition getPosition(const std::string& personID) const;
759  std::string getRoadID(const std::string& personID) const;
760  std::string getTypeID(const std::string& personID) const;
761  double getWaitingTime(const std::string& personID) const;
762  std::string getNextEdge(const std::string& personID) const;
763  std::string getVehicle(const std::string& personID) const;
764  int getRemainingStages(const std::string& personID) const;
765  int getStage(const std::string& personID, int nextStageIndex = 0) const;
766  std::vector<std::string> getEdges(const std::string& personID, int nextStageIndex = 0) const;
767 
768  void removeStages(const std::string& personID) const;
769  void add(const std::string& personID, const std::string& edgeID, double pos, double depart = DEPARTFLAG_NOW, const std::string typeID = "DEFAULT_PEDTYPE");
770  void appendWaitingStage(const std::string& personID, double duration, const std::string& description = "waiting", const std::string& stopID = "");
771  void appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration = -1, double speed = -1, const std::string& stopID = "");
772  void appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID = "");
773  void removeStage(const std::string& personID, int nextStageIndex) const;
774  void rerouteTraveltime(const std::string& personID) const;
775  void setSpeed(const std::string& personID, double speed) const;
776  void setType(const std::string& personID, const std::string& typeID) const;
777  void setLength(const std::string& personID, double length) const;
778  void setWidth(const std::string& personID, double width) const;
779  void setHeight(const std::string& personID, double height) const;
780  void setMinGap(const std::string& personID, double minGap) const;
781  void setColor(const std::string& personID, const TraCIColor& c) const;
782 
783  private:
785  PersonScope(const PersonScope& src);
786 
788  PersonScope& operator=(const PersonScope& src);
789  };
790 
791 
792 
793 public:
824 
825 
826 protected:
829 
832  void send_commandSimulationStep(SUMOTime time) const;
833 
834 
837  void send_commandClose() const;
838 
839 
846  void send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add = 0) const;
847 
848 
855  void send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const;
856 
857 
865  void send_commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const;
866 
867 
877  void send_commandSubscribeObjectContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
878  int domain, double range, const std::vector<int>& vars) const;
880 
881 
882  void send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane,
883  const double x, const double y, const double angle, const int keepRoute) const;
884 
885 
888 
895  void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
896 
900  int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
901 
902  void processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId = false) const;
904 
907  void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, SubscribedValues& into);
908 
909  template <class T>
910  static inline std::string toString(const T& t, std::streamsize accuracy = PRECISION) {
911  std::ostringstream oss;
912  oss.setf(std::ios::fixed , std::ios::floatfield);
913  oss << std::setprecision(accuracy);
914  oss << t;
915  return oss.str();
916  }
917 
919  void closeSocket();
920 
921 protected:
924 
925  SubscribedValues mySubscribedValues;
926  SubscribedContextValues mySubscribedContextValues;
927 };
928 
929 
930 #endif
931 
932 /****************************************************************************/
933 
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:795
#define DEPARTFLAG_NOW
LaneScope(TraCIAPI &parent)
Definition: TraCIAPI.h:290
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:923
C++ TraCI client API implementation.
Definition: TraCIAPI.h:63
void close()
ends the simulation and closes the connection
Definition: TraCIAPI.cpp:94
Scope for interaction with edges.
Definition: TraCIAPI.h:153
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:66
MeMeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:360
void setOrder(int order)
set priority (execution order) for the client
Definition: TraCIAPI.cpp:79
virtual ~PolygonScope()
Definition: TraCIAPI.h:420
std::map< int, TraCIValue > TraCIValues
{object->{variable->value}}
Definition: TraCIAPI.h:470
GUIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:200
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:128
TraCIScopeWrapper & operator=(const TraCIScopeWrapper &src)
invalidated assignment operator
JunctionScope junction
Scope for interaction with junctions.
Definition: TraCIAPI.h:801
PersonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:752
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:803
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:809
#define DEFAULT_VIEW
Definition: TraCIAPI.h:47
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:328
void load(const std::vector< std::string > &args)
Let sumo load a simulation using the given command line like options.
Definition: TraCIAPI.cpp:590
Scope for interaction with vehicles.
Definition: TraCIAPI.h:624
virtual ~RouteScope()
Definition: TraCIAPI.h:451
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:523
SubscribedContextValues mySubscribedContextValues
Definition: TraCIAPI.h:926
virtual ~LaneScope()
Definition: TraCIAPI.h:291
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:104
void simulationStep(SUMOTime time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:569
Scope for interaction with lane area detectors.
Definition: TraCIAPI.h:338
Scope for interaction with the gui.
Definition: TraCIAPI.h:198
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:819
void readVariableSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:548
std::map< std::string, SubscribedValues > SubscribedContextValues
Definition: TraCIAPI.h:472
Scope for interaction with routes.
Definition: TraCIAPI.h:448
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:799
TraCIPosition getPosition(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:425
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:231
POIScope(TraCIAPI &parent)
Definition: TraCIAPI.h:387
virtual ~MeMeScope()
Definition: TraCIAPI.h:361
Scope for interaction with POIs.
Definition: TraCIAPI.h:385
Scope for interaction with the simulation.
Definition: TraCIAPI.h:478
Scope for interaction with multi entry/-exit detectors.
Definition: TraCIAPI.h:358
virtual ~EdgeScope()
Definition: TraCIAPI.h:156
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:115
SubscribedValues mySubscribedValues
Definition: TraCIAPI.h:925
void send_commandMoveToXY(const std::string &vehicleID, const std::string &edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const
Definition: TraCIAPI.cpp:245
InductionLoopScope(TraCIAPI &parent)
Definition: TraCIAPI.h:233
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition: TraCIAPI.h:807
std::map< std::string, TraCIValues > SubscribedValues
Definition: TraCIAPI.h:471
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:559
A 3D-position.
Definition: TraCIDefs.h:71
PolygonScope(TraCIAPI &parent)
Definition: TraCIAPI.h:419
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:139
#define PRECISION
Definition: TraCIAPI.h:48
virtual ~JunctionScope()
Definition: TraCIAPI.h:267
double getFloat(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:373
~TraCIAPI()
Destructor.
Definition: TraCIAPI.cpp:60
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:815
Scope for interaction with polygons.
Definition: TraCIAPI.h:417
int getInt(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:364
int getByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:355
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition: TraCIAPI.h:910
int getUnsignedByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:346
double getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:382
Scope for interaction with vehicles.
Definition: TraCIAPI.h:750
Scope for interaction with junctions.
Definition: TraCIAPI.h:264
long long int SUMOTime
Definition: TraCIAPI.h:59
TrafficLightScope(TraCIAPI &parent)
Definition: TraCIAPI.h:525
virtual ~VehicleScope()
Definition: TraCIAPI.h:627
void readContextSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:555
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:304
TraCIPositionVector getPolygon(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:407
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, SubscribedValues &into)
Definition: TraCIAPI.cpp:487
virtual ~SimulationScope()
Definition: TraCIAPI.h:481
std::vector< std::string > getStringVector(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:460
EdgeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:155
void send_commandSubscribeObjectContext(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector< int > &vars) const
Sends a SubscribeContext request.
Definition: TraCIAPI.cpp:215
POIScope poi
Scope for interaction with POIs.
Definition: TraCIAPI.h:811
virtual ~POIScope()
Definition: TraCIAPI.h:388
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:187
virtual ~PersonScope()
Definition: TraCIAPI.h:753
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:817
Scope for interaction with lanes.
Definition: TraCIAPI.h:288
TraCIScopeWrapper(TraCIAPI &parent)
Constructor.
Definition: TraCIAPI.h:126
RouteScope(TraCIAPI &parent)
Definition: TraCIAPI.h:450
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:821
SUMOTime getSUMOTime(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:337
A 3D-bounding box.
Definition: TraCIDefs.h:90
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:813
virtual ~TraCIScopeWrapper()
Destructor.
Definition: TraCIAPI.h:129
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:265
VehicleTypeScope(TraCIAPI &parent)
Definition: TraCIAPI.h:561
virtual ~GUIScope()
Definition: TraCIAPI.h:201
TraCIAPI & myParent
The parent TraCI client which offers the connection.
Definition: TraCIAPI.h:134
TraCIPosition getPosition3D(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:438
SUMOTime LAST_TRAVEL_TIME_UPDATE
Definition: TraCIAPI.h:737
TraCIBoundary getBoundingBox(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:391
#define REMOVE_VAPORIZED
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:797
#define SUMOTime_MAX
Definition: TraCIAPI.h:60
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:166
TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:474
long long int SUMOTime
Definition: TraCIDefs.h:52
std::string getString(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:451
VehicleScope(TraCIAPI &parent)
Definition: TraCIAPI.h:626
SimulationScope(TraCIAPI &parent)
Definition: TraCIAPI.h:480
An abstract interface for accessing type-dependent values.
Definition: TraCIAPI.h:121
LaneAreaScope lanearea
Scope for interaction with lanes.
Definition: TraCIAPI.h:805
TraCIAPI()
Constructor.
Definition: TraCIAPI.cpp:48
virtual ~LaneAreaScope()
Definition: TraCIAPI.h:341
LaneAreaScope(TraCIAPI &parent)
Definition: TraCIAPI.h:340
A list of positions.
JunctionScope(TraCIAPI &parent)
Definition: TraCIAPI.h:266
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:823