SUMO - Simulation of Urban MObility
MSPModel.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The pedestrian following model (prototype)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2014-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <cmath>
31 #include <algorithm>
33 #include <microsim/MSNet.h>
34 #include <microsim/MSEdge.h>
35 #include <microsim/MSJunction.h>
36 #include <microsim/MSLane.h>
37 #include "MSPModel_Striping.h"
39 #include "MSPModel.h"
40 #ifdef BUILD_GRPC
41 #include "MSPModel_Remote.h"
42 #endif
43 
44 
45 // ===========================================================================
46 // static members
47 // ===========================================================================
49 
50 // named constants
51 const int MSPModel::FORWARD(1);
52 const int MSPModel::BACKWARD(-1);
54 
55 // parameters shared by all models
56 const double MSPModel::SAFETY_GAP(1.0);
57 
58 const double MSPModel::SIDEWALK_OFFSET(3);
59 
60 // ===========================================================================
61 // MSPModel method definitions
62 // ===========================================================================
63 
64 
65 MSPModel*
67  if (myModel == 0) {
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 != 0) {
92  delete myModel;
93  myModel = 0;
94  }
95 }
96 
97 
98 bool
99 MSPModel::canTraverse(int dir, const ConstMSEdgeVector& route) {
100  const MSJunction* junction = 0;
101  for (ConstMSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
102  const MSEdge* edge = *it;
103  if (junction != 0) {
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 false;
111  }
112  }
113  junction = dir == FORWARD ? edge->getToJunction() : edge->getFromJunction();
114  }
115  return true;
116 }
117 
118 /****************************************************************************/
virtual void cleanupHelper()
Definition: MSPModel.h:106
The pedestrian following model.
The base class for an intersection.
Definition: MSJunction.h:64
static const int FORWARD
Definition: MSPModel.h:106
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:169
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk ...
Definition: MSPModel.h:117
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:79
static MSPModel * myModel
Definition: MSPModel.h:123
The simulated network and simulation perfomer.
Definition: MSNet.h:89
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
The pedestrian following model.
Definition: MSPModel.h:56
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
A road/street connecting two junctions.
Definition: MSEdge.h:81
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:111
The pedestrian following model.
static MSPModel * getModel()
Definition: MSPModel.cpp:66
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:89
A storage for options typed value containers)
Definition: OptionsCont.h:99
static const int BACKWARD
Definition: MSPModel.h:110
static const double SAFETY_GAP
Definition: MSPModel.h:114
const MSJunction * getFromJunction() const
Definition: MSEdge.h:349
const MSJunction * getToJunction() const
Definition: MSEdge.h:353
static bool canTraverse(int dir, const ConstMSEdgeVector &route)
return whether the route may traversed with the given starting direction
Definition: MSPModel.cpp:99