SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ROJTREdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // An edge the jtr-router may route through
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2004-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <algorithm>
35 #include <cassert>
38 #include "ROJTREdge.h"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 ROJTREdge::ROJTREdge(const std::string& id, RONode* from, RONode* to, int index, const int priority)
50  : ROEdge(id, from, to, index, priority) {}
51 
52 
54  for (FollowerUsageCont::iterator i = myFollowingDefs.begin(); i != myFollowingDefs.end(); ++i) {
55  delete(*i).second;
56  }
57 }
58 
59 
60 void
61 ROJTREdge::addSuccessor(ROEdge* s, std::string) {
63  ROJTREdge* js = static_cast<ROJTREdge*>(s);
64  if (myFollowingDefs.find(js) == myFollowingDefs.end()) {
66  }
67 }
68 
69 
70 void
72  SUMOReal endTime, SUMOReal probability) {
73  FollowerUsageCont::iterator i = myFollowingDefs.find(follower);
74  if (i == myFollowingDefs.end()) {
75  WRITE_ERROR("The edges '" + getID() + "' and '" + follower->getID() + "' are not connected.");
76  return;
77  }
78  (*i).second->add(begTime, endTime, probability);
79 }
80 
81 
82 ROJTREdge*
83 ROJTREdge::chooseNext(const ROVehicle* const veh, SUMOReal time, const std::set<const ROEdge*>& avoid) const {
84  // if no usable follower exist, return 0
85  // their probabilities are not yet regarded
86  if (myFollowingEdges.size() == 0 || (veh != 0 && allFollowersProhibit(veh))) {
87  return 0;
88  }
89  // gather information about the probabilities at this time
91  // use the loaded definitions, first
92  for (FollowerUsageCont::const_iterator i = myFollowingDefs.begin(); i != myFollowingDefs.end(); ++i) {
93  if (avoid.count(i->first) == 0) {
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 (int i = 0; i < (int)myParsedTurnings.size(); ++i) {
102  if (avoid.count(myFollowingEdges[i]) == 0) {
103  if (veh == 0 || !myFollowingEdges[i]->prohibits(veh)) {
104  dist.add(myParsedTurnings[i], static_cast<ROJTREdge*>(myFollowingEdges[i]));
105  }
106  }
107  }
108  }
109  // if still no valid follower exists, return null
110  if (dist.getOverallProb() == 0) {
111  return 0;
112  }
113  // return one of the possible followers
114  return dist.get();
115 }
116 
117 
118 void
119 ROJTREdge::setTurnDefaults(const std::vector<SUMOReal>& defs) {
120  // I hope, we'll find a less ridiculous solution for this
121  std::vector<SUMOReal> tmp(defs.size()*myFollowingEdges.size(), 0);
122  // store in less common multiple
123  for (int i = 0; i < (int)defs.size(); ++i) {
124  for (int j = 0; j < (int)myFollowingEdges.size(); ++j) {
125  tmp[i * myFollowingEdges.size() + j] = (SUMOReal)(defs[i] / 100.0 / (myFollowingEdges.size()));
126  }
127  }
128  // parse from less common multiple
129  for (int i = 0; i < (int)myFollowingEdges.size(); ++i) {
130  SUMOReal value = 0;
131  for (int j = 0; j < (int)defs.size(); ++j) {
132  value += tmp[i * defs.size() + j];
133  }
134  myParsedTurnings.push_back((SUMOReal) value);
135  }
136 }
137 
138 
139 
140 /****************************************************************************/
141 
FollowerUsageCont myFollowingDefs
Storage for the probabilities of using a certain follower over time.
Definition: ROJTREdge.h:118
Represents a generic random distribution.
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
ROJTREdge * chooseNext(const ROVehicle *const veh, SUMOReal time, const std::set< const ROEdge * > &avoid) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:83
void setTurnDefaults(const std::vector< SUMOReal > &defs)
Sets the turning definition defaults.
Definition: ROJTREdge.cpp:119
std::vector< SUMOReal > myParsedTurnings
The defaults for turnings.
Definition: ROJTREdge.h:121
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:500
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A vehicle as used by router.
Definition: ROVehicle.h:60
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:271
T get(MTRand *which=0) const
Draw a sample of the distribution.
An edge the jtr-router may route through.
Definition: ROJTREdge.h:58
void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROJTREdge.cpp:61
A basic edge for routing applications.
Definition: ROEdge.h:77
~ROJTREdge()
Destructor.
Definition: ROJTREdge.cpp:53
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
ROJTREdge(const std::string &id, RONode *from, RONode *to, int index, const int priority)
Constructor.
Definition: ROJTREdge.cpp:49
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:109
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:253
#define SUMOReal
Definition: config.h:214
Base class for nodes used by the router.
Definition: RONode.h:53
void addFollowerProbability(ROJTREdge *follower, SUMOReal begTime, SUMOReal endTime, SUMOReal probability)
adds the information about the percentage of using a certain follower
Definition: ROJTREdge.cpp:71