View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.following;
2   
3   import org.opentrafficsim.base.parameters.ParameterException;
4   import org.opentrafficsim.base.parameters.ParameterSet;
5   import org.opentrafficsim.base.parameters.Parameters;
6   
7   import nl.tudelft.simulation.jstats.distributions.DistContinuous;
8   import nl.tudelft.simulation.jstats.distributions.DistNormal;
9   import nl.tudelft.simulation.jstats.streams.StreamInterface;
10  
11  /**
12   * Factory for IDM types.
13   * <p>
14   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 15 jan. 2018 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   * @param <T> IDM class
22   */
23  public class AbstractIDMFactory<T extends AbstractIDM> implements CarFollowingModelFactory<T>
24  {
25  
26      /** Single instance as it is state-less. */
27      private final T idm;
28  
29      /** Distribution for fSpeed parameter. */
30      private final DistContinuous fSpeed;
31  
32      /**
33       * Sets the idm model, which should be state-less.
34       * @param idm T; idm model, which should be state-less
35       * @param randomStream StreamInterface; random number stream
36       */
37      public AbstractIDMFactory(final T idm, final StreamInterface randomStream)
38      {
39          this.idm = idm;
40          this.fSpeed = new DistNormal(randomStream, 123.7 / 120.0, 0.1);
41      }
42  
43      /** {@inheritDoc} */
44      @Override
45      public final T generateCarFollowingModel()
46      {
47          return this.idm;
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public Parameters getParameters() throws ParameterException
53      {
54          ParameterSet parameters = new ParameterSet();
55          parameters.setDefaultParameters(AbstractIDM.class);
56          parameters.setParameter(AbstractIDM.FSPEED, this.fSpeed.draw());
57          return parameters;
58      }
59  
60  }