Eclipse SUMO - Simulation of Urban MObility
NBRequest.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // This class computes the logic of a junction
18 /****************************************************************************/
19 #ifndef NBRequest_h
20 #define NBRequest_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <bitset>
32 #include "NBConnectionDefs.h"
33 #include "NBContHelper.h"
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class NBEdge;
41 class NBJunctionTypeIO;
43 class OptionsCont;
45 class NBEdgeCont;
46 class OutputDevice;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
58 class NBRequest {
59 public:
65  NBRequest(const NBEdgeCont& ec,
66  NBNode* junction,
67  const EdgeVector& all,
68  const EdgeVector& incoming,
69  const EdgeVector& outgoing,
70  const NBConnectionProhibits& loadedProhibits);
71 
73  ~NBRequest();
74 
76  void buildBitfieldLogic();
77 
79  std::pair<int, int> getSizes() const;
80 
88  bool mustBrake(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
89  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo) const;
90 
91 
99  bool mustBrake(const NBEdge* const from, const NBEdge* const to, int fromLane, int toLane, bool includePedCrossings) const;
100 
108  static bool mustBrakeForCrossing(const NBNode* node, const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing);
109 
117  bool foes(const NBEdge* const from1, const NBEdge* const to1,
118  const NBEdge* const from2, const NBEdge* const to2) const;
119 
120 
129  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
130  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
131  bool regardNonSignalisedLowerPriority) const;
132 
134  void computeLogic(const bool checkLaneFoes);
135 
136  void writeLogic(OutputDevice& into) const;
137 
138  const std::string& getFoes(int linkIndex) const;
139  const std::string& getResponse(int linkIndex) const;
140 
142  friend std::ostream& operator<<(std::ostream& os, const NBRequest& r);
143 
145  static void reportWarnings();
146 
148  bool mergeConflict(const NBEdge* from, const NBEdge::Connection& con,
149  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
150 
152  bool oppositeLeftTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
153  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
154 
155 
156 private:
159  void setBlocking(NBEdge* from1, NBEdge* to1, NBEdge* from2, NBEdge* to2);
160 
163  int computeLaneResponse(NBEdge* from, int lane, int pos, const bool checkLaneFoes);
164 
167  int computeCrossingResponse(const NBNode::Crossing& crossing, int pos);
168 
188  std::string getResponseString(const NBEdge* const from, const NBEdge::Connection& c, const bool checkLaneFoes) const;
189 
190 
192  std::string getFoesString(NBEdge* from, NBEdge* to,
193  int fromLane, int toLane, const bool checkLaneFoes) const;
194 
195 
204  int getIndex(const NBEdge* const from, const NBEdge* const to) const;
205 
206 
208  int distanceCounterClockwise(NBEdge* from, NBEdge* to);
209 
212 
215 
216 
217  void resetSignalised();
218 
220  void resetCooperating();
221 
224  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
225 
227  bool checkLaneFoesByCooperation(const NBEdge* from, const NBEdge::Connection& con,
228  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
229 
233  bool laneConflict(const NBEdge* from, const NBEdge* to, int toLane, const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorToLane) const;
234 
235 
237  inline int numLinks() const;
238 
239 private:
242 
245 
248 
251 
253  typedef std::vector<bool> LinkInfoCont;
254 
256  typedef std::vector<LinkInfoCont> CombinationsCont;
257 
260 
263 
265  std::vector<std::string> myFoes;
266  std::vector<std::string> myResponse;
267  std::vector<bool> myHaveVia;
268 
269 private:
271 
273  NBRequest& operator=(const NBRequest& s) = delete;
274 };
275 
276 #endif
277 
278 /****************************************************************************/
279 
NBRequest::getSizes
std::pair< int, int > getSizes() const
returns the number of the junction's lanes and the number of the junction's links in respect.
Definition: NBRequest.cpp:493
NBRequest::mustBrakeForCrossing
static bool mustBrakeForCrossing(const NBNode *node, const NBEdge *const from, const NBEdge *const to, const NBNode::Crossing &crossing)
Returns the information whether the described flow must brake for the given crossing.
Definition: NBRequest.cpp:985
NBRequest::numLinks
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
Definition: NBRequest.cpp:1051
NBConnectionDefs.h
NBRequest::getIndex
int getIndex(const NBEdge *const from, const NBEdge *const to) const
Returns the index to the internal combination container for the given edge combination.
Definition: NBRequest.cpp:875
NBRequest::mustBrake
bool mustBrake(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBRequest.cpp:1001
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
NBRequest::getResponse
const std::string & getResponse(int linkIndex) const
Definition: NBRequest.cpp:382
NBRequest
Definition: NBRequest.h:58
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
NBRequest::CombinationsCont
std::vector< LinkInfoCont > CombinationsCont
definition of a container for link(edge->edge) X link(edge->edge) combinations (size = |myIncoming|*|...
Definition: NBRequest.h:256
NBRequest::myResponse
std::vector< std::string > myResponse
Definition: NBRequest.h:266
NBRequest::setBlocking
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
Definition: NBRequest.cpp:198
NBRequest::computeLaneResponse
int computeLaneResponse(NBEdge *from, int lane, int pos, const bool checkLaneFoes)
computes the response of a certain lane Returns the next link index within the junction
Definition: NBRequest.cpp:562
NBRequest::resetSignalised
void resetSignalised()
Definition: NBRequest.cpp:433
NBRequest::buildBitfieldLogic
void buildBitfieldLogic()
builds the bitset-representation of the logic
Definition: NBRequest.cpp:146
NBRequest::myIncoming
const EdgeVector & myIncoming
edges incoming to the junction
Definition: NBRequest.h:247
NBRequest::myFoes
std::vector< std::string > myFoes
precomputed right-of-way matrices for each lane-to-lane link
Definition: NBRequest.h:265
NBRequest::checkLaneFoesByClass
bool checkLaneFoesByClass(const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections must be checked for lane conflicts due to the vClasses involved
Definition: NBRequest.cpp:814
NBRequest::computeCrossingResponse
int computeCrossingResponse(const NBNode::Crossing &crossing, int pos)
computes the response of a certain crossing Returns the next link index within the junction
Definition: NBRequest.cpp:577
NBRequest::oppositeLeftTurnConflict
bool oppositeLeftTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether opposite left turns intersect
Definition: NBRequest.cpp:779
NBRequest::foes
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition: NBRequest.cpp:512
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBRequest::myHaveVia
std::vector< bool > myHaveVia
Definition: NBRequest.h:267
NBRequest::myNotBuild
static int myNotBuild
Definition: NBRequest.h:270
NBRequest::NBRequest
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
Definition: NBRequest.cpp:57
NBRequest::~NBRequest
~NBRequest()
destructor
Definition: NBRequest.cpp:142
NBRequest::LinkInfoCont
std::vector< bool > LinkInfoCont
definition of a container to store boolean informations about a link into
Definition: NBRequest.h:253
NBRequest::computeRightOutgoingLinkCrossings
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing right of the given link *‍/
Definition: NBRequest.cpp:162
NBRequest::getFoesString
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
Definition: NBRequest.cpp:687
NBRequest::computeLeftOutgoingLinkCrossings
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing left of the given link
Definition: NBRequest.cpp:180
NBRequest::distanceCounterClockwise
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
returns the distance between the incoming (from) and the outgoing (to) edge clockwise in edges
Definition: NBRequest.cpp:360
NBRequest::getFoes
const std::string & getFoes(int linkIndex) const
Definition: NBRequest.cpp:374
NBRequest::checkLaneFoesByCooperation
bool checkLaneFoesByCooperation(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections must be checked for lane conflicts due to disjunct target lanes
Definition: NBRequest.cpp:827
NBRequest::myJunction
NBNode * myJunction
the node the request is assigned to
Definition: NBRequest.h:241
UtilExceptions.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NBContHelper.h
NBRequest::myGoodBuilds
static int myGoodBuilds
Definition: NBRequest.h:270
NBRequest::forbids
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBRequest.cpp:531
NBConnectionProhibits
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
Definition: NBConnectionDefs.h:39
NBRequest::getResponseString
std::string getResponseString(const NBEdge *const from, const NBEdge::Connection &c, const bool checkLaneFoes) const
Writes the response of a certain link.
Definition: NBRequest.cpp:611
NBRequest::myOutgoing
const EdgeVector & myOutgoing
edges outgoing from the junction
Definition: NBRequest.h:250
NBRequest::writeLogic
void writeLogic(OutputDevice &into) const
Definition: NBRequest.cpp:390
NBRequest::myDone
CombinationsCont myDone
the link X link is done-checks
Definition: NBRequest.h:262
NBRequest::myAll
const EdgeVector & myAll
all (icoming and outgoing) of the junctions edges
Definition: NBRequest.h:244
NBRequest::computeLogic
void computeLogic(const bool checkLaneFoes)
writes the XML-representation of the logic as a bitset-logic XML representation
Definition: NBRequest.cpp:412
config.h
NBRequest::mergeConflict
bool mergeConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether multple connections from the same edge target the same lane
Definition: NBRequest.cpp:736
NBTrafficLightLogic
A SUMO-compliant built logic for a traffic light.
Definition: NBTrafficLightLogic.h:51
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBNode::Crossing
A definition of a pedestrian crossing.
Definition: NBNode.h:131
NBEdge::Connection
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:189
NBRequest::reportWarnings
static void reportWarnings()
reports warnings if any occurred
Definition: NBRequest.cpp:1011
NBRequest::operator=
NBRequest & operator=(const NBRequest &s)=delete
Invalidated assignment operator.
NBRequest::laneConflict
bool laneConflict(const NBEdge *from, const NBEdge *to, int toLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorToLane) const
return whether the given laneToLane connections prohibit each other under the assumption that the edg...
Definition: NBRequest.cpp:854
NBRequest::resetCooperating
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge
Definition: NBRequest.cpp:1020
NBRequest::myForbids
CombinationsCont myForbids
the link X link blockings
Definition: NBRequest.h:259
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:67
NBRequest::operator<<
friend std::ostream & operator<<(std::ostream &os, const NBRequest &r)
prints the request
Definition: NBRequest.cpp:887