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-sim.org/
12 // Copyright (C) 2001-2014 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, const int priority)
49  : ROEdge(id, from, to, index, priority) {}
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  // use the loaded definitions, first
91  for (FollowerUsageCont::const_iterator i = myFollowingDefs.begin(); i != myFollowingDefs.end(); ++i) {
92  if ((veh == 0 || !(*i).first->prohibits(veh)) && (*i).second->describesTime(time)) {
93  dist.add((*i).second->getValue(time), (*i).first);
94  }
95  }
96  // if no loaded definitions are valid for this time, try to use the defaults
97  if (dist.getOverallProb() == 0) {
98  for (size_t i = 0; i < myParsedTurnings.size(); ++i) {
99  if (veh == 0 || !myFollowingEdges[i]->prohibits(veh)) {
100  dist.add(myParsedTurnings[i], static_cast<ROJTREdge*>(myFollowingEdges[i]));
101  }
102  }
103  }
104  // if still no valid follower exists, return null
105  if (dist.getOverallProb() == 0) {
106  return 0;
107  }
108  // return one of the possible followers
109  return dist.get();
110 }
111 
112 
113 void
114 ROJTREdge::setTurnDefaults(const std::vector<SUMOReal>& defs) {
115  // I hope, we'll find a less ridiculous solution for this
116  std::vector<SUMOReal> tmp(defs.size()*myFollowingEdges.size(), 0);
117  // store in less common multiple
118  size_t i;
119  for (i = 0; i < defs.size(); ++i) {
120  for (size_t j = 0; j < myFollowingEdges.size(); ++j) {
121  tmp[i * myFollowingEdges.size() + j] = (SUMOReal)(defs[i] / 100.0 / (myFollowingEdges.size()));
122  }
123  }
124  // parse from less common multiple
125  for (i = 0; i < myFollowingEdges.size(); ++i) {
126  SUMOReal value = 0;
127  for (size_t j = 0; j < defs.size(); ++j) {
128  value += tmp[i * defs.size() + j];
129  }
130  myParsedTurnings.push_back((SUMOReal) value);
131  }
132 }
133 
134 
135 
136 /****************************************************************************/
137 
FollowerUsageCont myFollowingDefs
Storage for the probabilities of using a certain follower over time.
Definition: ROJTREdge.h:116
Represents a generic random distribution.
void addFollower(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROJTREdge.cpp:60
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
ROJTREdge(const std::string &id, RONode *from, RONode *to, unsigned int index, const int priority)
Constructor.
Definition: ROJTREdge.cpp:48
ROJTREdge * chooseNext(const ROVehicle *const veh, SUMOTime time) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:82
void setTurnDefaults(const std::vector< SUMOReal > &defs)
Sets the turning definition defaults.
Definition: ROJTREdge.cpp:114
std::vector< SUMOReal > myParsedTurnings
The defaults for turnings.
Definition: ROJTREdge.h:119
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A vehicle as used by router.
Definition: ROVehicle.h:58
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:345
T get(MTRand *which=0) const
Draw a sample of the distribution.
An edge the jtr-router may route through.
Definition: ROJTREdge.h:57
A basic edge for routing applications.
Definition: ROEdge.h:67
~ROJTREdge()
Destructor.
Definition: ROJTREdge.cpp:52
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
std::vector< ROEdge * > myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:419
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:218
#define SUMOReal
Definition: config.h:215
Base class for nodes used by the router.
Definition: RONode.h:46
virtual void addFollower(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:100
void addFollowerProbability(ROJTREdge *follower, SUMOTime begTime, SUMOTime endTime, SUMOReal probability)
adds the information about the percentage of using a certain follower
Definition: ROJTREdge.cpp:70