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 /****************************************************************************/
18 // This class computes the logic of a junction
19 /****************************************************************************/
20 #ifndef NBRequest_h
21 #define NBRequest_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <vector>
31 #include <map>
32 #include <bitset>
33 #include "NBConnectionDefs.h"
34 #include "NBContHelper.h"
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class NBEdge;
42 class NBJunctionTypeIO;
44 class OptionsCont;
46 class NBEdgeCont;
47 class OutputDevice;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
59 class NBRequest {
60 public:
66  NBRequest(const NBEdgeCont& ec,
67  NBNode* junction,
68  const EdgeVector& all,
69  const EdgeVector& incoming,
70  const EdgeVector& outgoing,
71  const NBConnectionProhibits& loadedProhibits);
72 
74  ~NBRequest();
75 
77  void buildBitfieldLogic();
78 
80  std::pair<int, int> getSizes() const;
81 
89  bool mustBrake(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
90  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo) const;
91 
92 
100  bool mustBrake(const NBEdge* const from, const NBEdge* const to, int fromLane, int toLane, bool includePedCrossings) const;
101 
109  static bool mustBrakeForCrossing(const NBNode* node, const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing);
110 
118  bool foes(const NBEdge* const from1, const NBEdge* const to1,
119  const NBEdge* const from2, const NBEdge* const to2) const;
120 
121 
130  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
131  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
132  bool regardNonSignalisedLowerPriority) const;
133 
135  void computeLogic(const bool checkLaneFoes);
136 
137  void writeLogic(OutputDevice& into) const;
138 
139  const std::string& getFoes(int linkIndex) const;
140  const std::string& getResponse(int linkIndex) const;
141 
143  friend std::ostream& operator<<(std::ostream& os, const NBRequest& r);
144 
146  static void reportWarnings();
147 
149  bool mergeConflict(const NBEdge* from, const NBEdge::Connection& con,
150  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
151 
153  bool oppositeLeftTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
154  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;
155 
156 
157 private:
160  void setBlocking(NBEdge* from1, NBEdge* to1, NBEdge* from2, NBEdge* to2);
161 
164  int computeLaneResponse(NBEdge* from, int lane, int pos, const bool checkLaneFoes);
165 
168  int computeCrossingResponse(const NBNode::Crossing& crossing, int pos);
169 
189  std::string getResponseString(const NBEdge* const from, const NBEdge::Connection& c, const bool checkLaneFoes) const;
190 
191 
193  std::string getFoesString(NBEdge* from, NBEdge* to,
194  int fromLane, int toLane, const bool checkLaneFoes) const;
195 
196 
205  int getIndex(const NBEdge* const from, const NBEdge* const to) const;
206 
207 
209  int distanceCounterClockwise(NBEdge* from, NBEdge* to);
210 
213 
216 
217 
218  void resetSignalised();
219 
221  void resetCooperating();
222 
225  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
226 
228  bool checkLaneFoesByCooperation(const NBEdge* from, const NBEdge::Connection& con,
229  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const;
230 
234  bool laneConflict(const NBEdge* from, const NBEdge* to, int toLane, const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorToLane) const;
235 
236 
238  inline int numLinks() const;
239 
240 private:
243 
246 
249 
252 
254  typedef std::vector<bool> LinkInfoCont;
255 
257  typedef std::vector<LinkInfoCont> CombinationsCont;
258 
260  CombinationsCont myForbids;
261 
263  CombinationsCont myDone;
264 
266  std::vector<std::string> myFoes;
267  std::vector<std::string> myResponse;
268  std::vector<bool> myHaveVia;
269 
270 private:
272 
274  NBRequest& operator=(const NBRequest& s) = delete;
275 };
276 
277 #endif
278 
279 /****************************************************************************/
280 
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
std::pair< int, int > getSizes() const
returns the number of the junction&#39;s lanes and the number of the junction&#39;s links in respect...
Definition: NBRequest.cpp:494
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing left of the given link
Definition: NBRequest.cpp:181
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:184
std::vector< bool > LinkInfoCont
definition of a container to store boolean informations about a link into
Definition: NBRequest.h:254
void writeLogic(OutputDevice &into) const
Definition: NBRequest.cpp:391
static int myNotBuild
Definition: NBRequest.h:271
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
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
Definition: NBRequest.cpp:58
A SUMO-compliant built logic for a traffic light.
The representation of a single edge during network building.
Definition: NBEdge.h:86
NBNode * myJunction
the node the request is assigned to
Definition: NBRequest.h:242
The base class for traffic light logic definitions.
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:612
static int myGoodBuilds
Definition: NBRequest.h:271
std::vector< LinkInfoCont > CombinationsCont
definition of a container for link(edge->edge) X link(edge->edge) combinations (size = |myIncoming|*|...
Definition: NBRequest.h:257
void buildBitfieldLogic()
builds the bitset-representation of the logic
Definition: NBRequest.cpp:147
const EdgeVector & myOutgoing
edges outgoing from the junction
Definition: NBRequest.h:251
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
Definition: NBRequest.cpp:199
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
const std::string & getFoes(int linkIndex) const
Definition: NBRequest.cpp:375
const EdgeVector & myIncoming
edges incoming to the junction
Definition: NBRequest.h:248
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
Definition: NBRequest.cpp:1051
CombinationsCont myDone
the link X link is done-checks
Definition: NBRequest.h:263
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
void computeLogic(const bool checkLaneFoes)
writes the XML-representation of the logic as a bitset-logic XML representation
Definition: NBRequest.cpp:413
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
static void reportWarnings()
reports warnings if any occurred
Definition: NBRequest.cpp:1011
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()
destructor
Definition: NBRequest.cpp:143
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:532
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing right of the given link */
Definition: NBRequest.cpp:163
std::vector< bool > myHaveVia
Definition: NBRequest.h:268
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
const std::string & getResponse(int linkIndex) const
Definition: NBRequest.cpp:383
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:513
const EdgeVector & myAll
all (icoming and outgoing) of the junctions edges
Definition: NBRequest.h:245
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
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:563
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 & operator=(const NBRequest &s)=delete
Invalidated assignment operator.
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
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:578
std::vector< std::string > myFoes
precomputed right-of-way matrices for each lane-to-lane link
Definition: NBRequest.h:266
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
A storage for options typed value containers)
Definition: OptionsCont.h:90
friend std::ostream & operator<<(std::ostream &os, const NBRequest &r)
prints the request
Definition: NBRequest.cpp:887
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
Definition: NBRequest.cpp:687
Represents a single node (junction) during network building.
Definition: NBNode.h:68
A definition of a pedestrian crossing.
Definition: NBNode.h:132
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
std::vector< std::string > myResponse
Definition: NBRequest.h:267
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
returns the distance between the incoming (from) and the outgoing (to) edge clockwise in edges ...
Definition: NBRequest.cpp:361
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge...
Definition: NBRequest.cpp:1020
CombinationsCont myForbids
the link X link blockings
Definition: NBRequest.h:260
void resetSignalised()
Definition: NBRequest.cpp:434