Class Link

java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.core.network.Link
All Implemented Interfaces:
Locatable, Identifiable, EventProducer, OtsShape, HierarchicallyTyped<LinkType,Link>
Direct Known Subclasses:
CapacityLink, Connector

A standard implementation of a link between two Nodes.

Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

$LastChangedDate$, @version $Revision$, by $Author$, initial version Aug 19, 2014

Author:
Alexander Verbraeck, Peter Knoppers
  • Field Details

    • GTU_REMOVE_EVENT

      public static final EventType GTU_REMOVE_EVENT
      The timed event type for pub/sub indicating the removal of a GTU from the link.
      Payload: Object[] {String gtuId, int count_after_removal}
    • GTU_ADD_EVENT

      public static final EventType GTU_ADD_EVENT
      The timed event type for pub/sub indicating the addition of a GTU to the link.
      Payload: Object[] {String gtuId, int count_after_addition}
  • Constructor Details

    • Link

      public Link(Network network, String id, Node startNode, Node endNode, LinkType linkType, OtsLine2d designLine, ContinuousPiecewiseLinearFunction elevation) throws NetworkException
      Construct a new link.
      Parameters:
      network - the network to which the link belongs
      id - the link id
      startNode - start node (directional)
      endNode - end node (directional)
      linkType - Link type to indicate compatibility with GTU types
      designLine - the OtsLine2d design line of the Link
      elevation - elevation given over fractional length, may be null.
      Throws:
      NetworkException - if link already exists in the network, if name of the link is not unique, or if the start node or the end node of the link are not registered in the network.
  • Method Details

    • addGTU

      public final void addGTU(Gtu gtu)
      Add a GTU to this link (e.g., for statistical purposes, or for a model on macro level). It is safe to add a GTU again. No warning or error will be given. The GTU_ADD_EVENT will only be fired when the GTU was not already on the link.
      Parameters:
      gtu - the GTU to add.
    • removeGTU

      public final void removeGTU(Gtu gtu)
      Remove a GTU from this link. It is safe to try to remove a GTU again. No warning or error will be given. The GTU_REMOVE_EVENT will only be fired when the GTU was on the link.
      Parameters:
      gtu - the GTU to remove.
    • getGTUs

      public final Set<Gtu> getGTUs()
      Provide a safe copy of the set of GTUs.
      Returns:
      a safe copy of the set of GTUs
    • getGTUCount

      public final int getGTUCount()
      Provide the number of GTUs on this link.
      Returns:
      the number of GTUs on this link
    • isConnector

      public boolean isConnector()
      Returns whether the link is a connector. By default this returns false.
      Returns:
      whether the link is a connector, by default this returns false.
    • getNetwork

      public Network getNetwork()
      Return the network in which this link is registered. Cannot be null.
      Returns:
      the network in which this link is registered
    • getId

      public final String getId()
      Specified by:
      getId in interface Identifiable
    • getStartNode

      public final Node getStartNode()
      Returns the start node.
      Returns:
      start node.
    • getEndNode

      public final Node getEndNode()
      Returns the end node.
      Returns:
      end node.
    • getType

      public final LinkType getType()
      Specified by:
      getType in interface HierarchicallyTyped<LinkType,Link>
    • getDesignLine

      public final OtsLine2d getDesignLine()
      Returns the design line.
      Returns:
      design line.
    • getAbsoluteContour

      public Polygon2d getAbsoluteContour()
      Specified by:
      getAbsoluteContour in interface OtsShape
    • getRelativeContour

      public Polygon2d getRelativeContour()
      Specified by:
      getRelativeContour in interface OtsShape
    • getSimulator

      public final OtsSimulatorInterface getSimulator()
      Returns the simulator.
      Returns:
      simulator.
    • getLength

      public final org.djunits.value.vdouble.scalar.Length getLength()
      Returns the length of the link.
      Returns:
      length of the link.
    • getLocation

      public DirectedPoint2d getLocation()
      Specified by:
      getLocation in interface Locatable
      Specified by:
      getLocation in interface OtsShape
    • getRelativeBounds

      public Bounds2d getRelativeBounds()
      Specified by:
      getRelativeBounds in interface Locatable
      Specified by:
      getRelativeBounds in interface OtsShape
    • getElevation

      public org.djunits.value.vdouble.scalar.Length getElevation(org.djunits.value.vdouble.scalar.Length position)
      Returns the elevation at the given position.
      Parameters:
      position - position.
      Returns:
      elevation at the given position.
    • getElevation

      public org.djunits.value.vdouble.scalar.Length getElevation(double fractionalPosition)
      Returns the elevation at the given fractional position.
      Parameters:
      fractionalPosition - fractional position.
      Returns:
      elevation at the given fractional position.
    • getGrade

      public double getGrade(org.djunits.value.vdouble.scalar.Length position)
      Returns the grade at the given position, given as delta_h / delta_x, as value without unit.
      Parameters:
      position - position
      Returns:
      grade at the given position
    • getGrade

      public double getGrade(double fractionalPosition)
      Returns the grade at the given fractional position, given as delta_h / delta_x, as value without unit.
      Parameters:
      fractionalPosition - fractional position
      Returns:
      grade at the given fractional position
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object