/****************************************************************************/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 NBDistrict.h14/// @author Daniel Krajzewicz15/// @author Sascha Krieg16/// @author Michael Behrisch17/// @date Sept 200218///19// A class representing a single district20/****************************************************************************/21#pragma once22#include <config.h>2324#include <vector>25#include <string>26#include <utility>27#include "NBCont.h"28#include <utils/common/Named.h>29#include <utils/common/VectorHelper.h>30#include <utils/geom/Position.h>31#include <utils/geom/PositionVector.h>323334// ===========================================================================35// class declarations36// ===========================================================================37class NBEdge;38class OutputDevice;394041// ===========================================================================42// class definitions43// ===========================================================================44/**45* @class NBDistrict46* @brief A class representing a single district47*48* A "district" is an area within the network which may be referenced by49* O/D-matrices. It stems from importing VISUM-networks. Work with VISUM-50* -networks also made it necessary that a district knows the edges at51* which new vehicles shall approach the simulated network (sources) and52* those to use when leaving the network (sinks). These connections to the53* network are weighted.54*55* Later work on VISUM required also parsing the shape of a district. This56* information is used by some external tools only, it is even not shown57* within the GUI.58*59* @todo Recheck whether this can be somehow joined with ODDistrict60*/61class NBDistrict : public Named {62public:63/** @brief Constructor with id, and position64*65* @param[in] id The id of the district66* @param[in] pos The position of the district67*/68NBDistrict(const std::string& id, const Position& pos);697071/** @brief Constructor without position72*73* The position must be computed later74*75* @param[in] id The id of the district76*/77NBDistrict(const std::string& id);787980/// @brief Destructor81~NBDistrict();828384/** @brief Adds a source85*86* It is checked whether the edge has already been added as a source. false87* is returned in this case. Otherwise, the source is pushed into88* the list of sources and the weight into the list of source weights.89* both lists stay sorted this way. true is returned.90*91* @param[in] source An edge that shall be used as source92* @param[in] weight The weight of the source93* @return Whether the source could be added (was not added before)94* @todo Consider using only one list for sources/weights95*/96bool addSource(NBEdge* const source, double weight);979899/** @brief Adds a sink100*101* It is checked whether the edge has already been added as a sink. false102* is returned in this case. Otherwise, the sink is pushed into103* the list of sink and the weight into the list of sink weights.104* both lists stay sorted this way. true is returned.105*106* @param[in] sink An edge that shall be used as sink107* @param[in] weight The weight of the sink108* @return Whether the sink could be added (was not added before)109* @todo Consider using only one list for sinks/weights110*/111bool addSink(NBEdge* const sink, double weight);112113114/** @brief Returns the position of this district's center115*116* @return The position of this district's center117* @todo Recheck when this information is set/needed118*/119const Position& getPosition() const {120return myPosition;121}122123124/** @brief Sets the center coordinates125*126* @param[in] pos The new center to assign127* @todo Recheck when this information is set/needed128*/129void setCenter(const Position& pos);130131132/** @brief Replaces incoming edges from the vector (sinks) by the given edge133*134* When an edge is split/joined/removed/etc., it may get necessary to replace prior135* edges by new ones. This method replaces all occurrences of the edges from136* "which" within incoming edges (sinks) by the given edge.137*138* The new sink edge's weight is the sum of the weights of the replaced edges.139*140* @param[in] which List of edges to replace141* @param[in] by The replacement142*/143void replaceIncoming(const EdgeVector& which, NBEdge* const by);144145146/** @brief Replaces outgoing edges from the vector (source) by the given edge147*148* When an edge is split/joined/removed/etc., it may get necessary to replace prior149* edges by new ones. This method replaces all occurrences of the edges from150* "which" within outgoing edges (sources) by the given edge.151*152* The new source edge's weight is the sum of the weights of the replaced edges.153*154* @param[in] which List of edges to replace155* @param[in] by The replacement156*/157void replaceOutgoing(const EdgeVector& which, NBEdge* const by);158159160/** @brief Removes the given edge from the lists of sources and sinks161*162* The according weights are removed, too.163*164* @param[in] e The edge to remove from sinks/sources165*/166void removeFromSinksAndSources(NBEdge* const e);167168169/** @brief Sets the shape of this district170*171* @param[in] p The new shape172*/173void addShape(const PositionVector& p);174175176/** @brief Returns the weights of the sources177* @return The source weights178*/179const std::vector<double>& getSourceWeights() const {180return mySourceWeights;181}182183184/** @brief Returns the sources185* @return The source edges186*/187const std::vector<NBEdge*>& getSourceEdges() const {188return mySources;189}190191192/** @brief Returns the weights of the sinks193* @return The sink weights194*/195const std::vector<double>& getSinkWeights() const {196return mySinkWeights;197}198199200/** @brief Returns the sinks201* @return The sink edges202*/203const std::vector<NBEdge*>& getSinkEdges() const {204return mySinks;205}206207208/** @brief Returns the shape209* @return The district's shape210*/211const PositionVector& getShape() const {212return myShape;213}214215216217/// @name Applying offset218/// @{219220/** @brief Applies an offset to the district221* @param[in] xoff The x-offset to apply222* @param[in] yoff The y-offset to apply223*/224void reshiftPosition(double xoff, double yoff);225226/// @brief mirror coordinates along the x-axis227void mirrorX();228/// @}229230231232233234private:235/// @brief Definition of a vector of connection weights236typedef std::vector<double> WeightsCont;237238/// @brief The sources (connection from district to network)239EdgeVector mySources;240241/// @brief The weights of the sources242WeightsCont mySourceWeights;243244/// @brief The sinks (connection from network to district)245EdgeVector mySinks;246247/// @brief The weights of the sinks248WeightsCont mySinkWeights;249250/// @brief The position of the district251Position myPosition;252253/// @brief The shape of the dsitrict254PositionVector myShape;255256257private:258/** invalid copy constructor */259NBDistrict(const NBDistrict& s);260261/** invalid assignment operator */262NBDistrict& operator=(const NBDistrict& s);263264265};266267268