Package org.opentrafficsim.core.network
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
public class Link
extends LocalEventProducer
implements HierarchicallyTyped<LinkType,Link>, OtsShape, Identifiable
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final EventTypeThe timed event type for pub/sub indicating the addition of a GTU to the link.static final EventTypeThe timed event type for pub/sub indicating the removal of a GTU from the link.Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITIONFields inherited from interface org.opentrafficsim.base.geometry.OtsShape
DEFAULT_POLYGON_SEGMENTS, WORLD_MARGIN_LINE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd a GTU to this link (e.g., for statistical purposes, or for a model on macro level).booleanfinal OtsLine2dReturns the design line.org.djunits.value.vdouble.scalar.LengthgetElevation(double fractionalPosition) Returns the elevation at the given fractional position.org.djunits.value.vdouble.scalar.LengthgetElevation(org.djunits.value.vdouble.scalar.Length position) Returns the elevation at the given position.final NodeReturns the end node.doublegetGrade(double fractionalPosition) Returns the grade at the given fractional position, given as delta_h / delta_x, as value without unit.doublegetGrade(org.djunits.value.vdouble.scalar.Length position) Returns the grade at the given position, given as delta_h / delta_x, as value without unit.final intProvide the number of GTUs on this link.getGTUs()Provide a safe copy of the set of GTUs.final StringgetId()final org.djunits.value.vdouble.scalar.LengthReturns the length of the link.Return the network in which this link is registered.final OtsSimulatorInterfaceReturns the simulator.final NodeReturns the start node.final LinkTypegetType()inthashCode()booleanReturns whether the link is a connector.final voidRemove a GTU from this link.toString()Methods inherited from class org.djutils.event.LocalEventProducer
getEventListenerMapMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from interface org.opentrafficsim.base.HierarchicallyTyped
isOfTypeMethods inherited from interface org.opentrafficsim.base.geometry.OtsShape
contains, contains, getAbsoluteBounds, getAbsoluteContour, getDirZ, signedDistance, signedDistance
-
Field Details
-
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
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 belongsid- the link idstartNode- start node (directional)endNode- end node (directional)linkType- Link type to indicate compatibility with GTU typesdesignLine- the OtsLine2d design line of the Linkelevation- elevation given over fractional length, may benull.- 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
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
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
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 returnsfalse.- Returns:
- whether the link is a connector, by default this returns
false.
-
getNetwork
Return the network in which this link is registered. Cannot be null.- Returns:
- the network in which this link is registered
-
getId
- Specified by:
getIdin interfaceIdentifiable
-
getStartNode
Returns the start node.- Returns:
- start node.
-
getEndNode
Returns the end node.- Returns:
- end node.
-
getType
- Specified by:
getTypein interfaceHierarchicallyTyped<LinkType,Link>
-
getDesignLine
Returns the design line.- Returns:
- design line.
-
getAbsoluteContour
- Specified by:
getAbsoluteContourin interfaceOtsShape
-
getRelativeContour
- Specified by:
getRelativeContourin interfaceOtsShape
-
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
- Specified by:
getLocationin interfaceLocatable- Specified by:
getLocationin interfaceOtsShape
-
getRelativeBounds
- Specified by:
getRelativeBoundsin interfaceLocatable- Specified by:
getRelativeBoundsin interfaceOtsShape
-
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
-
hashCode
public int hashCode() -
equals
-