SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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 <math.h>
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 
41 
42 // ===========================================================================
43 // static members
44 // ===========================================================================
46 
47 // named constants
48 const int MSPModel::FORWARD(1);
49 const int MSPModel::BACKWARD(-1);
51 
52 // parameters shared by all models
54 
56 
57 // ===========================================================================
58 // MSPModel method definitions
59 // ===========================================================================
60 
61 
62 MSPModel*
64  if (myModel == 0) {
66  MSNet* net = MSNet::getInstance();
67  const std::string model = oc.getString("pedestrian.model");
68  if (model == "striping") {
69  myModel = new MSPModel_Striping(oc, net);
70  } else if (model == "nonInteracting") {
71  myModel = new MSPModel_NonInteracting(oc, net);
72  } else {
73  throw ProcessError("Unknown pedestrian model '" + model + "'");
74  }
75  }
76  return myModel;
77 }
78 
79 
80 void
82  if (myModel != 0) {
84  delete myModel;
85  myModel = 0;
86  }
87 }
88 
89 
90 bool
91 MSPModel::canTraverse(int dir, const ConstMSEdgeVector& route) {
92  const MSJunction* junction = 0;
93  for (ConstMSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
94  const MSEdge* edge = *it;
95  if (junction != 0) {
96  //std::cout << " junction=" << junction->getID() << " edge=" << edge->getID() << "\n";
97  if (junction == edge->getFromJunction()) {
98  dir = FORWARD;
99  } else if (junction == edge->getToJunction()) {
100  dir = BACKWARD;
101  } else {
102  return false;
103  }
104  }
105  junction = dir == FORWARD ? edge->getToJunction() : edge->getFromJunction();
106  }
107  return true;
108 }
109 
110 /****************************************************************************/
virtual void cleanupHelper()
Definition: MSPModel.h:70
static const SUMOReal SAFETY_GAP
Definition: MSPModel.h:78
The pedestrian following model.
The base class for an intersection.
Definition: MSJunction.h:64
static const int FORWARD
Definition: MSPModel.h:70
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
static MSPModel * myModel
Definition: MSPModel.h:87
The simulated network and simulation perfomer.
Definition: MSNet.h:93
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
The pedestrian following model.
Definition: MSPModel.h:54
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:80
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:75
The pedestrian following model.
static MSPModel * getModel()
Definition: MSPModel.cpp:63
static const SUMOReal SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk ...
Definition: MSPModel.h:81
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:81
A storage for options typed value containers)
Definition: OptionsCont.h:99
static const int BACKWARD
Definition: MSPModel.h:74
#define SUMOReal
Definition: config.h:214
const MSJunction * getFromJunction() const
Definition: MSEdge.h:383
const MSJunction * getToJunction() const
Definition: MSEdge.h:387
static bool canTraverse(int dir, const ConstMSEdgeVector &route)
return whether the route may traversed with the given starting direction
Definition: MSPModel.cpp:91