/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file MSBitSetLogic.h14/// @author Christian Roessel15/// @author Daniel Krajzewicz16/// @author Sascha Krieg17/// @author Michael Behrisch18/// @date Wed, 12 Dez 200119///20// Container for holding a right-of-way matrix21/****************************************************************************/22#pragma once23#include <config.h>2425#include <bitset>26#include <vector>27#include "MSJunctionLogic.h"28#include "MSLogicJunction.h"293031// ===========================================================================32// class definitions33// ===========================================================================34/**35* @class MSBitSetLogic36*37* N is sum of the number of links of the junction's inLanes.38*/39template< int N >40class MSBitSetLogic : public MSJunctionLogic {41public:42/** @brief Container that holds the right of way bitsets.43Each link has its own44bitset. The bits in the bitsets correspond to the links. To create45a bitset for a particular link, set the bits to true that correspond46to links that have the right of way. All others set to false,47including the link's "own" link-bit. */48typedef std::vector< std::bitset< N > > Logic;4950/** @brief Container holding the information which internal lanes prohibt which links51Build the same way as Logic */52typedef std::vector< std::bitset< N > > Foes;535455public:56/// Use this constructor only.57MSBitSetLogic(int nLinks, const Logic& logic, const Foes& foes,58std::bitset<SUMO_MAX_CONNECTIONS> conts)59: MSJunctionLogic(nLinks), myLogic(logic),60myInternalLinksFoes(foes), myConts(conts) {}6162/// @brief Returns the response for the given link63const MSLogicJunction::LinkBits& getResponseFor(int linkIndex) const {64return myLogic[linkIndex];65}6667/// @brief Returns the foes for the given link68const MSLogicJunction::LinkBits& getFoesFor(int linkIndex) const {69return myInternalLinksFoes[linkIndex];70}7172bool getIsCont(int linkIndex) const {73return myConts.test(linkIndex);74}7576bool hasFoes() const {77for (const auto& i : myLogic) {78if (i.any()) {79return true;80}81}82return false;83}8485private:86/// junctions logic based on std::bitset87const Logic myLogic;8889/// internal lanes logic90const Foes myInternalLinksFoes;9192const std::bitset<SUMO_MAX_CONNECTIONS> myConts;9394private:95/// @brief Invalidated copy constructor.96MSBitSetLogic(const MSBitSetLogic&) = delete;9798/// @brief Invalidated assignment operator.99MSBitSetLogic& operator=(const MSBitSetLogic&) = delete;100101};102103104/** To make things easier we use a fixed size. SUMO_MAX_CONNECTIONS will hopefully be sufficient even for105large asian junctions.106So, here comes the type which should be used by the netbuilder. */107typedef MSBitSetLogic<SUMO_MAX_CONNECTIONS> MSBitsetLogic;108109110