Eclipse SUMO - Simulation of Urban MObility
MSPModel.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2014-2024 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 // The pedestrian following model (prototype)
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <cmath>
23 #include <algorithm>
25 #include <microsim/MSNet.h>
26 #include <microsim/MSEdge.h>
27 #include <microsim/MSJunction.h>
28 #include <microsim/MSLane.h>
29 #include <microsim/MSGlobals.h>
30 #include "MSPModel_Striping.h"
32 #include "MSPModel.h"
33 
34 
35 // ===========================================================================
36 // static members
37 // ===========================================================================
38 // named constants
39 const int MSPModel::FORWARD(1);
40 const int MSPModel::BACKWARD(-1);
42 
43 // parameters shared by all models
44 const double MSPModel::SAFETY_GAP(1.0);
45 const double MSPModel::SIDEWALK_OFFSET(3);
46 const double MSPModel::UNSPECIFIED_POS_LAT(std::numeric_limits<double>::max());
47 const double MSPModel::RANDOM_POS_LAT(-std::numeric_limits<double>::max());
48 
49 
50 // ===========================================================================
51 // MSPModel method definitions
52 // ===========================================================================
53 int
54 MSPModel::canTraverse(int dir, const ConstMSEdgeVector& route, int& passedEdges) {
55  const MSJunction* junction = nullptr;
56  for (ConstMSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
57  const MSEdge* edge = *it;
58  if (junction != nullptr) {
59  //std::cout << " junction=" << junction->getID() << " edge=" << edge->getID() << "\n";
60  if (junction == edge->getFromJunction()) {
61  dir = FORWARD;
62  } else if (junction == edge->getToJunction()) {
63  dir = BACKWARD;
64  } else {
65  return UNDEFINED_DIRECTION;
66  }
67  }
68  junction = dir == FORWARD ? edge->getToJunction() : edge->getFromJunction();
69  passedEdges++;
70  }
71  return dir;
72 }
73 
74 
75 /****************************************************************************/
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
A road/street connecting two junctions.
Definition: MSEdge.h:77
const MSJunction * getFromJunction() const
Definition: MSEdge.h:411
const MSJunction * getToJunction() const
Definition: MSEdge.h:415
The base class for an intersection.
Definition: MSJunction.h:58
static const int BACKWARD
Definition: MSPModel.h:120
static int canTraverse(int dir, const ConstMSEdgeVector &route, int &passedEdges)
Definition: MSPModel.cpp:54
static const int FORWARD
Definition: MSPModel.h:119
static const double RANDOM_POS_LAT
magic value to encode randomized lateral offset for persons when starting a walk
Definition: MSPModel.h:133
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition: MSPModel.h:127
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:121
static const double UNSPECIFIED_POS_LAT
the default lateral offset for persons when starting a walk
Definition: MSPModel.h:130
static const double SAFETY_GAP
Definition: MSPModel.h:124