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.org/sumo
3 // Copyright (C) 2014-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The pedestrian following model (prototype)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <cmath>
24 #include <algorithm>
26 #include <microsim/MSNet.h>
27 #include <microsim/MSEdge.h>
28 #include <microsim/MSJunction.h>
29 #include <microsim/MSLane.h>
30 #include "MSPModel_Striping.h"
32 #include "MSPModel.h"
33 #ifdef BUILD_GRPC
34 #include "MSPModel_Remote.h"
35 #endif
36 
37 
38 // ===========================================================================
39 // static members
40 // ===========================================================================
41 MSPModel* MSPModel::myModel(nullptr);
42 
43 // named constants
44 const int MSPModel::FORWARD(1);
45 const int MSPModel::BACKWARD(-1);
47 
48 // parameters shared by all models
49 const double MSPModel::SAFETY_GAP(1.0);
50 
51 const double MSPModel::SIDEWALK_OFFSET(3);
52 
53 // ===========================================================================
54 // MSPModel method definitions
55 // ===========================================================================
56 
57 
58 MSPModel*
60  if (myModel == nullptr) {
62  MSNet* net = MSNet::getInstance();
63  const std::string model = oc.getString("pedestrian.model");
64  if (model == "striping") {
65  myModel = new MSPModel_Striping(oc, net);
66  } else if (model == "nonInteracting") {
67  myModel = new MSPModel_NonInteracting(oc, net);
68 #ifdef BUILD_GRPC
69  } else if (model == "remote") {
70  myModel = new MSPModel_Remote(oc, net);
71 // std::cout << " remote model loaded" << std::endl;
72 #endif
73  } else {
74  throw ProcessError("Unknown pedestrian model '" + model + "'");
75  }
76  }
77  return myModel;
78 }
79 
80 
81 void
83  if (myModel != nullptr) {
85  delete myModel;
86  myModel = nullptr;
87  }
88 }
89 
90 
91 int
92 MSPModel::canTraverse(int dir, const ConstMSEdgeVector& route) {
93  const MSJunction* junction = nullptr;
94  for (ConstMSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
95  const MSEdge* edge = *it;
96  if (junction != nullptr) {
97  //std::cout << " junction=" << junction->getID() << " edge=" << edge->getID() << "\n";
98  if (junction == edge->getFromJunction()) {
99  dir = FORWARD;
100  } else if (junction == edge->getToJunction()) {
101  dir = BACKWARD;
102  } else {
103  return UNDEFINED_DIRECTION;
104  }
105  }
106  junction = dir == FORWARD ? edge->getToJunction() : edge->getFromJunction();
107  }
108  return dir;
109 }
110 
111 /****************************************************************************/
MSPModel
The pedestrian following model.
Definition: MSPModel.h:50
MSPModel_NonInteracting
The pedestrian following model.
Definition: MSPModel_NonInteracting.h:49
MSPModel_NonInteracting.h
MSPModel::canTraverse
static int canTraverse(int dir, const ConstMSEdgeVector &route)
Definition: MSPModel.cpp:92
MSNet.h
MSPModel::BACKWARD
static const int BACKWARD
Definition: MSPModel.h:104
MSJunction
The base class for an intersection.
Definition: MSJunction.h:61
OptionsCont.h
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:92
MSPModel::SAFETY_GAP
static const double SAFETY_GAP
Definition: MSPModel.h:108
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:202
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
MSEdge.h
MSPModel_Striping
The pedestrian following model.
Definition: MSPModel_Striping.h:51
MSPModel_Remote
Definition: MSPModel_Remote.h:27
MSEdge::getFromJunction
const MSJunction * getFromJunction() const
Definition: MSEdge.h:357
MSJunction.h
ProcessError
Definition: UtilExceptions.h:40
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
MSEdge::getToJunction
const MSJunction * getToJunction() const
Definition: MSEdge.h:361
MSPModel::myModel
static MSPModel * myModel
Definition: MSPModel.h:122
MSPModel::FORWARD
static const int FORWARD
Definition: MSPModel.h:100
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
MSPModel_Remote.h
MSPModel::cleanup
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:82
MSPModel::SIDEWALK_OFFSET
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition: MSPModel.h:111
MSPModel::cleanupHelper
virtual void cleanupHelper()
Definition: MSPModel.h:100
MSPModel::UNDEFINED_DIRECTION
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:105
MSPModel.h
MSPModel::getModel
static MSPModel * getModel()
Definition: MSPModel.cpp:59
config.h
MSLane.h
MSPModel_Striping.h