SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROJTREdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // An edge the jtr-router may route through
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <algorithm>
34 #include <cassert>
37 #include "ROJTREdge.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 ROJTREdge::ROJTREdge(const std::string& id, RONode* from, RONode* to, unsigned int index)
49  : ROEdge(id, from, to, index) {}
50 
51 
53  for (FollowerUsageCont::iterator i = myFollowingDefs.begin(); i != myFollowingDefs.end(); i++) {
54  delete(*i).second;
55  }
56 }
57 
58 
59 void
60 ROJTREdge::addFollower(ROEdge* s, std::string) {
62  ROJTREdge* js = static_cast<ROJTREdge*>(s);
63  if (myFollowingDefs.find(js) == myFollowingDefs.end()) {
65  }
66 }
67 
68 
69 void
71  SUMOTime endTime, SUMOReal probability) {
72  FollowerUsageCont::iterator i = myFollowingDefs.find(follower);
73  if (i == myFollowingDefs.end()) {
74  WRITE_ERROR("The edges '" + getID() + "' and '" + follower->getID() + "' are not connected.");
75  return;
76  }
77  (*i).second->add(begTime, endTime, probability);
78 }
79 
80 
81 ROJTREdge*
82 ROJTREdge::chooseNext(const ROVehicle* const veh, SUMOTime time) const {
83  // if no usable follower exist, return 0
84  // their probabilities are not yet regarded
85  if (myFollowingEdges.size() == 0 || (veh != 0 && allFollowersProhibit(veh))) {
86  return 0;
87  }
88  // gather information about the probabilities at this time
90  {
91  // use the loaded definitions, first
92  FollowerUsageCont::const_iterator i;
93  for (i = myFollowingDefs.begin(); i != myFollowingDefs.end(); i++) {
94  if ((veh == 0 || !(*i).first->prohibits(veh)) && (*i).second->describesTime(time)) {
95  dist.add((*i).second->getValue(time), (*i).first);
96  }
97  }
98  }
99  // if no loaded definitions are valid for this time, try to use the defaults
100  if (dist.getOverallProb() == 0) {
101  for (size_t i = 0; i < myParsedTurnings.size(); ++i) {
102  if (veh == 0 || !myFollowingEdges[i]->prohibits(veh)) {
103  dist.add(myParsedTurnings[i], static_cast<ROJTREdge*>(myFollowingEdges[i]));
104  }
105  }
106  }
107  // if still no valid follower exists, return null
108  if (dist.getOverallProb() == 0) {
109  return 0;
110  }
111  // return one of the possible followers
112  return dist.get();
113 }
114 
115 
116 void
117 ROJTREdge::setTurnDefaults(const std::vector<SUMOReal> &defs) {
118  // I hope, we'll find a less ridiculous solution for this
119  std::vector<SUMOReal> tmp(defs.size()*myFollowingEdges.size(), 0);
120  // store in less common multiple
121  size_t i;
122  for (i = 0; i < defs.size(); i++) {
123  for (size_t j = 0; j < myFollowingEdges.size(); j++) {
124  tmp[i * myFollowingEdges.size() + j] = (SUMOReal)
125  (defs[i] / 100.0 / (myFollowingEdges.size()));
126  }
127  }
128  // parse from less common multiple
129  for (i = 0; i < myFollowingEdges.size(); i++) {
130  SUMOReal value = 0;
131  for (size_t j = 0; j < defs.size(); j++) {
132  value += tmp[i * defs.size() + j];
133  }
134  myParsedTurnings.push_back((SUMOReal) value);
135  }
136 }
137 
138 
139 
140 /****************************************************************************/
141