Class ParameterSpace
- Direct Known Subclasses:
MOEADCommonParameterSpace,MOPSOParameterSpace,NSGAIICommonParameterSpace,RDEMOEACommonParameterSpace,YAMLParameterSpace
This class provides a framework for managing algorithm parameters in a hierarchical structure. It maintains two main collections:
- A map of all parameters for direct access by name (
parameterSpace) - An ordered list of top-level parameters that serve as entry points for configuration
(
topLevelParameters)
Key features:
- Hierarchical Parameter Management: Supports complex parameter hierarchies with conditional and global parameters
- Type Safety: Uses generics to ensure type safety for all parameter values
- Immutable Views: Provides unmodifiable views of parameters and top-level parameter lists
- Flexible Configuration: Allows dynamic addition and retrieval of parameters
Usage example:
// Create a custom parameter space
public class MyParameterSpace extends ParameterSpace {
public MyParameterSpace() {
// Add parameters
put(new IntegerParameter("populationSize", 50, 200, 100));
put(new DoubleParameter("mutationRate", 0.0, 1.0, 0.1));
// Mark as top-level parameters
addTopLevelParameter(get("populationSize"));
addTopLevelParameter(get("mutationRate"));
}
@Override
public ParameterSpace createInstance() {
return new MyParameterSpace();
}
}
// Usage
ParameterSpace space = new MyParameterSpace();
Parameterinvalid input: '<'?> popSize = space.get("populationSize");
Listinvalid input: '<'Parameterinvalid input: '<'?>> topParams = space.topLevelParameters();
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTopLevelParameter(Parameter<?> parameter) Adds a parameter to the list of top-level parameters.abstract ParameterSpaceCreates and configures a new instance of this parameter space.Parameter<?> Retrieves a parameter by its name.Returns an unmodifiable view of all parameters in this parameter space.voidAdds a parameter to the parameter space.Returns an unmodifiable list of top-level parameters in this parameter space.
-
Field Details
-
parameterSpace
-
topLevelParameters
-
-
Constructor Details
-
ParameterSpace
public ParameterSpace()Constructs a new, empty ParameterSpace.The constructor initializes the internal data structures for storing parameters. Subclasses should typically add parameters and set up their relationships in their constructors after calling
super().Example:
public class MyParameterSpace extends ParameterSpace { public MyParameterSpace() { super(); // Initializes parameter storage // Add parameters here } }
-
-
Method Details
-
put
Adds a parameter to the parameter space.The parameter's name must be unique within this parameter space. If a parameter with the same name already exists, it will be replaced.
- Parameters:
parameter- the parameter to add (must not be null)- Throws:
NullPointerException- if the parameter is null- See Also:
-
get
Retrieves a parameter by its name.- Parameters:
parameterName- the name of the parameter to retrieve (case-sensitive)- Returns:
- the corresponding parameter (never null)
- Throws:
IllegalArgumentException- if no parameter with the given name existsNullPointerException- if parameterName is null- See Also:
-
parameters
Returns an unmodifiable view of all parameters in this parameter space.The returned map includes all parameters, both top-level and nested, keyed by parameter name. The map is unmodifiable; to add parameters, use
put(Parameter).- Returns:
- an unmodifiable map of parameter names to their corresponding Parameter objects
- See Also:
-
topLevelParameters
Returns an unmodifiable list of top-level parameters in this parameter space.Top-level parameters are the main entry points for configuring the algorithm. These parameters are also included in the map returned by
parameters(). The order of parameters in the list matches the order in which they were added.- Returns:
- an unmodifiable list of top-level parameters (never null)
- See Also:
-
addTopLevelParameter
Adds a parameter to the list of top-level parameters.Top-level parameters serve as the main entry points for algorithm configuration. The parameter must have already been added to this parameter space using
put(Parameter)before calling this method.- Parameters:
parameter- the parameter to add as a top-level parameter (must not be null)- Throws:
IllegalArgumentException- if the parameter is not in this parameter spaceNullPointerException- if the parameter is null- See Also:
-
createInstance
Creates and configures a new instance of this parameter space.This method is part of the prototype pattern, allowing parameter spaces to be cloned with the same configuration. Implementations should return a new instance of the concrete parameter space class with the same parameter configuration.
Example implementation:
@Override public ParameterSpace createInstance() { return new MyParameterSpace(); }- Returns:
- a new instance of this parameter space
-