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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // This class computes the logic of a junction
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <string>
27 #include <vector>
28 #include <map>
29 #include <bitset>
30 #include "NBConnectionDefs.h"
31 #include "NBContHelper.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class NBEdge;
39 class NBJunctionTypeIO;
41 class OptionsCont;
43 class NBEdgeCont;
44 class OutputDevice;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
56 class NBRequest {
57 public:
63  NBRequest(const NBEdgeCont& ec,
64  NBNode* junction,
65  const EdgeVector& all,
66  const EdgeVector& incoming,
67  const EdgeVector& outgoing,
68  const NBConnectionProhibits& loadedProhibits);
69 
71  ~NBRequest();
72 
74  void buildBitfieldLogic();
75 
77  std::pair<int, int> getSizes() const;
78 
86  bool mustBrake(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
87  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo) const;
88 
89 
97  bool mustBrake(const NBEdge* const from, const NBEdge* const to, int fromLane, int toLane, bool includePedCrossings) const;
98 
106  static bool mustBrakeForCrossing(const NBNode* node, const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing);
107 
115  bool foes(const NBEdge* const from1, const NBEdge* const to1,
116  const NBEdge* const from2, const NBEdge* const to2) const;
117 
118 
127  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
128  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
129  bool regardNonSignalisedLowerPriority) const;
130 
132  void computeLogic(const bool checkLaneFoes);
133 
134  void writeLogic(OutputDevice& into) const;
135 
136  const std::string& getFoes(int linkIndex) const;
137  const std::string& getResponse(int linkIndex) const;
138 
140  friend std::ostream& operator<<(std::ostream& os, const NBRequest& r);
141 
143  static void reportWarnings();
144 
146  bool rightTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
147  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
148 
150  bool mergeConflict(const NBEdge* from, const NBEdge::Connection& con,
151  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
152 
154  bool oppositeLeftTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
155  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
156 
158  bool indirectLeftTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
159  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
160 
162  bool bidiConflict(const NBEdge* from, const NBEdge::Connection& con,
163  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
164 
165 
167  bool hasConflict() const;
168 
170  bool hasConflictAtLink(int linkIndex) const;
171 
172 private:
175  void setBlocking(NBEdge* from1, NBEdge* to1, NBEdge* from2, NBEdge* to2);
176 
179  int computeLaneResponse(NBEdge* from, int lane, int pos, const bool checkLaneFoes);
180 
183  int computeCrossingResponse(const NBNode::Crossing& crossing, int pos);
184 
204  std::string getResponseString(const NBEdge* const from, const NBEdge::Connection& c, const bool checkLaneFoes) const;
205 
206 
208  std::string getFoesString(NBEdge* from, NBEdge* to,
209  int fromLane, int toLane, const bool checkLaneFoes) const;
210 
211 
220  int getIndex(const NBEdge* const from, const NBEdge* const to) const;
221 
222 
224  int distanceCounterClockwise(NBEdge* from, NBEdge* to);
225 
228 
231 
232 
233  void resetSignalised();
234 
236  void resetCooperating();
237 
240  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
241 
243  bool checkLaneFoesByCooperation(const NBEdge* from, const NBEdge::Connection& con,
244  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
245 
249  bool laneConflict(const NBEdge* from, const NBEdge* to, int toLane, const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorToLane) const;
250 
251 
253  inline int numLinks() const;
254 
255 private:
258 
261 
264 
267 
269  typedef std::vector<bool> LinkInfoCont;
270 
272  typedef std::vector<LinkInfoCont> CombinationsCont;
273 
276 
279 
281  std::vector<std::string> myFoes;
282  std::vector<std::string> myResponse;
283  std::vector<bool> myHaveVia;
284 
285 private:
287 
289  NBRequest& operator=(const NBRequest& s) = delete;
290 };
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
The representation of a single edge during network building.
Definition: NBEdge.h:92
A definition of a pedestrian crossing.
Definition: NBNode.h:135
Represents a single node (junction) during network building.
Definition: NBNode.h:66
std::vector< std::string > myResponse
Definition: NBRequest.h:282
const EdgeVector & myOutgoing
edges outgoing from the junction
Definition: NBRequest.h:266
CombinationsCont myForbids
the link X link blockings
Definition: NBRequest.h:275
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:570
CombinationsCont myDone
the link X link is done-checks
Definition: NBRequest.h:278
const EdgeVector & myAll
all (icoming and outgoing) of the junctions edges
Definition: NBRequest.h:260
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:921
std::vector< std::string > myFoes
precomputed right-of-way matrices for each lane-to-lane link
Definition: NBRequest.h:281
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
returns the distance between the incoming (from) and the outgoing (to) edge clockwise in edges
Definition: NBRequest.cpp:369
bool bidiConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether straight connections are in conflict via bidirectional lane use
Definition: NBRequest.cpp:874
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:539
bool hasConflictAtLink(int linkIndex) const
whether there are conflicting streams of traffic for the given link index
Definition: NBRequest.cpp:1155
const EdgeVector & myIncoming
edges incoming to the junction
Definition: NBRequest.h:263
NBNode * myJunction
the node the request is assigned to
Definition: NBRequest.h:257
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
Definition: NBRequest.cpp:1160
const std::string & getFoes(int linkIndex) const
Definition: NBRequest.cpp:383
bool hasConflict() const
whether there are conflicting streams of traffic at this node
Definition: NBRequest.cpp:1145
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
Definition: NBRequest.cpp:715
void buildBitfieldLogic()
builds the bitset-representation of the logic
Definition: NBRequest.cpp:145
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:822
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:948
void resetSignalised()
Definition: NBRequest.cpp:442
bool indirectLeftTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether straight and indirect left turn are in conflict
Definition: NBRequest.cpp:857
friend std::ostream & operator<<(std::ostream &os, const NBRequest &r)
prints the request
Definition: NBRequest.cpp:981
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:969
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:1079
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing right of the given link *‍/
Definition: NBRequest.cpp:161
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:777
void writeLogic(OutputDevice &into) const
Definition: NBRequest.cpp:399
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
Definition: NBRequest.cpp:56
void computeLogic(const bool checkLaneFoes)
writes the XML-representation of the logic as a bitset-logic XML representation
Definition: NBRequest.cpp:421
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:617
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:502
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:1095
const std::string & getResponse(int linkIndex) const
Definition: NBRequest.cpp:391
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:585
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
Definition: NBRequest.cpp:197
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing left of the given link
Definition: NBRequest.cpp:179
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:906
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge
Definition: NBRequest.cpp:1114
~NBRequest()
destructor
Definition: NBRequest.cpp:141
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:520
static int myNotBuild
Definition: NBRequest.h:286
bool rightTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections crosses the foe connection from the same lane and must yield
Definition: NBRequest.cpp:764
static void reportWarnings()
reports warnings if any occurred
Definition: NBRequest.cpp:1105
NBRequest & operator=(const NBRequest &s)=delete
Invalidated assignment operator.
static int myGoodBuilds
Definition: NBRequest.h:286
std::vector< bool > LinkInfoCont
definition of a container to store boolean informations about a link into
Definition: NBRequest.h:269
std::vector< bool > myHaveVia
Definition: NBRequest.h:283
std::vector< LinkInfoCont > CombinationsCont
definition of a container for link(edge->edge) X link(edge->edge) combinations (size = |myIncoming|*|...
Definition: NBRequest.h:272
The base class for traffic light logic definitions.
A SUMO-compliant built logic for a traffic light.
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:201