SUMO - Simulation of Urban MObility
Person.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // C++ TraCI client API implementation
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
26 #include <microsim/MSEdge.h>
27 #include <microsim/MSNet.h>
30 #include <utils/geom/GeomHelper.h>
32 #include <utils/common/SUMOTime.h>
36 #include "VehicleType.h"
37 #include "Person.h"
38 
39 #define FAR_AWAY 1000.0
40 
41 //#define DEBUG_MOVEXY
42 //#define DEBUG_MOVEXY_ANGLE
43 
44 namespace libsumo {
45 // ===========================================================================
46 // static member initializations
47 // ===========================================================================
50 
51 
52 // ===========================================================================
53 // static member definitions
54 // ===========================================================================
55 std::vector<std::string>
58  std::vector<std::string> ids;
59  for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
60  if (i->second->getCurrentStageType() != MSTransportable::WAITING_FOR_DEPART) {
61  ids.push_back(i->first);
62  }
63  }
64  return std::move(ids);
65 }
66 
67 
68 int
71 }
72 
73 
75 Person::getPosition(const std::string& personID, const bool includeZ) {
76  return Helper::makeTraCIPosition(getPerson(personID)->getPosition(), includeZ);
77 }
78 
79 
80 double
81 Person::getAngle(const std::string& personID) {
82  return GeomHelper::naviDegree(getPerson(personID)->getAngle());
83 }
84 
85 
86 double
87 Person::getSpeed(const std::string& personID) {
88  return getPerson(personID)->getSpeed();
89 }
90 
91 
92 std::string
93 Person::getRoadID(const std::string& personID) {
94  return getPerson(personID)->getEdge()->getID();
95 }
96 
97 
98 double
99 Person::getLanePosition(const std::string& personID) {
100  return getPerson(personID)->getEdgePos();
101 }
102 
103 
105 Person::getColor(const std::string& personID) {
106  const RGBColor& col = getPerson(personID)->getParameter().color;
107  TraCIColor tcol;
108  tcol.r = col.red();
109  tcol.g = col.green();
110  tcol.b = col.blue();
111  tcol.a = col.alpha();
112  return tcol;
113 }
114 
115 
116 std::string
117 Person::getTypeID(const std::string& personID) {
118  return getPerson(personID)->getVehicleType().getID();
119 }
120 
121 
122 double
123 Person::getWaitingTime(const std::string& personID) {
124  return getPerson(personID)->getWaitingSeconds();
125 }
126 
127 
128 std::string
129 Person::getNextEdge(const std::string& personID) {
130  return getPerson(personID)->getNextEdge();
131 }
132 
133 
134 std::vector<std::string>
135 Person::getEdges(const std::string& personID, int nextStageIndex) {
136  MSTransportable* p = getPerson(personID);
137  if (nextStageIndex >= p->getNumRemainingStages()) {
138  throw TraCIException("The stage index must be lower than the number of remaining stages.");
139  }
140  if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
141  throw TraCIException("The negative stage index must refer to a valid previous stage.");
142  }
143  std::vector<std::string> edgeIDs;
144  for (auto& e : p->getEdges(nextStageIndex)) {
145  edgeIDs.push_back(e->getID());
146  }
147  return edgeIDs;
148 }
149 
150 
151 int
152 Person::getStage(const std::string& personID, int nextStageIndex) {
153  MSTransportable* p = getPerson(personID);
154  if (nextStageIndex >= p->getNumRemainingStages()) {
155  throw TraCIException("The stage index must be lower than the number of remaining stages.");
156  }
157  if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
158  throw TraCIException("The negative stage index must refer to a valid previous stage.");
159  }
160  return p->getStageType(nextStageIndex);
161 }
162 
163 
164 int
165 Person::getRemainingStages(const std::string& personID) {
166  return getPerson(personID)->getNumRemainingStages();
167 }
168 
169 
170 std::string
171 Person::getVehicle(const std::string& personID) {
172  const SUMOVehicle* veh = getPerson(personID)->getVehicle();
173  if (veh == nullptr) {
174  return "";
175  } else {
176  return veh->getID();
177  }
178 }
179 
180 
181 std::string
182 Person::getParameter(const std::string& personID, const std::string& param) {
183  return getPerson(personID)->getParameter().getParameter(param, "");
184 }
185 
186 
187 std::string
188 Person::getEmissionClass(const std::string& personID) {
189  return PollutantsInterface::getName(getPerson(personID)->getVehicleType().getEmissionClass());
190 }
191 
192 
193 std::string
194 Person::getShapeClass(const std::string& personID) {
195  return getVehicleShapeName(getPerson(personID)->getVehicleType().getGuiShape());
196 }
197 
198 
199 double
200 Person::getLength(const std::string& personID) {
201  return getPerson(personID)->getVehicleType().getLength();
202 }
203 
204 
205 double
206 Person::getSpeedFactor(const std::string& personID) {
207  return getPerson(personID)->getVehicleType().getSpeedFactor().getParameter()[0];
208 }
209 
210 
211 double
212 Person::getAccel(const std::string& personID) {
213  return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxAccel();
214 }
215 
216 
217 double
218 Person::getDecel(const std::string& personID) {
219  return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxDecel();
220 }
221 
222 
223 double Person::getEmergencyDecel(const std::string& personID) {
225 }
226 
227 
228 double Person::getApparentDecel(const std::string& personID) {
230 }
231 
232 
233 double Person::getActionStepLength(const std::string& personID) {
234  return getPerson(personID)->getVehicleType().getActionStepLengthSecs();
235 }
236 
237 
238 double
239 Person::getTau(const std::string& personID) {
241 }
242 
243 
244 double
245 Person::getImperfection(const std::string& personID) {
247 }
248 
249 
250 double
251 Person::getSpeedDeviation(const std::string& personID) {
252  return getPerson(personID)->getVehicleType().getSpeedFactor().getParameter()[1];
253 }
254 
255 
256 std::string
257 Person::getVehicleClass(const std::string& personID) {
258  return toString(getPerson(personID)->getVehicleType().getVehicleClass());
259 }
260 
261 
262 double
263 Person::getMinGap(const std::string& personID) {
264  return getPerson(personID)->getVehicleType().getMinGap();
265 }
266 
267 
268 double
269 Person::getMinGapLat(const std::string& personID) {
270  return getPerson(personID)->getVehicleType().getMinGapLat();
271 }
272 
273 
274 double
275 Person::getMaxSpeed(const std::string& personID) {
276  return getPerson(personID)->getVehicleType().getMaxSpeed();
277 }
278 
279 
280 double
281 Person::getMaxSpeedLat(const std::string& personID) {
282  return getPerson(personID)->getVehicleType().getMaxSpeedLat();
283 }
284 
285 
286 std::string
287 Person::getLateralAlignment(const std::string& personID) {
288  return toString(getPerson(personID)->getVehicleType().getPreferredLateralAlignment());
289 }
290 
291 
292 double
293 Person::getWidth(const std::string& personID) {
294  return getPerson(personID)->getVehicleType().getWidth();
295 }
296 
297 
298 double
299 Person::getHeight(const std::string& personID) {
300  return getPerson(personID)->getVehicleType().getHeight();
301 }
302 
303 
304 
305 
306 void
307 Person::setSpeed(const std::string& personID, double speed) {
308  getPerson(personID)->setSpeed(speed);
309 }
310 
311 
312 void
313 Person::setType(const std::string& personID, const std::string& typeID) {
314  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
315  if (vehicleType == nullptr) {
316  throw TraCIException("The vehicle type '" + typeID + "' is not known.");
317  }
318  getPerson(personID)->replaceVehicleType(vehicleType);
319 }
320 
321 
322 void
323 Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
324  MSTransportable* p;
325  try {
326  p = getPerson(personID);
327  } catch (TraCIException&) {
328  p = nullptr;
329  }
330 
331  if (p != nullptr) {
332  throw TraCIException("The person " + personID + " to add already exists.");
333  }
334 
335  SUMOTime depart = TIME2STEPS(departInSecs);
336  SUMOVehicleParameter vehicleParams;
337  vehicleParams.id = personID;
338 
339  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
340  if (!vehicleType) {
341  throw TraCIException("Invalid type '" + typeID + "' for person '" + personID + "'");
342  }
343 
344  const MSEdge* edge = MSEdge::dictionary(edgeID);
345  if (!edge) {
346  throw TraCIException("Invalid edge '" + edgeID + "' for person: '" + personID + "'");
347  }
348 
349  if (departInSecs < 0.) {
350  const int proc = (int) - departInSecs;
351  if (proc >= static_cast<int>(DEPART_DEF_MAX)) {
352  throw TraCIException("Invalid departure time." + toString(depart) + " " + toString(proc));
353  }
354  vehicleParams.departProcedure = (DepartDefinition)proc;
355  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
356  } else if (depart < MSNet::getInstance()->getCurrentTimeStep()) {
357  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
358  WRITE_WARNING("Departure time " + toString(departInSecs) + " for person '" + personID
359  + "' is in the past; using current time " + time2string(vehicleParams.depart) + " instead.");
360  } else {
361  vehicleParams.depart = depart;
362  }
363 
364  vehicleParams.departPosProcedure = DEPART_POS_GIVEN;
365  if (fabs(pos) > edge->getLength()) {
366  throw TraCIException("Invalid departure position.");
367  }
368  if (pos < 0) {
369  pos += edge->getLength();
370  }
371  vehicleParams.departPos = pos;
372 
373  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
375  plan->push_back(new MSTransportable::Stage_Waiting(edge, 0, depart, pos, "awaiting departure", true));
376 
377  try {
378  MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan, nullptr);
380  } catch (ProcessError& e) {
381  delete params;
382  delete plan;
383  throw TraCIException(e.what());
384  }
385 }
386 
387 
388 void
389 Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
390  MSTransportable* p = getPerson(personID);
391  const MSEdge* edge = MSEdge::dictionary(toEdge);
392  if (!edge) {
393  throw TraCIException("Invalid edge '" + toEdge + "' for person: '" + personID + "'");
394  }
395  if (lines.size() == 0) {
396  return throw TraCIException("Empty lines parameter for person: '" + personID + "'");
397  }
398  MSStoppingPlace* bs = nullptr;
399  if (stopID != "") {
401  if (bs == nullptr) {
402  throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
403  }
404  }
405  p->appendStage(new MSPerson::MSPersonStage_Driving(edge, bs, -NUMERICAL_EPS, StringTokenizer(lines).getVector()));
406 }
407 
408 
409 void
410 Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
411  MSTransportable* p = getPerson(personID);
412  if (duration < 0) {
413  throw TraCIException("Duration for person: '" + personID + "' must not be negative");
414  }
415  MSStoppingPlace* bs = nullptr;
416  if (stopID != "") {
418  if (bs == nullptr) {
419  throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
420  }
421  }
422  p->appendStage(new MSTransportable::Stage_Waiting(p->getArrivalEdge(), TIME2STEPS(duration), 0, p->getArrivalPos(), description, false));
423 }
424 
425 
426 void
427 Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edgeIDs, double arrivalPos, double duration, double speed, const std::string& stopID) {
428  MSTransportable* p = getPerson(personID);
429  ConstMSEdgeVector edges;
430  try {
431  MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
432  } catch (ProcessError& e) {
433  throw TraCIException(e.what());
434  }
435  if (edges.empty()) {
436  throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
437  }
438  if (fabs(arrivalPos) > edges.back()->getLength()) {
439  throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
440  }
441  if (arrivalPos < 0) {
442  arrivalPos += edges.back()->getLength();
443  }
444  if (speed < 0) {
445  speed = p->getVehicleType().getMaxSpeed();
446  }
447  MSStoppingPlace* bs = nullptr;
448  if (stopID != "") {
450  if (bs == nullptr) {
451  throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
452  }
453  }
454  p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, TIME2STEPS(duration), speed, p->getArrivalPos(), arrivalPos, 0));
455 }
456 
457 
458 void
459 Person::removeStage(const std::string& personID, int nextStageIndex) {
460  MSTransportable* p = getPerson(personID);
461  if (nextStageIndex >= p->getNumRemainingStages()) {
462  throw TraCIException("The stage index must be lower than the number of remaining stages.");
463  }
464  if (nextStageIndex < 0) {
465  throw TraCIException("The stage index may not be negative.");
466  }
467  p->removeStage(nextStageIndex);
468 }
469 
470 
471 void
472 Person::rerouteTraveltime(const std::string& personID) {
473  MSPerson* p = getPerson(personID);
474  if (p->getNumRemainingStages() == 0) {
475  throw TraCIException("Person '" + personID + "' has no remaining stages.");
476  }
477  const MSEdge* from = p->getEdge();
478  double departPos = p->getEdgePos();
479  // reroute to the start of the next-non-walking stage
480  int firstIndex;
482  firstIndex = 0;
483  } else if (p->getCurrentStageType() == MSTransportable::WAITING) {
485  throw TraCIException("Person '" + personID + "' cannot reroute after the current stop.");
486  }
487  firstIndex = 1;
488  } else {
489  throw TraCIException("Person '" + personID + "' cannot reroute in stage type '" + toString(p->getCurrentStageType()) + "'.");
490  }
491  int nextIndex = firstIndex + 1;
492  for (; nextIndex < p->getNumRemainingStages(); nextIndex++) {
494  break;
495  }
496  }
497  MSTransportable::Stage* destStage = p->getNextStage(nextIndex - 1);
498  const MSEdge* to = destStage->getEdges().back();
499  double arrivalPos = destStage->getArrivalPos();
500  double speed = p->getVehicleType().getMaxSpeed();
501  ConstMSEdgeVector newEdges;
502  MSNet::getInstance()->getPedestrianRouter().compute(from, to, departPos, arrivalPos, speed, 0, nullptr, newEdges);
503  if (newEdges.empty()) {
504  throw TraCIException("Could not find new route for person '" + personID + "'.");
505  }
506  ConstMSEdgeVector oldEdges = p->getEdges(firstIndex);
507  assert(!oldEdges.empty());
508  if (oldEdges.front()->getFunction() != EDGEFUNC_NORMAL) {
509  oldEdges.erase(oldEdges.begin());
510  }
511  //std::cout << " remainingStages=" << p->getNumRemainingStages() << " oldEdges=" << toString(oldEdges) << " newEdges=" << toString(newEdges) << " firstIndex=" << firstIndex << " nextIndex=" << nextIndex << "\n";
512  if (newEdges == oldEdges && (firstIndex + 1 == nextIndex)) {
513  return;
514  }
515  if (newEdges.front() != from) {
516  // @note: maybe this should be done automatically by the router
517  newEdges.insert(newEdges.begin(), from);
518  }
519  p->reroute(newEdges, departPos, firstIndex, nextIndex);
520 }
521 
522 
523 void
524 Person::moveTo(const std::string& personID, const std::string& edgeID, double /* position */) {
525  MSPerson* p = getPerson(personID);
526  MSEdge* e = MSEdge::dictionary(edgeID);
527  if (e == nullptr) {
528  throw TraCIException("Unknown edge '" + edgeID + "'.");
529  }
530  /*
531  switch (p->getStageType(0)) {
532  case MSTransportable::MOVING_WITHOUT_VEHICLE: {
533  MSPerson::MSPersonStage_Walking* s = dynamic_cast<MSPerson::MSPersonStage_Walking*>(p->getCurrentStage());
534  assert(s != 0);
535  const std::string error = s->moveTo(p, Simulation::getCurrentTime());
536  if (error != "") {
537  throw TraCIException("Command moveTo failed for person '" + personID + "' (" + error + ").");
538  }
539  break;
540  }
541  default:
542  */
543  throw TraCIException("Command moveTo is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
544  //}
545 }
546 
547 
548 void
549 Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRouteFlag) {
550  MSPerson* p = getPerson(personID);
551  bool keepRoute = (keepRouteFlag == 1);
552  bool mayLeaveNetwork = (keepRouteFlag == 2);
553  Position pos(x, y);
554 #ifdef DEBUG_MOVEXY
555  const double origAngle = angle;
556 #endif
557  // angle must be in [0,360] because it will be compared against those returned by naviDegree()
558  // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
559  if (angle != INVALID_DOUBLE_VALUE) {
560  while (angle >= 360.) {
561  angle -= 360.;
562  }
563  while (angle < 0.) {
564  angle += 360.;
565  }
566  }
567  Position currentPos = p->getPosition();
568 #ifdef DEBUG_MOVEXY
569  std::cout << std::endl << "begin person " << p->getID() << " lanePos:" << p->getEdgePos() << " edge:" << Named::getIDSecure(p->getEdge()) << "\n";
570  std::cout << " want pos:" << pos << " edgeID:" << edgeID << " origAngle:" << origAngle << " angle:" << angle << " keepRoute:" << keepRoute << std::endl;
571 #endif
572 
573  ConstMSEdgeVector edges;
574  MSLane* lane = nullptr;
575  double lanePos;
576  double lanePosLat = 0;
577  double bestDistance = std::numeric_limits<double>::max();
578  int routeOffset = 0;
579  bool found = false;
580  double maxRouteDistance = 100;
581 
583  ev.push_back(p->getEdge());
584  int routeIndex = 0;
585  MSLane* currentLane = const_cast<MSLane*>(getSidewalk<MSEdge, MSLane>(p->getEdge()));
586  switch (p->getStageType(0)) {
589  assert(s != 0);
590  ev = s->getEdges();
591  routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
592  }
593  break;
594  default:
595  break;
596  }
597  if (keepRoute) {
598  // case a): vehicle is on its earlier route
599  // we additionally assume it is moving forward (SUMO-limit);
600  // note that the route ("edges") is not changed in this case
601  found = Helper::moveToXYMap_matchingRoutePosition(pos, edgeID,
602  ev, routeIndex,
603  bestDistance, &lane, lanePos, routeOffset);
604  } else {
605  double speed = pos.distanceTo2D(p->getPosition()); // !!!veh->getSpeed();
606  found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, edgeID, angle,
607  speed, ev, routeIndex, currentLane, p->getEdgePos(), true,
608  bestDistance, &lane, lanePos, routeOffset, edges);
609  }
610  if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
611  // compute lateral offset
612  if (found) {
613  const double perpDist = lane->getShape().distance2D(pos, false);
614  if (perpDist != GeomHelper::INVALID_OFFSET) {
615  lanePosLat = perpDist;
616  if (!mayLeaveNetwork) {
617  lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + p->getVehicleType().getWidth()));
618  }
619  // figure out whether the offset is to the left or to the right
620  PositionVector tmp = lane->getShape();
621  try {
622  tmp.move2side(-lanePosLat); // moved to left
623  } catch (ProcessError&) {
624  WRITE_WARNING("Could not determine position on lane '" + lane->getID() + " at lateral position " + toString(-lanePosLat) + ".");
625  }
626  //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
627  if (tmp.distance2D(pos) > perpDist) {
628  lanePosLat = -lanePosLat;
629  }
630  }
631  }
632  if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
633  // mapped position may differ from pos
634  pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
635  }
636  assert((found && lane != 0) || (!found && lane == 0));
637  if (angle == INVALID_DOUBLE_VALUE) {
638  if (lane != nullptr) {
639  angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
640  } else {
641  // compute angle outside road network from old and new position
642  angle = GeomHelper::naviDegree(p->getPosition().angleTo2D(pos));
643  }
644  }
645  switch (p->getStageType(0)) {
647  Helper::setRemoteControlled(p, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
648  break;
649  }
650  default:
651  throw TraCIException("Command moveToXY is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
652  }
653  } else {
654  if (lane == nullptr) {
655  throw TraCIException("Could not map person '" + personID + "' no road found within " + toString(maxRouteDistance) + "m.");
656  } else {
657  throw TraCIException("Could not map person '" + personID + "' distance to road is " + toString(bestDistance) + ".");
658  }
659  }
660 }
661 
662 
665 void
666 Person::setParameter(const std::string& personID, const std::string& key, const std::string& value) {
667  MSTransportable* p = getPerson(personID);
668  ((SUMOVehicleParameter&)p->getParameter()).setParameter(key, value);
669 }
670 
671 void
672 Person::setLength(const std::string& personID, double length) {
673  getPerson(personID)->getSingularType().setLength(length);
674 }
675 
676 
677 void
678 Person::setMaxSpeed(const std::string& personID, double speed) {
679  getPerson(personID)->getSingularType().setMaxSpeed(speed);
680 }
681 
682 
683 void
684 Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
686 }
687 
688 
689 void
690 Person::setShapeClass(const std::string& personID, const std::string& clazz) {
692 }
693 
694 
695 void
696 Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
698 }
699 
700 
701 void
702 Person::setWidth(const std::string& personID, double width) {
703  getPerson(personID)->getSingularType().setWidth(width);
704 }
705 
706 
707 void
708 Person::setHeight(const std::string& personID, double height) {
709  getPerson(personID)->getSingularType().setHeight(height);
710 }
711 
712 
713 void
714 Person::setMinGap(const std::string& personID, double minGap) {
715  getPerson(personID)->getSingularType().setMinGap(minGap);
716 }
717 
718 
719 void
720 Person::setAccel(const std::string& personID, double accel) {
721  getPerson(personID)->getSingularType().setAccel(accel);
722 }
723 
724 
725 void
726 Person::setDecel(const std::string& personID, double decel) {
727  getPerson(personID)->getSingularType().setDecel(decel);
728 }
729 
730 
731 void
732 Person::setEmergencyDecel(const std::string& personID, double decel) {
733  getPerson(personID)->getSingularType().setEmergencyDecel(decel);
734 }
735 
736 
737 void
738 Person::setApparentDecel(const std::string& personID, double decel) {
739  getPerson(personID)->getSingularType().setApparentDecel(decel);
740 }
741 
742 
743 void
744 Person::setImperfection(const std::string& personID, double imperfection) {
745  getPerson(personID)->getSingularType().setImperfection(imperfection);
746 }
747 
748 
749 void
750 Person::setTau(const std::string& personID, double tau) {
751  getPerson(personID)->getSingularType().setTau(tau);
752 }
753 
754 
755 void
756 Person::setMinGapLat(const std::string& personID, double minGapLat) {
757  getPerson(personID)->getSingularType().setMinGapLat(minGapLat);
758 }
759 
760 
761 void
762 Person::setMaxSpeedLat(const std::string& personID, double speed) {
763  getPerson(personID)->getSingularType().setMaxSpeedLat(speed);
764 }
765 
766 
767 void
768 Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
770 }
771 
772 
773 void
774 Person::setSpeedFactor(const std::string& personID, double factor) {
775  getPerson(personID)->getSingularType().setSpeedFactor(factor);
776 }
777 
778 
779 void
780 Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
781  getPerson(personID)->getSingularType().setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset);
782 }
783 
784 
785 void
786 Person::setColor(const std::string& personID, const TraCIColor& c) {
787  const SUMOVehicleParameter& p = getPerson(personID)->getParameter();
788  p.color.set(c.r, c.g, c.b, c.a);
790 }
791 
792 
794 
795 
796 MSPerson*
797 Person::getPerson(const std::string& personID) {
799  MSPerson* p = dynamic_cast<MSPerson*>(c.get(personID));
800  if (p == nullptr) {
801  throw TraCIException("Person '" + personID + "' is not known");
802  }
803  return p;
804 }
805 
806 
807 void
808 Person::storeShape(const std::string& id, PositionVector& shape) {
809  shape.push_back(getPerson(id)->getPosition());
810 }
811 
812 
813 std::shared_ptr<VariableWrapper>
815  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
816 }
817 
818 
819 bool
820 Person::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
821  switch (variable) {
822  case TRACI_ID_LIST:
823  return wrapper->wrapStringList(objID, variable, getIDList());
824  case ID_COUNT:
825  return wrapper->wrapInt(objID, variable, getIDCount());
826  case VAR_POSITION:
827  return wrapper->wrapPosition(objID, variable, getPosition(objID));
828  case VAR_POSITION3D:
829  return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
830  case VAR_ANGLE:
831  return wrapper->wrapDouble(objID, variable, getAngle(objID));
832  case VAR_SPEED:
833  return wrapper->wrapDouble(objID, variable, getSpeed(objID));
834  case VAR_ROAD_ID:
835  return wrapper->wrapString(objID, variable, getRoadID(objID));
836  case VAR_LANEPOSITION:
837  return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
838  case VAR_COLOR:
839  return wrapper->wrapColor(objID, variable, getColor(objID));
840  case VAR_WAITING_TIME:
841  return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
842  case VAR_TYPE:
843  return wrapper->wrapString(objID, variable, getTypeID(objID));
844  case VAR_NEXT_EDGE:
845  return wrapper->wrapString(objID, variable, getNextEdge(objID));
847  return wrapper->wrapInt(objID, variable, getRemainingStages(objID));
848  case VAR_VEHICLE:
849  return wrapper->wrapString(objID, variable, getVehicle(objID));
850  default:
851  return false;
852  }
853 }
854 
855 
856 }
857 
858 
859 /****************************************************************************/
#define VAR_ROAD_ID
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
unsigned char g
Definition: TraCIDefs.h:139
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:234
void setMinGap(const double &minGap)
Set a new value for this type&#39;s minimum gap.
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
static double gLateralResolution
Definition: MSGlobals.h:85
static void rerouteTraveltime(const std::string &personID)
Definition: Person.cpp:472
RGBColor color
The vehicle&#39;s color, TraCI may change this.
virtual bool wrapInt(const std::string &objID, const int variable, const int value)=0
long long int SUMOTime
Definition: SUMOTime.h:36
static void moveTo(const std::string &personID, const std::string &edgeID, double position)
Definition: Person.cpp:524
std::map< std::string, MSTransportable * >::const_iterator constVehIt
Definition of the internal transportables map iterator.
static std::vector< std::string > getEdges(const std::string &personID, int nextStageIndex=0)
Definition: Person.cpp:135
double getArrivalPos() const
returns the final arrival pos
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector) ...
static void appendWalkingStage(const std::string &personID, const std::vector< std::string > &edgeIDs, double arrivalPos, double duration=-1, double speed=-1, const std::string &stopID="")
Definition: Person.cpp:427
const MSEdge * getEdge() const
Returns the current edge.
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:869
A lane area vehicles can halt at.
static std::string getParameter(const std::string &routeID, const std::string &param)
Definition: Person.cpp:182
#define VAR_POSITION
void setSpeed(double speed)
sets the walking speed (ignored in other stages)
void setTau(double tau)
Set a new value for this type&#39;s headway.
static void setType(const std::string &personID, const std::string &typeID)
Definition: Person.cpp:313
void setShape(SUMOVehicleShape shape)
Set a new value for this type&#39;s shape.
virtual double getEdgePos() const
Return the position on the edge.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
LIBSUMO_VEHICLE_TYPE_SETTER static LIBSUMO_SUBSCRIPTION_API void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Person.cpp:808
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:84
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:247
virtual double getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:251
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static double getSpeed(const std::string &personID)
Definition: Person.cpp:87
static int getIDCount()
Definition: Person.cpp:69
The position is given.
void setDecel(double decel)
Set a new value for this type&#39;s deceleration.
#define VAR_WAITING_TIME
#define VAR_TYPE
static MSPerson * getPerson(const std::string &id)
Definition: Person.cpp:797
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
#define VAR_VEHICLE
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
#define VAR_COLOR
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position ...
Definition: Position.h:254
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:165
const std::string & getNextEdge() const
return the list of internal edges if this person is walking and the pedestrian model allows it ...
Definition: MSPerson.cpp:605
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition: Named.h:71
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
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:788
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
void setApparentDecel(double apparentDecel)
Set a new value for this type&#39;s apparent deceleration.
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:77
static int getStage(const std::string &personID, int nextStageIndex=0)
Definition: Person.cpp:152
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:200
void setLength(const double &length)
Set a new value for this type&#39;s length.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
const std::string & getID() const
Returns the id.
Definition: Named.h:78
virtual bool wrapString(const std::string &objID, const int variable, const std::string &value)=0
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
virtual double getSpeed() const
the current speed of the transportable
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
const SUMOVehicleParameter & getParameter() const
void setMaxSpeed(const double &maxSpeed)
Set a new value for this type&#39;s maximum speed.
double getLength() const
return the length of the edge
Definition: MSEdge.h:568
void setImperfection(double imperfection)
Set a new value for this type&#39;s imperfection.
Tag for the last element in the enum for safe int casting.
#define VAR_NEXT_EDGE
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:530
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
#define VAR_POSITION3D
The car-following model and parameter.
Definition: MSVehicleType.h:66
static void setSpeed(const std::string &personID, double speed)
Definition: Person.cpp:307
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
void removeStage(int next)
removes the nth next stage
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:210
void setMinGapLat(const double &minGapLat)
Set a new value for this type&#39;s minimum lataral gap.
static SubscriptionResults mySubscriptionResults
Definition: Person.h:100
#define VAR_ANGLE
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
unsigned char b
Definition: TraCIDefs.h:139
A road/street connecting two junctions.
Definition: MSEdge.h:75
#define INVALID_DOUBLE_VALUE
Definition: TraCIDefs.h:42
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:180
MSTransportable::Stage * getCurrentStage() const
Return the current stage.
MSTransportable::Stage * getNextStage(int next) const
Return the current stage.
#define TRACI_ID_LIST
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static LIBSUMO_VEHICLE_TYPE_GETTER void add(const std::string &personID, const std::string &edgeID, double pos, double depart=DEPARTFLAG_NOW, const std::string typeID="DEFAULT_PEDTYPE")
Definition: Person.cpp:323
void setAccel(double accel)
Set a new value for this type&#39;s acceleration.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static std::string getTypeID(const std::string &personID)
Definition: Person.cpp:117
static void appendDrivingStage(const std::string &personID, const std::string &toEdge, const std::string &lines, const std::string &stopID="")
Definition: Person.cpp:389
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:776
static double getAngle(const std::string &personID)
Definition: Person.cpp:81
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:80
#define VAR_LANEPOSITION
ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition: MSPerson.cpp:134
A list of positions.
double compute(const E *from, const E *to, double departPos, double arrivalPos, double speed, SUMOTime msTime, const N *onlyNode, std::vector< const E *> &into, bool allEdges=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:226
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
void setHeight(const double &height)
Set a new value for this type&#39;s height.
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
static std::string getNextEdge(const std::string &personID)
Definition: Person.cpp:129
unsigned char a
Definition: TraCIDefs.h:139
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:263
double getArrivalPos() const
static ContextSubscriptionResults myContextSubscriptionResults
Definition: Person.h:101
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
T MIN2(T a, T b)
Definition: StdDefs.h:70
static double getWaitingTime(const std::string &personID)
Definition: Person.cpp:123
const std::string & getID() const
returns the id of the transportable
static int getRemainingStages(const std::string &personID)
Definition: Person.cpp:165
static std::string getVehicle(const std::string &personID)
Definition: Person.cpp:171
unsigned char r
Definition: TraCIDefs.h:139
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type&#39;s emission class.
double getMinGap() const
Get the free space in front of vehicles of this class.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:218
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:52
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:52
static void removeStage(const std::string &personID, int nextStageIndex)
Definition: Person.cpp:459
const int VEHPARS_COLOR_SET
const ConstMSEdgeVector & getRoute() const
Definition: MSPerson.h:168
void setSpeedFactor(const double &factor)
Set a new value for this type&#39;s speed factor.
MSPedestrianRouter & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:934
static std::vector< std::string > getIDList()
Definition: Person.cpp:56
void move2side(double amount)
move position vector to side using certain ammount
Definition: Edge.cpp:30
#define VAR_SPEED
void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset)
Set a new value for this type&#39;s action step length.
virtual bool wrapDouble(const std::string &objID, const int variable, const double value)=0
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
static void setParameter(const std::string &personID, const std::string &key, const std::string &value)
Definition: Person.cpp:666
virtual bool wrapPosition(const std::string &objID, const int variable, const TraCIPosition &value)=0
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition: Helper.cpp:739
const std::vector< const MSEdge * >::iterator getRouteStep() const
Definition: MSPerson.h:158
void appendStage(Stage *stage, int next=-1)
Appends the given stage to the current plan.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
static TraCIPosition getPosition(const std::string &personID, const bool includeZ=false)
Definition: Person.cpp:75
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
double departPos
(optional) The position the vehicle shall depart from
Structure representing possible vehicle parameter.
void setEmergencyDecel(double emergencyDecel)
Set a new value for this type&#39;s emergency deceleration.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
void reroute(ConstMSEdgeVector &newEdges, double departPos, int firstIndex, int nextIndex)
set new walk and replace the stages with relative indices in the interval [firstIndex, nextIndex[
Definition: MSPerson.cpp:665
virtual bool wrapColor(const std::string &objID, const int variable, const TraCIColor &value)=0
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:259
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:70
bool add(MSTransportable *transportable)
Adds a single transportable, returns false if an id clash occurred.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
void setWidth(const double &width)
Set a new value for this type&#39;s width.
double getActionStepLengthSecs() const
Returns this type&#39;s default action step length in seconds.
static void appendWaitingStage(const std::string &personID, double duration, const std::string &description="waiting", const std::string &stopID="")
Definition: Person.cpp:410
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:478
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)
Replaces the current vehicle type by the one given.
double getLength() const
Get vehicle&#39;s length [m].
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Person.cpp:820
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type&#39;s vehicle class.
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:63
const MSVehicleType & getVehicleType() const
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
static void moveToXY(const std::string &personID, const std::string &edgeID, const double x, const double y, double angle, const int keepRouteFlag)
Definition: Person.cpp:549
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Person.cpp:814
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, std::mt19937 *rng) const
Builds a new person.
#define NUMERICAL_EPS
Definition: config.h:148
#define ID_COUNT
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
void setMaxSpeedLat(const double &maxSpeedLat)
Set a new value for this type&#39;s maximum lateral speed.
void setPreferredLateralAlignment(LateralAlignment latAlignment)
Set vehicle&#39;s preferred lateral alignment.
static bool moveToXYMap_matchingRoutePosition(const Position &pos, const std::string &origID, const ConstMSEdgeVector &currentRoute, int routeIndex, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset)
Definition: Helper.cpp:986
A 3D-position.
Definition: TraCIDefs.h:107
#define VAR_STAGES_REMAINING
static std::string getRoadID(const std::string &personID)
Definition: Person.cpp:93
static double getLanePosition(const std::string &personID)
Definition: Person.cpp:99
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
const Distribution_Parameterized & getSpeedFactor() const
Returns this type&#39;s speed factor.
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:845
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.
StageType getCurrentStageType() const
the current stage type of the transportable
static bool moveToXYMap(const Position &pos, double maxRouteDistance, bool mayLeaveNetwork, const std::string &origID, const double angle, double speed, const ConstMSEdgeVector &currentRoute, const int routePosition, MSLane *currentLane, double currentLanePos, bool onRoad, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition: Helper.cpp:775