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 /****************************************************************************/
10 // An edge the jtr-router may route through
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2004-2014 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, unsigned 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::addFollower(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  SUMOTime 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, SUMOTime time) 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 ((veh == 0 || !(*i).first->prohibits(veh)) && (*i).second->describesTime(time)) {
94  dist.add((*i).second->getValue(time), (*i).first);
95  }
96  }
97  // if no loaded definitions are valid for this time, try to use the defaults
98  if (dist.getOverallProb() == 0) {
99  for (size_t i = 0; i < myParsedTurnings.size(); ++i) {
100  if (veh == 0 || !myFollowingEdges[i]->prohibits(veh)) {
101  dist.add(myParsedTurnings[i], static_cast<ROJTREdge*>(myFollowingEdges[i]));
102  }
103  }
104  }
105  // if still no valid follower exists, return null
106  if (dist.getOverallProb() == 0) {
107  return 0;
108  }
109  // return one of the possible followers
110  return dist.get();
111 }
112 
113 
114 void
115 ROJTREdge::setTurnDefaults(const std::vector<SUMOReal>& defs) {
116  // I hope, we'll find a less ridiculous solution for this
117  std::vector<SUMOReal> tmp(defs.size()*myFollowingEdges.size(), 0);
118  // store in less common multiple
119  size_t i;
120  for (i = 0; i < defs.size(); ++i) {
121  for (size_t j = 0; j < myFollowingEdges.size(); ++j) {
122  tmp[i * myFollowingEdges.size() + j] = (SUMOReal)(defs[i] / 100.0 / (myFollowingEdges.size()));
123  }
124  }
125  // parse from less common multiple
126  for (i = 0; i < myFollowingEdges.size(); ++i) {
127  SUMOReal value = 0;
128  for (size_t j = 0; j < defs.size(); ++j) {
129  value += tmp[i * defs.size() + j];
130  }
131  myParsedTurnings.push_back((SUMOReal) value);
132  }
133 }
134 
135 
136 
137 /****************************************************************************/
138 
FollowerUsageCont myFollowingDefs
Storage for the probabilities of using a certain follower over time.
Definition: ROJTREdge.h:117
Represents a generic random distribution.
void addFollower(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROJTREdge.cpp:61
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:49
ROJTREdge * chooseNext(const ROVehicle *const veh, SUMOTime time) 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:115
std::vector< SUMOReal > myParsedTurnings
The defaults for turnings.
Definition: ROJTREdge.h:120
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A vehicle as used by router.
Definition: ROVehicle.h:59
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:340
T get(MTRand *which=0) const
Draw a sample of the distribution.
An edge the jtr-router may route through.
Definition: ROJTREdge.h:58
A basic edge for routing applications.
Definition: ROEdge.h:69
~ROJTREdge()
Destructor.
Definition: ROJTREdge.cpp:53
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
std::vector< ROEdge * > myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:453
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:238
#define SUMOReal
Definition: config.h:215
Base class for nodes used by the router.
Definition: RONode.h:51
virtual void addFollower(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:103
void addFollowerProbability(ROJTREdge *follower, SUMOTime begTime, SUMOTime endTime, SUMOReal probability)
adds the information about the percentage of using a certain follower
Definition: ROJTREdge.cpp:71