Class ParameterFactoryByType
java.lang.Object
org.opentrafficsim.core.parameters.ParameterFactoryByType
- All Implemented Interfaces:
ParameterFactory
- Direct Known Subclasses:
ParameterFactoryOneShot
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCorrelates two parameter values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<C,T> void addCorrelation(ParameterType<C> first, ParameterType<T> then, ParameterFactoryByType.Correlation<C, T> correlation) Correlates one parameter to another for all GTU types.<C,T> void addCorrelation(GtuType gtuType, ParameterType<C> first, ParameterType<T> then, ParameterFactoryByType.Correlation<C, T> correlation) Correlates one parameter to another.<T> voidaddParameter(ParameterType<T> parameterType, T value) Add parameter for all GTU types.voidaddParameter(ParameterTypeDouble parameterType, double value) Add parameter for all GTU types.voidaddParameter(ParameterTypeDouble parameterType, DistContinuous distribution) Add parameter for all GTU types.<U extends Unit<U>,T extends org.djunits.value.vdouble.scalar.base.DoubleScalarRel<U, T>>
voidaddParameter(ParameterTypeNumeric<T> parameterType, ContinuousDistDoubleScalar.Rel<T, U> distribution) Add parameter for all GTU types.voidaddParameter(GtuType gtuType, ParameterType<Double> parameterType, DistContinuous distribution) Add parameter.voidaddParameter(GtuType gtuType, ParameterType<Integer> parameterType, DistDiscrete distribution) Add parameter.<T> voidaddParameter(GtuType gtuType, ParameterType<T> parameterType, T value) Add parameter.<U extends Unit<U>,T extends org.djunits.value.vdouble.scalar.base.DoubleScalarRel<U, T>>
voidaddParameter(GtuType gtuType, ParameterTypeNumeric<T> parameterType, ContinuousDistDoubleScalar.Rel<T, U> distribution) Add parameter.protected voidapplyCorrelationsAndSetValues(Parameters parameters, Map<ParameterType<?>, Object> baseValues, Map<ParameterType<?>, Map<ParameterType<?>, ParameterFactoryByType.Correlation<?, ?>>> typeCorrelations) Applies all given correlations to the values map and sets all values in the parameters.protected <T,C> T correlateValue(Object first, Object then, ParameterFactoryByType.Correlation<?, ?> correlation) Helper method to correlate a typed parameter.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.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.protected <T> booleansetParameterValue(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.protected voidsetValues(Parameters parameters, Map<ParameterType<?>, Object> values) Set all values from the map in the parameters.voidsetValues(Parameters parameters, GtuType gtuType) Creates a set of parameters for the provided GTU type.toString()
-
Constructor Details
-
ParameterFactoryByType
public ParameterFactoryByType()Constructor.
-
-
Method Details
-
setValues
Description copied from interface:ParameterFactoryCreates a set of parameters for the provided GTU type.- Specified by:
setValuesin interfaceParameterFactory- Parameters:
parameters- parametersgtuType- GTU type- Throws:
ParameterException- when illegal parameter value is set
-
getBaseValues
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<?>, getCorrelationsParameterFactoryByType.Correlation<?, ?>>> (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<?>, throws ParameterExceptionMap<ParameterType<?>, ParameterFactoryByType.Correlation<?, ?>>> typeCorrelations) 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 valuesbaseValues- 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 typeC- independent parameter type- Parameters:
first- independent valuethen- dependent valuecorrelation- correlation- Returns:
- correlated value
-
setValues
protected void setValues(Parameters parameters, Map<ParameterType<?>, Object> values) throws ParameterExceptionSet all values from the map in the parameters.- Parameters:
parameters- parametersvalues- 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- parametersparameterType- parameter typevalue- value- Returns:
- whether the value was successfully set
-
addParameter
Add parameter.- Type Parameters:
T- parameter value type- Parameters:
gtuType- the gtu typeparameterType- the parameter typevalue- the value of the parameter
-
addParameter
public <U extends Unit<U>,T extends org.djunits.value.vdouble.scalar.base.DoubleScalarRel<U, void addParameterT>> (GtuType gtuType, ParameterTypeNumeric<T> parameterType, ContinuousDistDoubleScalar.Rel<T, U> distribution) Add parameter.- Type Parameters:
U- unit typeT- parameter value type- Parameters:
gtuType- the gtu typeparameterType- the parameter typedistribution- 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 typeparameterType- the parameter typedistribution- the distribution of the parameter
-
addParameter
public void addParameter(GtuType gtuType, ParameterType<Double> parameterType, DistContinuous distribution) Add parameter.- Parameters:
gtuType- the gtu typeparameterType- the parameter typedistribution- the distribution of the parameter
-
addParameter
Add parameter for all GTU types.- Type Parameters:
T- type- Parameters:
parameterType- the parameter typevalue- the value of the parameter
-
addParameter
Add parameter for all GTU types.- Parameters:
parameterType- the parameter typevalue- the value of the parameter
-
addParameter
public <U extends Unit<U>,T extends org.djunits.value.vdouble.scalar.base.DoubleScalarRel<U, void addParameterT>> (ParameterTypeNumeric<T> parameterType, ContinuousDistDoubleScalar.Rel<T, U> distribution) Add parameter for all GTU types.- Type Parameters:
U- unit typeT- parameter value type- Parameters:
parameterType- the parameter typedistribution- ContinuousDistDoubleScalar.Rel<T,U>; the distribution of the parameter
-
addParameter
Add parameter for all GTU types.- Parameters:
parameterType- the parameter typedistribution- 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 benull, in which case the parameter can be correlated to an external source.- Type Parameters:
C- parameter value type of first parameterT- parameter value type of then parameter- Parameters:
gtuType- GTU typefirst- independent parameterthen- dependent parametercorrelation- 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 parameterT- parameter value type of then parameter- Parameters:
first- independent parameterthen- dependent parametercorrelation- correlation
-
toString
-