SUMO - Simulation of Urban MObility
MSPModel_Striping.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-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 /****************************************************************************/
16 // The pedestrian following model (prototype)
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <cmath>
25 #include <algorithm>
27 #include <utils/geom/GeomHelper.h>
30 #include <microsim/MSNet.h>
31 #include <microsim/MSEdge.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSJunction.h>
35 #include <microsim/MSGlobals.h>
37 #include "MSPModel_Striping.h"
38 
39 
40 // ===========================================================================
41 // DEBUGGING HELPERS
42 // ===========================================================================
43 //
44 #define DEBUGID1 ""
45 #define DEBUGID2 ""
46 //#define DEBUGCOND(PED) (false)
47 //#define DEBUGCOND(PED) ((PED).myPerson->getID() == DEBUGID1 || (PED).myPerson->getID() == DEBUGID2)
48 #define DEBUGCOND(PED) ((PED).myPerson->isSelected())
49 #define DEBUGCOND2(LANE) ((LANE)->isSelected())
50 //#define LOG_ALL 1
51 
53  for (int i = 0; i < (int)obs.size(); ++i) {
54  std::cout
55  << "(" << obs[i].description
56  << " x=(" << obs[i].xBack << "," << obs[i].xFwd
57  << ") s=" << obs[i].speed
58  << ") ";
59  }
60  std::cout << "\n";
61 }
62 
63 // ===========================================================================
64 // named (internal) constants
65 // ===========================================================================
66 
67 // distances are comparable with lower values being "more important"
68 const double MSPModel_Striping::DIST_FAR_AWAY(10000);
69 const double MSPModel_Striping::DIST_BEHIND(1000);
70 const double MSPModel_Striping::DIST_OVERLAP(-1);
71 
72 // ===========================================================================
73 // static members
74 // ===========================================================================
75 
79 
80 
81 // model parameters (static to simplify access from class PState
85 const double MSPModel_Striping::LOOKAHEAD_SAMEDIR(4.0); // seconds
86 const double MSPModel_Striping::LOOKAHEAD_ONCOMING(10.0); // seconds
87 const double MSPModel_Striping::LOOKAROUND_VEHICLES(60.0); // meters
88 const double MSPModel_Striping::LATERAL_PENALTY(-1.); // meters
89 const double MSPModel_Striping::OBSTRUCTED_PENALTY(-300000.); // meters
90 const double MSPModel_Striping::INAPPROPRIATE_PENALTY(-20000.); // meters
91 const double MSPModel_Striping::ONCOMING_CONFLICT_PENALTY(-1000.); // meters
92 const double MSPModel_Striping::OBSTRUCTION_THRESHOLD(MSPModel_Striping::OBSTRUCTED_PENALTY * 0.5); // despite obstruction, additional utility may have been added
93 const double MSPModel_Striping::SQUEEZE(0.7);
96 const double MSPModel_Striping::MAX_WAIT_TOLERANCE(120.); // seconds
98 const double MSPModel_Striping::MIN_STARTUP_DIST(0.4); // meters
99 
100 #define MINGAP_TO_VEHICLE 0.25
101 
102 
103 // ===========================================================================
104 // MSPModel_Striping method definitions
105 // ===========================================================================
106 
111  // configurable parameters
112  stripeWidth = oc.getFloat("pedestrian.striping.stripe-width");
113  dawdling = oc.getFloat("pedestrian.striping.dawdling");
114 
115  jamTime = string2time(oc.getString("pedestrian.striping.jamtime"));
116  if (jamTime <= 0) {
118  }
119 }
120 
121 
123 }
124 
125 
129  const MSLane* lane = getSidewalk<MSEdge, MSLane>(person->getEdge());
130  if (lane == 0) {
131  std::string error = "Person '" + person->getID() + "' could not find sidewalk on edge '" + person->getEdge()->getID() + "', time="
132  + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".";
133  if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
134  WRITE_WARNING(error);
135  return 0;
136  } else {
137  throw ProcessError(error);
138  }
139  }
140  PState* ped = new PState(person, stage, lane);
141  myActiveLanes[lane].push_back(ped);
143  return ped;
144 }
145 
146 
147 void
149  PState* ped = dynamic_cast<PState*>(pState);
150  assert(ped != 0);
151  myActiveLanes[lane].push_back(ped);
152 }
153 
154 
155 void
157  const MSLane* lane = dynamic_cast<PState*>(state)->myLane;
158  Pedestrians& pedestrians = myActiveLanes[lane];
159  for (Pedestrians::iterator it = pedestrians.begin(); it != pedestrians.end(); ++it) {
160  if (*it == state) {
161  pedestrians.erase(it);
162  return;
163  }
164  }
165 }
166 
167 
168 bool
169 MSPModel_Striping::blockedAtDist(const MSLane* lane, double vehSide, double vehWidth,
170  double oncomingGap, std::vector<const MSPerson*>* collectBlockers) {
171  const Pedestrians& pedestrians = getPedestrians(lane);
172  for (Pedestrians::const_iterator it_ped = pedestrians.begin(); it_ped != pedestrians.end(); ++it_ped) {
173  const PState& ped = **it_ped;
174  const double leaderFrontDist = (ped.myDir == FORWARD ? vehSide - ped.myRelX : ped.myRelX - vehSide);
175  const double leaderBackDist = leaderFrontDist + ped.getLength();
176  if DEBUGCOND(ped) {
177  std::cout << SIMTIME << " lane=" << lane->getID() << " dir=" << ped.myDir << " pX=" << ped.myRelX << " pL=" << ped.getLength()
178  << " vehSide=" << vehSide
179  << " vehWidth=" << vehWidth
180  << " lBD=" << leaderBackDist
181  << " lFD=" << leaderFrontDist
182  << "\n";
183  }
184  if (leaderBackDist >= -vehWidth
185  && (leaderFrontDist < 0
186  // give right of way to (close) approaching pedestrians unless they are standing
187  || (leaderFrontDist <= oncomingGap && ped.myWaitingTime < TIME2STEPS(2.0)))) {
188  // found one pedestrian that is not completely past the crossing point
189  //std::cout << SIMTIME << " blocking pedestrian foeLane=" << lane->getID() << " ped=" << ped.myPerson->getID() << " dir=" << ped.myDir << " pX=" << ped.myRelX << " pL=" << ped.getLength() << " fDTC=" << distToCrossing << " lBD=" << leaderBackDist << "\n";
190  if (collectBlockers == 0) {
191  return true;
192  } else {
193  collectBlockers->push_back(ped.myPerson);
194  }
195  }
196  }
197  if (collectBlockers == 0) {
198  return false;
199  } else {
200  return collectBlockers->size() > 0;
201  }
202 }
203 
204 
205 bool
207  return getPedestrians(lane).size() > 0;
208 }
209 
210 
211 bool
213  return usingInternalLanesStatic();
214 }
215 
216 bool
219 }
220 
222 MSPModel_Striping::nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime) {
223  PersonDist result((const MSPerson*)0, -1);
224  double closest = std::numeric_limits<double>::max();
225  const Pedestrians& pedestrians = getPedestrians(lane);
226  for (Pedestrians::const_iterator it_ped = pedestrians.begin(); it_ped != pedestrians.end(); ++it_ped) {
227  const PState& ped = **it_ped;
228  // account for distance covered by oncoming pedestrians
229  double relX2 = ped.myRelX - (ped.myDir == FORWARD ? 0 : stopTime * ped.myPerson->getVehicleType().getMaxSpeed());
230  if (ped.myRelX > minPos && (result.first == 0 || closest > relX2)) {
231  const double center = lane->getWidth() - (ped.myRelY + stripeWidth * 0.5);
232  const double halfWidth = 0.5 * ped.myPerson->getVehicleType().getWidth();
233  const bool overlap = (center + halfWidth > minRight && center - halfWidth < maxLeft);
234  if DEBUGCOND(ped) {
235  std::cout << " nextBlocking lane=" << lane->getID()
236  << " minPos=" << minPos << " minRight=" << minRight << " maxLeft=" << maxLeft
237  << " stopTime=" << stopTime
238  << " pedY=" << ped.myRelY
239  << " pedX=" << ped.myRelX
240  << " relX2=" << relX2
241  << " center=" << center
242  << " pedLeft=" << center + halfWidth
243  << " pedRight=" << center - halfWidth
244  << " overlap=" << overlap
245  << "\n";
246  }
247  if (overlap) {
248  closest = relX2;
249  result.first = ped.myPerson;
250  result.second = relX2 - minPos - (ped.myDir == FORWARD ? ped.myPerson->getVehicleType().getLength() : 0);
251  }
252  }
253  }
254  return result;
255 }
256 
257 
260  ActiveLanes::iterator it = myActiveLanes.find(lane);
261  if (it != myActiveLanes.end()) {
262  //std::cout << " found lane=" << lane->getID() << " n=" << it->second.size() << "\n";
263  return (it->second);
264  } else {
265  return noPedestrians;
266  }
267 }
268 
269 
270 void
272  myActiveLanes.clear();
274  myWalkingAreaPaths.clear(); // need to recompute when lane pointers change
275  myMinNextLengths.clear();
276 }
277 
278 
279 int
281  return (int)floor(lane->getWidth() / stripeWidth);
282 }
283 
284 int
286  if (from == 0 || to == 0) {
287  return UNDEFINED_DIRECTION;
288  } else if (MSLinkContHelper::getConnectingLink(*from, *to)) {
289  return FORWARD;
290  } else if (MSLinkContHelper::getConnectingLink(*to, *from)) {
291  return BACKWARD;
292  } else {
293  return UNDEFINED_DIRECTION;
294  }
295 }
296 
297 
298 void
300  if (myWalkingAreaPaths.size() > 0) {
301  return;
302  }
303  for (MSEdgeVector::const_iterator i = MSEdge::getAllEdges().begin(); i != MSEdge::getAllEdges().end(); ++i) {
304  const MSEdge* edge = *i;
305  if (edge->isWalkingArea()) {
306  const MSLane* walkingArea = getSidewalk<MSEdge, MSLane>(edge);
307  myMinNextLengths[walkingArea] = walkingArea->getLength();
308  // build all possible paths across this walkingArea
309  // gather all incident lanes
310  std::vector<const MSLane*> lanes;
311  const MSEdgeVector& incoming = edge->getPredecessors();
312  for (int j = 0; j < (int)incoming.size(); ++j) {
313  lanes.push_back(getSidewalk<MSEdge, MSLane>(incoming[j]));
314  }
315  const MSEdgeVector& outgoing = edge->getSuccessors();
316  for (int j = 0; j < (int)outgoing.size(); ++j) {
317  lanes.push_back(getSidewalk<MSEdge, MSLane>(outgoing[j]));
318  }
319  // build all combinations
320  for (int j = 0; j < (int)lanes.size(); ++j) {
321  for (int k = 0; k < (int)lanes.size(); ++k) {
322  if (j != k) {
323  // build the walkingArea
324  const MSLane* from = lanes[j];
325  const MSLane* to = lanes[k];
326  const int fromDir = MSLinkContHelper::getConnectingLink(*from, *walkingArea) != 0 ? FORWARD : BACKWARD;
327  const int toDir = MSLinkContHelper::getConnectingLink(*walkingArea, *to) != 0 ? FORWARD : BACKWARD;
328  PositionVector shape;
329  Position fromPos = from->getShape()[fromDir == FORWARD ? -1 : 0];
330  Position toPos = to->getShape()[toDir == FORWARD ? 0 : -1];
331  const double maxExtent = fromPos.distanceTo2D(toPos) / 4; // prevent sharp corners
332  const double extrapolateBy = MIN2(maxExtent, walkingArea->getWidth() / 2);
333  // assemble shape
334  shape.push_back(fromPos);
335  if (extrapolateBy > POSITION_EPS) {
336  PositionVector fromShp = from->getShape();
337  fromShp.extrapolate(extrapolateBy);
338  shape.push_back_noDoublePos(fromDir == FORWARD ? fromShp.back() : fromShp.front());
339  PositionVector nextShp = to->getShape();
340  nextShp.extrapolate(extrapolateBy);
341  shape.push_back_noDoublePos(toDir == FORWARD ? nextShp.front() : nextShp.back());
342  }
343  shape.push_back_noDoublePos(toPos);
344  if (shape.size() < 2) {
345  PositionVector fromShp = from->getShape();
346  fromShp.extrapolate(1.5 * POSITION_EPS); // noDoublePos requires a difference of POSITION_EPS in at least one coordinate
347  shape.push_back_noDoublePos(fromDir == FORWARD ? fromShp.back() : fromShp.front());
348  assert(shape.size() == 2);
349  }
350  if (fromDir == BACKWARD) {
351  // will be walking backward on walkingArea
352  shape = shape.reverse();
353  }
354  WalkingAreaPath wap = WalkingAreaPath(from, walkingArea, to, shape);
355  myWalkingAreaPaths[std::make_pair(from, to)] = wap;
356  myMinNextLengths[walkingArea] = MIN2(myMinNextLengths[walkingArea], wap.length);
357  }
358  }
359  }
360  }
361  }
362 }
363 
364 
367  assert(walkingArea->isWalkingArea());
368  std::vector<const MSLane*> lanes;
369  const MSEdgeVector& incoming = walkingArea->getPredecessors();
370  for (int j = 0; j < (int)incoming.size(); ++j) {
371  lanes.push_back(getSidewalk<MSEdge, MSLane>(incoming[j]));
372  }
373  const MSEdgeVector& outgoing = walkingArea->getSuccessors();
374  for (int j = 0; j < (int)outgoing.size(); ++j) {
375  lanes.push_back(getSidewalk<MSEdge, MSLane>(outgoing[j]));
376  }
377  if (lanes.size() < 1) {
378  throw ProcessError("Invalid walkingarea '" + walkingArea->getID() + "' does not allow continuation.");
379  }
380  return &myWalkingAreaPaths[std::make_pair(lanes.front(), lanes.back())];
381 }
382 
383 
385 MSPModel_Striping::getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane) {
386  const MSEdge* currentEdge = &currentLane->getEdge();
387  const MSJunction* junction = ped.myDir == FORWARD ? currentEdge->getToJunction() : currentEdge->getFromJunction();
388  const MSEdge* nextRouteEdge = ped.myStage->getNextRouteEdge();
389  const MSLane* nextRouteLane = getSidewalk<MSEdge, MSLane>(nextRouteEdge);
390  // result values
391  const MSLane* nextLane = nextRouteLane;
392  MSLink* link = 0;
393  int nextDir = UNDEFINED_DIRECTION;
394 
395  if (nextRouteLane == 0 && nextRouteEdge != 0) {
396  std::string error = "Person '" + ped.myPerson->getID() + "' could not find sidewalk on edge '" + nextRouteEdge->getID() + "', time="
397  + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".";
398  if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
399  WRITE_WARNING(error);
400  nextRouteLane = nextRouteEdge->getLanes().front();
401  } else {
402  throw ProcessError(error);
403  }
404  }
405 
406  if (nextRouteLane != 0) {
407  if (currentEdge->isInternal()) {
408  assert(junction == currentEdge->getFromJunction());
409  nextDir = junction == nextRouteEdge->getFromJunction() ? FORWARD : BACKWARD;
410  if (nextDir == FORWARD) {
411  nextLane = currentLane->getLinkCont()[0]->getViaLaneOrLane();
412  } else {
413  nextLane = currentLane->getLogicalPredecessorLane();
414  }
415  if DEBUGCOND(ped) {
416  std::cout << " internal\n";
417  }
418  } else if (currentEdge->isCrossing()) {
419  nextDir = ped.myDir;
420  if (ped.myDir == FORWARD) {
421  nextLane = currentLane->getLinkCont()[0]->getLane();
422  } else {
423  nextLane = currentLane->getLogicalPredecessorLane();
424  }
425  if DEBUGCOND(ped) {
426  std::cout << " crossing\n";
427  }
428  } else if (currentEdge->isWalkingArea()) {
429  ConstMSEdgeVector crossingRoute;
430  // departPos can be 0 because the direction of the walkingArea does not matter
431  // for the arrivalPos, we need to make sure that the route does not deviate across other junctions
432  const int nextRouteEdgeDir = nextRouteEdge->getFromJunction() == junction ? FORWARD : BACKWARD;
433  const double arrivalPos = (nextRouteEdge == ped.myStage->getRoute().back()
434  ? ped.myStage->getArrivalPos()
435  : (nextRouteEdgeDir == FORWARD ? 0 : nextRouteEdge->getLength()));
436  MSEdgeVector prohibited;
437  if (prevLane != 0) {
438  prohibited.push_back(&prevLane->getEdge());
439  }
440  MSNet::getInstance()->getPedestrianRouter(prohibited).compute(currentEdge, nextRouteEdge, 0, arrivalPos, ped.myStage->getMaxSpeed(ped.myPerson), 0, junction, crossingRoute, true);
441  if DEBUGCOND(ped) {
442  std::cout
443  << " nre=" << nextRouteEdge->getID()
444  << " nreDir=" << nextRouteEdgeDir
445  << " aPos=" << arrivalPos
446  << " crossingRoute=" << toString(crossingRoute)
447  << "\n";
448  }
449  if (crossingRoute.size() > 1) {
450  const MSEdge* nextEdge = crossingRoute[1];
451  nextLane = getSidewalk<MSEdge, MSLane>(crossingRoute[1]);
452  assert((nextEdge->getFromJunction() == junction || nextEdge->getToJunction() == junction));
453  assert(nextLane != prevLane);
454  nextDir = connectedDirection(currentLane, nextLane);
455  if DEBUGCOND(ped) {
456  std::cout << " nextDir=" << nextDir << "\n";
457  }
458  assert(nextDir != UNDEFINED_DIRECTION);
459  if (nextDir == FORWARD) {
460  link = MSLinkContHelper::getConnectingLink(*currentLane, *nextLane);
461  } else {
462  link = MSLinkContHelper::getConnectingLink(*nextLane, *currentLane);
463  if (nextEdge->isCrossing() && link->getTLLogic() == 0) {
464  const MSLane* oppositeWalkingArea = nextLane->getLogicalPredecessorLane();
465  link = MSLinkContHelper::getConnectingLink(*oppositeWalkingArea, *nextLane);
466  }
467  }
468  assert(link != 0);
469  } else {
470  if DEBUGCOND(ped) {
471  std::cout << SIMTIME
472  << " no route from '" << (currentEdge == 0 ? "NULL" : currentEdge->getID())
473  << "' to '" << (nextRouteEdge == 0 ? "NULL" : nextRouteEdge->getID())
474  << "\n";
475  }
476  WRITE_WARNING("Person '" + ped.myPerson->getID() + "' could not find route across junction '" + junction->getID()
477  + "' from walkingArea '" + currentEdge->getID()
478  + "' to edge '" + nextRouteEdge->getID() + "', time=" +
479  time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
480  // error indicated by nextDir == UNDEFINED_DIRECTION
481  nextLane = nextRouteLane;
482  }
483  } else if (currentEdge == nextRouteEdge) {
484  // strange loop in this route. No need to use walkingArea
485  nextDir = -ped.myDir;
486  } else {
487  // normal edge. by default use next / previous walking area
488  nextDir = ped.myDir;
489  nextLane = getNextWalkingArea(currentLane, ped.myDir, link);
490  if (nextLane != 0) {
491  // walking area found
492  if DEBUGCOND(ped) {
493  std::cout << " next walkingArea " << (nextDir == FORWARD ? "forward" : "backward") << "\n";
494  }
495  } else {
496  // walk forward by default
497  nextDir = junction == nextRouteEdge->getToJunction() ? BACKWARD : FORWARD;
498  // try to use a direct link as fallback
499  // direct links only exist if built explicitly. They are used to model tl-controlled links if there are no crossings
500  if (ped.myDir == FORWARD) {
501  link = MSLinkContHelper::getConnectingLink(*currentLane, *nextRouteLane);
502  if (link != 0) {
503  if DEBUGCOND(ped) {
504  std::cout << " direct forward\n";
505  }
506  nextLane = MSLinkContHelper::getInternalFollowingLane(currentLane, nextRouteLane);
507  }
508  } else {
509  link = MSLinkContHelper::getConnectingLink(*nextRouteLane, *currentLane);
510  if (link != 0) {
511  if DEBUGCOND(ped) {
512  std::cout << " direct backward\n";
513  }
514  nextLane = MSLinkContHelper::getInternalFollowingLane(nextRouteLane, currentLane);
515  if (nextLane != nullptr) {
516  // advance to the end of consecutive internal lanes
517  while (nextLane->getLinkCont()[0]->getViaLaneOrLane()->isInternal()) {
518  nextLane = nextLane->getLinkCont()[0]->getViaLaneOrLane();
519  }
520  }
521  }
522  }
523  }
524  if (nextLane == 0) {
525  // no internal lane found
526  nextLane = nextRouteLane;
527  if DEBUGCOND(ped) {
528  std::cout << SIMTIME << " no next lane found for " << currentLane->getID() << " dir=" << ped.myDir << "\n";
529  }
530  if (usingInternalLanesStatic() && currentLane->getLinkCont().size() > 0) {
531  WRITE_WARNING("Person '" + ped.myPerson->getID() + "' could not find route across junction '" + junction->getID()
532  + "' from edge '" + currentEdge->getID()
533  + "' to edge '" + nextRouteEdge->getID() + "', time=" +
534  time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
535  }
536  } else if (nextLane->getLength() <= POSITION_EPS) {
537  // internal lane too short
538  nextLane = nextRouteLane;
539  }
540  }
541  }
542  if DEBUGCOND(ped) {
543  std::cout << SIMTIME
544  << " p=" << ped.myPerson->getID()
545  << " l=" << currentLane->getID()
546  << " nl=" << (nextLane == 0 ? "NULL" : nextLane->getID())
547  << " nrl=" << (nextRouteLane == 0 ? "NULL" : nextRouteLane->getID())
548  << " d=" << nextDir
549  << " link=" << (link == 0 ? "NULL" : link->getViaLaneOrLane()->getID())
550  << " pedDir=" << ped.myDir
551  << "\n";
552  }
553  assert(nextLane != 0 || nextRouteLane == 0);
554  return NextLaneInfo(nextLane, link, nextDir);
555 }
556 
557 
558 const MSLane*
559 MSPModel_Striping::getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link) {
560  if (dir == FORWARD) {
561  const MSLinkCont& links = currentLane->getLinkCont();
562  for (MSLinkCont::const_iterator it = links.begin(); it != links.end(); ++it) {
563  if ((*it)->getLane()->getEdge().isWalkingArea()) {
564  link = *it;
565  return (*it)->getLane();
566  }
567  }
568  } else {
569  const std::vector<MSLane::IncomingLaneInfo>& laneInfos = currentLane->getIncomingLanes();
570  for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = laneInfos.begin(); it != laneInfos.end(); ++it) {
571  if ((*it).lane->getEdge().isWalkingArea()) {
572  link = (*it).viaLink;
573  return (*it).lane;
574  }
575  }
576  }
577  return 0;
578 }
579 
580 
582 MSPModel_Striping::getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes) {
583  const PState& ego = *pedestrians[egoIndex];
584  Obstacles obs(stripes, Obstacle(ego.myDir));
585  std::vector<bool> haveBlocker(stripes, false);
586  for (int index = egoIndex + 1; index < (int)pedestrians.size(); index++) {
587  const PState& p = *pedestrians[index];
588  if DEBUGCOND(ego) {
589  std::cout << SIMTIME << " ped=" << ego.myPerson->getID() << " checking neighbor " << p.myPerson->getID();
590  }
591  if (!p.myWaitingToEnter) {
592  const Obstacle o(p);
593  if DEBUGCOND(ego) {
594  std::cout << " dist=" << ego.distanceTo(o) << std::endl;
595  }
596  if (ego.distanceTo(o) == DIST_BEHIND) {
597  break;
598  }
599  if (ego.distanceTo(o) == DIST_OVERLAP) {
600  obs[p.stripe()] = o;
601  obs[p.otherStripe()] = o;
602  haveBlocker[p.stripe()] = true;
603  haveBlocker[p.otherStripe()] = true;
604  }
605  if (!haveBlocker[p.stripe()]) {
606  obs[p.stripe()] = o;
607  }
608  if (!haveBlocker[p.otherStripe()]) {
609  obs[p.otherStripe()] = o;
610  }
611  }
612  }
613  if DEBUGCOND(ego) {
614  std::cout << SIMTIME << " ped=" << ego.myPerson->getID() << " neighObs=";
615  DEBUG_PRINT(obs);
616  }
617  return obs;
618 }
619 
620 
621 int
622 MSPModel_Striping::getStripeOffset(int origStripes, int destStripes, bool addRemainder) {
623  int offset = (destStripes - origStripes) / 2;
624  if (addRemainder) {
625  offset += (destStripes - origStripes) % 2;
626  }
627  return offset;
628 }
629 
630 
633  MSLane* lane, const MSLane* nextLane, int stripes, int nextDir,
634  double currentLength, int currentDir) {
635  if (nextLanesObs.count(nextLane) == 0) {
636  const double nextLength = nextLane->getEdge().isWalkingArea() ? myMinNextLengths[nextLane] : nextLane->getLength();
637  // figure out the which pedestrians are ahead on the next lane
638  const int nextStripes = numStripes(nextLane);
639  // do not move past the end of the next lane in a single step
640  Obstacles obs(stripes, Obstacle(nextDir == FORWARD ? nextLength : 0, 0, OBSTACLE_NEXTEND, "nextEnd", 0));
641 
642  const int offset = getStripeOffset(nextStripes, stripes, currentDir != nextDir && nextStripes > stripes);
643  //std::cout << SIMTIME << " getNextLaneObstacles"
644  // << " nextLane=" << nextLane->getID()
645  // << " nextLength=" << nextLength
646  // << " nextDir=" << nextDir
647  // << " currentLength=" << currentLength
648  // << " currentDir=" << currentDir
649  // << " stripes=" << stripes
650  // << " nextStripes=" << nextStripes
651  // << " offset=" << offset
652  // << "\n";
653  if (nextStripes < stripes) {
654  // some stripes do not continue
655  for (int ii = 0; ii < stripes; ++ii) {
656  if (ii < offset || ii >= nextStripes + offset) {
657  obs[ii] = Obstacle(nextDir == FORWARD ? 0 : nextLength, 0, OBSTACLE_END, "stripeEnd", 0);
658  }
659  }
660  }
661  Pedestrians& pedestrians = getPedestrians(nextLane);
662  if (nextLane->getEdge().isWalkingArea()) {
663  transformToCurrentLanePositions(obs, currentDir, nextDir, currentLength, nextLength);
664  // complex transformation into the coordinate system of the current lane
665  // (pedestrians on next lane may walk at arbitrary angles relative to the current lane)
666  double lateral_offset = (lane->getWidth() - stripeWidth) * 0.5;
667  if ((stripes - nextStripes) % 2 != 0) {
668  lateral_offset += 0.5 * stripeWidth;
669  }
670  nextDir = currentDir;
671  // transform pedestrians into the current coordinate system
672  for (int ii = 0; ii < (int)pedestrians.size(); ++ii) {
673  PState& p = *pedestrians[ii];
674  if (p.myWaitingToEnter || p.myAmJammed) {
675  continue;
676  }
677  Position relPos = lane->getShape().transformToVectorCoordinates(p.getPosition(*p.myStage, -1), true);
678  const double newY = relPos.y() + lateral_offset;
679  //if (p.myPerson->getID() == "ped200") std::cout << " ped=" << p.myPerson->getID() << " relX=" << relPos.x() << " relY=" << newY << " latOff=" << lateral_offset << " s=" << p.stripe(newY) << " os=" << p.otherStripe(newY) << "\n";
680  if ((currentDir == FORWARD && relPos.x() >= lane->getLength()) || (currentDir == BACKWARD && relPos.x() < 0)) {
681  addCloserObstacle(obs, relPos.x(), p.stripe(newY), stripes, p.myPerson->getID(), p.myPerson->getVehicleType().getWidth(), currentDir, OBSTACLE_PED);
682  addCloserObstacle(obs, relPos.x(), p.otherStripe(newY), stripes, p.myPerson->getID(), p.myPerson->getVehicleType().getWidth(), currentDir, OBSTACLE_PED);
683  }
684  }
685  } else {
686  // simple transformation into the coordinate system of the current lane
687  // (only need to worry about currentDir and nextDir)
688  // XXX consider waitingToEnter on nextLane
689  sort(pedestrians.begin(), pedestrians.end(), by_xpos_sorter(nextDir));
690  for (int ii = 0; ii < (int)pedestrians.size(); ++ii) {
691  const PState& p = *pedestrians[ii];
692  if (p.myWaitingToEnter || p.myAmJammed) {
693  continue;
694  }
695  double newY = p.myRelY;
696  Obstacle pObs(p);
697  if (nextDir != currentDir) {
698  newY = (nextStripes - 1) * stripeWidth - newY;
699  pObs.speed *= -1;
700  }
701  newY += offset * stripeWidth;
702  const int stripe = p.stripe(newY);
703  if (stripe >= 0 && stripe < stripes) {
704  obs[stripe] = pObs;
705  }
706  const int otherStripe = p.otherStripe(newY);
707  if (otherStripe >= 0 && otherStripe < stripes) {
708  obs[otherStripe] = pObs;
709  }
710  }
711  if (nextLane->getEdge().isCrossing()) {
712  // add vehicle obstacles
713  addCrossingVehs(nextLane, stripes, offset, nextDir, obs);
714  }
715  if (nextLane->getVehicleNumberWithPartials() > 0) {
716  Obstacles vehObs = getVehicleObstacles(nextLane, nextDir);
717  PState::mergeObstacles(obs, vehObs, nextDir, offset);
718  }
719  transformToCurrentLanePositions(obs, currentDir, nextDir, currentLength, nextLength);
720  }
721  nextLanesObs[nextLane] = obs;
722  }
723  return nextLanesObs[nextLane];
724 }
725 
726 void
727 MSPModel_Striping::transformToCurrentLanePositions(Obstacles& obs, int currentDir, int nextDir, double currentLength, double nextLength) {
728  for (int ii = 0; ii < (int)obs.size(); ++ii) {
729  Obstacle& o = obs[ii];
730  if (currentDir == FORWARD) {
731  if (nextDir == FORWARD) {
732  o.xFwd += currentLength;
733  o.xBack += currentLength;
734  } else {
735  const double tmp = o.xFwd;
736  o.xFwd = currentLength + nextLength - o.xBack;
737  o.xBack = currentLength + nextLength - tmp;
738  }
739  } else {
740  if (nextDir == FORWARD) {
741  const double tmp = o.xFwd;
742  o.xFwd = -o.xBack;
743  o.xBack = -tmp;
744  } else {
745  o.xFwd -= nextLength;
746  o.xBack -= nextLength;
747  }
748  }
749  }
750 }
751 
752 
753 void
754 MSPModel_Striping::addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir, ObstacleType type) {
755  if (stripe >= 0 && stripe < numStripes) {
756  if ((dir == FORWARD && x - width / 2. < obs[stripe].xBack) || (dir == BACKWARD && x + width / 2. > obs[stripe].xFwd)) {
757  obs[stripe] = Obstacle(x, 0, type, id, width);
758  }
759  }
760 }
761 
762 void
763 MSPModel_Striping::moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir) {
764  for (ActiveLanes::iterator it_lane = myActiveLanes.begin(); it_lane != myActiveLanes.end(); ++it_lane) {
765  const MSLane* lane = it_lane->first;
766  Pedestrians& pedestrians = it_lane->second;
767  if (pedestrians.size() == 0) {
768  continue;
769  }
770  //std::cout << SIMTIME << ">>> lane=" << lane->getID() << " numPeds=" << pedestrians.size() << "\n";
771  if (lane->getEdge().isWalkingArea()) {
772  const double lateral_offset = (lane->getWidth() - stripeWidth) * 0.5;
773  const double minY = stripeWidth * - 0.5 + NUMERICAL_EPS;
774  const double maxY = stripeWidth * (numStripes(lane) - 0.5) - NUMERICAL_EPS;
775  const WalkingAreaPath* debugPath = 0;
776  // need to handle each walkingAreaPath seperately and transform
777  // coordinates beforehand
778  std::set<const WalkingAreaPath*, walkingarea_path_sorter> paths;
779  for (Pedestrians::iterator it = pedestrians.begin(); it != pedestrians.end(); ++it) {
780  const PState* p = *it;
781  assert(p->myWalkingAreaPath != 0);
782  if (p->myDir == dir) {
783  paths.insert(p->myWalkingAreaPath);
784  if DEBUGCOND(*p) {
785  debugPath = p->myWalkingAreaPath;
786  std::cout << SIMTIME << " debugging WalkingAreaPath from=" << debugPath->from->getID() << " to=" << debugPath->to->getID() << "\n";
787  }
788  }
789  }
790  for (std::set<const WalkingAreaPath*, walkingarea_path_sorter>::iterator it = paths.begin(); it != paths.end(); ++it) {
791  const WalkingAreaPath* path = *it;
792  Pedestrians toDelete;
793  Pedestrians transformedPeds;
794  transformedPeds.reserve(pedestrians.size());
795  for (Pedestrians::iterator it_p = pedestrians.begin(); it_p != pedestrians.end(); ++it_p) {
796  PState* p = *it_p;
797  if (p->myWalkingAreaPath == path
798  // opposite direction is already in the correct coordinate system
799  || (p->myWalkingAreaPath->from == path->to && p->myWalkingAreaPath->to == path->from)) {
800  transformedPeds.push_back(p);
801  if (path == debugPath) std::cout << " ped=" << p->myPerson->getID() << " relX=" << p->myRelX << " relY=" << p->myRelY << " (untransformed), vecCoord="
802  << path->shape.transformToVectorCoordinates(p->getPosition(*p->myStage, -1)) << "\n";
803  } else {
804  const Position relPos = path->shape.transformToVectorCoordinates(p->getPosition(*p->myStage, -1));
805  const double newY = relPos.y() + lateral_offset;
806  if (relPos != Position::INVALID && newY >= minY && newY <= maxY) {
807  PState* tp = new PState(*p);
808  tp->myRelX = relPos.x();
809  tp->myRelY = newY;
810  // only an obstacle, speed may be orthogonal to dir
811  tp->myDir = !dir;
812  tp->mySpeed = 0;
813  toDelete.push_back(tp);
814  transformedPeds.push_back(tp);
815  if (path == debugPath) {
816  std::cout << " ped=" << p->myPerson->getID() << " relX=" << relPos.x() << " relY=" << newY << " (transformed), vecCoord=" << relPos << "\n";
817  }
818  } else {
819  if (path == debugPath) {
820  std::cout << " ped=" << p->myPerson->getID() << " relX=" << relPos.x() << " relY=" << newY << " (invalid), vecCoord=" << relPos << "\n";
821  }
822  }
823  }
824  }
825  moveInDirectionOnLane(transformedPeds, lane, currentTime, changedLane, dir);
826  arriveAndAdvance(pedestrians, currentTime, changedLane, dir);
827  // clean up
828  for (Pedestrians::iterator it_p = toDelete.begin(); it_p != toDelete.end(); ++it_p) {
829  delete *it_p;
830  }
831  }
832  } else {
833  moveInDirectionOnLane(pedestrians, lane, currentTime, changedLane, dir);
834  arriveAndAdvance(pedestrians, currentTime, changedLane, dir);
835  }
836  }
837 }
838 
839 
840 void
841 MSPModel_Striping::arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir) {
842  // advance to the next lane / arrive at destination
843  sort(pedestrians.begin(), pedestrians.end(), by_xpos_sorter(dir));
844  // can't use iterators because we do concurrent modification
845  for (int i = 0; i < (int)pedestrians.size(); i++) {
846  PState* const p = pedestrians[i];
847  if (p->myDir == dir && p->distToLaneEnd() < 0) {
848  // moveToNextLane may trigger re-insertion (for consecutive
849  // walks) so erase must be called first
850  pedestrians.erase(pedestrians.begin() + i);
851  i--;
852  p->moveToNextLane(currentTime);
853  if (p->myLane != 0) {
854  changedLane.insert(p->myPerson);
855  myActiveLanes[p->myLane].push_back(p);
856  } else {
857  // end walking stage and destroy PState
858  p->myStage->moveToNextEdge(p->myPerson, currentTime);
860  }
861  }
862  }
863 }
864 
865 
866 void
867 MSPModel_Striping::moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir) {
868  const int stripes = numStripes(lane);
869  //std::cout << " laneWidth=" << lane->getWidth() << " stripeWidth=" << stripeWidth << " stripes=" << stripes << "\n";
870  Obstacles obs(stripes, Obstacle(dir)); // continously updated
871  NextLanesObstacles nextLanesObs; // continously updated
872  sort(pedestrians.begin(), pedestrians.end(), by_xpos_sorter(dir));
873 
874  Obstacles crossingVehs(stripes, Obstacle(dir));
875  bool hasCrossingVehObs = false;
876  if (lane->getEdge().isCrossing()) {
877  hasCrossingVehObs = addCrossingVehs(lane, stripes, 0, dir, crossingVehs);
878  }
879 
880  for (int ii = 0; ii < (int)pedestrians.size(); ++ii) {
881  PState& p = *pedestrians[ii];
882  //std::cout << SIMTIME << "CHECKING" << p.myPerson->getID() << "\n";
883  Obstacles currentObs = obs;
884  if (p.myDir != dir || changedLane.count(p.myPerson) != 0) {
885  if (!p.myWaitingToEnter) {
886  //if DEBUGCOND(p) {
887  // std::cout << " obs=" << p.myPerson->getID() << " y=" << p.myRelY << " stripe=" << p.stripe() << " oStripe=" << p.otherStripe() << "\n";
888  //}
889  Obstacle o(p);
890  if (p.myDir != dir && p.mySpeed == 0) {
891  // ensure recognition of oncoming
892  o.speed = (p.myDir == FORWARD ? 0.1 : -0.1);
893  }
894  obs[p.stripe()] = o;
895  obs[p.otherStripe()] = o;
896  }
897  continue;
898  }
899  if DEBUGCOND(p) {
900  std::cout << SIMTIME << " ped=" << p.myPerson->getID() << " currentObs=";
901  gDebugFlag1 = true;
902  DEBUG_PRINT(currentObs);
903  }
904  const MSLane* nextLane = p.myNLI.lane;
905  const MSLink* link = p.myNLI.link;
906  const double dist = p.distToLaneEnd();
907  const double speed = p.myStage->getMaxSpeed(p.myPerson);
908  if (nextLane != 0 && dist <= LOOKAHEAD_ONCOMING) {
909  const double currentLength = (p.myWalkingAreaPath == 0 ? lane->getLength() : p.myWalkingAreaPath->length);
910  const Obstacles& nextObs = getNextLaneObstacles(
911  nextLanesObs, lane, nextLane, stripes,
912  p.myNLI.dir, currentLength, dir);
913 
914  if DEBUGCOND(p) {
915  std::cout << SIMTIME << " ped=" << p.myPerson->getID() << " nextObs=";
916  DEBUG_PRINT(nextObs);
917  }
918  p.mergeObstacles(currentObs, nextObs);
919  }
920  if DEBUGCOND(p) {
921  std::cout << SIMTIME << " ped=" << p.myPerson->getID() << " obsWithNext=";
922  DEBUG_PRINT(currentObs);
923  }
924  p.mergeObstacles(currentObs, getNeighboringObstacles(pedestrians, ii, stripes));
925  if DEBUGCOND(p) {
926  std::cout << SIMTIME << " ped=" << p.myPerson->getID() << " obsWithNeigh=";
927  DEBUG_PRINT(currentObs);
928  }
929  // time gap to pass the intersection ahead of a vehicle.
930  const double passingClearanceTime = 2;
931  const double passingLength = p.getLength() + passingClearanceTime * speed;
932  // check link state
933  if DEBUGCOND(p) {
934  gDebugFlag1 = true;
935  std::cout << " link=" << (link == nullptr ? "NULL" : link->getViaLaneOrLane()->getID())
936  << " dist=" << dist << " d2=" << dist - p.getMinGap() << " la=" << LOOKAHEAD_SAMEDIR* speed
937  << " opened=" << (link == nullptr ? "NULL" : toString(link->opened(currentTime - DELTA_T, speed, speed, passingLength, p.getImpatience(currentTime), speed, 0, 0, 0, p.ignoreRed(link)))) << "\n";
938  gDebugFlag1 = false;
939  }
940  if (link != 0
941  // only check close before junction, @todo we should take deceleration into account here
942  && dist - p.getMinGap() < LOOKAHEAD_SAMEDIR * speed
943  // persons move before vehicles so we subtract DELTA_TO because they cannot rely on vehicles having passed the intersection in the current time step
944  && !link->opened(currentTime - DELTA_T, speed, speed, passingLength, p.getImpatience(currentTime), speed, 0, 0, 0, p.ignoreRed(link))) {
945  // prevent movement passed a closed link
946  Obstacles closedLink(stripes, Obstacle(p.myRelX + dir * (dist + NUMERICAL_EPS), 0, OBSTACLE_LINKCLOSED, "closedLink_" + link->getViaLaneOrLane()->getID(), 0));
947  p.mergeObstacles(currentObs, closedLink);
948  if DEBUGCOND(p) {
949  std::cout << SIMTIME << " ped=" << p.myPerson->getID() << " obsWitTLS=";
950  DEBUG_PRINT(currentObs);
951  }
952  // consider rerouting over another crossing
953  if (p.myWalkingAreaPath != 0) {
954  // @todo actually another path would be needed starting at the current position
956  }
957  }
958  if (&lane->getEdge() == p.myStage->getDestination() && p.myStage->getDestinationStop() != 0) {
959  Obstacles arrival(stripes, Obstacle(p.myStage->getArrivalPos() + dir * p.getMinGap(), 0, OBSTACLE_ARRIVALPOS, "arrival", 0));
960  p.mergeObstacles(currentObs, arrival);
961  }
962 
963  if (lane->getVehicleNumberWithPartials() > 0) {
964  // react to vehicles on the same lane
965  // @todo: improve efficiency by using the same iterator for all pedestrians on this lane
966  Obstacles vehObs = getVehicleObstacles(lane, dir, &p);
967  p.mergeObstacles(currentObs, vehObs);
968  if DEBUGCOND(p) {
969  std::cout << SIMTIME << " ped=" << p.myPerson->getID() << " obsWithVehs=";
970  DEBUG_PRINT(currentObs);
971  }
972  }
973  if (hasCrossingVehObs) {
974  p.mergeObstacles(currentObs, crossingVehs);
975  if DEBUGCOND(p) {
976  std::cout << SIMTIME << " ped=" << p.myPerson->getID() << " obsWithVehs2=";
977  DEBUG_PRINT(currentObs);
978  }
979  }
980 
981  // walk, taking into account all obstacles
982  p.walk(currentObs, currentTime);
983  gDebugFlag1 = false;
984  if (!p.myWaitingToEnter && !p.myAmJammed) {
985  Obstacle o(p);
986  obs[p.stripe()] = o;
987  obs[p.otherStripe()] = o;
989  for (int coll = 0; coll < ii; ++coll) {
990  PState& c = *pedestrians[coll];
991  if (!c.myWaitingToEnter && c.myWalkingAreaPath == 0 && !c.myAmJammed) {
992  if (c.stripe() == p.stripe() || p.stripe() == c.otherStripe() || p.otherStripe() == c.stripe() || p.otherStripe() == c.otherStripe()) {
993  Obstacle cObs(c);
994  // we check only for real collisions, no min gap violations
995  if (p.distanceTo(cObs, false) == DIST_OVERLAP) {
996  WRITE_WARNING("Collision of person '" + p.myPerson->getID() + "' and person '" + c.myPerson->getID()
997  + "', lane='" + lane->getID() + "', time=" + time2string(currentTime) + ".");
998  }
999  }
1000  }
1001  }
1002  }
1003  }
1004  //std::cout << SIMTIME << p.myPerson->getID() << " lane=" << lane->getID() << " x=" << p.myRelX << "\n";
1005  }
1006 }
1007 
1008 bool
1009 MSPModel_Striping::addCrossingVehs(const MSLane* crossing, int stripes, double lateral_offset, int dir, Obstacles& obs) {
1010  bool hasCrossingVehObs = false;
1011  const MSLink::LinkLeaders linkLeaders = crossing->getLinkCont().front()->getLeaderInfo(0, crossing->getLength());
1012  if (linkLeaders.size() > 0) {
1013  for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
1014  // the vehicle to enter the junction first has priority
1015  const MSVehicle* veh = (*it).vehAndGap.first;
1016  if (veh != 0) {
1017  Obstacle vo((*it).distToCrossing, 0, OBSTACLE_VEHICLE, veh->getID(), veh->getVehicleType().getWidth() + 2 * MINGAP_TO_VEHICLE);
1018  // relY increases from left to right (the other way around from vehicles)
1019  const double bGap = veh->getCarFollowModel().brakeGap(veh->getSpeed(), veh->getCarFollowModel().getMaxDecel(), 0);
1020  double vehYmin;
1021  double vehYmax;
1022  if ((*it).fromLeft) {
1023  vehYmin = -(*it).vehAndGap.second + lateral_offset; // vehicle back
1024  vehYmax = vehYmin + veh->getVehicleType().getLength() + bGap + MINGAP_TO_VEHICLE;
1025  vehYmin -= MINGAP_TO_VEHICLE;
1026  } else {
1027  vehYmax = crossing->getWidth() + (*it).vehAndGap.second - lateral_offset; // vehicle back
1028  vehYmin = vehYmax - veh->getVehicleType().getLength() - bGap - MINGAP_TO_VEHICLE;
1029  vehYmax += MINGAP_TO_VEHICLE;
1030 
1031  }
1032  for (int s = MAX2(0, PState::stripe(vehYmin)); s < MIN2(PState::stripe(vehYmax), stripes); ++s) {
1033  if ((dir == FORWARD && obs[s].xBack > vo.xBack)
1034  || (dir == BACKWARD && obs[s].xFwd < vo.xFwd)) {
1035  obs[s] = vo;
1036  hasCrossingVehObs = true;
1037  }
1038  }
1039  if (DEBUGCOND2(crossing)) {
1040  std::cout << SIMTIME
1041  << " crossingVeh=" << veh->getID()
1042  << " lane=" << crossing->getID()
1043  << " latOffset=" << lateral_offset
1044  << " dir=" << dir
1045  << " stripes=" << stripes
1046  << " dist=" << (*it).distToCrossing
1047  << " gap=" << (*it).vehAndGap.second
1048  << " brakeGap=" << bGap
1049  << " fromLeft=" << (*it).fromLeft
1050  << " ymin=" << vehYmin
1051  << " ymax=" << vehYmax
1052  << " smin=" << PState::stripe(vehYmin)
1053  << " smax=" << PState::stripe(vehYmax)
1054  << "\n";
1055  DEBUG_PRINT(obs);
1056  }
1057  }
1058  }
1059  }
1060  return hasCrossingVehObs;
1061 }
1062 
1063 
1066  const int stripes = numStripes(lane);
1067  Obstacles vehObs(stripes, Obstacle(dir));
1068  int current = -1;
1069  double minX = 0.;
1070  double maxX = 0.;
1071  double pRelY = -1.;
1072  double pWidth = 0.;
1073  std::string pID;
1074  bool debug = DEBUGCOND2(lane);
1075  if (ped != 0) {
1076  current = ped->stripe();
1077  minX = ped->getMinX();
1078  maxX = ped->getMaxX();
1079  pRelY = ped->myRelY;
1080  pWidth = ped->myPerson->getVehicleType().getWidth();
1081  pID = ped->myPerson->getID();
1082  debug = DEBUGCOND(*ped);
1083  } else if (dir == BACKWARD) {
1084  // checking vehicles on the next lane. Use entry point as reference
1085  minX = lane->getLength();
1086  maxX = lane->getLength();
1087  }
1088  MSLane::AnyVehicleIterator begin = (dir == FORWARD ? lane->anyVehiclesUpstreamBegin() : lane->anyVehiclesBegin());
1089  MSLane::AnyVehicleIterator end = (dir == FORWARD ? lane->anyVehiclesUpstreamEnd() : lane->anyVehiclesEnd());
1090  for (MSLane::AnyVehicleIterator it = begin; it != end; ++it) {
1091  const MSVehicle* veh = *it;
1092  const double vehBack = veh->getBackPositionOnLane(lane);
1093  const double vehFront = vehBack + veh->getVehicleType().getLength();
1094  // ensure that vehicles are not blocked
1095  const double vehNextSpeed = MAX2(veh->getSpeed(), 1.0);
1096  const double clearance = SAFETY_GAP + vehNextSpeed * LOOKAHEAD_SAMEDIR;
1097  if ((dir == FORWARD && vehFront + clearance > minX && vehBack <= maxX + LOOKAHEAD_SAMEDIR)
1098  || (dir == BACKWARD && vehBack < maxX && vehFront >= minX - LOOKAROUND_VEHICLES)) {
1099  Obstacle vo(vehBack, veh->getSpeed(), OBSTACLE_VEHICLE, veh->getID(), 0);
1100  // moving vehicles block space along their path
1101  vo.xFwd += veh->getVehicleType().getLength() + clearance;
1102  vo.xBack -= SAFETY_GAP;
1103  // relY increases from left to right (the other way around from vehicles)
1104  // XXX lateral offset for partial vehicles
1105  const double vehYmax = 0.5 * (lane->getWidth() + veh->getVehicleType().getWidth() - stripeWidth) - veh->getLateralPositionOnLane();
1106  const double vehYmin = vehYmax - veh->getVehicleType().getWidth();
1107  for (int s = MAX2(0, PState::stripe(vehYmin)); s < MIN2(PState::stripe(vehYmax) + 1, stripes); ++s) {
1108  vehObs[s] = vo;
1109  if (s == current && vehFront + SAFETY_GAP < minX) {
1110  // ignore if aleady overlapping while vehicle is still behind
1111  if (pRelY - pWidth < vehYmax &&
1112  pRelY + pWidth > vehYmin && dir == FORWARD) {
1113  if (debug) {
1114  std::cout << " ignoring vehicle on stripe " << s << "\n";
1115  }
1116  if (dir == FORWARD) {
1117  vehObs[s] = Obstacle(dir);
1118  } else {
1119  vehObs[s].xFwd = MIN2(vo.xFwd, vehFront + SAFETY_GAP);
1120  }
1121  }
1122  }
1123  }
1124  if (debug) {
1125  std::cout << SIMTIME << " ped=" << pID << " veh=" << veh->getID() << " obstacle on lane=" << lane->getID()
1126  << "\n"
1127  << " ymin=" << vehYmin
1128  << " ymax=" << vehYmax
1129  << " smin=" << PState::stripe(vehYmin)
1130  << " smax=" << PState::stripe(vehYmax)
1131  << " relY=" << pRelY
1132  << " current=" << current
1133  << "\n";
1134  }
1135  }
1136  }
1137  return vehObs;
1138 }
1139 
1140 
1141 // ===========================================================================
1142 // MSPModel_Striping::Obstacle method definitions
1143 // ===========================================================================
1145  xFwd(dir * dist), // by default, far away when seen in dir
1146  xBack(dir * dist), // by default, far away when seen in dir
1147  speed(0),
1148  type(OBSTACLE_NONE),
1149  description("") {
1150 }
1151 
1152 
1154  xFwd(ped.getMaxX()),
1155  xBack(ped.getMinX()),
1156  speed(ped.myDir * ped.mySpeed),
1157  type(OBSTACLE_PED),
1158  description(ped.myPerson->getID()) {
1159  assert(!ped.myWaitingToEnter);
1160 }
1161 
1162 
1163 // ===========================================================================
1164 // MSPModel_Striping::PState method definitions
1165 // ===========================================================================
1166 
1167 
1169  myPerson(person),
1170  myStage(stage),
1171  myLane(lane),
1172  myRelX(stage->getDepartPos()),
1173  myRelY(stage->getDepartPosLat()),
1174  myDir(FORWARD),
1175  mySpeed(0),
1176  myWaitingToEnter(true),
1177  myWaitingTime(0),
1178  myWalkingAreaPath(0),
1179  myAmJammed(false),
1180  myRemoteXYPos(Position::INVALID),
1181  myAngle(std::numeric_limits<double>::max()) {
1182  const MSEdge* currentEdge = &lane->getEdge();
1183  const ConstMSEdgeVector& route = myStage->getRoute();
1184  assert(!route.empty());
1185  if (route.size() == 1) {
1186  // only a single edge, move towards end pos
1188  } else if (route.front()->getFunction() != EDGEFUNC_NORMAL) {
1189  // start on an intersection
1190  myDir = FORWARD;
1191  if (route.front()->isWalkingArea()) {
1192  myWalkingAreaPath = getArbitraryPath(route.front());
1193  }
1194  } else {
1195  const bool mayStartForward = canTraverse(FORWARD, route) != UNDEFINED_DIRECTION;
1196  const bool mayStartBackward = canTraverse(BACKWARD, route) != UNDEFINED_DIRECTION;
1197  if DEBUGCOND(*this) {
1198  std::cout << " initialize dir for " << myPerson->getID() << " forward=" << mayStartForward << " backward=" << mayStartBackward << "\n";
1199  }
1200  if (mayStartForward && mayStartBackward) {
1201  // figure out the best direction via routing
1202  ConstMSEdgeVector crossingRoute;
1203  MSNet::getInstance()->getPedestrianRouter().compute(currentEdge, route.back(), myRelX, myStage->getArrivalPos(), myStage->getMaxSpeed(person), 0, 0, crossingRoute, true);
1204  if (crossingRoute.size() > 1) {
1205  // route found
1206  const MSEdge* nextEdge = crossingRoute[1];
1207  if (nextEdge->getFromJunction() == currentEdge->getFromJunction() || nextEdge->getToJunction() == currentEdge->getFromJunction()) {
1208  myDir = BACKWARD;
1209  }
1210  }
1211  if DEBUGCOND(*this) {
1212  std::cout << " crossingRoute=" << toString(crossingRoute) << "\n";
1213  }
1214  } else {
1215  myDir = !mayStartBackward ? FORWARD : BACKWARD;
1216  }
1217  }
1218  if (lane->getVehicleNumberWithPartials() > 0 && myRelY == 0) {
1219  // better start next to the road if nothing was specified
1220  myRelY -= stripeWidth;
1221  }
1222  if (myDir == FORWARD) {
1223  // start at the right side of the sidewalk
1224  myRelY = stripeWidth * (numStripes(lane) - 1) - myRelY;
1225  }
1226  if DEBUGCOND(*this) {
1227  std::cout << " added new pedestrian " << myPerson->getID() << " on " << lane->getID() << " myRelX=" << myRelX << " myRelY=" << myRelY << " dir=" << myDir << " route=" << toString(myStage->getRoute()) << "\n";
1228  }
1229 
1230  myNLI = getNextLane(*this, lane, 0);
1231 }
1232 
1233 
1234 double
1235 MSPModel_Striping::PState::getMinX(const bool includeMinGap) const {
1236  // @todo speed should have an influence here because faster persons need more space
1237  if (myDir == FORWARD) {
1238  return myRelX - getLength();
1239  }
1240  return myRelX - (includeMinGap ? getMinGap() : 0.);
1241 }
1242 
1243 
1244 double
1245 MSPModel_Striping::PState::getMaxX(const bool includeMinGap) const {
1246  // @todo speed should have an influence here because faster persons need more space
1247  if (myDir == FORWARD) {
1248  return myRelX + (includeMinGap ? getMinGap() : 0.);
1249  }
1250  return myRelX + getLength();
1251 }
1252 
1253 
1254 double
1256  return myPerson->getVehicleType().getLength();
1257 }
1258 
1259 
1260 double
1262  return myPerson->getVehicleType().getMinGap();
1263 }
1264 
1265 
1266 int
1268  return (int)floor(relY / stripeWidth + 0.5);
1269 }
1270 
1271 
1272 int
1274  const int s = stripe(relY);
1275  const double offset = relY - s * stripeWidth;
1276  const double threshold = MAX2(NUMERICAL_EPS, stripeWidth - SQUEEZE * myPerson->getVehicleType().getWidth());
1277  int result;
1278  if (offset > threshold) {
1279  result = s + 1;
1280  } else if (offset < -threshold) {
1281  result = s - 1;
1282  } else {
1283  result = s;
1284  }
1285  //std::cout.setf(std::ios::fixed , std::ios::floatfield);
1286  //std::cout << std::setprecision(5);
1287  //if DEBUGCOND(*this) std::cout << " otherStripe " << myPerson->getID() << " offset=" << offset << " threshold=" << threshold << " rawResult=" << result << "\n";
1288  return result;
1289 }
1290 
1291 int
1293  return MIN2(MAX2(0, stripe(myRelY)), numStripes(myLane) - 1);
1294 }
1295 
1296 
1297 int
1299  return MIN2(MAX2(0, otherStripe(myRelY)), numStripes(myLane) - 1);
1300 }
1301 
1302 
1303 double
1305  if (myStage->getNextRouteEdge() == 0) {
1306  return myDir * (myStage->getArrivalPos() - myRelX) - POSITION_EPS;
1307  } else {
1308  const double length = myWalkingAreaPath == 0 ? myLane->getLength() : myWalkingAreaPath->length;
1309  return myDir == FORWARD ? length - myRelX : myRelX;
1310  }
1311 }
1312 
1313 
1314 bool
1316  double dist = distToLaneEnd();
1317  if (DEBUGCOND(*this)) {
1318  std::cout << SIMTIME << " ped=" << myPerson->getID() << " myRelX=" << myRelX << " dist=" << dist << "\n";
1319  }
1320  if (dist <= 0) {
1321  //if (ped.myPerson->getID() == DEBUG1) {
1322  // std::cout << SIMTIME << " addToLane x=" << ped.myRelX << " newDir=" << newDir << " newLane=" << newLane->getID() << " walkingAreaShape=" << walkingAreaShape << "\n";
1323  //}
1324  //std::cout << " changing to " << newLane->getID() << " myRelY=" << ped.myRelY << " oldStripes=" << numStripes(myLane) << " newStripes=" << numStripes(newLane);
1325  //std::cout << " newY=" << ped.myRelY << " myDir=" << ped.myDir << " newDir=" << newDir;
1326  const int oldDir = myDir;
1327  const MSLane* oldLane = myLane;
1328  myLane = myNLI.lane;
1329  myDir = myNLI.dir;
1330  const bool normalLane = (myLane == 0 || myLane->getEdge().getFunction() == EDGEFUNC_NORMAL || &myLane->getEdge() == myStage->getNextRouteEdge());
1331  if DEBUGCOND(*this) {
1332  std::cout << SIMTIME
1333  << " ped=" << myPerson->getID()
1334  << " moveToNextLane old=" << oldLane->getID()
1335  << " new=" << (myLane == 0 ? "NULL" : myLane->getID())
1336  << " oldDir=" << oldDir
1337  << " newDir=" << myDir
1338  << " myRelX=" << myRelX
1339  << " dist=" << dist
1340  << "\n";
1341  }
1342  if (myLane == nullptr) {
1344  }
1345  // moveToNextEdge might destroy the person and thus mess up the heap. Better check first
1346  if (myStage->getRouteStep() == myStage->getRoute().end() - 1) {
1347  myLane = nullptr;
1348  } else {
1349  const bool arrived = myStage->moveToNextEdge(myPerson, currentTime, normalLane ? nullptr : &myLane->getEdge());
1350  UNUSED_PARAMETER(arrived);
1351  assert(!arrived);
1352  assert(myDir != UNDEFINED_DIRECTION);
1353  myNLI = getNextLane(*this, myLane, oldLane);
1354  assert(myNLI.lane != oldLane); // do not turn around
1355  if DEBUGCOND(*this) {
1356  std::cout << " nextLane=" << (myNLI.lane == 0 ? "NULL" : myNLI.lane->getID()) << "\n";
1357  }
1358  if (myLane->getEdge().isWalkingArea()) {
1359  if (myNLI.dir != UNDEFINED_DIRECTION) {
1360  myWalkingAreaPath = &myWalkingAreaPaths[std::make_pair(oldLane, myNLI.lane)];
1361  assert(myWalkingAreaPath->from != 0);
1362  assert(myWalkingAreaPath->to != 0);
1363  assert(myWalkingAreaPath->shape.size() >= 2);
1364  if DEBUGCOND(*this) {
1365  std::cout << " mWAPath shape=" << myWalkingAreaPath->shape << " length=" << myWalkingAreaPath->length << "\n";
1366  }
1367  } else {
1368  // disconnnected route. move to the next edge
1369  if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
1370  // try to determine direction from topology, otherwise maintain current direction
1371  const MSEdge* currRouteEdge = myStage->getRouteEdge();
1372  const MSEdge* nextRouteEdge = myStage->getNextRouteEdge();
1373  if ((nextRouteEdge->getToJunction() == currRouteEdge->getFromJunction())
1374  || nextRouteEdge->getToJunction() == currRouteEdge->getToJunction()) {
1375  myDir = BACKWARD;
1376  } else if ((nextRouteEdge->getFromJunction() == currRouteEdge->getFromJunction())
1377  || nextRouteEdge->getFromJunction() == currRouteEdge->getToJunction()) {
1378  myDir = FORWARD;
1379  }
1380  myStage->moveToNextEdge(myPerson, currentTime, 0);
1381  myLane = myNLI.lane;
1382  assert(myLane != 0);
1383  assert(myLane->getEdge().getFunction() == EDGEFUNC_NORMAL);
1384  myNLI = getNextLane(*this, myLane, oldLane);
1385  myWalkingAreaPath = 0;
1386  } else {
1387  throw ProcessError("Disconnected walk for person '" + myPerson->getID() + "'.");
1388  }
1389  }
1390  } else {
1391  myWalkingAreaPath = 0;
1392  }
1393  // adapt x to fit onto the new lane
1394  // (make sure we do not move past the end of the new lane since that
1395  // lane was not checked for obstacles)
1396  const double newLength = (myWalkingAreaPath == 0 ? myLane->getLength() : myWalkingAreaPath->length);
1397  if (-dist > newLength) {
1398  assert(OptionsCont::getOptions().getBool("ignore-route-errors"));
1399  // should not happen because the end of myLane should have been an obstacle as well
1400  // (only when the route is broken)
1401  dist = -newLength;
1402  }
1403  if (myDir == BACKWARD) {
1404  myRelX = newLength + dist;
1405  } else {
1406  myRelX = -dist;
1407  }
1408  if DEBUGCOND(*this) {
1409  std::cout << SIMTIME << " update myRelX ped=" << myPerson->getID()
1410  << " newLength=" << newLength
1411  << " dist=" << dist
1412  << " myRelX=" << myRelX
1413  << "\n";
1414  }
1415  // adjust to change in direction
1416  if (myDir != oldDir) {
1417  myRelY = (numStripes(oldLane) - 1) * stripeWidth - myRelY;
1418  }
1419  // adjust to differences in sidewalk width
1420  const int offset = getStripeOffset(numStripes(oldLane), numStripes(myLane), oldDir != myDir && numStripes(myLane) < numStripes(oldLane));
1421  myRelY += offset * stripeWidth;
1422  if DEBUGCOND(*this) {
1423  std::cout << SIMTIME << " transformY ped=" << myPerson->getID()
1424  << " newLane=" << Named::getIDSecure(myLane)
1425  << " newY=" << myRelY
1426  << " os=" << numStripes(oldLane) << " ns=" << numStripes(myLane)
1427  << " od=" << oldDir << " nd=" << myDir
1428  << " offset=" << offset << "\n";
1429  }
1430  }
1431  return true;
1432  } else {
1433  return false;
1434  }
1435 }
1436 
1437 
1438 void
1440  myAngle = std::numeric_limits<double>::max(); // set on first access or via remote control
1441  const int stripes = (int)obs.size();
1442  const int sMax = stripes - 1;
1443  assert(stripes == numStripes(myLane));
1444  const double vMax = myStage->getMaxSpeed(myPerson);
1445  // ultimate goal is to choose the prefered stripe (chosen)
1446  const int current = stripe();
1447  const int other = otherStripe();
1448  // compute distances
1449  std::vector<double> distance(stripes);
1450  for (int i = 0; i < stripes; ++i) {
1451  distance[i] = distanceTo(obs[i], obs[i].type == OBSTACLE_PED);
1452  }
1453  // compute utility for all stripes
1454  std::vector<double> utility(stripes, 0);
1455  // forbid stripes which are blocked and also all stripes behind them
1456  for (int i = 0; i < stripes; ++i) {
1457  if (distance[i] == DIST_OVERLAP) {
1458  if (i == current && (!myWaitingToEnter || stripe() != stripe(myRelY))) {
1459  utility[i] += OBSTRUCTED_PENALTY;
1460  }
1461  if (i < current) {
1462  for (int j = 0; j <= i; ++j) {
1463  utility[j] += OBSTRUCTED_PENALTY;
1464  }
1465  }
1466  if (i > current) {
1467  for (int j = i; j < stripes; ++j) {
1468  utility[j] += OBSTRUCTED_PENALTY;
1469  }
1470  }
1471  }
1472  }
1473  // forbid a portion of the leftmost stripes (in walking direction).
1474  // lanes with stripes less than 1 / RESERVE_FOR_ONCOMING_FACTOR
1475  // may still deadlock in heavy pedestrian traffic
1476  const bool onJunction = myLane->getEdge().isWalkingArea() || myLane->getEdge().isCrossing();
1477  const int reserved = (int)floor(stripes * (onJunction ? RESERVE_FOR_ONCOMING_FACTOR_JUNCTIONS : RESERVE_FOR_ONCOMING_FACTOR));
1478  if (myDir == FORWARD) {
1479  for (int i = 0; i < reserved; ++i) {
1480  utility[i] += INAPPROPRIATE_PENALTY * (i == current ? 0.5 : 1);
1481  }
1482  } else {
1483  for (int i = sMax; i > sMax - reserved; --i) {
1484  utility[i] += INAPPROPRIATE_PENALTY * (i == current ? 0.5 : 1);
1485  }
1486  }
1487  // adapt utility based on obstacles
1488  for (int i = 0; i < stripes; ++i) {
1489  if (obs[i].speed * myDir < 0) {
1490  // penalize evasion to the left
1491  if (myDir == FORWARD && i > 0) {
1492  utility[i - 1] -= 0.5;
1493  } else if (myDir == BACKWARD && i < sMax) {
1494  utility[i + 1] -= 0.5;
1495  }
1496  }
1497  // compute expected distance achievable by staying on this stripe for a time horizon
1498  const double walkDist = MAX2(0., distance[i]); // disregard special distance flags
1499  const double lookAhead = obs[i].speed * myDir >= 0 ? LOOKAHEAD_SAMEDIR : LOOKAHEAD_ONCOMING;
1500  const double expectedDist = MIN2(vMax * LOOKAHEAD_SAMEDIR, walkDist + obs[i].speed * myDir * lookAhead);
1501  if (DEBUGCOND(*this)) {
1502  std::cout << " util=" << utility[i] << " exp=" << expectedDist << " dist=" << distance[i] << "\n";
1503  }
1504  if (expectedDist >= 0) {
1505  utility[i] += expectedDist;
1506  } else {
1507  // let only the distance count
1508  utility[i] += ONCOMING_CONFLICT_PENALTY + distance[i];
1509  }
1510  }
1511  // discourage use of the leftmost lane (in walking direction) if there are oncoming
1512  if (myDir == FORWARD && obs[0].speed < 0) {
1513  utility[0] += ONCOMING_CONFLICT_PENALTY;
1514  } else if (myDir == BACKWARD && obs[sMax].speed > 0) {
1515  utility[sMax] += ONCOMING_CONFLICT_PENALTY;
1516  }
1517  // penalize lateral movement (if the current stripe permits walking)
1518  if (distance[current] > 0 && myWaitingTime == 0) {
1519  for (int i = 0; i < stripes; ++i) {
1520  utility[i] += abs(i - current) * LATERAL_PENALTY;
1521  }
1522  }
1523 
1524  // select best stripe
1525  int chosen = current;
1526  for (int i = 0; i < stripes; ++i) {
1527  if (utility[chosen] < utility[i]) {
1528  chosen = i;
1529  }
1530  }
1531  // compute speed components along both axes
1532  const int next = (chosen == current ? current : (chosen < current ? current - 1 : current + 1));
1533  const double xDist = MIN3(distance[current], distance[other], distance[next]);
1534  // XXX preferred gap differs between approaching a standing obstacle or a moving obstacle
1535  const double preferredGap = NUMERICAL_EPS;
1536  double xSpeed = MIN2(vMax, MAX2(0., DIST2SPEED(xDist - preferredGap)));
1537  if (xSpeed < NUMERICAL_EPS) {
1538  xSpeed = 0.;
1539  }
1540  if (DEBUGCOND(*this)) {
1541  std::cout << " xSpeedPotential=" << xSpeed << "\n";
1542  }
1543  // avoid tiny steps
1544  // XXX pressure from behind?
1545  if (mySpeed == 0 && xDist < MIN_STARTUP_DIST &&
1546  // unless walking towards a short lane
1547  !(
1548  (xDist == distance[current] && obs[current].type >= OBSTACLE_END)
1549  || (xDist == distance[other] && obs[other].type >= OBSTACLE_END)
1550  || (xDist == distance[next] && obs[next].type >= OBSTACLE_END))
1551  ) {
1552  xSpeed = 0;
1553  }
1554  if (xSpeed == 0) {
1555  if (myWaitingTime > jamTime || myAmJammed) {
1556  // squeeze slowly through the crowd ignoring others
1557  if (!myAmJammed) {
1559  WRITE_WARNING("Person '" + myPerson->getID()
1560  + "' is jammed on edge '" + myStage->getEdge()->getID()
1561  + "', time=" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
1562  myAmJammed = true;
1563  }
1564  xSpeed = vMax / 4;
1565  }
1566  } else if (stripe(myRelY) >= 0 && stripe(myRelY) <= sMax) {
1567  myAmJammed = false;
1568  }
1569  // dawdling
1570  const double dawdle = MIN2(xSpeed, RandHelper::rand() * vMax * dawdling);
1571  xSpeed -= dawdle;
1572 
1573  // XXX ensure that diagonal speed <= vMax
1574  // avoid deadlocks on narrow sidewalks
1575  //if (oncoming && xSpeed == 0 && myStage->getWaitingTime(currentTime) > TIME2STEPS(ONCOMIN_PATIENCE)) {
1576  // if DEBUGCOND(*this) std::cout << " stepping asside to resolve oncoming deadlock\n";
1577  // xSpeed = POSITION_EPS; // reset myWaitingTime
1578  // if (myDir == FORWARD && chosen < sMax) {
1579  // chosen += 1;
1580  // } else if (myDir == BACKWARD && chosen > 0) {
1581  // chosen -= 1;
1582  // }
1583  //}
1584  const double maxYSpeed = MIN2(MAX2(vMax * LATERAL_SPEED_FACTOR, vMax - xSpeed), stripeWidth);
1585  double ySpeed = 0;
1586  double yDist = 0;
1587  if (utility[next] > OBSTRUCTION_THRESHOLD && utility[chosen] > OBSTRUCTION_THRESHOLD) {
1588  // don't move laterally if the stripes are blocked
1589  yDist = (chosen * stripeWidth) - myRelY;
1590  if (fabs(yDist) > NUMERICAL_EPS) {
1591  ySpeed = (yDist > 0 ?
1592  MIN2(maxYSpeed, DIST2SPEED(yDist)) :
1593  MAX2(-maxYSpeed, DIST2SPEED(yDist)));
1594  }
1595  } else if (utility[next] <= OBSTRUCTION_THRESHOLD && obs[next].type == OBSTACLE_VEHICLE
1596  // still on the road
1597  && stripe() == stripe(myRelY)) {
1598  // step aside to let the vehicle pass
1599  myRelY += myDir * vMax;
1600  }
1601  // DEBUG
1602  if DEBUGCOND(*this) {
1603  std::cout << SIMTIME
1604  << " ped=" << myPerson->getID()
1605  << " edge=" << myStage->getEdge()->getID()
1606  << " x=" << myRelX
1607  << " y=" << myRelY
1608  << " d=" << myDir
1609  << " pvx=" << mySpeed
1610  << " cur=" << current
1611  << " cho=" << chosen
1612  << " oth=" << other
1613  << " nxt=" << next
1614  << " vx=" << xSpeed
1615  << " dawdle=" << dawdle
1616  << " vy=" << ySpeed
1617  << " xd=" << xDist
1618  << " yd=" << yDist
1619  << " vMax=" << myStage->getMaxSpeed(myPerson)
1620  << " wTime=" << myStage->getWaitingTime(currentTime)
1621  << " jammed=" << myAmJammed
1622  << "\n distance=" << toString(distance)
1623  << "\n utility=" << toString(utility)
1624  << "\n";
1625  DEBUG_PRINT(obs);
1626  }
1627  myRelX += SPEED2DIST(xSpeed * myDir);
1628  myRelY += SPEED2DIST(ySpeed);
1629  mySpeed = xSpeed;
1630  if (xSpeed >= SUMO_const_haltingSpeed) {
1631  myWaitingToEnter = false;
1632  myWaitingTime = 0;
1633  } else {
1635  }
1636 }
1637 
1638 
1639 double
1641  return MAX2(0., MIN2(1., myPerson->getVehicleType().getImpatience()
1643 }
1644 
1645 
1646 double
1648  return myRelX;
1649 }
1650 
1651 
1652 Position
1654  if (myLane == 0) {
1655  // pedestrian has already finished
1656  return Position::INVALID;
1657  }
1658  const double lateral_offset = myRelY + (stripeWidth - myLane->getWidth()) * 0.5;
1659  if (myWalkingAreaPath == 0) {
1660  return stage.getLanePosition(myLane, myRelX, lateral_offset);
1661  } else {
1662  //if DEBUGCOND(*this) {
1663  // std::cout << SIMTIME
1664  // << " getPosition (walkingArea)"
1665  // << " p=" << myPerson->getID()
1666  // << " x=" << myRelX
1667  // << " y=" << myRelY
1668  // << " latOffset=" << lateral_offset
1669  // << " shape=" << myWalkingAreaPath->shape
1670  // << " pos=" << myWalkingAreaPath->shape.positionAtOffset(myRelX, lateral_offset)
1671  // << "\n";
1672  //}
1673  return myWalkingAreaPath->shape.positionAtOffset(myRelX, lateral_offset);
1674  }
1675 }
1676 
1677 
1678 double
1680  if (myAngle != std::numeric_limits<double>::max()) {
1681  return myAngle;
1682  }
1683  if (myLane == 0) {
1684  // pedestrian has already finished
1685  return 0;
1686  }
1688  double angle = shp.rotationAtOffset(myRelX) + (myDir == MSPModel::BACKWARD ? M_PI : 0);
1689  if (angle > M_PI) {
1690  angle -= 2 * M_PI;
1691  }
1692  myAngle = angle;
1693  return angle;
1694 }
1695 
1696 
1697 SUMOTime
1699  return myWaitingTime;
1700 }
1701 
1702 
1703 double
1705  return mySpeed;
1706 }
1707 
1708 
1709 const MSEdge*
1711  return myNLI.lane == 0 ? 0 : &myNLI.lane->getEdge();
1712 }
1713 
1714 void
1716  double lanePosLat, double angle, int routeOffset,
1717  const ConstMSEdgeVector& edges, SUMOTime t) {
1718  UNUSED_PARAMETER(p);
1719  assert(p == myPerson);
1720  myAngle = angle;
1722  /*
1723  std::cout << " MSPModel_Striping::PState::moveToXY"
1724  << " pos=" << pos
1725  << " lane=" << lane->getID()
1726  << " lanePos=" << lanePos
1727  << " lanePosLat=" << lanePosLat
1728  << " angle=" << angle
1729  << " routeOffset=" << routeOffset
1730  << " myRelX=" << myRelX << " myRelY=" << myRelY;
1731  */
1732  //std::cout << " newX=" << myRelX << " newY=" << myRelY << "\n";
1733  if (lane != 0) {
1735  const MSLane* sidewalk = getSidewalk<MSEdge, MSLane>(&lane->getEdge());
1736  if (lane != sidewalk) {
1737  MSPModel_Striping* pm = dynamic_cast<MSPModel_Striping*>(MSPModel::getModel());
1738  assert(pm != 0);
1739  // add a new active lane
1740  pm->remove(this);
1741  pm->add(this, lane);
1742  }
1743  if (edges.empty()) {
1744  // map within route
1745  myStage->setRouteIndex(myPerson, routeOffset);
1746  if (lane->getEdge().isInternal()) {
1747  myStage->moveToNextEdge(myPerson, t, &lane->getEdge());
1748  }
1749  } else {
1750  // map to new edge
1751  }
1752  myLane = lane;
1753  myRelX = lanePos;
1754  myRelY = (myLane->getWidth() - stripeWidth) * 0.5 - lanePosLat;
1755  } else {
1756  // map outside the network
1757  myRemoteXYPos = pos;
1758  }
1759 
1760 }
1761 
1762 
1763 
1764 double
1765 MSPModel_Striping::PState::distanceTo(const Obstacle& obs, const bool includeMinGap) const {
1766  // check for overlap
1767  const double maxX = getMaxX(includeMinGap);
1768  const double minX = getMinX(includeMinGap);
1769  //if (DEBUGCOND(*this)) {
1770  // std::cout << std::setprecision(2) << " distanceTo=" << obs.description << " maxX=" << maxX << " minX=" << minX << " obs.xFwd=" << obs.xFwd << " obs.xBack=" << obs.xBack << "\n";
1771  //}
1772  if ((obs.xFwd >= maxX && obs.xBack <= maxX) || (obs.xFwd <= maxX && obs.xFwd >= minX)) {
1773  // avoid blocking by itself on looped route
1774  return (obs.type == OBSTACLE_PED && obs.description == myPerson->getID()) ? DIST_FAR_AWAY : DIST_OVERLAP;
1775  }
1776  if (myDir == FORWARD) {
1777  return obs.xFwd < minX ? DIST_BEHIND : obs.xBack - maxX;
1778  } else {
1779  return obs.xBack > maxX ? DIST_BEHIND : minX - obs.xFwd;
1780  }
1781 }
1782 
1783 
1784 void
1786  for (int i = 0; i < (int)into.size(); ++i) {
1787  if (gDebugFlag1) {
1788  std::cout << " i=" << i << " intoDist=" << distanceTo(into[i]) << " obs2Dist=" << distanceTo(obs2[i]) << "\n";
1789  }
1790  const double dO = distanceTo(obs2[i]);
1791  const double dI = distanceTo(into[i]);
1792  if (dO < dI) {
1793  into[i] = obs2[i];
1794  } else if (dO == dI && (
1795  obs2[i].type == OBSTACLE_PED ||
1796  obs2[i].type == OBSTACLE_VEHICLE)) {
1797  into[i] = obs2[i];
1798  }
1799  }
1800 }
1801 
1802 void
1803 MSPModel_Striping::PState::mergeObstacles(Obstacles& into, const Obstacles& obs2, int dir, int offset) {
1804  for (int i = 0; i < (int)into.size(); ++i) {
1805  int i2 = i + offset;
1806  if (i2 >= 0 && i2 < (int)obs2.size()) {
1807  if (dir == FORWARD) {
1808  if (obs2[i2].xBack < into[i].xBack) {
1809  into[i] = obs2[i2];
1810  }
1811  } else {
1812  if (obs2[i2].xFwd > into[i].xFwd) {
1813  into[i] = obs2[i2];
1814  }
1815  }
1816  }
1817  }
1818 }
1819 
1820 
1821 bool
1823  if (link->haveRed()) {
1824  const double ignoreRedTime = myPerson->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_DRIVE_AFTER_RED_TIME, -1);
1825  if (ignoreRedTime >= 0) {
1826  const double redDuration = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - link->getLastStateChange());
1827  if (DEBUGCOND(*this)) {
1828  std::cout << SIMTIME << " ignoreRedTime=" << ignoreRedTime << " redDuration=" << redDuration << "\n";
1829  }
1830  return ignoreRedTime > redDuration;
1831  } else {
1832  return false;
1833  }
1834  } else {
1835  return false;
1836  }
1837 }
1838 
1839 // ===========================================================================
1840 // MSPModel_Striping::MovePedestrians method definitions
1841 // ===========================================================================
1842 //
1843 
1844 SUMOTime
1846  std::set<MSPerson*> changedLane;
1847  myModel->moveInDirection(currentTime, changedLane, FORWARD);
1848  myModel->moveInDirection(currentTime, changedLane, BACKWARD);
1849  // DEBUG
1850 #ifdef LOG_ALL
1851  for (ActiveLanes::const_iterator it_lane = myModel->getActiveLanes().begin(); it_lane != myModel->getActiveLanes().end(); ++it_lane) {
1852  const MSLane* lane = it_lane->first;
1853  Pedestrians pedestrians = it_lane->second;
1854  if (pedestrians.size() == 0) {
1855  continue;
1856  }
1857  sort(pedestrians.begin(), pedestrians.end(), by_xpos_sorter(FORWARD));
1858  std::cout << SIMTIME << " lane=" << lane->getID();
1859  for (int ii = 0; ii < (int)pedestrians.size(); ++ii) {
1860  const PState& p = *pedestrians[ii];
1861  std::cout << " (" << p.myPerson->getID() << " " << p.myRelX << "," << p.myRelY << " " << p.myDir << ")";
1862  }
1863  std::cout << "\n";
1864  }
1865 #endif
1866  return DELTA_T;
1867 }
1868 
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:762
bool gDebugFlag1
global utility flags for debugging
Definition: StdDefs.cpp:32
static NextLaneInfo getNextLane(const PState &ped, const MSLane *currentLane, const MSLane *prevLane)
computes the successor lane for the given pedestrian and sets the link as well as the direction to us...
#define DIST2SPEED(x)
Definition: SUMOTime.h:50
double getImpatience(SUMOTime now) const
returns the impatience
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition: MSLane.cpp:2370
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver&#39;s reaction time tau (i...
Definition: MSCFModel.h:307
void moveInDirection(SUMOTime currentTime, std::set< MSPerson *> &changedLane, int dir)
move all pedestrians forward and advance to the next lane if applicable
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:617
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
double getJMParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
static const double LATERAL_SPEED_FACTOR
static const double SQUEEZE
#define SPEED2DIST(x)
Definition: SUMOTime.h:48
MSPerson::MSPersonStage_Walking * myStage
static const double DIST_BEHIND
void moveInDirectionOnLane(Pedestrians &pedestrians, const MSLane *lane, SUMOTime currentTime, std::set< MSPerson *> &changedLane, int dir)
move pedestrians forward on one lane
static const double LOOKAHEAD_ONCOMING
static int numStripes(const MSLane *lane)
return the maximum number of pedestrians walking side by side
static Obstacles getNeighboringObstacles(const Pedestrians &pedestrians, int egoIndex, int stripes)
Obstacle(int dir, double dist=DIST_FAR_AWAY)
create No-Obstacle
const MSEdge * getEdge() const
Returns the current edge.
double getMinGap() const
return the minimum gap of the pedestrian
sorts the persons by position on the lane. If dir is forward, higher x positions come first...
static WalkingAreaPath * getArbitraryPath(const MSEdge *walkingArea)
return an arbitrary path across the given walkingArea
static const MSLane * getNextWalkingArea(const MSLane *currentLane, const int dir, MSLink *&link)
return the next walkingArea in the given direction
bool ignoreRed(const MSLink *link) const
whether the pedestrian may ignore a red light
static int connectedDirection(const MSLane *from, const MSLane *to)
returns the direction in which these lanes are connectioned or 0 if they are not
WalkingAreaPath * myWalkingAreaPath
the current walkingAreaPath or 0
static const double MIN_STARTUP_DIST
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:243
The pedestrian following model.
information regarding surround Pedestrians (and potentially other things)
const MSEdge * getDestination() const
returns the destination edge
const MSEdgeVector & getPredecessors() const
Definition: MSEdge.h:337
The base class for an intersection.
Definition: MSJunction.h:60
double y() const
Returns the y-position.
Definition: Position.h:61
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
double getMaxSpeed(const MSPerson *person) const
accessors to be used by MSPModel
Definition: MSPerson.cpp:346
#define INVALID
PState(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, const MSLane *lane)
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSPerson.cpp:88
AnyVehicleIterator is a structure, which manages the iteration through all vehicles on the lane...
Definition: MSLane.h:100
static const int FORWARD
Definition: MSPModel.h:100
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
double x() const
Returns the x-position.
Definition: Position.h:56
void registerJammed()
register a jammed transportable
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:162
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
T MAX2(T a, T b)
Definition: StdDefs.h:68
void remove(PedestrianState *state)
remove the specified person from the pedestrian simulation
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:507
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:449
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:62
PositionVector reverse() const
reverse position vector
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
bool usingInternalLanes()
whether movements on intersections are modelled /
std::map< std::pair< const MSLane *, const MSLane * >, WalkingAreaPath > WalkingAreaPaths
const std::string & getID() const
Returns the id.
Definition: Named.h:69
bool moveToNextLane(SUMOTime currentTime)
return whether this pedestrian has passed the end of the current lane and update myRelX if so ...
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
void moveToXY(MSPerson *p, Position pos, MSLane *lane, double lanePos, double lanePosLat, double angle, int routeOffset, const ConstMSEdgeVector &edges, SUMOTime t)
try to move person to the given position
static bool usingInternalLanesStatic()
static MSPModel * myModel
Definition: MSPModel.h:122
double getLength() const
return the length of the edge
Definition: MSEdge.h:563
double getMaxX(const bool includeMinGap=true) const
return the maximum position on the lane
static WalkingAreaPaths myWalkingAreaPaths
store for walkinArea elements
const MSJunction * getToJunction() const
Definition: MSEdge.h:346
double getLength() const
return the length of the pedestrian
#define MINGAP_TO_VEHICLE
static const double LATERAL_PENALTY
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:523
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
PersonDist nextBlocking(const MSLane *lane, double minPos, double minRight, double maxLeft, double stopTime=0)
returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or 0 ...
double mySpeed
the current walking speed
static const double OBSTRUCTION_THRESHOLD
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
The simulated network and simulation perfomer.
Definition: MSNet.h:85
bool myAmJammed
whether the person is jammed
int getVehicleNumberWithPartials() const
Returns the number of vehicles on this lane (including partial occupators)
Definition: MSLane.h:380
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
#define SIMTIME
Definition: SUMOTime.h:65
static Pedestrians noPedestrians
empty pedestrian vector
static bool gCheck4Accidents
Definition: MSGlobals.h:76
void mergeObstacles(Obstacles &into, const Obstacles &obs2)
replace obstacles in the first vector with obstacles from the second if they are closer to me ...
NextLaneInfo myNLI
information about the upcoming lane
static const double RESERVE_FOR_ONCOMING_FACTOR_JUNCTIONS
A road/street connecting two junctions.
Definition: MSEdge.h:75
Pedestrians & getPedestrians(const MSLane *lane)
retrieves the pedestian vector for the given lane (may be empty)
static int canTraverse(int dir, const ConstMSEdgeVector &route)
Definition: MSPModel.cpp:92
const MSCFModel & getCarFollowModel() const
Returns the vehicle&#39;s car following model definition.
Definition: MSVehicle.h:887
double xFwd
maximal position on the current lane in forward direction
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:105
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
SUMOTime execute(SUMOTime currentTime)
Executes the command.
static const double OBSTRUCTED_PENALTY
static const double DIST_OVERLAP
static MSPModel * getModel()
Definition: MSPModel.cpp:59
#define DEBUGCOND2(LANE)
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:748
void walk(const Obstacles &obs, SUMOTime currentTime)
perform position update
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static int getStripeOffset(int origStripes, int destStripes, bool addRemainder)
static Obstacles getVehicleObstacles(const MSLane *lane, int dir, PState *ped=0)
retrieve vehicle obstacles on the given lane
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 myRelY
the orthogonal shift on the current lane
Position myRemoteXYPos
remote-controlled position
double xBack
maximal position on the current lane in backward direction
double myRelX
the advancement along the current lane
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:402
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
double myAngle
cached angle
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
double getSpeed(const MSPerson::MSPersonStage_Walking &stage) const
return the current speed of the person
static double fromNaviDegree(const double angle)
Definition: GeomHelper.cpp:197
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the network coordinate of the person
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:256
double distToLaneEnd() const
the absolute distance to the end of the lane in walking direction (or to the arrivalPos) ...
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:42
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
static double dawdling
T MIN2(T a, T b)
Definition: StdDefs.h:62
AnyVehicleIterator anyVehiclesEnd() const
end iterator for iterating over all vehicles touching this lane in downstream direction ...
Definition: MSLane.h:411
AnyVehicleIterator anyVehiclesBegin() const
begin iterator for iterating over all vehicles touching this lane in downstream direction ...
Definition: MSLane.h:405
#define POSITION_EPS
Definition: config.h:172
const std::string & getID() const
returns the id of the transportable
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:598
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:69
double getMinGap() const
Get the free space in front of vehicles of this class.
std::map< const MSLane *, Obstacles, lane_by_numid_sorter > NextLanesObstacles
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:218
AnyVehicleIterator anyVehiclesUpstreamBegin() const
begin iterator for iterating over all vehicles touching this lane in upstream direction ...
Definition: MSLane.h:417
double getArrivalPos() const
Definition: MSPerson.h:153
bool isCrossing() const
return whether this edge is a pedestrian crossing
Definition: MSEdge.h:229
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:224
SUMOTime myWaitingTime
the consecutive time spent at speed 0
const ConstMSEdgeVector & getRoute() const
Definition: MSPerson.h:167
int myDir
the walking direction on the current lane (1 forward, -1 backward)
static const double LOOKAHEAD_SAMEDIR
const SUMOVTypeParameter & getParameter() const
MSPedestrianRouter & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:906
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
double speed
speed relative to lane direction (positive means in the same direction)
const Obstacles & getNextLaneObstacles(NextLanesObstacles &nextLanesObs, const MSLane *lane, const MSLane *nextLane, int stripes, int nextDir, double currentLength, int currentDir)
void cleanupHelper()
remove state at simulation end
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)
register the given person as a pedestrian
static const double RESERVE_FOR_ONCOMING_FACTOR
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:436
void arriveAndAdvance(Pedestrians &pedestrians, SUMOTime currentTime, std::set< MSPerson *> &changedLane, int dir)
handle arrivals and lane advancement
static void transformToCurrentLanePositions(Obstacles &o, int currentDir, int nextDir, double currentLength, double nextLength)
abstract base class for managing callbacks to retrieve various state information from the model ...
Definition: MSPModel.h:128
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
std::pair< const MSPerson *, double > PersonDist
Definition: MSPModel.h:38
bool hasPedestrians(const MSLane *lane)
whether the given lane has pedestrians on it
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: MSEdge.cpp:924
const std::vector< const MSEdge * >::iterator getRouteStep() const
Definition: MSPerson.h:157
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
std::map< const MSLane *, double > MinNextLengths
ObstacleType type
whether this obstacle denotes a border or a pedestrian
static const double DIST_FAR_AWAY
double getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
abstract methods inherited from PedestrianState
static const double ONCOMING_CONFLICT_PENALTY
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const
return the list of internal edges if the pedestrian is on an intersection
std::vector< PState * > Pedestrians
SUMOTime getWaitingTime(SUMOTime now) const
the time this transportable spent waiting
Definition: MSPerson.cpp:122
#define SUMOTime_MAX
Definition: SUMOTime.h:37
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
static double stripeWidth
model parameters
static const double INAPPROPRIATE_PENALTY
bool myWaitingToEnter
whether the pedestrian is waiting to start its walk
#define M_PI
Definition: odrSpiral.cpp:40
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:773
const MSJunction * getFromJunction() const
Definition: MSEdge.h:342
double distanceTo(const Obstacle &obs, const bool includeMinGap=true) const
bool moveToNextEdge(MSPerson *person, SUMOTime currentTime, MSEdge *nextInternal=nullptr)
move forward and return whether the person arrived
Definition: MSPerson.cpp:312
A storage for options typed value containers)
Definition: OptionsCont.h:92
Container for pedestrian state and individual position update function.
std::vector< Obstacle > Obstacles
double getLength() const
Get vehicle&#39;s length [m].
AnyVehicleIterator anyVehiclesUpstreamEnd() const
end iterator for iterating over all vehicles touching this lane in upstream direction ...
Definition: MSLane.h:423
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition: StdDefs.h:52
#define DEBUGCOND(PED)
static const int BACKWARD
Definition: MSPModel.h:104
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:243
const MSVehicleType & getVehicleType() const
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle&#39;s position relative to the given lane.
Definition: MSVehicle.cpp:3445
const MSEdge * getRouteEdge() const
Definition: MSPerson.h:161
static const double SAFETY_GAP
Definition: MSPModel.h:108
double getMinX(const bool includeMinGap=true) const
return the minimum position on the lane
T MIN3(T a, T b, T c)
Definition: StdDefs.h:75
#define NUMERICAL_EPS
Definition: config.h:148
void push_back_noDoublePos(const Position &p)
insert in back a non double position
static void DEBUG_PRINT(const Obstacles &obs)
double getImpatience() const
Returns this type&#39;s impatience.
static void addCloserObstacle(Obstacles &obs, double x, int stripe, int numStripes, const std::string &id, double width, int dir, ObstacleType type)
const MSEdge * getNextRouteEdge() const
Definition: MSPerson.h:164
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
static SUMOTime jamTime
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1940
int myNumActivePedestrians
the total number of active pedestrians
double getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the direction in which the person faces in degrees
static MinNextLengths myMinNextLengths
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:479
std::string description
the id / description of the obstacle
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the time the person spent standing
static void initWalkingAreaPaths(const MSNet *net)
MSPModel_Striping(const OptionsCont &oc, MSNet *net)
Constructor (it should not be necessary to construct more than one instance)
const std::string & getID() const
Returns the name of the vehicle.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static const double MAX_WAIT_TOLERANCE
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
ActiveLanes myActiveLanes
store of all lanes which have pedestrians on them
const MSLane * myLane
the current lane of this pedestrian
Position transformToVectorCoordinates(const Position &p, bool extend=false) const
return position p within the length-wise coordinate system defined by this position vector...
bool blockedAtDist(const MSLane *lane, double vehSide, double vehWidth, double oncomingGap, std::vector< const MSPerson *> *collectBlockers)
whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries ...
SumoXMLEdgeFunc getFunction() const
Returns the edge type (SumoXMLEdgeFunc)
Definition: MSEdge.h:219
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:274
static bool addCrossingVehs(const MSLane *crossing, int stripes, double lateral_offset, int dir, Obstacles &crossingVehs)
add vehicles driving across
static const double LOOKAROUND_VEHICLES
StageType getCurrentStageType() const
the current stage type of the transportable
void setRouteIndex(MSPerson *person, int routeOffset)
place person on a previously passed edge
Definition: MSPerson.cpp:337