SUMO - Simulation of Urban MObility
TraCIServerAPI_Person.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // APIs for getting/setting person values via TraCI
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #ifndef NO_TRACI
32 
36 #include <microsim/MSNet.h>
37 #include <microsim/MSEdge.h>
38 #include "TraCIConstants.h"
39 #include "TraCIServer.h"
40 #include "TraCIServerAPI_Person.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 bool
49  tcpip::Storage& outputStorage) {
50  // variable
51  int variable = inputStorage.readUnsignedByte();
52  std::string id = inputStorage.readString();
53  // check variable
54  if (variable != ID_LIST && variable != ID_COUNT
55  && variable != VAR_POSITION && variable != VAR_POSITION3D && variable != VAR_ANGLE && variable != VAR_SPEED
56  && variable != VAR_ROAD_ID && variable != VAR_LANEPOSITION
57  && variable != VAR_WIDTH && variable != VAR_LENGTH && variable != VAR_MINGAP
58  && variable != VAR_TYPE && variable != VAR_SHAPECLASS && variable != VAR_COLOR
59  && variable != VAR_WAITING_TIME && variable != VAR_PARAMETER
60  && variable != VAR_NEXT_EDGE
61  && variable != VAR_EDGES
62  && variable != VAR_STAGE
63  && variable != VAR_STAGES_REMAINING
64  && variable != VAR_VEHICLE
65  ) {
66  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "Get Person Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
67  }
68  // begin response building
69  tcpip::Storage tempMsg;
70  // response-code, variableID, objectID
72  tempMsg.writeUnsignedByte(variable);
73  tempMsg.writeString(id);
75  if (variable == ID_LIST || variable == ID_COUNT) {
76  if (variable == ID_LIST) {
77  std::vector<std::string> ids;
78  for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
79  if (i->second->getCurrentStageType() != MSTransportable::WAITING_FOR_DEPART) {
80  ids.push_back(i->first);
81  }
82  }
84  tempMsg.writeStringList(ids);
85  } else {
87  tempMsg.writeInt((int) c.size());
88  }
89  } else {
90  MSTransportable* p = c.get(id);
91  if (p == 0) {
92  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "Person '" + id + "' is not known", outputStorage);
93  }
94  switch (variable) {
95  case VAR_POSITION: {
97  tempMsg.writeDouble(p->getPosition().x());
98  tempMsg.writeDouble(p->getPosition().y());
99  }
100  break;
101  case VAR_POSITION3D:
103  tempMsg.writeDouble(p->getPosition().x());
104  tempMsg.writeDouble(p->getPosition().y());
105  tempMsg.writeDouble(p->getPosition().z());
106  break;
107  case VAR_ANGLE:
110  break;
111  case VAR_SPEED:
113  tempMsg.writeDouble(p->getSpeed());
114  break;
115  case VAR_ROAD_ID:
117  tempMsg.writeString(p->getEdge()->getID());
118  break;
119  case VAR_LANEPOSITION:
121  tempMsg.writeDouble(p->getEdgePos());
122  break;
123  case VAR_COLOR:
124  tempMsg.writeUnsignedByte(TYPE_COLOR);
125  tempMsg.writeUnsignedByte(p->getParameter().color.red());
126  tempMsg.writeUnsignedByte(p->getParameter().color.green());
127  tempMsg.writeUnsignedByte(p->getParameter().color.blue());
128  tempMsg.writeUnsignedByte(p->getParameter().color.alpha());
129  break;
130  case VAR_WAITING_TIME:
132  tempMsg.writeDouble(p->getWaitingSeconds());
133  break;
134  case VAR_TYPE:
136  tempMsg.writeString(p->getVehicleType().getID());
137  break;
138  case VAR_NEXT_EDGE:
140  tempMsg.writeString(dynamic_cast<MSPerson*>(p)->getNextEdge());
141  break;
142  case VAR_EDGES: {
143  int nextStageIndex = 0;
144  if (!server.readTypeCheckingInt(inputStorage, nextStageIndex)) {
145  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The message must contain the stage index.", outputStorage);
146  }
147  if (nextStageIndex >= p->getNumRemainingStages()) {
148  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The stage index must be lower than the number of remaining stages.", outputStorage);
149  }
150  if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
151  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The negative stage index must refer to a valid previous stage.", outputStorage);
152  }
153  ConstMSEdgeVector edges = p->getEdges(nextStageIndex);
155  tempMsg.writeInt((int)edges.size());
156  for (ConstMSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
157  tempMsg.writeString((*i)->getID());
158  }
159  break;
160  }
161  case VAR_STAGE: {
162  int nextStageIndex = 0;
163  if (!server.readTypeCheckingInt(inputStorage, nextStageIndex)) {
164  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The message must contain the stage index.", outputStorage);
165  }
166  if (nextStageIndex >= p->getNumRemainingStages()) {
167  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The stage index must be lower than the number of remaining stages.", outputStorage);
168  }
169  if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
170  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The negative stage index must refer to a valid previous stage.", outputStorage);
171  }
173  tempMsg.writeInt(p->getStageType(nextStageIndex));
174  break;
175  }
178  tempMsg.writeInt(p->getNumRemainingStages());
179  break;
180  case VAR_VEHICLE: {
181  const SUMOVehicle* veh = p->getVehicle();
183  tempMsg.writeString(veh == 0 ? "" : veh->getID());
184  break;
185  }
186  case VAR_PARAMETER: {
187  std::string paramName = "";
188  if (!server.readTypeCheckingString(inputStorage, paramName)) {
189  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
190  }
192  tempMsg.writeString(p->getParameter().getParameter(paramName, ""));
193  }
194  default:
196  break;
197  }
198  }
199  server.writeStatusCmd(CMD_GET_PERSON_VARIABLE, RTYPE_OK, "", outputStorage);
200  server.writeResponseWithLength(outputStorage, tempMsg);
201  return true;
202 }
203 
204 
205 bool
207  tcpip::Storage& outputStorage) {
208  std::string warning = ""; // additional description for response
209  // variable
210  int variable = inputStorage.readUnsignedByte();
211  if (variable != VAR_PARAMETER
212  && variable != ADD
213  && variable != APPEND_STAGE
214  && variable != REMOVE_STAGE
215  && variable != VAR_SPEED
216  && variable != VAR_TYPE
217  && variable != VAR_LENGTH
218  && variable != VAR_WIDTH
219  && variable != VAR_HEIGHT
220  && variable != VAR_MINGAP
221  && variable != VAR_COLOR
222  ) {
223  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Change Person State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
224  }
225  // id
227  std::string id = inputStorage.readString();
228  const bool shouldExist = variable != ADD;
229  MSTransportable* p = c.get(id);
230  if (p == 0 && shouldExist) {
231  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Person '" + id + "' is not known", outputStorage);
232  }
233  // process
234  switch (variable) {
235  case VAR_SPEED: {
236  double speed = 0;
237  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
238  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Setting speed requires a double.", outputStorage);
239  }
240  // set the speed for all (walking) stages
241  p->setSpeed(speed);
242  // modify the vType so that stages added later are also affected
243  TraCIServerAPI_VehicleType::setVariable(CMD_SET_VEHICLE_VARIABLE, variable, getSingularType(p).getID(), server, inputStorage, outputStorage);
244  }
245  break;
246  case VAR_TYPE: {
247  std::string vTypeID;
248  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
249  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "The vehicle type id must be given as a string.", outputStorage);
250  }
251  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
252  if (vehicleType == 0) {
253  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle type '" + vTypeID + "' is not known.", outputStorage);
254  }
255  p->replaceVehicleType(vehicleType);
256  break;
257  }
258  case ADD: {
259  if (p != 0) {
260  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "The person " + id + " to add already exists.", outputStorage);
261  }
262  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
263  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Adding a person requires a compound object.", outputStorage);
264  }
265  if (inputStorage.readInt() != 4) {
266  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Adding a person needs four parameters.", outputStorage);
267  }
268  SUMOVehicleParameter vehicleParams;
269  vehicleParams.id = id;
270 
271  std::string vTypeID;
272  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
273  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "First parameter (type) requires a string.", outputStorage);
274  }
275  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
276  if (!vehicleType) {
277  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid type '" + vTypeID + "' for person '" + id + "'", outputStorage);
278  }
279 
280  std::string edgeID;
281  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
282  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Second parameter (edge) requires a string.", outputStorage);
283  }
284  const MSEdge* edge = MSEdge::dictionary(edgeID);
285  if (!edge) {
286  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid edge '" + edgeID + "' for person: '" + id + "'", outputStorage);
287  }
288  int depart;
289  if (!server.readTypeCheckingInt(inputStorage, depart)) {
290  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Third parameter (depart) requires an integer.", outputStorage);
291  }
292  if (depart < 0) {
293  const int proc = -depart;
294  if (proc >= static_cast<int>(DEPART_DEF_MAX)) {
295  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid departure time.", outputStorage);
296  }
297  vehicleParams.departProcedure = (DepartDefinition)proc;
298  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
299  } else if (depart < MSNet::getInstance()->getCurrentTimeStep()) {
300  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
301  WRITE_WARNING("Departure time for person '" + id + "' is in the past; using current time instead.");
302  } else {
303  vehicleParams.depart = depart;
304  }
305 
306  double pos;
307  if (!server.readTypeCheckingDouble(inputStorage, pos)) {
308  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);
309  }
310  vehicleParams.departPosProcedure = DEPART_POS_GIVEN;
311  if (fabs(pos) > edge->getLength()) {
312  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid departure position.", outputStorage);
313  }
314  if (pos < 0) {
315  pos += edge->getLength();
316  }
317  vehicleParams.departPos = pos;
318 
319  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
321  plan->push_back(new MSTransportable::Stage_Waiting(*edge, 0, depart, pos, "awaiting departure", true));
322 
323  try {
324  MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan);
326  } catch (ProcessError& e) {
327  delete params;
328  delete plan;
329  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, e.what(), outputStorage);
330  }
331  }
332  break;
333  case APPEND_STAGE: {
334  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
335  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Adding a person stage requires a compound object.", outputStorage);
336  }
337  int numParameters = inputStorage.readInt();
338  int stageType;
339  if (!server.readTypeCheckingInt(inputStorage, stageType)) {
340  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first parameter for adding a stage must be the stage type given as int.", outputStorage);
341  }
342  // append driving stage
343  if (stageType == MSTransportable::DRIVING) {
344  if (numParameters != 4) {
345  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Adding a driving stage needs four parameters.", outputStorage);
346  }
347  std::string edgeID;
348  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
349  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Second parameter (edge) requires a string.", outputStorage);
350  }
351  const MSEdge* edge = MSEdge::dictionary(edgeID);
352  if (!edge) {
353  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid edge '" + edgeID + "' for person: '" + id + "'", outputStorage);
354  }
355  std::string lines;
356  if (!server.readTypeCheckingString(inputStorage, lines)) {
357  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Third parameter (lines) requires a string.", outputStorage);
358  }
359  if (lines.size() == 0) {
360  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Empty lines parameter for person: '" + id + "'", outputStorage);
361  }
362  std::string stopID;
363  MSStoppingPlace* bs = 0;
364  if (!server.readTypeCheckingString(inputStorage, stopID)) {
365  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
366  }
367  if (stopID != "") {
368  bs = MSNet::getInstance()->getBusStop(stopID);
369  if (bs == 0) {
370  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid stopping place id '" + stopID + "' for person: '" + id + "'", outputStorage);
371  }
372  }
373  p->appendStage(new MSPerson::MSPersonStage_Driving(*edge, bs, -NUMERICAL_EPS, StringTokenizer(lines).getVector()));
374 
375  // append waiting stage
376  } else if (stageType == MSTransportable::WAITING) {
377  if (numParameters != 4) {
378  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Adding a waiting stage needs four parameters.", outputStorage);
379  }
380  int duration;
381  if (!server.readTypeCheckingInt(inputStorage, duration)) {
382  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Second parameter (duration) requires an int.", outputStorage);
383  }
384  if (duration < 0) {
385  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Duration for person: '" + id + "' must not be negative", outputStorage);
386  }
387  std::string description;
388  if (!server.readTypeCheckingString(inputStorage, description)) {
389  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Third parameter (description) requires a string.", outputStorage);
390  }
391  std::string stopID;
392  MSStoppingPlace* bs = 0;
393  if (!server.readTypeCheckingString(inputStorage, stopID)) {
394  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
395  }
396  if (stopID != "") {
397  bs = MSNet::getInstance()->getBusStop(stopID);
398  if (bs == 0) {
399  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid stopping place id '" + stopID + "' for person: '" + id + "'", outputStorage);
400  }
401  }
402  p->appendStage(new MSTransportable::Stage_Waiting(*p->getArrivalEdge(), duration, 0, p->getArrivalPos(), description, false));
403 
404  // append walking stage
405  } else if (stageType == MSTransportable::MOVING_WITHOUT_VEHICLE) {
406  if (numParameters != 6) {
407  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Adding a walking stage needs six parameters.", outputStorage);
408  }
409  std::vector<std::string> edgeIDs;
410  if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
411  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Second parameter (edges) route must be defined as a list of edge ids.", outputStorage);
412  }
413  ConstMSEdgeVector edges;
414  try {
415  MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
416  } catch (ProcessError& e) {
417  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, e.what(), outputStorage);
418  }
419  if (edges.empty()) {
420  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Empty edge list for walking stage of person '" + id + "'.", outputStorage);
421  }
422  double arrivalPos;
423  if (!server.readTypeCheckingDouble(inputStorage, arrivalPos)) {
424  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Third parameter (arrivalPos) requires a double.", outputStorage);
425  }
426  if (fabs(arrivalPos) > edges.back()->getLength()) {
427  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid arrivalPos for walking stage of person '" + id + "'.", outputStorage);
428  }
429  if (arrivalPos < 0) {
430  arrivalPos += edges.back()->getLength();
431  }
432  int duration;
433  if (!server.readTypeCheckingInt(inputStorage, duration)) {
434  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Fourth parameter (duration) requires an int.", outputStorage);
435  }
436  double speed;
437  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
438  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Fifth parameter (speed) requires a double.", outputStorage);
439  }
440  if (speed < 0) {
441  speed = p->getVehicleType().getMaxSpeed();
442  }
443  std::string stopID;
444  MSStoppingPlace* bs = 0;
445  if (!server.readTypeCheckingString(inputStorage, stopID)) {
446  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
447  }
448  if (stopID != "") {
449  bs = MSNet::getInstance()->getBusStop(stopID);
450  if (bs == 0) {
451  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid stopping place id '" + stopID + "' for person: '" + id + "'", outputStorage);
452  }
453  }
454  p->appendStage(new MSPerson::MSPersonStage_Walking(edges, bs, duration, speed, p->getArrivalPos(), arrivalPos, 0));
455 
456 
457  } else {
458  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "Invalid stage type for person '" + id + "'", outputStorage);
459  }
460  }
461  break;
462  case REMOVE_STAGE: {
463  int nextStageIndex = 0;
464  if (!server.readTypeCheckingInt(inputStorage, nextStageIndex)) {
465  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The message must contain the stage index.", outputStorage);
466  }
467  if (nextStageIndex >= p->getNumRemainingStages()) {
468  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The stage index must be lower than the number of remaining stages.", outputStorage);
469  }
470  if (nextStageIndex < 0) {
471  return server.writeErrorStatusCmd(CMD_GET_PERSON_VARIABLE, "The stage index may not be negative.", outputStorage);
472  }
473  p->removeStage(nextStageIndex);
474  }
475  break;
476  case VAR_PARAMETER: {
477  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
478  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
479  }
480  //readt itemNo
481  inputStorage.readInt();
482  std::string name;
483  if (!server.readTypeCheckingString(inputStorage, name)) {
484  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
485  }
486  std::string value;
487  if (!server.readTypeCheckingString(inputStorage, value)) {
488  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
489  }
490  ((SUMOVehicleParameter&) p->getParameter()).addParameter(name, value);
491  }
492  break;
493  default:
494  try {
495  if (!TraCIServerAPI_VehicleType::setVariable(CMD_SET_PERSON_VARIABLE, variable, getSingularType(p).getID(), server, inputStorage, outputStorage)) {
496  return false;
497  }
498  } catch (ProcessError& e) {
499  return server.writeErrorStatusCmd(CMD_SET_PERSON_VARIABLE, e.what(), outputStorage);
500  }
501  break;
502  }
503  server.writeStatusCmd(CMD_SET_PERSON_VARIABLE, RTYPE_OK, warning, outputStorage);
504  return true;
505 }
506 
507 
508 bool
509 TraCIServerAPI_Person::getPosition(const std::string& id, Position& p) {
510  MSPerson* person = dynamic_cast<MSPerson*>(MSNet::getInstance()->getPersonControl().get(id));
511  if (person == 0) {
512  return false;
513  }
514  p = person->getPosition();
515  return true;
516 }
517 
518 
521  const MSVehicleType& oType = t->getVehicleType();
522  std::string newID = oType.getID().find('@') == std::string::npos ? oType.getID() + "@" + t->getID() : oType.getID();
523  MSVehicleType* type = MSVehicleType::buildSingularType(newID, &oType);
524  t->replaceVehicleType(type);
525  return *type;
526 }
527 
528 
529 
530 #endif
531 
532 
533 /****************************************************************************/
534 
#define VAR_ROAD_ID
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
RGBColor color
The vehicle&#39;s color, TraCI may change this.
#define VAR_LENGTH
std::map< std::string, MSTransportable * >::const_iterator constVehIt
Definition of the internal transportables map iterator.
double getArrivalPos() const
returns the final arrival pos
double z() const
Returns the z-position.
Definition: Position.h:73
#define TYPE_COMPOUND
const MSEdge * getEdge() const
Returns the current edge.
#define POSITION_2D
A lane area vehicles can halt at.
#define VAR_POSITION
void setSpeed(double speed)
sets the walking speed (ignored in other stages)
virtual double getEdgePos() const
Return the position on the edge.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new person.
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
double y() const
Returns the y-position.
Definition: Position.h:68
The position is given.
#define RTYPE_OK
#define VAR_HEIGHT
#define VAR_WAITING_TIME
#define CMD_GET_PERSON_VARIABLE
#define VAR_TYPE
#define VAR_VEHICLE
double x() const
Returns the x-position.
Definition: Position.h:63
#define VAR_COLOR
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
int size() const
Returns the number of known transportables.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
#define APPEND_STAGE
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
#define TYPE_COLOR
#define TYPE_STRINGLIST
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
#define POSITION_3D
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:728
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
const std::string & getID() const
Returns the id.
Definition: Named.h:66
virtual double getSpeed() const
the current speed of the transportable
#define VAR_STAGE
virtual void writeUnsignedByte(int)
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
const SUMOVehicleParameter & getParameter() const
double getLength() const
return the length of the edge
Definition: MSEdge.h:586
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
Tag for the last element in the enum for safe int casting.
static bool getVariable(const int variable, const std::string &v, tcpip::Storage &tempMsg)
Processes a value request for the given type.
#define VAR_NEXT_EDGE
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
#define REMOVE_STAGE
virtual void writeInt(int)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
#define VAR_POSITION3D
The car-following model and parameter.
Definition: MSVehicleType.h:74
#define TYPE_STRING
virtual int readUnsignedByte()
static bool getPosition(const std::string &id, Position &p)
Returns the named persons&#39;s position.
void removeStage(int next)
removes the nth next stage
#define VAR_ANGLE
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
static MSVehicleType * buildSingularType(const std::string &id, const MSVehicleType *from)
Duplicates the microsim vehicle type giving it a the given id.
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:187
#define VAR_SHAPECLASS
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xce: Change Person State)
Representation of a vehicle.
Definition: SUMOVehicle.h:67
virtual int readInt()
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:730
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void appendStage(Stage *stage)
Appends the given stage to the current plan.
#define VAR_LANEPOSITION
virtual double getAngle() const
return the current angle of the transportable
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:310
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
virtual void writeStringList(const std::vector< std::string > &s)
SUMOTime depart
The vehicle&#39;s departure time.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:257
#define CMD_SET_VEHICLE_VARIABLE
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
const std::string & getID() const
returns the id of the transportable
virtual std::string readString()
#define VAR_EDGES
#define ADD
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:74
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xae: Get Person Variable)
#define VAR_SPEED
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
double departPos
(optional) The position the vehicle shall depart from
static bool setVariable(const int cmd, const int variable, const std::string &id, TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value for the given type.
virtual void writeString(const std::string &s)
static MSVehicleType & getSingularType(MSTransportable *const t)
Structure representing possible vehicle parameter.
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:66
virtual Position getPosition() const
Return the Network coordinate of the transportable.
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
bool add(MSTransportable *transportable)
Adds a single transportable, returns false if an id clash occured.
#define RESPONSE_GET_PERSON_VARIABLE
const std::string & getID() const
Returns the name of the vehicle type.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
StageType getStageType(int next) const
the stage type for the nth next stage
void replaceVehicleType(MSVehicleType *type)
replace myVType
virtual void writeDouble(double)
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
const MSEdge * getArrivalEdge() const
returns the final arrival edge
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
const MSVehicleType & getVehicleType() const
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
#define NUMERICAL_EPS
Definition: config.h:151
#define CMD_SET_PERSON_VARIABLE
#define VAR_PARAMETER
#define ID_COUNT
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
#define TYPE_INTEGER
#define VAR_MINGAP
#define ID_LIST
#define VAR_STAGES_REMAINING
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:827
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:784
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
DepartDefinition
Possible ways to depart.
int getNumStages() const
Return the total number stages in this persons plan.
std::string id
The vehicle&#39;s id.
#define VAR_WIDTH