Class AbstractLinearOptimizer
- java.lang.Object
-
- org.apache.commons.math.optimization.linear.AbstractLinearOptimizer
-
- All Implemented Interfaces:
LinearOptimizer
- Direct Known Subclasses:
SimplexSolver
public abstract class AbstractLinearOptimizer extends java.lang.Object implements LinearOptimizer
Base class for implementing linear optimizers.This base class handles the boilerplate methods associated to thresholds settings and iterations counters.
- Since:
- 2.0
- Version:
- $Revision: 925812 $ $Date: 2010-03-21 16:49:31 +0100 (dim. 21 mars 2010) $
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_ITERATIONSDefault maximal number of iterations allowed.protected LinearObjectiveFunctionfunctionLinear objective function.protected GoalTypegoalType of optimization goal: eitherGoalType.MAXIMIZEorGoalType.MINIMIZE.protected java.util.Collection<LinearConstraint>linearConstraintsLinear constraints.protected booleannonNegativeWhether to restrict the variables to non-negative values.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLinearOptimizer()Simple constructor with default settings.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract RealPointValuePairdoOptimize()Perform the bulk of optimization algorithm.intgetIterations()Get the number of iterations realized by the algorithm.intgetMaxIterations()Get the maximal number of iterations of the algorithm.protected voidincrementIterationsCounter()Increment the iterations counter by 1.RealPointValuePairoptimize(LinearObjectiveFunction f, java.util.Collection<LinearConstraint> constraints, GoalType goalType, boolean restrictToNonNegative)Optimizes an objective function.voidsetMaxIterations(int maxIterations)Set the maximal number of iterations of the algorithm.
-
-
-
Field Detail
-
DEFAULT_MAX_ITERATIONS
public static final int DEFAULT_MAX_ITERATIONS
Default maximal number of iterations allowed.- See Also:
- Constant Field Values
-
function
protected LinearObjectiveFunction function
Linear objective function.- Since:
- 2.1
-
linearConstraints
protected java.util.Collection<LinearConstraint> linearConstraints
Linear constraints.- Since:
- 2.1
-
goal
protected GoalType goal
Type of optimization goal: eitherGoalType.MAXIMIZEorGoalType.MINIMIZE.- Since:
- 2.1
-
nonNegative
protected boolean nonNegative
Whether to restrict the variables to non-negative values.- Since:
- 2.1
-
-
Method Detail
-
setMaxIterations
public void setMaxIterations(int maxIterations)
Set the maximal number of iterations of the algorithm.- Specified by:
setMaxIterationsin interfaceLinearOptimizer- Parameters:
maxIterations- maximal number of function calls
-
getMaxIterations
public int getMaxIterations()
Get the maximal number of iterations of the algorithm.- Specified by:
getMaxIterationsin interfaceLinearOptimizer- Returns:
- maximal number of iterations
-
getIterations
public int getIterations()
Get the number of iterations realized by the algorithm.The number of evaluations corresponds to the last call to the
optimizemethod. It is 0 if the method has not been called yet.- Specified by:
getIterationsin interfaceLinearOptimizer- Returns:
- number of iterations
-
incrementIterationsCounter
protected void incrementIterationsCounter() throws OptimizationExceptionIncrement the iterations counter by 1.- Throws:
OptimizationException- if the maximal number of iterations is exceeded
-
optimize
public RealPointValuePair optimize(LinearObjectiveFunction f, java.util.Collection<LinearConstraint> constraints, GoalType goalType, boolean restrictToNonNegative) throws OptimizationException
Optimizes an objective function.- Specified by:
optimizein interfaceLinearOptimizer- Parameters:
f- linear objective functionconstraints- linear constraintsgoalType- type of optimization goal: eitherGoalType.MAXIMIZEorGoalType.MINIMIZErestrictToNonNegative- whether to restrict the variables to non-negative values- Returns:
- point/value pair giving the optimal value for objective function
- Throws:
OptimizationException- if no solution fulfilling the constraints can be found in the allowed number of iterations
-
doOptimize
protected abstract RealPointValuePair doOptimize() throws OptimizationException
Perform the bulk of optimization algorithm.- Returns:
- the point/value pair giving the optimal value for objective function
- Throws:
OptimizationException- if no solution fulfilling the constraints can be found in the allowed number of iterations
-
-