public abstract class AbstractLinearOptimizer extends Object implements LinearOptimizer
This base class handles the boilerplate methods associated to thresholds settings and iterations counters.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_ITERATIONS
Default maximal number of iterations allowed.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractLinearOptimizer()
Simple constructor with default settings.
|
Modifier and Type | Method and Description |
---|---|
protected abstract PointValuePair |
doOptimize()
Perform the bulk of optimization algorithm.
|
protected Collection<LinearConstraint> |
getConstraints() |
protected LinearObjectiveFunction |
getFunction() |
protected GoalType |
getGoalType() |
int |
getIterations()
Get the number of iterations realized by the algorithm.
|
int |
getMaxIterations()
Get the maximal number of iterations of the algorithm.
|
protected void |
incrementIterationsCounter()
Increment the iterations counter by 1.
|
PointValuePair |
optimize(LinearObjectiveFunction f,
Collection<LinearConstraint> constraints,
GoalType goalType,
boolean restrictToNonNegative)
Optimizes an objective function.
|
protected boolean |
restrictToNonNegative() |
void |
setMaxIterations(int maxIterations)
Set the maximal number of iterations of the algorithm.
|
public static final int DEFAULT_MAX_ITERATIONS
protected AbstractLinearOptimizer()
The maximal number of evaluation is set to its default value.
protected boolean restrictToNonNegative()
true
if the variables are restricted to non-negative values.protected GoalType getGoalType()
protected LinearObjectiveFunction getFunction()
protected Collection<LinearConstraint> getConstraints()
public void setMaxIterations(int maxIterations)
setMaxIterations
in interface LinearOptimizer
maxIterations
- maximal number of function callspublic int getMaxIterations()
getMaxIterations
in interface LinearOptimizer
public int getIterations()
The number of evaluations corresponds to the last call to the
optimize
method. It is 0 if the method has not been called yet.
getIterations
in interface LinearOptimizer
protected void incrementIterationsCounter() throws MaxCountExceededException
MaxCountExceededException
- if the maximal number
of iterations is exceededpublic PointValuePair optimize(LinearObjectiveFunction f, Collection<LinearConstraint> constraints, GoalType goalType, boolean restrictToNonNegative) throws MathIllegalStateException
optimize
in interface LinearOptimizer
f
- linear objective functionconstraints
- linear constraintsgoalType
- type of optimization goal: either GoalType.MAXIMIZE
or GoalType.MINIMIZE
restrictToNonNegative
- whether to restrict the variables to non-negative valuesMathIllegalStateException
- if no solution fulfilling the constraints
can be found in the allowed number of iterationsprotected abstract PointValuePair doOptimize() throws MathIllegalStateException
MathIllegalStateException
- if no solution fulfilling the constraints
can be found in the allowed number of iterationsCopyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.