SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
10 // Copyright (C) 2014-2014 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 "MSNet.h"
34 #include "MSEdge.h"
35 #include "MSJunction.h"
36 #include "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 std::vector<const MSEdge*>& route) {
110  const MSJunction* junction = 0;
111  for (std::vector<const MSEdge*>::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 /****************************************************************************/