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 /****************************************************************************/
14 // The pedestrian following model (prototype)
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
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 #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 #ifdef HAVE_FOX
54 FXMutex MSPModel::myInitializationMutex(true);
55 #endif
56 
57 // ===========================================================================
58 // MSPModel method definitions
59 // ===========================================================================
60 
61 
62 MSPModel*
64 #ifdef HAVE_FOX
65  FXConditionalLock lock(myInitializationMutex, MSGlobals::gNumSimThreads > 1);
66 #endif
67  if (myModel == nullptr) {
69  MSNet* net = MSNet::getInstance();
70  const std::string model = oc.getString("pedestrian.model");
71  if (model == "striping") {
72  myModel = new MSPModel_Striping(oc, net);
73  } else if (model == "nonInteracting") {
74  myModel = new MSPModel_NonInteracting(oc, net);
75 #ifdef BUILD_GRPC
76  } else if (model == "remote") {
77  myModel = new MSPModel_Remote(oc, net);
78 // std::cout << " remote model loaded" << std::endl;
79 #endif
80  } else {
81  throw ProcessError("Unknown pedestrian model '" + model + "'");
82  }
83  }
84  return myModel;
85 }
86 
87 
88 void
90  if (myModel != nullptr) {
92  delete myModel;
93  myModel = nullptr;
94  }
95 }
96 
97 
98 int
99 MSPModel::canTraverse(int dir, const ConstMSEdgeVector& route) {
100  const MSJunction* junction = nullptr;
101  for (ConstMSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
102  const MSEdge* edge = *it;
103  if (junction != nullptr) {
104  //std::cout << " junction=" << junction->getID() << " edge=" << edge->getID() << "\n";
105  if (junction == edge->getFromJunction()) {
106  dir = FORWARD;
107  } else if (junction == edge->getToJunction()) {
108  dir = BACKWARD;
109  } else {
110  return UNDEFINED_DIRECTION;
111  }
112  }
113  junction = dir == FORWARD ? edge->getToJunction() : edge->getFromJunction();
114  }
115  return dir;
116 }
117 
118 /****************************************************************************/
MSPModel
The pedestrian following model.
Definition: MSPModel.h:52
MSPModel_NonInteracting
The pedestrian following model.
Definition: MSPModel_NonInteracting.h:48
MSPModel_NonInteracting.h
MSPModel::canTraverse
static int canTraverse(int dir, const ConstMSEdgeVector &route)
Definition: MSPModel.cpp:99
MSNet.h
MSPModel::BACKWARD
static const int BACKWARD
Definition: MSPModel.h:106
MSJunction
The base class for an intersection.
Definition: MSJunction.h:60
OptionsCont.h
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:91
MSPModel::SAFETY_GAP
static const double SAFETY_GAP
Definition: MSPModel.h:110
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:201
MSGlobals::gNumSimThreads
static int gNumSimThreads
how many threads to use for simulation
Definition: MSGlobals.h:123
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:75
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
MSEdge.h
MSPModel_Striping
The pedestrian following model.
Definition: MSPModel_Striping.h:50
MSPModel_Remote
Definition: MSPModel_Remote.h:26
MSEdge::getFromJunction
const MSJunction * getFromJunction() const
Definition: MSEdge.h:359
MSJunction.h
FXConditionalLock
A scoped lock which only triggers on condition.
Definition: FXConditionalLock.h:36
ProcessError
Definition: UtilExceptions.h:39
MSGlobals.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSEdge::getToJunction
const MSJunction * getToJunction() const
Definition: MSEdge.h:363
MSPModel::myModel
static MSPModel * myModel
Definition: MSPModel.h:131
MSPModel::FORWARD
static const int FORWARD
Definition: MSPModel.h:102
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
MSPModel_Remote.h
MSPModel::cleanup
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:89
MSPModel::SIDEWALK_OFFSET
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition: MSPModel.h:113
MSPModel::cleanupHelper
virtual void cleanupHelper()
Definition: MSPModel.h:102
MSPModel::UNDEFINED_DIRECTION
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:107
MSPModel.h
MSPModel::getModel
static MSPModel * getModel()
Definition: MSPModel.cpp:63
config.h
MSLane.h
MSPModel_Striping.h