SUMO - Simulation of Urban MObility
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-2017 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 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 ROJTREdge::ROJTREdge(const std::string& id, RONode* from, RONode* to, int index, const int priority)
46  : ROEdge(id, from, to, index, priority) {}
47 
48 
50  for (FollowerUsageCont::iterator i = myFollowingDefs.begin(); i != myFollowingDefs.end(); ++i) {
51  delete(*i).second;
52  }
53 }
54 
55 
56 void
57 ROJTREdge::addSuccessor(ROEdge* s, std::string) {
59  ROJTREdge* js = static_cast<ROJTREdge*>(s);
60  if (myFollowingDefs.find(js) == myFollowingDefs.end()) {
62  }
63 }
64 
65 
66 void
67 ROJTREdge::addFollowerProbability(ROJTREdge* follower, double begTime,
68  double endTime, double probability) {
69  FollowerUsageCont::iterator i = myFollowingDefs.find(follower);
70  if (i == myFollowingDefs.end()) {
71  WRITE_ERROR("The edges '" + getID() + "' and '" + follower->getID() + "' are not connected.");
72  return;
73  }
74  (*i).second->add(begTime, endTime, probability);
75 }
76 
77 
78 ROJTREdge*
79 ROJTREdge::chooseNext(const ROVehicle* const veh, double time, const std::set<const ROEdge*>& avoid) const {
80  // if no usable follower exist, return 0
81  // their probabilities are not yet regarded
82  if (myFollowingEdges.size() == 0 || (veh != 0 && allFollowersProhibit(veh))) {
83  return 0;
84  }
85  // gather information about the probabilities at this time
87  // use the loaded definitions, first
88  for (FollowerUsageCont::const_iterator i = myFollowingDefs.begin(); i != myFollowingDefs.end(); ++i) {
89  if (avoid.count(i->first) == 0) {
90  if ((veh == 0 || !(*i).first->prohibits(veh)) && (*i).second->describesTime(time)) {
91  dist.add((*i).first, (*i).second->getValue(time));
92  }
93  }
94  }
95  // if no loaded definitions are valid for this time, try to use the defaults
96  if (dist.getOverallProb() == 0) {
97  for (int i = 0; i < (int)myParsedTurnings.size(); ++i) {
98  if (avoid.count(myFollowingEdges[i]) == 0) {
99  if (veh == 0 || !myFollowingEdges[i]->prohibits(veh)) {
100  dist.add(static_cast<ROJTREdge*>(myFollowingEdges[i]), myParsedTurnings[i]);
101  }
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<double>& defs) {
116  // I hope, we'll find a less ridiculous solution for this
117  std::vector<double> tmp(defs.size()*myFollowingEdges.size(), 0);
118  // store in less common multiple
119  for (int i = 0; i < (int)defs.size(); ++i) {
120  for (int j = 0; j < (int)myFollowingEdges.size(); ++j) {
121  tmp[i * myFollowingEdges.size() + j] = (double)(defs[i] / 100.0 / (myFollowingEdges.size()));
122  }
123  }
124  // parse from less common multiple
125  for (int i = 0; i < (int)myFollowingEdges.size(); ++i) {
126  double value = 0;
127  for (int j = 0; j < (int)defs.size(); ++j) {
128  value += tmp[i * defs.size() + j];
129  }
130  myParsedTurnings.push_back((double) value);
131  }
132 }
133 
134 
135 
136 /****************************************************************************/
137 
FollowerUsageCont myFollowingDefs
Storage for the probabilities of using a certain follower over time.
Definition: ROJTREdge.h:118
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:267
Represents a generic random distribution.
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:263
const std::string & getID() const
Returns the id.
Definition: Named.h:66
std::vector< double > myParsedTurnings
The defaults for turnings.
Definition: ROJTREdge.h:121
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:510
A vehicle as used by router.
Definition: ROVehicle.h:60
An edge the jtr-router may route through.
Definition: ROJTREdge.h:58
void addFollowerProbability(ROJTREdge *follower, double begTime, double endTime, double probability)
adds the information about the percentage of using a certain follower
Definition: ROJTREdge.cpp:67
void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROJTREdge.cpp:57
A basic edge for routing applications.
Definition: ROEdge.h:77
T get(MTRand *which=0) const
Draw a sample of the distribution.
~ROJTREdge()
Destructor.
Definition: ROJTREdge.cpp:49
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
ROJTREdge(const std::string &id, RONode *from, RONode *to, int index, const int priority)
Constructor.
Definition: ROJTREdge.cpp:45
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:105
void setTurnDefaults(const std::vector< double > &defs)
Sets the turning definition defaults.
Definition: ROJTREdge.cpp:115
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
ROJTREdge * chooseNext(const ROVehicle *const veh, double time, const std::set< const ROEdge *> &avoid) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:79
Base class for nodes used by the router.
Definition: RONode.h:53
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.