SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSBitSetLogic.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // »missingDescription«/****************************************************************************/ // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/ // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors /****************************************************************************/ // // This file is part of SUMO. // SUMO is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // /****************************************************************************/ #ifndef MSBitSetLogic_h #define MSBitSetLogic_h // =========================================================================== // included modules // =========================================================================== #ifdef _MSC_VER #include <windows_config.h> #else #include <config.h> #endif #include <bitset> #include <vector> #include "MSJunctionLogic.h" #include "MSLogicJunction.h" // =========================================================================== // class definitions // =========================================================================== /** * @class MSBitSetLogic * * N is sum of the number of links of the junction's inLanes. */ template< size_t N > class MSBitSetLogic : public MSJunctionLogic { public: /** @brief Container that holds the right of way bitsets. Each link has it's own bitset. The bits in the bitsets correspond to the links. To create a bitset for a particular link, set the bits to true that correspond to links that have the right of way. All others set to false, including the link's "own" link-bit. */ typedef std::vector< std::bitset< N > > Logic; /** @brief Container holding the information which internal lanes prohibt which links Build the same way as Logic */ typedef std::vector< std::bitset< N > > Foes; public: /// Use this constructor only. MSBitSetLogic(unsigned int nLinks, Logic* logic, Foes* foes, std::bitset<64> conts) : MSJunctionLogic(nLinks), myLogic(logic), myInternalLinksFoes(foes), myConts(conts) {} /// Destructor. ~MSBitSetLogic() { delete myLogic; delete myInternalLinksFoes; } /// Returns the foes of the given link const MSLogicJunction::LinkFoes& getFoesFor(unsigned int linkIndex) const { return (*myLogic)[linkIndex]; } const std::bitset<64>& getInternalFoesFor(unsigned int linkIndex) const { return (*myInternalLinksFoes)[linkIndex]; } bool getIsCont(unsigned int linkIndex) const { return myConts.test(linkIndex); } virtual bool isCrossing() const { for (typename Logic::const_iterator i = myLogic->begin(); i != myLogic->end(); ++i) { if ((*i).any()) { return true; } } return false; } private: /// junctions logic based on std::bitset Logic* myLogic; /// internal lanes logic Foes* myInternalLinksFoes; std::bitset<64> myConts; private: /// @brief Invalidated copy constructor. MSBitSetLogic(const MSBitSetLogic&); /// @brief Invalidated assignment operator. MSBitSetLogic& operator=(const MSBitSetLogic&); }; /** To make things easier we use a fixed size. 64 will be sufficient even for pathological junctions. If it will consume to much space, reduce it to 32. So, here comes the type which should be used by the netbuilder. */ typedef MSBitSetLogic< 64 > MSBitsetLogic; #endif /****************************************************************************/
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2013 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 MSBitSetLogic_h
24 #define MSBitSetLogic_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 <bitset>
37 #include <vector>
38 #include "MSJunctionLogic.h"
39 #include "MSLogicJunction.h"
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
50 template< size_t N >
52 public:
59  typedef std::vector< std::bitset< N > > Logic;
60 
63  typedef std::vector< std::bitset< N > > Foes;
64 
65 
66 public:
68  MSBitSetLogic(unsigned int nLinks,
69  Logic* logic,
70  Foes* foes,
71  std::bitset<64> conts)
72  : MSJunctionLogic(nLinks), myLogic(logic),
73  myInternalLinksFoes(foes), myConts(conts) {}
74 
75 
78  delete myLogic;
79  delete myInternalLinksFoes;
80  }
81 
82 
84  const MSLogicJunction::LinkFoes& getFoesFor(unsigned int linkIndex) const {
85  return (*myLogic)[linkIndex];
86  }
87 
88  const std::bitset<64>& getInternalFoesFor(unsigned int linkIndex) const {
89  return (*myInternalLinksFoes)[linkIndex];
90  }
91 
92  bool getIsCont(unsigned int linkIndex) const {
93  return myConts.test(linkIndex);
94  }
95 
96  virtual bool isCrossing() const {
97  for (typename Logic::const_iterator i = myLogic->begin(); i != myLogic->end(); ++i) {
98  if ((*i).any()) {
99  return true;
100  }
101  }
102  return false;
103  }
104 
105 private:
108 
111 
112  std::bitset<64> myConts;
113 
114 private:
117 
120 
121 };
122 
123 
128 
129 
130 #endif
131 
132 /****************************************************************************/
133 
MSBitSetLogic(unsigned int nLinks, Logic *logic, Foes *foes, std::bitset< 64 > conts)
Use this constructor only.
Definition: MSBitSetLogic.h:68
virtual bool isCrossing() const
Definition: MSBitSetLogic.h:96
unsigned int nLinks()
Returns the logic&#39;s number of links.
Logic * myLogic
junctions logic based on std::bitset
bool getIsCont(unsigned int linkIndex) const
Definition: MSBitSetLogic.h:92
~MSBitSetLogic()
Destructor.
Definition: MSBitSetLogic.h:77
MSBitSetLogic & operator=(const MSBitSetLogic &)
Invalidated assignment operator.
std::vector< std::bitset< N > > Foes
Container holding the information which internal lanes prohibt which links Build the same way as Logi...
Definition: MSBitSetLogic.h:63
std::bitset< 64 > myConts
MSBitSetLogic< 64 > MSBitsetLogic
std::bitset< 64 > LinkFoes
Container for link foes.
std::vector< std::bitset< N > > Logic
Container that holds the right of way bitsets. Each link has it&#39;s own bitset. The bits in the bitsets...
Definition: MSBitSetLogic.h:59
Foes * myInternalLinksFoes
internal lanes logic
const MSLogicJunction::LinkFoes & getFoesFor(unsigned int linkIndex) const
Returns the foes of the given link.
Definition: MSBitSetLogic.h:84
const std::bitset< 64 > & getInternalFoesFor(unsigned int linkIndex) const
Definition: MSBitSetLogic.h:88