Package org.opentrafficsim.core.network
Class OTSLink
java.lang.Object
nl.tudelft.simulation.event.EventProducer
org.opentrafficsim.core.network.OTSLink
- All Implemented Interfaces:
Serializable,Locatable,EventProducerInterface,Identifiable,Drawable,Link
- Direct Known Subclasses:
CapacityOTSLink
public class OTSLink extends EventProducer implements Link, Serializable, Locatable
A standard implementation of a link between two OTSNodes.
Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
$LastChangedDate: 2019-07-15 11:39:08 +0200 (Mon, 15 Jul 2019) $, @version $Revision: 5564 $, by $Author: pknoppers $,
initial version Aug 19, 2014
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from interface nl.tudelft.simulation.event.EventProducerInterface
FIRST_POSITION, LAST_POSITIONFields inherited from interface org.opentrafficsim.core.network.Link
GTU_ADD_EVENT, GTU_REMOVE_EVENT -
Constructor Summary
Constructors Modifier Constructor Description OTSLink(Network network, String id, Node startNode, Node endNode, LinkType linkType, OTSLine3D designLine, OTSSimulatorInterface simulator)Construct a new link.protectedOTSLink(Network newNetwork, OTSSimulatorInterface newSimulator, OTSLink link)Clone a link for a new network. -
Method Summary
Modifier and Type Method Description voidaddGTU(GTU gtu)Add a GTU to this link (e.g., for statistical purposes, or for a model on macro level).OTSLinkclone(Network newNetwork, OTSSimulatorInterface newSimulator)Clone the OTSLink for e.g., copying a network.booleanequals(Object obj)javax.media.j3d.BoundsgetBounds()OTSLine3DgetDesignLine()LongitudinalDirectionalitygetDirectionality(GTUType gtuType)This method returns the directionality of the link for a GTU type.NodegetEndNode()intgetGTUCount()Provide the number of GTUs on this link.Set<GTU>getGTUs()Provide a safe copy of the set of GTUs.StringgetId()LengthgetLength()LinkTypegetLinkType()DirectedPointgetLocation()NetworkgetNetwork()Return the network in which this link is registered.OTSSimulatorInterfacegetSimulator()NodegetStartNode()inthashCode()voidremoveGTU(GTU gtu)Remove a GTU from this link.StringtoString()Methods inherited from class nl.tudelft.simulation.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, removeAllListeners, removeAllListeners, removeListener
-
Constructor Details
-
OTSLink
public OTSLink(Network network, String id, Node startNode, Node endNode, LinkType linkType, OTSLine3D designLine, OTSSimulatorInterface simulator) throws NetworkExceptionConstruct a new link.- Parameters:
network- Network; the network to which the link belongsid- String; the link idstartNode- Node; start node (directional)endNode- Node; end node (directional)linkType- LinkType; Link type to indicate compatibility with GTU typesdesignLine- OTSLine3D; the OTSLine3D design line of the Linksimulator- OTSSimulatorInterface; the simulator on which events can be scheduled- 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.
-
OTSLink
protected OTSLink(Network newNetwork, OTSSimulatorInterface newSimulator, OTSLink link) throws NetworkExceptionClone a link for a new network.- Parameters:
newNetwork- Network; the new network to which the clone belongsnewSimulator- OTSSimulatorInterface; the new simulator for this networklink- OTSLink; the link to clone from- 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
-
getDirectionality
This method returns the directionality of the link for a GTU type. It might be that the link is FORWARD (from start node to end node) for the GTU type CAR, but BOTH for the GTU type BICYCLE (i.e., bicycles can also go from end node to start node). If there is no entry for the given GTU Type, the values of GTUType.ALL will be returned. If this entry is not present, LongitudinalDirectionality.NONE will be returned.- Specified by:
getDirectionalityin interfaceLink- Parameters:
gtuType- GTUType; the GTU type to request the directionality for- Returns:
- the longitudinal directionality of the link (FORWARD, BACKWARD, BOTH or NONE) for the given GTU type. NONE will be returned if no directionality is given.
-
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. -
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. -
getGTUs
Provide a safe copy of the set of GTUs. -
getGTUCount
public final int getGTUCount()Provide the number of GTUs on this link.- Specified by:
getGTUCountin interfaceLink- Returns:
- int; the number of GTUs on this link
-
getNetwork
Return the network in which this link is registered. Cannot be null.- Specified by:
getNetworkin interfaceLink- Returns:
- Network; the network in which this link is registered
-
getId
- Specified by:
getIdin interfaceIdentifiable- Specified by:
getIdin interfaceLink- Returns:
- id.
-
getStartNode
- Specified by:
getStartNodein interfaceLink- Returns:
- start node.
-
getEndNode
- Specified by:
getEndNodein interfaceLink- Returns:
- end node.
-
getLinkType
- Specified by:
getLinkTypein interfaceLink- Returns:
- the link type.
-
getDesignLine
- Specified by:
getDesignLinein interfaceLink- Returns:
- the design line.
-
getSimulator
- Specified by:
getSimulatorin interfaceLink- Returns:
- the simulator.
-
getLength
-
getLocation
- Specified by:
getLocationin interfaceLocatable
-
getBounds
public javax.media.j3d.Bounds getBounds() -
toString
-
hashCode
public int hashCode() -
equals
-
clone
public OTSLink clone(Network newNetwork, OTSSimulatorInterface newSimulator) throws NetworkExceptionClone the OTSLink for e.g., copying a network.- Parameters:
newNetwork- Network; the new network to which the clone belongsnewSimulator- OTSSimulatorInterface; the new simulator for this network- Returns:
- a clone of this object
- Throws:
NetworkException- in case the cloning fails
-