1 package org.opentrafficsim.road.gtu.generator;
2
3 import java.util.Set;
4
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.opentrafficsim.core.distributions.ProbabilityException;
7 import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
8 import org.opentrafficsim.core.gtu.GTUCharacteristics;
9 import org.opentrafficsim.core.gtu.GTUException;
10 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
11 import org.opentrafficsim.core.idgenerator.IdGenerator;
12 import org.opentrafficsim.core.network.OTSNetwork;
13 import org.opentrafficsim.core.network.route.RouteGenerator;
14 import org.opentrafficsim.road.gtu.generator.GTUTypeGenerator.GTUTypeInfo;
15 import org.opentrafficsim.road.gtu.lane.LaneBasedGTUCharacteristics;
16 import org.opentrafficsim.road.gtu.lane.LaneBasedGTUCharacteristicsGenerator;
17 import org.opentrafficsim.road.gtu.strategical.route.LaneBasedStrategicalRoutePlannerFactory;
18 import org.opentrafficsim.road.network.lane.DirectedLanePosition;
19
20
21
22
23
24
25
26
27
28
29
30 public class CharacteristicsGenerator implements LaneBasedGTUCharacteristicsGenerator
31 {
32
33
34 private final LaneBasedStrategicalRoutePlannerFactory strategicalFactory;
35
36
37 private final RouteGenerator routeGenerator;
38
39
40 private final IdGenerator idGenerator;
41
42
43 private final OTSDEVSSimulatorInterface simulator;
44
45
46 private final OTSNetwork network;
47
48
49 private final GTUTypeGenerator gtuTypeGenerator;
50
51
52 private final Speed generationSpeed;
53
54
55 private final Set<DirectedLanePosition> positions;
56
57
58
59
60
61
62
63
64
65
66
67 public CharacteristicsGenerator(final LaneBasedStrategicalRoutePlannerFactory strategicalFactory,
68 final RouteGenerator routeGenerator, final IdGenerator idGenerator, final OTSDEVSSimulatorInterface simulator,
69 final OTSNetwork network, final GTUTypeGenerator gtuTypeGenerator, final Speed generationSpeed,
70 final Set<DirectedLanePosition> positions)
71 {
72 this.strategicalFactory = strategicalFactory;
73 this.routeGenerator = routeGenerator;
74 this.idGenerator = idGenerator;
75 this.simulator = simulator;
76 this.network = network;
77 this.gtuTypeGenerator = gtuTypeGenerator;
78 this.generationSpeed = generationSpeed;
79 this.positions = positions;
80 }
81
82
83 @Override
84 public LaneBasedGTUCharacteristics draw() throws ProbabilityException, ParameterException, GTUException
85 {
86 GTUTypeInfo info = this.gtuTypeGenerator.draw();
87 GTUCharacteristics gtuCharacteristics = new GTUCharacteristics(info.getGtuType(), this.idGenerator, info.getLength(),
88 info.getWidth(), info.getMaximumSpeed(), this.simulator, this.network);
89 return new LaneBasedGTUCharacteristics(gtuCharacteristics, this.strategicalFactory, this.routeGenerator.draw(),
90 Speed.min(this.generationSpeed, info.getMaximumSpeed()), this.positions);
91 }
92
93
94 @Override
95 public OTSDEVSSimulatorInterface getSimulator() throws ProbabilityException
96 {
97 return this.simulator;
98 }
99
100 }