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-2020 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 
157 
159  bool hasConflict() const;
160 
162  bool hasConflictAtLink(int linkIndex) const;
163 
164 private:
167  void setBlocking(NBEdge* from1, NBEdge* to1, NBEdge* from2, NBEdge* to2);
168 
171  int computeLaneResponse(NBEdge* from, int lane, int pos, const bool checkLaneFoes);
172 
175  int computeCrossingResponse(const NBNode::Crossing& crossing, int pos);
176 
196  std::string getResponseString(const NBEdge* const from, const NBEdge::Connection& c, const bool checkLaneFoes) const;
197 
198 
200  std::string getFoesString(NBEdge* from, NBEdge* to,
201  int fromLane, int toLane, const bool checkLaneFoes) const;
202 
203 
212  int getIndex(const NBEdge* const from, const NBEdge* const to) const;
213 
214 
216  int distanceCounterClockwise(NBEdge* from, NBEdge* to);
217 
220 
223 
224 
225  void resetSignalised();
226 
228  void resetCooperating();
229 
232  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
233 
235  bool checkLaneFoesByCooperation(const NBEdge* from, const NBEdge::Connection& con,
236  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
237 
241  bool laneConflict(const NBEdge* from, const NBEdge* to, int toLane, const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorToLane) const;
242 
243 
245  inline int numLinks() const;
246 
247 private:
250 
253 
256 
259 
261  typedef std::vector<bool> LinkInfoCont;
262 
264  typedef std::vector<LinkInfoCont> CombinationsCont;
265 
268 
271 
273  std::vector<std::string> myFoes;
274  std::vector<std::string> myResponse;
275  std::vector<bool> myHaveVia;
276 
277 private:
279 
281  NBRequest& operator=(const NBRequest& s) = delete;
282 };
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:34
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:91
A definition of a pedestrian crossing.
Definition: NBNode.h:129
Represents a single node (junction) during network building.
Definition: NBNode.h:66
std::vector< std::string > myResponse
Definition: NBRequest.h:274
const EdgeVector & myOutgoing
edges outgoing from the junction
Definition: NBRequest.h:258
CombinationsCont myForbids
the link X link blockings
Definition: NBRequest.h:267
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:561
CombinationsCont myDone
the link X link is done-checks
Definition: NBRequest.h:270
const EdgeVector & myAll
all (icoming and outgoing) of the junctions edges
Definition: NBRequest.h:252
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:847
std::vector< std::string > myFoes
precomputed right-of-way matrices for each lane-to-lane link
Definition: NBRequest.h:273
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
returns the distance between the incoming (from) and the outgoing (to) edge clockwise in edges
Definition: NBRequest.cpp:359
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:530
bool hasConflictAtLink(int linkIndex) const
whether there are conflicting streams of traffic for the given link index
Definition: NBRequest.cpp:1082
const EdgeVector & myIncoming
edges incoming to the junction
Definition: NBRequest.h:255
NBNode * myJunction
the node the request is assigned to
Definition: NBRequest.h:249
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
Definition: NBRequest.cpp:1087
const std::string & getFoes(int linkIndex) const
Definition: NBRequest.cpp:373
bool hasConflict() const
whether there are conflicting streams of traffic at this node
Definition: NBRequest.cpp:1072
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
Definition: NBRequest.cpp:692
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:799
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:874
void resetSignalised()
Definition: NBRequest.cpp:432
friend std::ostream & operator<<(std::ostream &os, const NBRequest &r)
prints the request
Definition: NBRequest.cpp:907
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:895
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:1005
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:754
void writeLogic(OutputDevice &into) const
Definition: NBRequest.cpp:389
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:411
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:610
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:492
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:1021
const std::string & getResponse(int linkIndex) const
Definition: NBRequest.cpp:381
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:576
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:834
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge
Definition: NBRequest.cpp:1040
~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:511
static int myNotBuild
Definition: NBRequest.h:278
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:741
static void reportWarnings()
reports warnings if any occurred
Definition: NBRequest.cpp:1031
NBRequest & operator=(const NBRequest &s)=delete
Invalidated assignment operator.
static int myGoodBuilds
Definition: NBRequest.h:278
std::vector< bool > LinkInfoCont
definition of a container to store boolean informations about a link into
Definition: NBRequest.h:261
std::vector< bool > myHaveVia
Definition: NBRequest.h:275
std::vector< LinkInfoCont > CombinationsCont
definition of a container for link(edge->edge) X link(edge->edge) combinations (size = |myIncoming|*|...
Definition: NBRequest.h:264
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:60
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:188