Connector.java

  1. package org.opentrafficsim.core.network;

  2. import org.djutils.exceptions.Throw;
  3. import org.djutils.exceptions.Try;
  4. import org.opentrafficsim.core.geometry.OtsLine3d;

  5. /**
  6.  * Special link type that represents a connector.
  7.  * <p>
  8.  * Copyright (c) 2022-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  9.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  10.  * </p>
  11.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  12.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  13.  * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
  14.  */
  15. public class Connector extends Link
  16. {

  17.     /** */
  18.     private static final long serialVersionUID = 20230131L;

  19.     /** Weight value to divide origin or destination flow over connectors. */
  20.     private double demandWeight = 0.0;

  21.     /**
  22.      * Construct a new link.
  23.      * @param network Network; the network to which the link belongs
  24.      * @param id String; the link id
  25.      * @param startNode Node; start node (directional)
  26.      * @param endNode Node; end node (directional)
  27.      * @param linkType LinkType; Link type to indicate compatibility with GTU types
  28.      * @throws NetworkException if link already exists in the network, if name of the link is not unique, if the start node
  29.      *             or the end node of the link are not registered in the network, or if neither node is a centroid.
  30.      */
  31.     public Connector(final Network network, final String id, final Node startNode, final Node endNode, final LinkType linkType)
  32.             throws NetworkException
  33.     {
  34.         super(network, id, startNode, endNode, linkType,
  35.                 Try.assign(() -> new OtsLine3d(startNode.getPoint(), endNode.getPoint()), "Could not create connector line."));
  36.         Throw.when(!startNode.isCentroid() && !endNode.isCentroid(), NetworkException.class,
  37.                 "At least on node connected to a Connector should be a centroid.");
  38.     }

  39.     /**
  40.      * Sets the demand weight. This is only applicable to links of type CONNECTOR.
  41.      * @param demandWeight double; demand weight, which is any positive value
  42.      */
  43.     public final void setDemandWeight(final double demandWeight)
  44.     {
  45.         Throw.when(demandWeight < 0.0, IllegalArgumentException.class, "Demand weight should be positive.");
  46.         this.demandWeight = demandWeight;
  47.     }

  48.     /**
  49.      * Clears the demand weight, which is equal to setting it to 0.0.
  50.      */
  51.     public final void clearDemandWeight()
  52.     {
  53.         this.demandWeight = 0.0;
  54.     }

  55.     /**
  56.      * Returns the demand weight.
  57.      * @return double; demand weight, any positive value.
  58.      */
  59.     public final double getDemandWeight()
  60.     {
  61.         return this.demandWeight;
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     public boolean isConnector()
  66.     {
  67.         return true;
  68.     }

  69. }