View Javadoc
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   * <p>
22   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
24   * <p>
25   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 16 nov. 2016 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
28   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
29   */
30  public class CharacteristicsGenerator implements LaneBasedGTUCharacteristicsGenerator
31  {
32  
33      /** Strategical factory. */
34      private final LaneBasedStrategicalRoutePlannerFactory strategicalFactory;
35  
36      /** Route generator. */
37      private final RouteGenerator routeGenerator;
38  
39      /** Id generator. */
40      private final IdGenerator idGenerator;
41  
42      /** Simulator. */
43      private final OTSDEVSSimulatorInterface simulator;
44  
45      /** Network. */
46      private final OTSNetwork network;
47  
48      /** GTU type generator. */
49      private final GTUTypeGenerator gtuTypeGenerator;
50  
51      /** GTU generation speed. */
52      private final Speed generationSpeed;
53  
54      /** GTU generation positions. */
55      private final Set<DirectedLanePosition> positions;
56  
57      /**
58       * @param strategicalFactory strategical planner factory
59       * @param routeGenerator route generator
60       * @param idGenerator generator for the GTU id
61       * @param simulator the simulator
62       * @param network the network
63       * @param gtuTypeGenerator the generator for the GTU type
64       * @param generationSpeed the initial speed
65       * @param positions the positions for generation
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      /** {@inheritDoc} */
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      /** {@inheritDoc} */
94      @Override
95      public OTSDEVSSimulatorInterface getSimulator() throws ProbabilityException
96      {
97          return this.simulator;
98      }
99  
100 }