LCOV - code coverage report
Current view: top level - src/netbuild - NBDistrict.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 75.0 % 4 3
Test Date: 2024-12-21 15:45:41 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 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    NBDistrict.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Sascha Krieg
      17              : /// @author  Michael Behrisch
      18              : /// @date    Sept 2002
      19              : ///
      20              : // A class representing a single district
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <vector>
      26              : #include <string>
      27              : #include <utility>
      28              : #include "NBCont.h"
      29              : #include <utils/common/Named.h>
      30              : #include <utils/common/VectorHelper.h>
      31              : #include <utils/geom/Position.h>
      32              : #include <utils/geom/PositionVector.h>
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // class declarations
      37              : // ===========================================================================
      38              : class NBEdge;
      39              : class OutputDevice;
      40              : 
      41              : 
      42              : // ===========================================================================
      43              : // class definitions
      44              : // ===========================================================================
      45              : /**
      46              :  * @class NBDistrict
      47              :  * @brief A class representing a single district
      48              :  *
      49              :  * A "district" is an area within the network which may be referenced by
      50              :  *  O/D-matrices. It stems from importing VISUM-networks. Work with VISUM-
      51              :  *  -networks also made it necessary that a district knows the edges at
      52              :  *  which new vehicles shall approach the simulated network (sources) and
      53              :  *  those to use when leaving the network (sinks). These connections to the
      54              :  *  network are weighted.
      55              :  *
      56              :  * Later work on VISUM required also parsing the shape of a district. This
      57              :  *  information is used by some external tools only, it is even not shown
      58              :  *  within the GUI.
      59              :  *
      60              :  * @todo Recheck whether this can be somehow joined with ODDistrict
      61              :  */
      62              : class NBDistrict : public Named {
      63              : public:
      64              :     /** @brief Constructor with id, and position
      65              :      *
      66              :      * @param[in] id The id of the district
      67              :      * @param[in] pos The position of the district
      68              :      */
      69              :     NBDistrict(const std::string& id, const Position& pos);
      70              : 
      71              : 
      72              :     /** @brief Constructor without position
      73              :      *
      74              :      * The position must be computed later
      75              :      *
      76              :      * @param[in] id The id of the district
      77              :      */
      78              :     NBDistrict(const std::string& id);
      79              : 
      80              : 
      81              :     /// @brief Destructor
      82              :     ~NBDistrict();
      83              : 
      84              : 
      85              :     /** @brief Adds a source
      86              :      *
      87              :      * It is checked whether the edge has already been added as a source. false
      88              :      *  is returned in this case. Otherwise, the source is pushed into
      89              :      *  the list of sources and the weight into the list of source weights.
      90              :      *  both lists stay sorted this way. true is returned.
      91              :      *
      92              :      * @param[in] source An edge that shall be used as source
      93              :      * @param[in] weight The weight of the source
      94              :      * @return Whether the source could be added (was not added before)
      95              :      * @todo Consider using only one list for sources/weights
      96              :      */
      97              :     bool addSource(NBEdge* const source, double weight);
      98              : 
      99              : 
     100              :     /** @brief Adds a sink
     101              :      *
     102              :      * It is checked whether the edge has already been added as a sink. false
     103              :      *  is returned in this case. Otherwise, the sink is pushed into
     104              :      *  the list of sink and the weight into the list of sink weights.
     105              :      *  both lists stay sorted this way. true is returned.
     106              :      *
     107              :      * @param[in] sink An edge that shall be used as sink
     108              :      * @param[in] weight The weight of the sink
     109              :      * @return Whether the sink could be added (was not added before)
     110              :      * @todo Consider using only one list for sinks/weights
     111              :      */
     112              :     bool addSink(NBEdge* const sink, double weight);
     113              : 
     114              : 
     115              :     /** @brief Returns the position of this district's center
     116              :      *
     117              :      * @return The position of this district's center
     118              :      * @todo Recheck when this information is set/needed
     119              :      */
     120              :     const Position& getPosition() const {
     121            0 :         return myPosition;
     122              :     }
     123              : 
     124              : 
     125              :     /** @brief Sets the center coordinates
     126              :      *
     127              :      * @param[in] pos The new center to assign
     128              :      * @todo Recheck when this information is set/needed
     129              :      */
     130              :     void setCenter(const Position& pos);
     131              : 
     132              : 
     133              :     /** @brief Replaces incoming edges from the vector (sinks) by the given edge
     134              :      *
     135              :      * When an edge is split/joined/removed/etc., it may get necessary to replace prior
     136              :      *  edges by new ones. This method replaces all occurrences of the edges from
     137              :      *  "which" within incoming edges (sinks) by the given edge.
     138              :      *
     139              :      * The new sink edge's weight is the sum of the weights of the replaced edges.
     140              :      *
     141              :      * @param[in] which List of edges to replace
     142              :      * @param[in] by The replacement
     143              :      */
     144              :     void replaceIncoming(const EdgeVector& which, NBEdge* const by);
     145              : 
     146              : 
     147              :     /** @brief Replaces outgoing edges from the vector (source) by the given edge
     148              :      *
     149              :      * When an edge is split/joined/removed/etc., it may get necessary to replace prior
     150              :      *  edges by new ones. This method replaces all occurrences of the edges from
     151              :      *  "which" within outgoing edges (sources) by the given edge.
     152              :      *
     153              :      * The new source edge's weight is the sum of the weights of the replaced edges.
     154              :      *
     155              :      * @param[in] which List of edges to replace
     156              :      * @param[in] by The replacement
     157              :      */
     158              :     void replaceOutgoing(const EdgeVector& which, NBEdge* const by);
     159              : 
     160              : 
     161              :     /** @brief Removes the given edge from the lists of sources and sinks
     162              :      *
     163              :      * The according weights are removed, too.
     164              :      *
     165              :      * @param[in] e The edge to remove from sinks/sources
     166              :      */
     167              :     void removeFromSinksAndSources(NBEdge* const e);
     168              : 
     169              : 
     170              :     /** @brief Sets the shape of this district
     171              :      *
     172              :      * @param[in] p The new shape
     173              :      */
     174              :     void addShape(const PositionVector& p);
     175              : 
     176              : 
     177              :     /** @brief Returns the weights of the sources
     178              :      * @return The source weights
     179              :      */
     180              :     const std::vector<double>& getSourceWeights() const {
     181           50 :         return mySourceWeights;
     182              :     }
     183              : 
     184              : 
     185              :     /** @brief Returns the sources
     186              :      * @return The source edges
     187              :      */
     188              :     const std::vector<NBEdge*>& getSourceEdges() const {
     189              :         return mySources;
     190              :     }
     191              : 
     192              : 
     193              :     /** @brief Returns the weights of the sinks
     194              :      * @return The sink weights
     195              :      */
     196              :     const std::vector<double>& getSinkWeights() const {
     197           50 :         return mySinkWeights;
     198              :     }
     199              : 
     200              : 
     201              :     /** @brief Returns the sinks
     202              :      * @return The sink edges
     203              :      */
     204              :     const std::vector<NBEdge*>& getSinkEdges() const {
     205              :         return mySinks;
     206              :     }
     207              : 
     208              : 
     209              :     /** @brief Returns the shape
     210              :      * @return The district's shape
     211              :      */
     212              :     const PositionVector& getShape() const {
     213           30 :         return myShape;
     214              :     }
     215              : 
     216              : 
     217              : 
     218              :     /// @name Applying offset
     219              :     /// @{
     220              : 
     221              :     /** @brief Applies an offset to the district
     222              :      * @param[in] xoff The x-offset to apply
     223              :      * @param[in] yoff The y-offset to apply
     224              :      */
     225              :     void reshiftPosition(double xoff, double yoff);
     226              : 
     227              :     /// @brief mirror coordinates along the x-axis
     228              :     void mirrorX();
     229              :     /// @}
     230              : 
     231              : 
     232              : 
     233              : 
     234              : 
     235              : private:
     236              :     /// @brief Definition of a vector of connection weights
     237              :     typedef std::vector<double> WeightsCont;
     238              : 
     239              :     /// @brief The sources (connection from district to network)
     240              :     EdgeVector mySources;
     241              : 
     242              :     /// @brief The weights of the sources
     243              :     WeightsCont mySourceWeights;
     244              : 
     245              :     /// @brief The sinks (connection from network to district)
     246              :     EdgeVector mySinks;
     247              : 
     248              :     /// @brief The weights of the sinks
     249              :     WeightsCont mySinkWeights;
     250              : 
     251              :     /// @brief The position of the district
     252              :     Position myPosition;
     253              : 
     254              :     /// @brief The shape of the dsitrict
     255              :     PositionVector myShape;
     256              : 
     257              : 
     258              : private:
     259              :     /** invalid copy constructor */
     260              :     NBDistrict(const NBDistrict& s);
     261              : 
     262              :     /** invalid assignment operator */
     263              :     NBDistrict& operator=(const NBDistrict& s);
     264              : 
     265              : 
     266              : };
        

Generated by: LCOV version 2.0-1