Class ComposableDoubleProblem
- All Implemented Interfaces:
java.io.Serializable,BoundedProblem<java.lang.Double,DoubleSolution>,DoubleProblem,Problem<DoubleSolution>
public class ComposableDoubleProblem extends java.lang.Object implements DoubleProblem
ComposableDoubleProblem problem = new ComposableDoubleProblem() .setName("Schaffer") .addVariable(-10, 10) .addVariable(-10, 10) .addFunction((x) -> x[0] * x[0]) .addFunction((x) -> (x[0] - 2.0) * (x[0] - 2.0));
The Srinivas constrained problem can be defined in this way:
ComposableDoubleProblem problem; problem = new ComposableDoubleProblem() .setName("Srinivas") .addVariable(-20.0, 20.0) .addVariable(-20.0, 20.0) .addFunction((x) -> 2.0 + (x[0] - 2.0) * (x[0] - 2.0) + (x[1] - 1.0) * (x[1] - 1.0)) .addFunction((x) -> 9.0 * x[0] - (x[1] - 1.0) * (x[1] - 1.0)) .addConstraint((x) -> 1.0 - (x[0] * x[0] + x[1] * x[1]) / 225.0) .addConstraint((x) -> (3.0 * x[1] - x[0]) / 10.0 - 1.0) ;
Note that this class does not inherits from AbstractDoubleProblem.
As defined, this class would make possible to add more variables, objectives and constraints to an existing problem on the fly.
This class does not intend to be a replacement of the existing of AbstractDoubleProblem; it is merely an alternative way of defining a problem.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description ComposableDoubleProblem() -
Method Summary
Modifier and Type Method Description ComposableDoubleProblemaddConstraint(java.util.function.Function<java.lang.Double[],java.lang.Double> constraint)ComposableDoubleProblemaddFunction(java.util.function.Function<java.lang.Double[],java.lang.Double> objective)ComposableDoubleProblemaddVariable(double lowerBound, double upperBound)DoubleSolutioncreateSolution()DoubleSolutionevaluate(DoubleSolution solution)This method receives a solution, evaluates it, and returns the evaluated solution.java.util.List<org.apache.commons.lang3.tuple.Pair<java.lang.Double,java.lang.Double>>getBounds()Deprecated.java.util.List<Bounds<java.lang.Double>>getBoundsForVariables()java.lang.DoublegetLowerBound(int index)Deprecated.java.lang.StringgetName()intgetNumberOfConstraints()intgetNumberOfObjectives()intgetNumberOfVariables()java.lang.DoublegetUpperBound(int index)Deprecated.ComposableDoubleProblemsetName(java.lang.String name)
-
Constructor Details
-
ComposableDoubleProblem
public ComposableDoubleProblem()
-
-
Method Details
-
addFunction
public ComposableDoubleProblem addFunction(java.util.function.Function<java.lang.Double[],java.lang.Double> objective) -
addConstraint
public ComposableDoubleProblem addConstraint(java.util.function.Function<java.lang.Double[],java.lang.Double> constraint) -
addVariable
-
setName
-
getNumberOfVariables
public int getNumberOfVariables()- Specified by:
getNumberOfVariablesin interfaceProblem<DoubleSolution>
-
getNumberOfObjectives
public int getNumberOfObjectives()- Specified by:
getNumberOfObjectivesin interfaceProblem<DoubleSolution>
-
getNumberOfConstraints
public int getNumberOfConstraints()- Specified by:
getNumberOfConstraintsin interfaceProblem<DoubleSolution>
-
getName
public java.lang.String getName()- Specified by:
getNamein interfaceProblem<DoubleSolution>
-
getLowerBound
@Deprecated public java.lang.Double getLowerBound(int index)Deprecated.- Specified by:
getLowerBoundin interfaceBoundedProblem<java.lang.Double,DoubleSolution>- Parameters:
index- index of the variable- Returns:
- lower bound of the variable
-
getUpperBound
@Deprecated public java.lang.Double getUpperBound(int index)Deprecated.- Specified by:
getUpperBoundin interfaceBoundedProblem<java.lang.Double,DoubleSolution>- Parameters:
index- index of the variable- Returns:
- upper bound of the variable
-
createSolution
- Specified by:
createSolutionin interfaceProblem<DoubleSolution>
-
getBounds
@Deprecated public java.util.List<org.apache.commons.lang3.tuple.Pair<java.lang.Double,java.lang.Double>> getBounds()Deprecated.- Specified by:
getBoundsin interfaceBoundedProblem<java.lang.Double,DoubleSolution>- Returns:
- A list with pairs
for each of the decision variables
-
getBoundsForVariables
- Specified by:
getBoundsForVariablesin interfaceBoundedProblem<java.lang.Double,DoubleSolution>- Returns:
- A list with
Boundsfor each of the decision variables
-
evaluate
Description copied from interface:ProblemThis method receives a solution, evaluates it, and returns the evaluated solution.- Specified by:
evaluatein interfaceProblem<DoubleSolution>- Returns:
-