Eclipse SUMO - Simulation of Urban MObility
libsumo/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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #include <config.h>
21 
24 #include <microsim/MSEdge.h>
25 #include <microsim/MSLane.h>
26 #include <microsim/MSNet.h>
32 #include <libsumo/TraCIConstants.h>
33 #include <utils/geom/GeomHelper.h>
35 #include <utils/common/SUMOTime.h>
39 #include "Helper.h"
40 #include "VehicleType.h"
41 #include "Person.h"
42 
43 #define FAR_AWAY 1000.0
44 
45 //#define DEBUG_MOVEXY
46 //#define DEBUG_MOVEXY_ANGLE
47 
48 namespace libsumo {
49 // ===========================================================================
50 // static member initializations
51 // ===========================================================================
52 SubscriptionResults Person::mySubscriptionResults;
53 ContextSubscriptionResults Person::myContextSubscriptionResults;
54 
55 
56 // ===========================================================================
57 // static member definitions
58 // ===========================================================================
59 std::vector<std::string>
60 Person::getIDList() {
62  std::vector<std::string> ids;
63  for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
64  if (i->second->getCurrentStageType() != MSStageType::WAITING_FOR_DEPART) {
65  ids.push_back(i->first);
66  }
67  }
68  return ids;
69 }
70 
71 
72 int
73 Person::getIDCount() {
75 }
76 
77 
78 TraCIPosition
79 Person::getPosition(const std::string& personID, const bool includeZ) {
80  return Helper::makeTraCIPosition(getPerson(personID)->getPosition(), includeZ);
81 }
82 
83 
84 TraCIPosition
85 Person::getPosition3D(const std::string& personID) {
86  return Helper::makeTraCIPosition(getPerson(personID)->getPosition(), true);
87 }
88 
89 
90 double
91 Person::getAngle(const std::string& personID) {
92  return GeomHelper::naviDegree(getPerson(personID)->getAngle());
93 }
94 
95 
96 double
97 Person::getSlope(const std::string& personID) {
98  MSPerson* person = getPerson(personID);
99  const double ep = person->getEdgePos();
100  const MSLane* lane = getSidewalk<MSEdge, MSLane>(person->getEdge());
101  if (lane == nullptr) {
102  lane = person->getEdge()->getLanes()[0];
103  }
104  const double gp = lane->interpolateLanePosToGeometryPos(ep);
105  return lane->getShape().slopeDegreeAtOffset(gp);
106 }
107 
108 
109 double
110 Person::getSpeed(const std::string& personID) {
111  return getPerson(personID)->getSpeed();
112 }
113 
114 
115 std::string
116 Person::getRoadID(const std::string& personID) {
117  return getPerson(personID)->getEdge()->getID();
118 }
119 
120 
121 std::string
122 Person::getLaneID(const std::string& personID) {
123  return Named::getIDSecure(getPerson(personID)->getLane(), "");
124 }
125 
126 
127 double
128 Person::getLanePosition(const std::string& personID) {
129  return getPerson(personID)->getEdgePos();
130 }
131 
132 std::vector<TraCIReservation>
133 Person::getTaxiReservations(int stateFilter) {
134  std::vector<TraCIReservation> result;
136  if (dispatcher != nullptr) {
137  MSDispatch_TraCI* traciDispatcher = dynamic_cast<MSDispatch_TraCI*>(dispatcher);
138  if (traciDispatcher == nullptr) {
139  throw TraCIException("device.taxi.dispatch-algorithm 'traci' has not been loaded");
140  }
141  for (Reservation* res : dispatcher->getReservations()) {
142  if (filterReservation(stateFilter, res, result)) {
143  if (res->state == Reservation::NEW) {
144  res->state = Reservation::RETRIEVED;
145  }
146  }
147  }
148  const bool includeRunning = stateFilter == 0 || (stateFilter & (Reservation::ASSIGNED | Reservation::ONBOARD)) != 0;
149  if (includeRunning) {
150  for (const Reservation* res : dispatcher->getRunningReservations()) {
151  filterReservation(stateFilter, res, result);
152  }
153  }
154  }
155  std::sort(result.begin(), result.end(), reservation_by_id_sorter());
156  return result;
157 }
158 
159 int
160 Person::reservation_by_id_sorter::operator()(const TraCIReservation& r1, const TraCIReservation& r2) const {
161  return r1.id < r2.id;
162 }
163 
164 
165 std::string
166 Person::splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs) {
168  if (dispatcher != nullptr) {
169  MSDispatch_TraCI* traciDispatcher = dynamic_cast<MSDispatch_TraCI*>(dispatcher);
170  if (traciDispatcher != nullptr) {
171  return traciDispatcher->splitReservation(reservationID, personIDs);
172  }
173  }
174  throw TraCIException("device.taxi.dispatch-algorithm 'traci' has not been loaded");
175 }
176 
177 bool
178 Person::filterReservation(int stateFilter, const Reservation* res, std::vector<libsumo::TraCIReservation>& reservations) {
179  if (stateFilter != 0 && stateFilter != res->state) {
180  return false;
181  }
182  std::vector<std::string> personIDs;
183  for (MSTransportable* p : res->persons) {
184  personIDs.push_back(p->getID());
185  }
186  std::sort(personIDs.begin(), personIDs.end());
187  reservations.push_back(TraCIReservation(res->id,
188  personIDs,
189  res->group,
190  res->from->getID(),
191  res->to->getID(),
192  res->fromPos,
193  res->toPos,
194  STEPS2TIME(res->pickupTime),
196  res->state
197  ));
198  return true;
199 }
200 
201 
202 TraCIColor
203 Person::getColor(const std::string& personID) {
204  const RGBColor& col = getPerson(personID)->getParameter().color;
205  TraCIColor tcol;
206  tcol.r = col.red();
207  tcol.g = col.green();
208  tcol.b = col.blue();
209  tcol.a = col.alpha();
210  return tcol;
211 }
212 
213 
214 std::string
215 Person::getTypeID(const std::string& personID) {
216  return getPerson(personID)->getVehicleType().getID();
217 }
218 
219 
220 double
221 Person::getWaitingTime(const std::string& personID) {
222  return getPerson(personID)->getWaitingSeconds();
223 }
224 
225 
226 std::string
227 Person::getNextEdge(const std::string& personID) {
228  return getPerson(personID)->getNextEdge();
229 }
230 
231 
232 std::vector<std::string>
233 Person::getEdges(const std::string& personID, int nextStageIndex) {
234  MSTransportable* p = getPerson(personID);
235  if (nextStageIndex >= p->getNumRemainingStages()) {
236  throw TraCIException("The stage index must be lower than the number of remaining stages.");
237  }
238  if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
239  throw TraCIException("The negative stage index must refer to a valid previous stage.");
240  }
241  std::vector<std::string> edgeIDs;
242  for (auto& e : p->getEdges(nextStageIndex)) {
243  if (e != nullptr) {
244  edgeIDs.push_back(e->getID());
245  }
246  }
247  return edgeIDs;
248 }
249 
250 
251 TraCIStage
252 Person::getStage(const std::string& personID, int nextStageIndex) {
253  MSTransportable* p = getPerson(personID);
254  TraCIStage result;
255  if (nextStageIndex >= p->getNumRemainingStages()) {
256  throw TraCIException("The stage index must be lower than the number of remaining stages.");
257  }
258  if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
259  throw TraCIException("The negative stage index " + toString(nextStageIndex) + " must refer to a valid previous stage.");
260  }
261  //stageType, arrivalPos, edges, destStop, vType, and description can be retrieved directly from the base Stage class.
262  MSStage* stage = p->getNextStage(nextStageIndex);
263  result.type = (int)stage->getStageType();
264  result.arrivalPos = stage->getArrivalPos();
265  for (auto e : stage->getEdges()) {
266  if (e != nullptr) {
267  result.edges.push_back(e->getID());
268  }
269  }
270  MSStoppingPlace* destinationStop = stage->getDestinationStop();
271  if (destinationStop != nullptr) {
272  result.destStop = destinationStop->getID();
273  }
274  result.description = stage->getStageDescription(p->isPerson());
275  result.length = stage->getDistance();
276  if (result.length == -1.) {
277  result.length = INVALID_DOUBLE_VALUE;
278  }
279  result.departPos = INVALID_DOUBLE_VALUE;
280  result.cost = INVALID_DOUBLE_VALUE;
281  result.depart = stage->getDeparted() >= 0 ? STEPS2TIME(stage->getDeparted()) : INVALID_DOUBLE_VALUE;
282  result.travelTime = stage->getArrived() >= 0 ? STEPS2TIME(stage->getArrived() - stage->getDeparted()) : INVALID_DOUBLE_VALUE;
283  // Some stage type dependant attributes
284  switch (stage->getStageType()) {
285  case MSStageType::DRIVING: {
286  MSStageDriving* const drivingStage = static_cast<MSStageDriving*>(stage);
287  result.vType = drivingStage->getVehicleType();
288  result.intended = drivingStage->getIntendedVehicleID();
289  if (result.depart < 0 && drivingStage->getIntendedDepart() >= 0) {
290  result.depart = STEPS2TIME(drivingStage->getIntendedDepart());
291  }
292  const std::set<std::string> lines = drivingStage->getLines();
293  for (auto line = lines.begin(); line != lines.end(); line++) {
294  if (line != lines.begin()) {
295  result.line += " ";
296  }
297  result.line += *line;
298  }
299  break;
300  }
301  case MSStageType::WALKING: {
302  auto* walkingStage = (MSPerson::MSPersonStage_Walking*) stage;
303  result.departPos = walkingStage->getDepartPos();
304  break;
305  }
306  case MSStageType::WAITING: {
307  auto* waitingStage = (MSStageWaiting*) stage;
308  if (waitingStage->getDuration() > 0) {
309  result.travelTime = STEPS2TIME(waitingStage->getDuration());
310  }
311  break;
312  }
313  default:
314  break;
315  }
316  return result;
317 }
318 
319 
320 int
321 Person::getRemainingStages(const std::string& personID) {
322  return getPerson(personID)->getNumRemainingStages();
323 }
324 
325 
326 std::string
327 Person::getVehicle(const std::string& personID) {
328  const SUMOVehicle* veh = getPerson(personID)->getVehicle();
329  if (veh == nullptr) {
330  return "";
331  } else {
332  return veh->getID();
333  }
334 }
335 
336 
337 std::string
338 Person::getParameter(const std::string& personID, const std::string& param) {
339  return getPerson(personID)->getParameter().getParameter(param, "");
340 }
341 
342 
344 
345 
346 std::string
347 Person::getEmissionClass(const std::string& personID) {
348  return PollutantsInterface::getName(getPerson(personID)->getVehicleType().getEmissionClass());
349 }
350 
351 
352 std::string
353 Person::getShapeClass(const std::string& personID) {
354  return getVehicleShapeName(getPerson(personID)->getVehicleType().getGuiShape());
355 }
356 
357 
358 double
359 Person::getLength(const std::string& personID) {
360  return getPerson(personID)->getVehicleType().getLength();
361 }
362 
363 
364 double
365 Person::getSpeedFactor(const std::string& personID) {
366  return getPerson(personID)->getSpeedFactor();
367 }
368 
369 
370 double
371 Person::getAccel(const std::string& personID) {
372  return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxAccel();
373 }
374 
375 
376 double
377 Person::getDecel(const std::string& personID) {
378  return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxDecel();
379 }
380 
381 
382 double Person::getEmergencyDecel(const std::string& personID) {
383  return getPerson(personID)->getVehicleType().getCarFollowModel().getEmergencyDecel();
384 }
385 
386 
387 double Person::getApparentDecel(const std::string& personID) {
388  return getPerson(personID)->getVehicleType().getCarFollowModel().getApparentDecel();
389 }
390 
391 
392 double Person::getActionStepLength(const std::string& personID) {
393  return getPerson(personID)->getVehicleType().getActionStepLengthSecs();
394 }
395 
396 
397 double
398 Person::getTau(const std::string& personID) {
399  return getPerson(personID)->getVehicleType().getCarFollowModel().getHeadwayTime();
400 }
401 
402 
403 double
404 Person::getImperfection(const std::string& personID) {
405  return getPerson(personID)->getVehicleType().getCarFollowModel().getImperfection();
406 }
407 
408 
409 double
410 Person::getSpeedDeviation(const std::string& personID) {
411  return getPerson(personID)->getVehicleType().getSpeedFactor().getParameter()[1];
412 }
413 
414 
415 std::string
416 Person::getVehicleClass(const std::string& personID) {
417  return toString(getPerson(personID)->getVehicleType().getVehicleClass());
418 }
419 
420 
421 double
422 Person::getMinGap(const std::string& personID) {
423  return getPerson(personID)->getVehicleType().getMinGap();
424 }
425 
426 
427 double
428 Person::getMinGapLat(const std::string& personID) {
429  return getPerson(personID)->getVehicleType().getMinGapLat();
430 }
431 
432 
433 double
434 Person::getMaxSpeed(const std::string& personID) {
435  return getPerson(personID)->getVehicleType().getMaxSpeed();
436 }
437 
438 
439 double
440 Person::getMaxSpeedLat(const std::string& personID) {
441  return getPerson(personID)->getVehicleType().getMaxSpeedLat();
442 }
443 
444 
445 std::string
446 Person::getLateralAlignment(const std::string& personID) {
447  return toString(getPerson(personID)->getVehicleType().getPreferredLateralAlignment());
448 }
449 
450 
451 double
452 Person::getWidth(const std::string& personID) {
453  return getPerson(personID)->getVehicleType().getWidth();
454 }
455 
456 
457 double
458 Person::getHeight(const std::string& personID) {
459  return getPerson(personID)->getVehicleType().getHeight();
460 }
461 
462 
463 int
464 Person::getPersonCapacity(const std::string& personID) {
465  return getPerson(personID)->getVehicleType().getPersonCapacity();
466 }
467 
468 
469 void
470 Person::setSpeed(const std::string& personID, double speed) {
471  getPerson(personID)->setSpeed(speed);
472 }
473 
474 
475 void
476 Person::setType(const std::string& personID, const std::string& typeID) {
477  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
478  if (vehicleType == nullptr) {
479  throw TraCIException("The vehicle type '" + typeID + "' is not known.");
480  }
481  getPerson(personID)->replaceVehicleType(vehicleType);
482 }
483 
484 
485 void
486 Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
487  MSTransportable* p;
488  try {
489  p = getPerson(personID);
490  } catch (TraCIException&) {
491  p = nullptr;
492  }
493 
494  if (p != nullptr) {
495  throw TraCIException("The person " + personID + " to add already exists.");
496  }
497 
498  SUMOTime depart = TIME2STEPS(departInSecs);
499  SUMOVehicleParameter vehicleParams;
500  vehicleParams.id = personID;
501 
502  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
503  if (!vehicleType) {
504  throw TraCIException("Invalid type '" + typeID + "' for person '" + personID + "'");
505  }
506 
507  const MSEdge* edge = MSEdge::dictionary(edgeID);
508  if (!edge) {
509  throw TraCIException("Invalid edge '" + edgeID + "' for person: '" + personID + "'");
510  }
511 
512  if (departInSecs < 0.) {
513  const int proc = (int) - departInSecs;
514  if (proc >= static_cast<int>(DEPART_DEF_MAX)) {
515  throw TraCIException("Invalid departure time." + toString(depart) + " " + toString(proc));
516  }
517  vehicleParams.departProcedure = (DepartDefinition)proc;
518  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
519  } else if (depart < MSNet::getInstance()->getCurrentTimeStep()) {
520  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
521  WRITE_WARNING("Departure time=" + toString(departInSecs) + " for person '" + personID
522  + "' is in the past; using current time=" + time2string(vehicleParams.depart) + " instead.");
523  } else {
524  vehicleParams.depart = depart;
525  }
526 
528  if (fabs(pos) > edge->getLength()) {
529  throw TraCIException("Invalid departure position.");
530  }
531  if (pos < 0) {
532  pos += edge->getLength();
533  }
534  vehicleParams.departPos = pos;
535 
536  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
538  plan->push_back(new MSStageWaiting(edge, nullptr, 0, depart, pos, "awaiting departure", true));
539 
540  try {
541  MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan, nullptr);
543  } catch (ProcessError& e) {
544  delete params;
545  delete plan;
546  throw TraCIException(e.what());
547  }
548 }
549 
550 MSStage*
551 Person::convertTraCIStage(const TraCIStage& stage, const std::string personID) {
552  MSStoppingPlace* bs = nullptr;
553  if (!stage.destStop.empty()) {
554  bs = MSNet::getInstance()->getStoppingPlace(stage.destStop, SUMO_TAG_BUS_STOP);
555  if (bs == nullptr) {
557  if (bs == nullptr) {
558  throw TraCIException("Invalid stopping place id '" + stage.destStop + "' for person: '" + personID + "'");
559  } else {
560  // parkingArea is not a proper arrival place
561  bs = nullptr;
562  }
563  }
564  }
565  switch (stage.type) {
566  case STAGE_DRIVING: {
567  if (stage.edges.empty()) {
568  throw TraCIException("The stage should have at least one edge");
569  }
570  std::string toId = stage.edges.back();
571  MSEdge* to = MSEdge::dictionary(toId);
572  if (!to) {
573  throw TraCIException("Invalid edge '" + toId + "' for person: '" + personID + "'");
574  }
575  //std::string fromId = stage.edges.front();
576  //MSEdge* from = MSEdge::dictionary(fromId);
577  //if (!from) {
578  // throw TraCIException("Invalid edge '" + fromId + "' for person: '" + personID + "'");
579  //}
580  if (stage.line.empty()) {
581  throw TraCIException("Empty lines parameter for person: '" + personID + "'");
582  }
583  double arrivalPos = stage.arrivalPos;
584  if (arrivalPos == INVALID_DOUBLE_VALUE) {
585  if (bs != nullptr) {
586  arrivalPos = bs->getEndLanePosition();
587  } else {
588  arrivalPos = to->getLength();
589  }
590  }
591  return new MSStageDriving(nullptr, to, bs, arrivalPos, StringTokenizer(stage.line).getVector());
592  }
593 
594  case STAGE_WALKING: {
595  MSTransportable* p = getPerson(personID);
596  ConstMSEdgeVector edges;
597  try {
598  MSEdge::parseEdgesList(stage.edges, edges, "<unknown>");
599  } catch (ProcessError& e) {
600  throw TraCIException(e.what());
601  }
602  if (edges.empty()) {
603  throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
604  }
605  double arrivalPos = stage.arrivalPos;
606  if (fabs(arrivalPos) > edges.back()->getLength()) {
607  throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
608  }
609  if (arrivalPos < 0) {
610  arrivalPos += edges.back()->getLength();
611  }
612  double speed = p->getVehicleType().getMaxSpeed();
613  return new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, -1, speed, p->getArrivalPos(), arrivalPos, 0);
614  }
615 
616  case STAGE_WAITING: {
617  MSTransportable* p = getPerson(personID);
618  if (stage.travelTime < 0) {
619  throw TraCIException("Duration for person: '" + personID + "' must not be negative");
620  }
621  return new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(stage.travelTime), 0, p->getArrivalPos(), stage.description, false);
622  }
623  default:
624  return nullptr;
625  }
626 }
627 
628 
629 void
630 Person::appendStage(const std::string& personID, const TraCIStage& stage) {
631  MSTransportable* p = getPerson(personID);
632  MSStage* personStage = convertTraCIStage(stage, personID);
633  p->appendStage(personStage);
634 }
635 
636 
637 void
638 Person::replaceStage(const std::string& personID, const int stageIndex, const TraCIStage& stage) {
639  MSTransportable* p = getPerson(personID);
640  if (stageIndex >= p->getNumRemainingStages()) {
641  throw TraCIException("Specified stage index: is not valid for person " + personID);
642  }
643  MSStage* personStage = convertTraCIStage(stage, personID);
644  // removing the current stage triggers abort+proceed so the replacement
645  // stage must be ready beforehand
646  p->appendStage(personStage, stageIndex + 1);
647  p->removeStage(stageIndex);
648 }
649 
650 
651 void
652 Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
653  MSTransportable* p = getPerson(personID);
654  const MSEdge* edge = MSEdge::dictionary(toEdge);
655  if (!edge) {
656  throw TraCIException("Invalid edge '" + toEdge + "' for person: '" + personID + "'");
657  }
658  if (lines.size() == 0) {
659  throw TraCIException("Empty lines parameter for person: '" + personID + "'");
660  }
661  MSStoppingPlace* bs = nullptr;
662  if (stopID != "") {
664  if (bs == nullptr) {
665  throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
666  }
667  }
668  p->appendStage(new MSStageDriving(nullptr, edge, bs, edge->getLength() - NUMERICAL_EPS, StringTokenizer(lines).getVector()));
669 }
670 
671 
672 void
673 Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
674  MSTransportable* p = getPerson(personID);
675  if (duration < 0) {
676  throw TraCIException("Duration for person: '" + personID + "' must not be negative");
677  }
678  MSStoppingPlace* bs = nullptr;
679  if (stopID != "") {
681  if (bs == nullptr) {
682  throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
683  }
684  }
685  p->appendStage(new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(duration), 0, p->getArrivalPos(), description, false));
686 }
687 
688 
689 void
690 Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edgeIDs, double arrivalPos, double duration, double speed, const std::string& stopID) {
691  MSTransportable* p = getPerson(personID);
692  ConstMSEdgeVector edges;
693  try {
694  MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
695  } catch (ProcessError& e) {
696  throw TraCIException(e.what());
697  }
698  if (edges.empty()) {
699  throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
700  }
701  if (fabs(arrivalPos) > edges.back()->getLength()) {
702  throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
703  }
704  if (arrivalPos < 0) {
705  arrivalPos += edges.back()->getLength();
706  }
707  if (speed < 0) {
708  speed = p->getVehicleType().getMaxSpeed();
709  }
710  MSStoppingPlace* bs = nullptr;
711  if (stopID != "") {
713  if (bs == nullptr) {
714  throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
715  }
716  }
717  p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, TIME2STEPS(duration), speed, p->getArrivalPos(), arrivalPos, 0));
718 }
719 
720 
721 void
722 Person::removeStage(const std::string& personID, int nextStageIndex) {
723  MSTransportable* p = getPerson(personID);
724  if (nextStageIndex >= p->getNumRemainingStages()) {
725  throw TraCIException("The stage index must be lower than the number of remaining stages.");
726  }
727  if (nextStageIndex < 0) {
728  throw TraCIException("The stage index may not be negative.");
729  }
730  p->removeStage(nextStageIndex);
731 }
732 
733 
734 void
735 Person::rerouteTraveltime(const std::string& personID) {
736  MSPerson* p = getPerson(personID);
737  if (p->getNumRemainingStages() == 0) {
738  throw TraCIException("Person '" + personID + "' has no remaining stages.");
739  }
740  const MSEdge* from = p->getEdge();
741  double departPos = p->getEdgePos();
742  // reroute to the start of the next-non-walking stage
743  int firstIndex;
745  firstIndex = 0;
746  } else if (p->getCurrentStageType() == MSStageType::WAITING) {
747  if (p->getNumRemainingStages() < 2 || p->getStageType(1) != MSStageType::WALKING) {
748  throw TraCIException("Person '" + personID + "' cannot reroute after the current stop.");
749  }
750  firstIndex = 1;
751  } else {
752  throw TraCIException("Person '" + personID + "' cannot reroute in stage type '" + toString((int)p->getCurrentStageType()) + "'.");
753  }
754  int nextIndex = firstIndex + 1;
755  for (; nextIndex < p->getNumRemainingStages(); nextIndex++) {
756  if (p->getStageType(nextIndex) != MSStageType::WALKING) {
757  break;
758  }
759  }
760  MSStage* destStage = p->getNextStage(nextIndex - 1);
761  const MSEdge* to = destStage->getEdges().back();
762  double arrivalPos = destStage->getArrivalPos();
763  double speed = p->getVehicleType().getMaxSpeed();
764  ConstMSEdgeVector newEdges;
765  MSNet::getInstance()->getPedestrianRouter(0).compute(from, to, departPos, arrivalPos, speed, 0, nullptr, newEdges);
766  if (newEdges.empty()) {
767  throw TraCIException("Could not find new route for person '" + personID + "'.");
768  }
769  ConstMSEdgeVector oldEdges = p->getEdges(firstIndex);
770  assert(!oldEdges.empty());
771  if (oldEdges.front()->getFunction() != SumoXMLEdgeFunc::NORMAL) {
772  oldEdges.erase(oldEdges.begin());
773  }
774  //std::cout << " remainingStages=" << p->getNumRemainingStages() << " oldEdges=" << toString(oldEdges) << " newEdges=" << toString(newEdges) << " firstIndex=" << firstIndex << " nextIndex=" << nextIndex << "\n";
775  if (newEdges == oldEdges && (firstIndex + 1 == nextIndex)) {
776  return;
777  }
778  if (newEdges.front() != from) {
779  // @note: maybe this should be done automatically by the router
780  newEdges.insert(newEdges.begin(), from);
781  }
782  p->reroute(newEdges, departPos, firstIndex, nextIndex);
783 }
784 
785 
786 void
787 Person::moveTo(const std::string& personID, const std::string& edgeID, double /* position */) {
788  MSPerson* p = getPerson(personID);
789  MSEdge* e = MSEdge::dictionary(edgeID);
790  if (e == nullptr) {
791  throw TraCIException("Unknown edge '" + edgeID + "'.");
792  }
793  /*
794  switch (p->getStageType(0)) {
795  case MSTransportable::MOVING_WITHOUT_VEHICLE: {
796  MSPerson::MSPersonStage_Walking* s = dynamic_cast<MSPerson::MSPersonStage_Walking*>(p->getCurrentStage());
797  assert(s != 0);
798  const std::string error = s->moveTo(p, Simulation::getCurrentTime());
799  if (error != "") {
800  throw TraCIException("Command moveTo failed for person '" + personID + "' (" + error + ").");
801  }
802  break;
803  }
804  default:
805  */
806  throw TraCIException("Command moveTo is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
807  //}
808 }
809 
810 
811 void
812 Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
813  MSPerson* p = getPerson(personID);
814  const bool doKeepRoute = (keepRoute & 1) != 0;
815  const bool mayLeaveNetwork = (keepRoute & 2) != 0;
816  const bool ignorePermissions = (keepRoute & 4) != 0;
817  SUMOVehicleClass vClass = ignorePermissions ? SVC_IGNORING : p->getVClass();
818  Position pos(x, y);
819 #ifdef DEBUG_MOVEXY
820  const double origAngle = angle;
821 #endif
822  // angle must be in [0,360] because it will be compared against those returned by naviDegree()
823  // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
824  if (angle != INVALID_DOUBLE_VALUE) {
825  while (angle >= 360.) {
826  angle -= 360.;
827  }
828  while (angle < 0.) {
829  angle += 360.;
830  }
831  }
832  Position currentPos = p->getPosition();
833 #ifdef DEBUG_MOVEXY
834  std::cout << std::endl << "begin person " << p->getID() << " lanePos:" << p->getEdgePos() << " edge:" << Named::getIDSecure(p->getEdge()) << "\n";
835  std::cout << " want pos:" << pos << " edgeID:" << edgeID << " origAngle:" << origAngle << " angle:" << angle << " keepRoute:" << keepRoute << std::endl;
836 #endif
837 
838  ConstMSEdgeVector edges;
839  MSLane* lane = nullptr;
840  double lanePos;
841  double lanePosLat = 0;
842  double bestDistance = std::numeric_limits<double>::max();
843  int routeOffset = 0;
844  bool found = false;
845  double maxRouteDistance = matchThreshold;
846 
848  ev.push_back(p->getEdge());
849  int routeIndex = 0;
850  MSLane* currentLane = const_cast<MSLane*>(getSidewalk<MSEdge, MSLane>(p->getEdge()));
851  switch (p->getStageType(0)) {
852  case MSStageType::WALKING: {
854  assert(s != 0);
855  ev = s->getEdges();
856  routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
857  }
858  break;
859  default:
860  break;
861  }
862  if (doKeepRoute) {
863  // case a): vehicle is on its earlier route
864  // we additionally assume it is moving forward (SUMO-limit);
865  // note that the route ("edges") is not changed in this case
866  found = Helper::moveToXYMap_matchingRoutePosition(pos, edgeID,
867  ev, routeIndex, vClass, true,
868  bestDistance, &lane, lanePos, routeOffset);
869  } else {
870  double speed = pos.distanceTo2D(p->getPosition()); // !!!veh->getSpeed();
871  found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, edgeID, angle,
872  speed, ev, routeIndex, currentLane, p->getEdgePos(), currentLane != nullptr,
873  vClass, true,
874  bestDistance, &lane, lanePos, routeOffset, edges);
875  if (edges.size() != 0 && ev.size() > 1) {
876  // try to rebuild the route
877  const MSEdge* origEdge = p->getEdge();
878  assert(lane != nullptr);
879  const MSJunction* originalTarget = nullptr;
880  if (origEdge->isNormal()) {
881  if (routeIndex == 0) {
882  if (origEdge->getToJunction() == ev[1]->getToJunction() || origEdge->getToJunction() == ev[1]->getFromJunction()) {
883  originalTarget = origEdge->getToJunction();
884  } else {
885  originalTarget = origEdge->getFromJunction();
886  }
887  } else {
888  if (origEdge->getToJunction() == ev[routeIndex - 1]->getToJunction() || origEdge->getToJunction() == ev[routeIndex - 1]->getFromJunction()) {
889  originalTarget = origEdge->getFromJunction();
890  } else {
891  originalTarget = origEdge->getToJunction();
892  }
893  }
894  } else {
895  originalTarget = origEdge->getToJunction();
896  assert(originalTarget == origEdge->getFromJunction());
897  }
898  const MSEdge* newEdge = edges[0];
899  if (edges[0]->getFromJunction() == originalTarget || edges[0]->getToJunction() == originalTarget) {
900  edges = ev;
901  edges[routeIndex] = newEdge;
902  }
903  }
904  }
905  if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
906  // compute lateral offset
907  if (found) {
908  const double perpDist = lane->getShape().distance2D(pos, false);
909  if (perpDist != GeomHelper::INVALID_OFFSET) {
910  lanePosLat = perpDist;
911  if (!mayLeaveNetwork) {
912  lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + p->getVehicleType().getWidth()));
913  }
914  // figure out whether the offset is to the left or to the right
915  PositionVector tmp = lane->getShape();
916  try {
917  tmp.move2side(-lanePosLat); // moved to left
918  } catch (ProcessError&) {
919  WRITE_WARNING("Could not determine position on lane '" + lane->getID() + " at lateral position " + toString(-lanePosLat) + ".");
920  }
921  //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
922  if (tmp.distance2D(pos) > perpDist) {
923  lanePosLat = -lanePosLat;
924  }
925  }
926  }
927  if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
928  // mapped position may differ from pos
929  pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
930  }
931  assert((found && lane != 0) || (!found && lane == 0));
932  switch (p->getStageType(0)) {
933  case MSStageType::WALKING: {
934  if (angle == INVALID_DOUBLE_VALUE) {
935  // walking angle cannot be deduced from road angle so we always use the last pos
936  angle = GeomHelper::naviDegree(p->getPosition().angleTo2D(pos));
937  }
938  break;
939  }
942  FALLTHROUGH;
943  case MSStageType::WAITING: {
944  if (p->getNumRemainingStages() <= 1 || p->getStageType(1) != MSStageType::WALKING) {
945  // insert walking stage after the current stage
946  ConstMSEdgeVector route({p->getEdge()});
947  const double departPos = p->getCurrentStage()->getArrivalPos();
948  p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), route, nullptr, -1, -1, departPos, departPos, 0), 1);
949  }
950  // abort waiting stage and proceed to walking stage
951  p->removeStage(0);
952  assert(p->getStageType(0) == MSStageType::WALKING);
953  if (angle == INVALID_DOUBLE_VALUE) {
954  if (lane != nullptr && !lane->getEdge().isWalkingArea()) {
955  angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
956  } else {
957  // compute angle outside road network or on walkingarea from old and new position
958  angle = GeomHelper::naviDegree(p->getPosition().angleTo2D(pos));
959  }
960  }
961  break;
962  }
963  default:
964  throw TraCIException("Command moveToXY is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
965  }
966  Helper::setRemoteControlled(p, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
967  } else {
968  if (lane == nullptr) {
969  throw TraCIException("Could not map person '" + personID + "' no road found within " + toString(maxRouteDistance) + "m.");
970  } else {
971  throw TraCIException("Could not map person '" + personID + "' distance to road is " + toString(bestDistance) + ".");
972  }
973  }
974 }
975 
976 
979 void
980 Person::setParameter(const std::string& personID, const std::string& key, const std::string& value) {
981  MSTransportable* p = getPerson(personID);
982  ((SUMOVehicleParameter&)p->getParameter()).setParameter(key, value);
983 }
984 
985 void
986 Person::setLength(const std::string& personID, double length) {
987  getPerson(personID)->getSingularType().setLength(length);
988 }
989 
990 
991 void
992 Person::setMaxSpeed(const std::string& personID, double speed) {
993  getPerson(personID)->getSingularType().setMaxSpeed(speed);
994 }
995 
996 
997 void
998 Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
999  getPerson(personID)->getSingularType().setVClass(getVehicleClassID(clazz));
1000 }
1001 
1002 
1003 void
1004 Person::setShapeClass(const std::string& personID, const std::string& clazz) {
1005  getPerson(personID)->getSingularType().setShape(getVehicleShapeID(clazz));
1006 }
1007 
1008 
1009 void
1010 Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
1011  getPerson(personID)->getSingularType().setEmissionClass(PollutantsInterface::getClassByName(clazz));
1012 }
1013 
1014 
1015 void
1016 Person::setWidth(const std::string& personID, double width) {
1017  getPerson(personID)->getSingularType().setWidth(width);
1018 }
1019 
1020 
1021 void
1022 Person::setHeight(const std::string& personID, double height) {
1023  getPerson(personID)->getSingularType().setHeight(height);
1024 }
1025 
1026 
1027 void
1028 Person::setMinGap(const std::string& personID, double minGap) {
1029  getPerson(personID)->getSingularType().setMinGap(minGap);
1030 }
1031 
1032 
1033 void
1034 Person::setAccel(const std::string& personID, double accel) {
1035  getPerson(personID)->getSingularType().setAccel(accel);
1036 }
1037 
1038 
1039 void
1040 Person::setDecel(const std::string& personID, double decel) {
1041  getPerson(personID)->getSingularType().setDecel(decel);
1042 }
1043 
1044 
1045 void
1046 Person::setEmergencyDecel(const std::string& personID, double decel) {
1047  getPerson(personID)->getSingularType().setEmergencyDecel(decel);
1048 }
1049 
1050 
1051 void
1052 Person::setApparentDecel(const std::string& personID, double decel) {
1053  getPerson(personID)->getSingularType().setApparentDecel(decel);
1054 }
1055 
1056 
1057 void
1058 Person::setImperfection(const std::string& personID, double imperfection) {
1059  getPerson(personID)->getSingularType().setImperfection(imperfection);
1060 }
1061 
1062 
1063 void
1064 Person::setTau(const std::string& personID, double tau) {
1065  getPerson(personID)->getSingularType().setTau(tau);
1066 }
1067 
1068 
1069 void
1070 Person::setMinGapLat(const std::string& personID, double minGapLat) {
1071  getPerson(personID)->getSingularType().setMinGapLat(minGapLat);
1072 }
1073 
1074 
1075 void
1076 Person::setMaxSpeedLat(const std::string& personID, double speed) {
1077  getPerson(personID)->getSingularType().setMaxSpeedLat(speed);
1078 }
1079 
1080 
1081 void
1082 Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
1083  double lao;
1085  if (SUMOVTypeParameter::parseLatAlignment(latAlignment, lao, lad)) {
1086  getPerson(personID)->getSingularType().setPreferredLateralAlignment(lad, lao);
1087  } else {
1088  throw TraCIException("Unknown value '" + latAlignment + "' when setting latAlignment for person '" + personID + "';\n must be one of (\"right\", \"center\", \"arbitrary\", \"nice\", \"compact\", \"left\" or a float)");
1089  }
1090 }
1091 
1092 
1093 void
1094 Person::setSpeedFactor(const std::string& personID, double factor) {
1095  getPerson(personID)->setSpeedFactor(factor);
1096 }
1097 
1098 
1099 void
1100 Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
1101  getPerson(personID)->getSingularType().setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset);
1102 }
1103 
1104 void
1105 Person::remove(const std::string& personID, char /*reason*/) {
1106  MSPerson* person = getPerson(personID);
1107  // remove all stages after the current and then abort the current stage
1108  // (without adding a zero-length waiting stage)
1109  while (person->getNumRemainingStages() > 1) {
1110  person->removeStage(1);
1111  }
1112  person->removeStage(0, false);
1113 }
1114 
1115 void
1116 Person::setColor(const std::string& personID, const TraCIColor& c) {
1117  const SUMOVehicleParameter& p = getPerson(personID)->getParameter();
1118  p.color.set((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b, (unsigned char)c.a);
1120 }
1121 
1122 
1124 
1125 
1126 MSPerson*
1127 Person::getPerson(const std::string& personID) {
1128  return Helper::getPerson(personID);
1129 }
1130 
1131 
1132 void
1133 Person::storeShape(const std::string& id, PositionVector& shape) {
1134  shape.push_back(getPerson(id)->getPosition());
1135 }
1136 
1137 
1138 std::shared_ptr<VariableWrapper>
1139 Person::makeWrapper() {
1140  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
1141 }
1142 
1143 
1144 bool
1145 Person::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
1146  switch (variable) {
1147  case TRACI_ID_LIST:
1148  return wrapper->wrapStringList(objID, variable, getIDList());
1149  case ID_COUNT:
1150  return wrapper->wrapInt(objID, variable, getIDCount());
1151  case VAR_POSITION:
1152  return wrapper->wrapPosition(objID, variable, getPosition(objID));
1153  case VAR_POSITION3D:
1154  return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
1155  case VAR_ANGLE:
1156  return wrapper->wrapDouble(objID, variable, getAngle(objID));
1157  case VAR_SLOPE:
1158  return wrapper->wrapDouble(objID, variable, getSlope(objID));
1159  case VAR_SPEED:
1160  return wrapper->wrapDouble(objID, variable, getSpeed(objID));
1161  case VAR_ROAD_ID:
1162  return wrapper->wrapString(objID, variable, getRoadID(objID));
1163  case VAR_LANE_ID:
1164  return wrapper->wrapString(objID, variable, getLaneID(objID));
1165  case VAR_LANEPOSITION:
1166  return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
1167  case VAR_COLOR:
1168  return wrapper->wrapColor(objID, variable, getColor(objID));
1169  case VAR_WAITING_TIME:
1170  return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
1171  case VAR_TYPE:
1172  return wrapper->wrapString(objID, variable, getTypeID(objID));
1173  case VAR_SPEED_FACTOR:
1174  return wrapper->wrapDouble(objID, variable, getSpeedFactor(objID));
1175  case VAR_NEXT_EDGE:
1176  return wrapper->wrapString(objID, variable, getNextEdge(objID));
1177  case VAR_STAGES_REMAINING:
1178  return wrapper->wrapInt(objID, variable, getRemainingStages(objID));
1179  case VAR_VEHICLE:
1180  return wrapper->wrapString(objID, variable, getVehicle(objID));
1182  paramData->readUnsignedByte();
1183  return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
1185  paramData->readUnsignedByte();
1186  return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
1187  case VAR_TAXI_RESERVATIONS:
1188  // we cannot use the general fall through here because we do not have an object id
1189  return false;
1190  default:
1191  return libsumo::VehicleType::handleVariable(getTypeID(objID), variable, wrapper, paramData);
1192  }
1193 }
1194 
1195 
1196 }
1197 
1198 
1199 /****************************************************************************/
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:32
LatAlignmentDefinition
Possible ways to choose the lateral alignment, i.e., how vehicles align themselves within their lane.
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
const int VEHPARS_COLOR_SET
@ GIVEN
The position is given.
DepartDefinition
Possible ways to depart.
@ DEPART_DEF_MAX
Tag for the last element in the enum for safe int casting.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
#define FALLTHROUGH
Definition: StdDefs.h:35
T MIN2(T a, T b)
Definition: StdDefs.h:74
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:69
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:115
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:50
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:192
static MSDispatch * getDispatchAlgorithm()
A dispatch algorithm that services customers in reservation order and always sends the closest availa...
std::string splitReservation(std::string resID, std::vector< std::string > personIDs)
split existing reservations and return the new reservation id
An algorithm that performs distpach for a taxi fleet.
Definition: MSDispatch.h:102
std::vector< Reservation * > getReservations()
retrieve all reservations
Definition: MSDispatch.cpp:169
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
Definition: MSDispatch.cpp:179
A road/street connecting two junctions.
Definition: MSEdge.h:77
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:281
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:942
bool isNormal() const
return whether this edge is an internal edge
Definition: MSEdge.h:257
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
const MSJunction * getFromJunction() const
Definition: MSEdge.h:397
double getLength() const
return the length of the edge
Definition: MSEdge.h:641
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition: MSEdge.cpp:885
const MSJunction * getToJunction() const
Definition: MSEdge.h:401
static double gLateralResolution
Definition: MSGlobals.h:88
The base class for an intersection.
Definition: MSJunction.h:58
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:674
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:478
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:499
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:556
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:376
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:318
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1250
MSPedestrianRouter & getPedestrianRouter(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1380
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1059
void reroute(ConstMSEdgeVector &newEdges, double departPos, int firstIndex, int nextIndex)
set new walk and replace the stages with relative indices in the interval [firstIndex,...
Definition: MSPerson.cpp:511
const std::set< std::string > & getLines() const
SUMOTime getIntendedDepart() const
std::string getIntendedVehicleID() const
std::string getVehicleType() const
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition: MSStage.cpp:111
virtual double getArrivalPos() const
Definition: MSStage.h:89
SUMOTime getDeparted() const
get departure time of stage
Definition: MSStage.cpp:126
virtual std::string getStageDescription(const bool isPerson) const =0
return (brief) string representation of the current stage
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:80
SUMOTime getArrived() const
get arrival time of stage
Definition: MSStage.cpp:131
MSStageType getStageType() const
Definition: MSStage.h:117
virtual double getDistance() const =0
get travel distance in this stage
ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition: MSStage.cpp:613
const std::vector< const MSEdge * >::iterator getRouteStep() const
Definition: MSStage.h:527
const std::vector< const MSEdge * > & getRoute() const
Definition: MSStage.h:523
A lane area vehicles can halt at.
double getEndLanePosition() const
Returns the end position of this stop.
std::map< std::string, MSTransportable * >::const_iterator constVehIt
Definition of the internal transportables map iterator.
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
void forceDeparture()
register forced (traci) departure
int size() const
Returns the number of known transportables.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, SumoRNG *rng) const
Builds a new person.
bool add(MSTransportable *transportable)
Adds a single transportable, returns false if an id clash occurred.
virtual double getEdgePos() const
Return the position on the edge.
SUMOVehicleClass getVClass() const
Returns the object's access class.
const MSEdge * getArrivalEdge() const
returns the final arrival edge
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
MSStageType getStageType(int next) const
the stage type for the nth next stage
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
void removeStage(int next, bool stayInSim=true)
removes the nth next stage
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
bool isPerson() const
Whether it is a person.
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
Position getPosition(const double) const
Return current position (x/y, cartesian)
double getArrivalPos() const
returns the final arrival pos
int getNumStages() const
Return the total number stages in this persons plan.
MSStageType getCurrentStageType() const
the current stage type of the transportable
const MSEdge * getEdge() const
Returns the current edge.
MSStage * getCurrentStage() const
Return the current stage.
MSStage * getNextStage(int next) const
Return the current stage.
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
The car-following model and parameter.
Definition: MSVehicleType.h:62
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getMaxSpeed() const
Get vehicle's maximum speed [m/s].
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:67
const std::string & getID() const
Returns the id.
Definition: Named.h:74
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...
C++ TraCI client API implementation.
Definition: Person.h:35
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:252
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:262
A list of positions.
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
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)
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
double slopeDegreeAtOffset(double pos) const
Returns the slope at the given length.
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.cpp:74
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.cpp:92
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.cpp:80
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.cpp:86
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:98
static bool parseLatAlignment(const std::string &val, double &lao, LatAlignmentDefinition &lad)
Parses and validates a given latAlignment value.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Structure representing possible vehicle parameter.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
double departPos
(optional) The position the vehicle shall depart from
RGBColor color
The vehicle's color, TraCI may change this.
std::string id
The vehicle's id.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
std::vector< std::string > getVector()
return vector of strings
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:378
static bool moveToXYMap_matchingRoutePosition(const Position &pos, const std::string &origID, const ConstMSEdgeVector &currentRoute, int routeIndex, SUMOVehicleClass vClass, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset)
Definition: Helper.cpp:1659
static MSPerson * getPerson(const std::string &id)
Definition: Helper.cpp:489
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition: Helper.cpp:1333
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, const MSLane *currentLane, double currentLanePos, bool onRoad, SUMOVehicleClass vClass, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition: Helper.cpp:1369
virtual std::string readString()
Definition: storage.cpp:180
virtual int readUnsignedByte()
Definition: storage.cpp:155
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_TYPE
TRACI_CONST int VAR_VEHICLE
TRACI_CONST int VAR_WAITING_TIME
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:279
TRACI_CONST int VAR_ROAD_ID
TRACI_CONST int VAR_TAXI_RESERVATIONS
TRACI_CONST int VAR_SPEED_FACTOR
TRACI_CONST int VAR_ANGLE
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_POSITION
TRACI_CONST int STAGE_WAITING
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:278
TRACI_CONST int VAR_SLOPE
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LANEPOSITION
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int STAGE_WALKING
TRACI_CONST int VAR_POSITION3D
TRACI_CONST int VAR_SPEED
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_NEXT_EDGE
TRACI_CONST int STAGE_DRIVING
TRACI_CONST int VAR_STAGES_REMAINING
SUMOTime pickupTime
Definition: MSDispatch.h:72
std::string id
Definition: MSDispatch.h:69
const MSEdge * to
Definition: MSDispatch.h:75
double fromPos
Definition: MSDispatch.h:74
const MSEdge * from
Definition: MSDispatch.h:73
SUMOTime reservationTime
Definition: MSDispatch.h:71
std::string group
Definition: MSDispatch.h:77
ReservationState state
Definition: MSDispatch.h:80
std::set< MSTransportable * > persons
Definition: MSDispatch.h:70
double toPos
Definition: MSDispatch.h:76