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