/****************************************************************************/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 NGNet.h14/// @author Markus Hartinger15/// @author Daniel Krajzewicz16/// @author Michael Behrisch17/// @date Mar, 200318///19// The class storing the generated network20/****************************************************************************/21#pragma once22#include <config.h>2324#include <utils/distribution/Distribution_Parameterized.h>25#include "NGEdge.h"26#include "NGNode.h"272829// ===========================================================================30// class declarations31// ===========================================================================32class NBNetBuilder;333435// ===========================================================================36// class definitions37// ===========================================================================38/**39* @class NGNet40* @brief The class storing the generated network41*42* An instance of this class stores both the edges and the nodes build during43* the generation of a network (using any type of generation algorithm).44* These instances are later transformed into netbuild-structures using toNB().45*/46class NGNet {47public:48/// @brief Constructor49NGNet(NBNetBuilder& nb);505152/// @brief Destructor53~NGNet();545556/** @brief Returns the node at the given position57*58* Searches for a node with the given position within myNodeList.59* Returns the matching node, if one exists, or 0 otherwise.60*61* @param[in] xPos The x-position of the searched node62* @param[in] yPos The y-position of the searched node63* @return The node with the given position, or 0 if no such node exists64*/65NGNode* findNode(int xPos, int yPos);666768/** @brief Returns the next free id69*70* Uses the value of myLastID to return a new (numeric) id. Increases71* myLastID.72*73* @return A new, unique numerical id74*/75std::string getNextFreeID();767778/** @brief Returns the x-position resulting from the given radius and angle79*80* @param[in] radius The radius of the circle81* @param[in] phi The angle the position is located at82* @return The x-position at the described circle at angle phi83*/84double radialToX(double radius, double phi);858687/** @brief Returns the y-position resulting from the given radius and angle88*89* @param[in] radius The radius of the circle90* @param[in] phi The angle the position is located at91* @return The y-position at the described circle at angle phi92*/93double radialToY(double radius, double phi);949596/** @brief Creates a grid network97*98* Performs a double-loop over numX, then numY. Builds NGNodes99* at the according positions and connects them using NGNet::connect.100* Stores both the nodes and the edges within the internal container.101*102* The nodes get an id using <RUNNING_X>/<RUNNING_Y>. The ids103* of the links are set in NGNet::connect.104*105* @param[in] numX The number of nodes in x-direction106* @param[in] numY The number of nodes in y-direction107* @param[in] spaceX The space between nodes in x-direction108* @param[in] spaceY The space between nodes in y-direction109* @param[in] xAttachLength The length of streets attached at the border in x-direction110* @param[in] yAttachLength The length of streets attached at the border in y-direction111* @see NGNet::connect112*/113void createChequerBoard(int numX, int numY, double spaceX, double spaceY, double xAttachLength, double yAttachLength);114115116/** @brief Creates a spider network117*118* Creates a spider web by going through all arms and then all circles in a loop.119* Builds the NGNodes at the positions obtained using radialToX and radialToY and120* connects them using NGNet::connect. Builds optionally a center node, and connects121* it, too.122*123* The nodes get an id using <RUNNING_ARM_NUMBER>/<RUNNING_CIRCLE_NUMBER>.124* The ids of the links are set in NGNet::connect.125*126* @param[in] numRadDiv The number of arms to build127* @param[in] numCircles The number of circles to build128* @param[in] spaceRad The distance between the circles129* @param[in] hasCenter Information whether a center node shall be built130* @see NGNet::connect131* @todo consolidate the name of the center node132*/133void createSpiderWeb(int numRadDiv, int numCircles, double spaceRad, bool hasCenter, double attachLength);134135136/** @brief Converts the stored network into its netbuilder-representation137*138* Goes through all stored nodes, first, converts them into their netbuilder139* representations using NGNode::buildNBNode, and stores the built NBNodes into the140* net builder myNetBuilder.141*142* Then, the method goes through all edges, converts them into their netbuilder143* representations using NGEdge::buildNBEdge, and stores the built NBEdges into the144* net builder myNetBuilder.145*146* If one of the nodes is controlled by a tls and the built logic could not be added147* to net builder's storage, a ProcessError is thrown. This in fact may only happen148* when two same ids occur, what is not possible.149*150* @exception ProcessError If a built tls logic could not be added (should never happen)151* @todo Check whether throwing an exception is really necessary, here152*/153void toNB() const;154155156/** @brief Adds the given node to the network157*158* The node is added to myNodeList.159*160* @param[in] node The node to add161*/162void add(NGNode* node);163164165/** @brief Adds the given edge to the network166*167* The edge is added to myEdgeList.168*169* @param[in] edge The edge to add170*/171void add(NGEdge* edge);172173174/** @brief Returns the number of stored nodes175*176* @return The number of stored nodes177*/178int nodeNo() const;179180181private:182/** @brief Connects both nodes with two edges, one for each direction183*184* Builds one link for each direction and appends the links to myEdgeList.185* The name of a link is as following: <FROM_NODE_ID>to<TO_NODE_ID>.186*187* @param[in] node1 The first node to connect188* @param[in] node2 The second node to connect189*/190void connect(NGNode* node1, NGNode* node2);191192/// @brief return a letter code for the given integer index193std::string alphabeticalCode(int i, int iMax);194195/// @brief get distribution from option196static Distribution_Parameterized getDistribution(const std::string& option);197198private:199/// @brief The last ID given to node or link200int myLastID;201202/// @brief Whether to use alphanumericalIDs203const bool myAlphaIDs;204205/// @brief The builder used to build NB*-structures206NBNetBuilder& myNetBuilder;207208/// @brief The list of nodes209NGNodeList myNodeList;210211/// @brief The list of links212NGEdgeList myEdgeList;213214private:215/// @brief Invalidated copy constructor.216NGNet(const NGNet&);217218/// @brief Invalidated assignment operator.219NGNet& operator=(const NGNet&);220221};222223224