1 package org.opentrafficsim.core.network;
2
3 import java.io.Serializable;
4
5 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
6
7 import org.opentrafficsim.core.unit.FrequencyUnit;
8 import org.opentrafficsim.core.unit.LengthUnit;
9 import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
10
11 /**
12 * <p>
13 * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
15 * <p>
16 * @version Aug 19, 2014 <br>
17 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
19 * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
20 * @param <IDL> the ID type of the Link, e.g., String or Integer.
21 * @param <IDN> the ID type of the Node, e.g., String or Integer.
22 * @param <P> the type of Point that the Node uses.
23 * @param <N> the type of Node that this Link uses.
24 */
25 public abstract class AbstractLink<IDL, IDN, P, N extends AbstractNode<IDN, P>> implements Link<IDL, N>, Serializable,
26 LocatableInterface
27 {
28 /** */
29 private static final long serialVersionUID = 20150101L;
30
31 /** Link id. */
32 private final IDL id;
33
34 /** Start node (directional). */
35 private final N startNode;
36
37 /** End node (directional). */
38 private final N endNode;
39
40 /** Link length in a length unit. */
41 private final DoubleScalar.Rel<LengthUnit> length;
42
43 /** Link capacity in vehicles per time unit. This is a mutable property (e.g., blockage). */
44 private DoubleScalar.Abs<FrequencyUnit> capacity;
45
46 /**
47 * Construct a new link.
48 * @param id the link id
49 * @param startNode start node (directional)
50 * @param endNode end node (directional)
51 * @param length link length in a length unit
52 * @param capacity link capacity in GTUs per hour
53 */
54 public AbstractLink(final IDL id, final N startNode, final N endNode, final DoubleScalar.Rel<LengthUnit> length,
55 final DoubleScalar.Abs<FrequencyUnit> capacity)
56 {
57 this.id = id;
58 this.startNode = startNode;
59 this.endNode = endNode;
60 // TODO Add directionality to a link?
61 this.startNode.addLinkOut(this);
62 this.endNode.addLinkIn(this);
63 this.length = length;
64 setCapacity(capacity);
65 }
66
67 /**
68 * Construct a a new link with infinite capacity.
69 * @param id the link id
70 * @param startNode start node (directional)
71 * @param endNode end node (directional)
72 * @param length link length in a length unit
73 */
74 public AbstractLink(final IDL id, final N startNode, final N endNode, final DoubleScalar.Rel<LengthUnit> length)
75 {
76 this(id, startNode, endNode, length, new DoubleScalar.Abs<FrequencyUnit>(Double.POSITIVE_INFINITY,
77 FrequencyUnit.PER_SECOND));
78 }
79
80 /**
81 * @return id.
82 */
83 public final IDL getId()
84 {
85 return this.id;
86 }
87
88 /**
89 * @return start node.
90 */
91 public final N getStartNode()
92 {
93 return this.startNode;
94 }
95
96 /**
97 * @return end node.
98 */
99 public final N getEndNode()
100 {
101 return this.endNode;
102 }
103
104 /**
105 * @return link capacity.
106 */
107 public final DoubleScalar.Abs<FrequencyUnit> getCapacity()
108 {
109 return this.capacity;
110 }
111
112 /**
113 * @param capacity set the link capacity.
114 */
115 public final void setCapacity(final DoubleScalar.Abs<FrequencyUnit> capacity)
116 {
117 this.capacity = capacity;
118 }
119
120 /**
121 * @return length.
122 */
123 public final DoubleScalar.Rel<LengthUnit> getLength()
124 {
125 return this.length;
126 }
127
128 /** {@inheritDoc} */
129 @Override
130 @SuppressWarnings("checkstyle:designforextension")
131 public String toString()
132 {
133 return this.id.toString();
134 }
135
136 }