SUMO - Simulation of Urban MObility
NBRequest.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // This class computes the logic of a junction
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 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 #ifndef NBRequest_h
24 #define NBRequest_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <vector>
38 #include <map>
39 #include <bitset>
40 #include "NBConnectionDefs.h"
41 #include "NBContHelper.h"
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class NBEdge;
49 class NBJunctionTypeIO;
51 class OptionsCont;
53 class NBEdgeCont;
54 class OutputDevice;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
66 class NBRequest {
67 public:
73  NBRequest(const NBEdgeCont& ec,
74  NBNode* junction,
75  const EdgeVector& all,
76  const EdgeVector& incoming,
77  const EdgeVector& outgoing,
78  const NBConnectionProhibits& loadedProhibits);
79 
81  ~NBRequest();
82 
84  void buildBitfieldLogic();
85 
88  std::pair<unsigned int, unsigned int> getSizes() const;
89 
97  bool mustBrake(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
98  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo) const;
99 
100 
108  bool mustBrake(const NBEdge* const from, const NBEdge* const to, int fromLane, int toLane, bool includePedCrossings) const;
109 
117  static bool mustBrakeForCrossing(const NBNode* node, const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing);
118 
126  bool foes(const NBEdge* const from1, const NBEdge* const to1,
127  const NBEdge* const from2, const NBEdge* const to2) const;
128 
129 
138  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
139  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
140  bool regardNonSignalisedLowerPriority) const;
141 
144  void writeLogic(std::string key, OutputDevice& into, const bool checkLaneFoes) const;
145 
147  friend std::ostream& operator<<(std::ostream& os, const NBRequest& r);
148 
150  static void reportWarnings();
151 
153  static bool mergeConflict(const NBEdge* from, const NBEdge::Connection& con,
154  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes);
155 
156 
157 private:
160  void setBlocking(NBEdge* from1, NBEdge* to1, NBEdge* from2, NBEdge* to2);
161 
164  int writeLaneResponse(OutputDevice& od, NBEdge* from, int lane,
165  int pos, const bool checkLaneFoes) const;
166 
169  int writeCrossingResponse(OutputDevice& od, const NBNode::Crossing& crossing, int pos) const;
170 
190  std::string getResponseString(int tlIndex, const NBEdge* const from, const NBEdge* const to,
191  int fromLane, int toLane, bool mayDefinitelyPass, const bool checkLaneFoes) const;
192 
193 
195  std::string getFoesString(NBEdge* from, NBEdge* to,
196  int fromLane, int toLane, const bool checkLaneFoes) const;
197 
198 
207  int getIndex(const NBEdge* const from, const NBEdge* const to) const;
208 
209 
212  size_t distanceCounterClockwise(NBEdge* from, NBEdge* to);
213 
217 
221 
222 
223  void resetSignalised();
224 
225 
227  void resetCooperating();
228 
232  bool laneConflict(const NBEdge* from, const NBEdge* to, int toLane, const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorToLane) const;
233 
235  inline size_t numLinks() const;
236 
237 
238 private:
241 
244 
247 
250 
252  const std::vector<NBNode::Crossing>& myCrossings;
253 
256  typedef std::vector<bool> LinkInfoCont;
257 
260  typedef std::vector<LinkInfoCont> CombinationsCont;
261 
263  typedef std::map<NBEdge*, LaneVector> OccupiedLanes;
264 
266  CombinationsCont myForbids;
267 
269  CombinationsCont myDone;
270 
271 private:
272  static size_t myGoodBuilds, myNotBuild;
273 
274 private:
276  NBRequest& operator=(const NBRequest& s);
277 };
278 
279 #endif
280 
281 /****************************************************************************/
282 
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:659
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
Definition: NBRequest.cpp:190
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:148
std::vector< bool > LinkInfoCont
Definition: NBRequest.h:256
int writeCrossingResponse(OutputDevice &od, const NBNode::Crossing &crossing, int pos) const
writes the response of a certain crossing Returns the next link index within the junction ...
Definition: NBRequest.cpp:495
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
Definition: NBRequest.cpp:66
A SUMO-compliant built logic for a traffic light.
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:441
The representation of a single edge during network building.
Definition: NBEdge.h:70
NBNode * myJunction
the node the request is assigned to
Definition: NBRequest.h:240
The base class for traffic light logic definitions.
std::vector< LinkInfoCont > CombinationsCont
Definition: NBRequest.h:260
void buildBitfieldLogic()
Definition: NBRequest.cpp:156
const EdgeVector & myOutgoing
Definition: NBRequest.h:249
static bool mergeConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes)
whether multple connections from the same edge target the same lane
Definition: NBRequest.cpp:624
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
Definition: NBRequest.cpp:208
NBRequest & operator=(const NBRequest &s)
Invalidated assignment operator.
void writeLogic(std::string key, OutputDevice &into, const bool checkLaneFoes) const
Definition: NBRequest.cpp:325
size_t distanceCounterClockwise(NBEdge *from, NBEdge *to)
Definition: NBRequest.cpp:310
const EdgeVector & myIncoming
Definition: NBRequest.h:246
CombinationsCont myDone
Definition: NBRequest.h:269
static void reportWarnings()
reports warnings if any occured
Definition: NBRequest.cpp:775
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:749
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:765
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:637
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
Definition: NBRequest.cpp:172
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
Definition: NBRequest.cpp:582
const EdgeVector & myAll
Definition: NBRequest.h:243
std::map< NBEdge *, LaneVector > OccupiedLanes
Definition: NBRequest.h:263
size_t numLinks() const
return to total number of edge-to-edge connections of this request-logic
Definition: NBRequest.cpp:816
static size_t myNotBuild
Definition: NBRequest.h:272
std::string getResponseString(int tlIndex, const NBEdge *const from, const NBEdge *const to, int fromLane, int toLane, bool mayDefinitelyPass, const bool checkLaneFoes) const
Writes the response of a certain link.
Definition: NBRequest.cpp:531
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
int writeLaneResponse(OutputDevice &od, NBEdge *from, int lane, int pos, const bool checkLaneFoes) const
writes the response of a certain lane Returns the next link index within the junction ...
Definition: NBRequest.cpp:473
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
A storage for options typed value containers)
Definition: OptionsCont.h:108
friend std::ostream & operator<<(std::ostream &os, const NBRequest &r)
prints the request
Definition: NBRequest.cpp:671
const std::vector< NBNode::Crossing > & myCrossings
Definition: NBRequest.h:252
Represents a single node (junction) during network building.
Definition: NBNode.h:74
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:422
A definition of a pedestrian crossing.
Definition: NBNode.h:132
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
static size_t myGoodBuilds
Definition: NBRequest.h:272
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge...
Definition: NBRequest.cpp:784
CombinationsCont myForbids
Definition: NBRequest.h:266
std::pair< unsigned int, unsigned 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:403
void resetSignalised()
Definition: NBRequest.cpp:343