Class ParameterFactoryByType

java.lang.Object
org.opentrafficsim.core.parameters.ParameterFactoryByType
All Implemented Interfaces:
ParameterFactory
Direct Known Subclasses:
ParameterFactoryOneShot

public class ParameterFactoryByType extends Object implements ParameterFactory
Sets parameter values based on the the GTU type. This includes stochastic parameters. Parameters may also be defined for all GTU types. Similarly, correlations between two parameters can be determined, for all or a specific GTU type.

Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Constructor Details

    • ParameterFactoryByType

      public ParameterFactoryByType()
      Constructor.
  • Method Details

    • setValues

      public void setValues(Parameters parameters, GtuType gtuType) throws ParameterException
      Description copied from interface: ParameterFactory
      Creates a set of parameters for the provided GTU type.
      Specified by:
      setValues in interface ParameterFactory
      Parameters:
      parameters - parameters
      gtuType - GTU type
      Throws:
      ParameterException - when illegal parameter value is set
    • getBaseValues

      protected Map<ParameterType<?>,Object> getBaseValues(GtuType gtuType)
      Gathers all the base values set by the factory, fixed or random, as given for the GTU type's hierarchy.
      Parameters:
      gtuType - GTU type
      Returns:
      all the base values set by the factory
    • getCorrelations

      protected Map<ParameterType<?>,Map<ParameterType<?>,ParameterFactoryByType.Correlation<?,?>>> getCorrelations(GtuType gtuType)
      Gathers all the correlations from the factory, as given for the GTU type's hierarchy. This method should return all correlations, regardless of circular or multiple dependencies. It is up to implementations using this method to deal with that (throwing exception or solving is specific way).
      Parameters:
      gtuType - GTU type
      Returns:
      all the correlations from the factory, by dependent parameter type and independent parameter type
    • applyCorrelationsAndSetValues

      protected void applyCorrelationsAndSetValues(Parameters parameters, Map<ParameterType<?>,Object> baseValues, Map<ParameterType<?>,Map<ParameterType<?>,ParameterFactoryByType.Correlation<?,?>>> typeCorrelations) throws ParameterException
      Applies all given correlations to the values map and sets all values in the parameters.
      Parameters:
      parameters - possible source of independent parameters (for parameters not defined in this factory), and receives all final parameters values
      baseValues - base values map (altered by this method)
      typeCorrelations - correlations as gathered for a relevant GTU type, by dependent parameter type and independent parameter type
      Throws:
      ParameterException - when a parameter is dependent on multiple parameters or a parameter was correlated beyond its bounds
    • correlateValue

      protected <T, C> T correlateValue(Object first, Object then, ParameterFactoryByType.Correlation<?,?> correlation)
      Helper method to correlate a typed parameter.
      Type Parameters:
      T - dependent parameter type
      C - independent parameter type
      Parameters:
      first - independent value
      then - dependent value
      correlation - correlation
      Returns:
      correlated value
    • setValues

      protected void setValues(Parameters parameters, Map<ParameterType<?>,Object> values) throws ParameterException
      Set all values from the map in the parameters.
      Parameters:
      parameters - parameters
      values - value map
      Throws:
      ParameterException - if a parameter was correlated beyond its bounds
    • setParameterValue

      protected <T> boolean setParameterValue(Parameters parameters, ParameterType<?> parameterType, Object value)
      Helper method to set a type parameter and catch exception due to bound and a different required order for the parameters to be set.
      Type Parameters:
      T - value type
      Parameters:
      parameters - parameters
      parameterType - parameter type
      value - value
      Returns:
      whether the value was successfully set
    • addParameter

      public <T> void addParameter(GtuType gtuType, ParameterType<T> parameterType, T value)
      Add parameter.
      Type Parameters:
      T - parameter value type
      Parameters:
      gtuType - the gtu type
      parameterType - the parameter type
      value - the value of the parameter
    • addParameter

      public <U extends Unit<U>, T extends org.djunits.value.vdouble.scalar.base.DoubleScalarRel<U, T>> void addParameter(GtuType gtuType, ParameterTypeNumeric<T> parameterType, ContinuousDistDoubleScalar.Rel<T,U> distribution)
      Add parameter.
      Type Parameters:
      U - unit type
      T - parameter value type
      Parameters:
      gtuType - the gtu type
      parameterType - the parameter type
      distribution - ContinuousDistDoubleScalar.Rel<T,U>; the distribution of the parameter
    • addParameter

      public void addParameter(GtuType gtuType, ParameterType<Integer> parameterType, DistDiscrete distribution)
      Add parameter.
      Parameters:
      gtuType - the gtu type
      parameterType - the parameter type
      distribution - the distribution of the parameter
    • addParameter

      public void addParameter(GtuType gtuType, ParameterType<Double> parameterType, DistContinuous distribution)
      Add parameter.
      Parameters:
      gtuType - the gtu type
      parameterType - the parameter type
      distribution - the distribution of the parameter
    • addParameter

      public <T> void addParameter(ParameterType<T> parameterType, T value)
      Add parameter for all GTU types.
      Type Parameters:
      T - type
      Parameters:
      parameterType - the parameter type
      value - the value of the parameter
    • addParameter

      public void addParameter(ParameterTypeDouble parameterType, double value)
      Add parameter for all GTU types.
      Parameters:
      parameterType - the parameter type
      value - the value of the parameter
    • addParameter

      public <U extends Unit<U>, T extends org.djunits.value.vdouble.scalar.base.DoubleScalarRel<U, T>> void addParameter(ParameterTypeNumeric<T> parameterType, ContinuousDistDoubleScalar.Rel<T,U> distribution)
      Add parameter for all GTU types.
      Type Parameters:
      U - unit type
      T - parameter value type
      Parameters:
      parameterType - the parameter type
      distribution - ContinuousDistDoubleScalar.Rel<T,U>; the distribution of the parameter
    • addParameter

      public void addParameter(ParameterTypeDouble parameterType, DistContinuous distribution)
      Add parameter for all GTU types.
      Parameters:
      parameterType - the parameter type
      distribution - the distribution of the parameter
    • addCorrelation

      public <C, T> void addCorrelation(GtuType gtuType, ParameterType<C> first, ParameterType<T> then, ParameterFactoryByType.Correlation<C,T> correlation)
      Correlates one parameter to another. The parameter 'first' may also be null, in which case the parameter can be correlated to an external source.
      Type Parameters:
      C - parameter value type of first parameter
      T - parameter value type of then parameter
      Parameters:
      gtuType - GTU type
      first - independent parameter
      then - dependent parameter
      correlation - correlation
    • addCorrelation

      public <C, T> void addCorrelation(ParameterType<C> first, ParameterType<T> then, ParameterFactoryByType.Correlation<C,T> correlation)
      Correlates one parameter to another for all GTU types.
      Type Parameters:
      C - parameter value type of first parameter
      T - parameter value type of then parameter
      Parameters:
      first - independent parameter
      then - dependent parameter
      correlation - correlation
    • toString

      public String toString()
      Overrides:
      toString in class Object