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-2015 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 
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
56 
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  } else {
75  throw ProcessError("Unknown pedestrian model '" + model + "'");
76  }
77  }
78  return myModel;
79 }
80 
81 
82 void
84  if (myModel != 0) {
86  delete myModel;
87  myModel = 0;
88  }
89 }
90 
91 
92 MSLane*
94  if (edge == 0) {
95  return 0;
96  }
97  assert(edge->getLanes().size() > 0);
98  const std::vector<MSLane*>& lanes = edge->getLanes();
99  for (std::vector<MSLane*>::const_iterator it = lanes.begin(); it != lanes.end(); ++it) {
100  if ((*it)->allowsVehicleClass(SVC_PEDESTRIAN)) {
101  return *it;
102  }
103  }
104  return lanes.front();
105 }
106 
107 
108 bool
109 MSPModel::canTraverse(int dir, const ConstMSEdgeVector& route) {
110  const MSJunction* junction = 0;
111  for (ConstMSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
112  const MSEdge* edge = *it;
113  if (junction != 0) {
114  //std::cout << " junction=" << junction->getID() << " edge=" << edge->getID() << "\n";
115  if (junction == edge->getFromJunction()) {
116  dir = FORWARD;
117  } else if (junction == edge->getToJunction()) {
118  dir = BACKWARD;
119  } else {
120  return false;
121  }
122  }
123  junction = dir == FORWARD ? edge->getToJunction() : edge->getFromJunction();
124  }
125  return true;
126 }
127 
128 /****************************************************************************/
virtual void cleanupHelper()
Definition: MSPModel.h:73
static const SUMOReal SAFETY_GAP
Definition: MSPModel.h:81
is a pedestrian
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:186
The pedestrian following model.
The base class for an intersection.
Definition: MSJunction.h:61
static const int FORWARD
Definition: MSPModel.h:73
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
static MSLane * getSidewalk(const MSEdge *edge)
return the appropriate lane to walk on
Definition: MSPModel.cpp:93
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:79
static MSPModel * myModel
Definition: MSPModel.h:90
The simulated network and simulation perfomer.
Definition: MSNet.h:94
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
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:81
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:78
The pedestrian following model.
static MSPModel * getModel()
Definition: MSPModel.cpp:65
static const SUMOReal SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk ...
Definition: MSPModel.h:84
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:83
A storage for options typed value containers)
Definition: OptionsCont.h:108
static const int BACKWARD
Definition: MSPModel.h:77
#define SUMOReal
Definition: config.h:218
const MSJunction * getFromJunction() const
Definition: MSEdge.h:345
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
const MSJunction * getToJunction() const
Definition: MSEdge.h:349
static bool canTraverse(int dir, const ConstMSEdgeVector &route)
return whether the route may traversed with the given starting direction
Definition: MSPModel.cpp:109