Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/MSBitSetLogic.h
185785 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file MSBitSetLogic.h
15
/// @author Christian Roessel
16
/// @author Daniel Krajzewicz
17
/// @author Sascha Krieg
18
/// @author Michael Behrisch
19
/// @date Wed, 12 Dez 2001
20
///
21
// Container for holding a right-of-way matrix
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
26
#include <bitset>
27
#include <vector>
28
#include "MSJunctionLogic.h"
29
#include "MSLogicJunction.h"
30
31
32
// ===========================================================================
33
// class definitions
34
// ===========================================================================
35
/**
36
* @class MSBitSetLogic
37
*
38
* N is sum of the number of links of the junction's inLanes.
39
*/
40
template< int N >
41
class MSBitSetLogic : public MSJunctionLogic {
42
public:
43
/** @brief Container that holds the right of way bitsets.
44
Each link has its own
45
bitset. The bits in the bitsets correspond to the links. To create
46
a bitset for a particular link, set the bits to true that correspond
47
to links that have the right of way. All others set to false,
48
including the link's "own" link-bit. */
49
typedef std::vector< std::bitset< N > > Logic;
50
51
/** @brief Container holding the information which internal lanes prohibt which links
52
Build the same way as Logic */
53
typedef std::vector< std::bitset< N > > Foes;
54
55
56
public:
57
/// Use this constructor only.
58
MSBitSetLogic(int nLinks, const Logic& logic, const Foes& foes,
59
std::bitset<SUMO_MAX_CONNECTIONS> conts)
60
: MSJunctionLogic(nLinks), myLogic(logic),
61
myInternalLinksFoes(foes), myConts(conts) {}
62
63
/// @brief Returns the response for the given link
64
const MSLogicJunction::LinkBits& getResponseFor(int linkIndex) const {
65
return myLogic[linkIndex];
66
}
67
68
/// @brief Returns the foes for the given link
69
const MSLogicJunction::LinkBits& getFoesFor(int linkIndex) const {
70
return myInternalLinksFoes[linkIndex];
71
}
72
73
bool getIsCont(int linkIndex) const {
74
return myConts.test(linkIndex);
75
}
76
77
bool hasFoes() const {
78
for (const auto& i : myLogic) {
79
if (i.any()) {
80
return true;
81
}
82
}
83
return false;
84
}
85
86
private:
87
/// junctions logic based on std::bitset
88
const Logic myLogic;
89
90
/// internal lanes logic
91
const Foes myInternalLinksFoes;
92
93
const std::bitset<SUMO_MAX_CONNECTIONS> myConts;
94
95
private:
96
/// @brief Invalidated copy constructor.
97
MSBitSetLogic(const MSBitSetLogic&) = delete;
98
99
/// @brief Invalidated assignment operator.
100
MSBitSetLogic& operator=(const MSBitSetLogic&) = delete;
101
102
};
103
104
105
/** To make things easier we use a fixed size. SUMO_MAX_CONNECTIONS will hopefully be sufficient even for
106
large asian junctions.
107
So, here comes the type which should be used by the netbuilder. */
108
typedef MSBitSetLogic<SUMO_MAX_CONNECTIONS> MSBitsetLogic;
109
110