1 package org.opentrafficsim.core.gtu;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Acceleration;
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.djunits.value.vdouble.scalar.Speed;
8 import org.djutils.exceptions.Throw;
9 import org.opentrafficsim.base.parameters.ParameterException;
10 import org.opentrafficsim.core.distributions.ConstantGenerator;
11 import org.opentrafficsim.core.distributions.Generator;
12 import org.opentrafficsim.core.distributions.ProbabilityException;
13
14
15
16
17
18
19
20
21
22
23
24 public class TemplateGTUType implements Serializable, Generator<GTUCharacteristics>
25 {
26
27 private static final long serialVersionUID = 20141230L;
28
29
30 private final GTUType gtuType;
31
32
33 private final Generator<Length> lengthGenerator;
34
35
36 private final Generator<Length> widthGenerator;
37
38
39 private final Generator<Speed> maximumSpeedGenerator;
40
41
42 private final Generator<Acceleration> maxAcceleration;
43
44
45 private final Generator<Acceleration> maxDeceleration;
46
47
48
49
50
51
52
53
54
55
56
57 public TemplateGTUType(final GTUType gtuType, final Generator<Length> lengthGenerator,
58 final Generator<Length> widthGenerator, final Generator<Speed> maximumSpeedGenerator) throws NullPointerException
59 {
60 this(gtuType, lengthGenerator, widthGenerator, maximumSpeedGenerator,
61 new ConstantGenerator<>(Acceleration.createSI(3.0)), new ConstantGenerator<>(Acceleration.createSI(-8.0)));
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76 public TemplateGTUType(final GTUType gtuType, final Generator<Length> lengthGenerator,
77 final Generator<Length> widthGenerator, final Generator<Speed> maximumSpeedGenerator,
78 final Generator<Acceleration> maximumAccelerationGenerator,
79 final Generator<Acceleration> maximumDecelerationGenerator) throws NullPointerException
80 {
81 Throw.whenNull(gtuType, "gtuType is null");
82 Throw.whenNull(lengthGenerator, "lengthGenerator is null");
83 Throw.whenNull(widthGenerator, "widthGenerator is null");
84 Throw.whenNull(maximumSpeedGenerator, "maximumSpeedGenerator is null");
85 Throw.whenNull(maximumAccelerationGenerator, "maximumAccelerationGenerator is null");
86 Throw.whenNull(maximumDecelerationGenerator, "maximumDecelerationGenerator is null");
87
88 this.gtuType = gtuType;
89 this.lengthGenerator = lengthGenerator;
90 this.widthGenerator = widthGenerator;
91 this.maximumSpeedGenerator = maximumSpeedGenerator;
92 this.maxAcceleration = maximumAccelerationGenerator;
93 this.maxDeceleration = maximumDecelerationGenerator;
94 }
95
96
97
98
99
100
101
102 @Override
103 @SuppressWarnings("checkstyle:designforextension")
104 public GTUCharacteristics draw() throws ProbabilityException, ParameterException
105 {
106 Acceleration acceleration = this.maxAcceleration.draw();
107 Acceleration deceleration = this.maxDeceleration.draw();
108 Throw.when(acceleration.si <= 0, IllegalArgumentException.class, "Acceleration should be above 0.");
109 Throw.when(deceleration.si >= 0, IllegalArgumentException.class, "Deceleration should be below 0.");
110 Length length = this.lengthGenerator.draw();
111 return new GTUCharacteristics(this.gtuType, length, this.widthGenerator.draw(), this.maximumSpeedGenerator.draw(),
112 acceleration, deceleration, length.multiplyBy(0.75));
113 }
114
115
116
117
118 @SuppressWarnings("checkstyle:designforextension")
119 public GTUType getGTUType()
120 {
121 return this.gtuType;
122 }
123
124
125 @Override
126 @SuppressWarnings("checkstyle:designforextension")
127 public String toString()
128 {
129 return String.format("TemplateGTUType [%s, %s, %s, %s]", this.gtuType, this.lengthGenerator, this.widthGenerator,
130 this.maximumSpeedGenerator);
131 }
132
133 }