SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2001-2014 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(bool leftHanded);
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 
106  bool mustBrake(const NBEdge* const from, const NBEdge* const to) const; // !!!
107 
114  bool mustBrakeForCrossing(const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing) const;
115 
123  bool foes(const NBEdge* const from1, const NBEdge* const to1,
124  const NBEdge* const from2, const NBEdge* const to2) const;
125 
126 
135  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
136  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
137  bool regardNonSignalisedLowerPriority) const;
138 
141  void writeLogic(std::string key, OutputDevice& into, const bool checkLaneFoes) const;
142 
144  friend std::ostream& operator<<(std::ostream& os, const NBRequest& r);
145 
147  static void reportWarnings();
148 
149 
150 private:
153  void setBlocking(bool leftHanded, NBEdge* from1, NBEdge* to1, NBEdge* from2, NBEdge* to2);
154 
157  int writeLaneResponse(OutputDevice& od, NBEdge* from, int lane,
158  int pos, const bool checkLaneFoes) const;
159 
162  int writeCrossingResponse(OutputDevice& od, const NBNode::Crossing& crossing, int pos) const;
163 
182  std::string getResponseString(const NBEdge* const from, const NBEdge* const to,
183  int fromLane, int toLane, bool mayDefinitelyPass, const bool checkLaneFoes) const;
184 
185 
187  std::string getFoesString(NBEdge* from, NBEdge* to,
188  int fromLane, int toLane, const bool checkLaneFoes) const;
189 
190 
199  int getIndex(const NBEdge* const from, const NBEdge* const to) const;
200 
201 
204  size_t distanceCounterClockwise(NBEdge* from, NBEdge* to);
205 
208  void computeRightOutgoingLinkCrossings(bool leftHanded, NBEdge* from, NBEdge* to);
209 
212  void computeLeftOutgoingLinkCrossings(bool leftHanded, NBEdge* from, NBEdge* to);
213 
214 
215  void resetSignalised();
216 
217 
219  void resetCooperating();
220 
224  bool laneConflict(const NBEdge* from, const NBEdge* to, int toLane, const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorToLane) const;
225 
228  bool rightTurnConflict(const NBEdge* from, const NBEdge* to, int fromLane, const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorFromLane) const;
229 
231  inline size_t numLinks() const;
232 
233 
234 private:
237 
240 
243 
246 
248  const std::vector<NBNode::Crossing>& myCrossings;
249 
252  typedef std::vector<bool> LinkInfoCont;
253 
256  typedef std::vector<LinkInfoCont> CombinationsCont;
257 
259  typedef std::map<NBEdge*, LaneVector> OccupiedLanes;
260 
263 
266 
267 private:
268  static size_t myGoodBuilds, myNotBuild;
269 
270 private:
272  NBRequest& operator=(const NBRequest& s);
273 };
274 
275 #endif
276 
277 /****************************************************************************/
278 
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:670
void computeLeftOutgoingLinkCrossings(bool leftHanded, NBEdge *from, NBEdge *to)
Definition: NBRequest.cpp:192
std::vector< bool > LinkInfoCont
Definition: NBRequest.h:252
bool mustBrakeForCrossing(const NBEdge *const from, const NBEdge *const to, const NBNode::Crossing &crossing) const
Returns the information whether the described flow must brake for the given crossing.
Definition: NBRequest.cpp:730
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:503
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
Definition: NBRequest.cpp:68
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:452
The representation of a single edge during network building.
Definition: NBEdge.h:71
NBNode * myJunction
the node the request is assigned to
Definition: NBRequest.h:236
The base class for traffic light logic definitions.
std::vector< LinkInfoCont > CombinationsCont
Definition: NBRequest.h:256
const EdgeVector & myOutgoing
Definition: NBRequest.h:245
NBRequest & operator=(const NBRequest &s)
Invalidated assignment operator.
void writeLogic(std::string key, OutputDevice &into, const bool checkLaneFoes) const
Definition: NBRequest.cpp:336
std::string getResponseString(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:539
size_t distanceCounterClockwise(NBEdge *from, NBEdge *to)
Definition: NBRequest.cpp:321
const EdgeVector & myIncoming
Definition: NBRequest.h:242
CombinationsCont myDone
Definition: NBRequest.h:265
static void reportWarnings()
reports warnings if any occured
Definition: NBRequest.cpp:756
bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane) const
return whether the given laneToLane connection is a right turn which must yield to pedestrian or bicy...
Definition: NBRequest.cpp:647
void buildBitfieldLogic(bool leftHanded)
Definition: NBRequest.cpp:158
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:746
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:625
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:585
const EdgeVector & myAll
Definition: NBRequest.h:239
void setBlocking(bool leftHanded, NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
Definition: NBRequest.cpp:210
std::map< NBEdge *, LaneVector > OccupiedLanes
Definition: NBRequest.h:259
size_t numLinks() const
return to total number of edge-to-edge connections of this request-logic
Definition: NBRequest.cpp:797
static size_t myNotBuild
Definition: NBRequest.h:268
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:484
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:38
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:682
const std::vector< NBNode::Crossing > & myCrossings
Definition: NBRequest.h:248
Represents a single node (junction) during network building.
Definition: NBNode.h:75
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:433
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:268
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge...
Definition: NBRequest.cpp:765
CombinationsCont myForbids
Definition: NBRequest.h:262
std::pair< unsigned int, unsigned int > getSizes() const
returns the number of the junction's lanes and the number of the junction's links in respect...
Definition: NBRequest.cpp:414
void computeRightOutgoingLinkCrossings(bool leftHanded, NBEdge *from, NBEdge *to)
Definition: NBRequest.cpp:174
void resetSignalised()
Definition: NBRequest.cpp:354