View Javadoc
1   package org.opentrafficsim.core.network;
2   
3   import java.io.Serializable;
4   import java.util.Set;
5   
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.opentrafficsim.base.Identifiable;
8   import org.opentrafficsim.core.animation.Drawable;
9   import org.opentrafficsim.core.geometry.OTSLine3D;
10  import org.opentrafficsim.core.gtu.GTU;
11  import org.opentrafficsim.core.gtu.GTUType;
12  
13  import nl.tudelft.simulation.dsol.animation.Locatable;
14  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
15  import nl.tudelft.simulation.event.EventType;
16  
17  /**
18   * Link as a connection between two Nodes.
19   * <p>
20   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22   * <p>
23   * $LastChangedDate: 2019-01-06 01:35:05 +0100 (Sun, 06 Jan 2019) $, @version $Revision: 4831 $, by $Author: averbraeck $,
24   * initial version Aug 19, 2014 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27   */
28  public interface Link extends Locatable, Serializable, Identifiable, Drawable
29  {
30      /**
31       * Return the network in which this link is registered. Cannot be null.
32       * @return Network; the network in which this link is registered
33       */
34      Network getNetwork();
35  
36      /** @return id. */
37      @Override
38      String getId();
39  
40      /** @return start node. */
41      Node getStartNode();
42  
43      /** @return end node. */
44      Node getEndNode();
45  
46      /** @return the link type. */
47      LinkType getLinkType();
48  
49      /** @return the design line. */
50      OTSLine3D getDesignLine();
51  
52      /** @return the simulator. */
53      SimulatorInterface.TimeDoubleUnit getSimulator();
54  
55      /** @return length of the link. */
56      Length getLength();
57  
58      /**
59       * This method returns the directionality of the link for a GTU type. It might be that the link is FORWARD (from start node
60       * 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
61       * node). If there is no entry for the given GTU Type, the values of GTUType.ALL will be returned. If this entry is not
62       * present, LongitudinalDirectionality.NONE will be returned.
63       * @param gtuType GTUType; the GTU type to request the directionality for
64       * @return the longitudinal directionality of the link (FORWARD, BACKWARD, BOTH or NONE) for the given GTU type. NONE will
65       *         be returned if no directionality is given.
66       */
67      LongitudinalDirectionality getDirectionality(GTUType gtuType);
68  
69      /**
70       * 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
71       * warning or error will be given. The GTU_ADD_EVENT will only be fired when the GTU was not already on the link.
72       * @param gtu GTU; the GTU to add.
73       */
74      void addGTU(GTU gtu);
75  
76      /**
77       * Remove a GTU from this link. It is safe to try to remove a GTU again. No warning or error will be given. The
78       * GTU_REMOVE_EVENT will only be fired when the GTU was on the link.
79       * @param gtu GTU; the GTU to remove.
80       */
81      void removeGTU(GTU gtu);
82  
83      /**
84       * Provide a safe copy of the set of GTUs.
85       * @return Set&lt;GTU&gt;; a safe copy of the set of GTUs
86       */
87      Set<GTU> getGTUs();
88  
89      /**
90       * Provide the number of GTUs on this link.
91       * @return int; the number of GTUs on this link
92       */
93      int getGTUCount();
94  
95      /**
96       * The <b>timed</b> event type for pub/sub indicating the addition of a GTU to the link. <br>
97       * Payload: Object[] {String gtuId, GTU gtu, int count_after_addition}
98       */
99      EventType GTU_ADD_EVENT = new EventType("LINK.GTU.ADD");
100 
101     /**
102      * The <b>timed</b> event type for pub/sub indicating the removal of a GTU from the link. <br>
103      * Payload: Object[] {String gtuId, GTU gtu, int count_after_removal}
104      */
105     EventType GTU_REMOVE_EVENT = new EventType("LINK.GTU.REMOVE");
106 
107 }