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