Variable visibility: "protected" -> "private". Added getter methods.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1296553 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-03-03 01:52:06 +00:00
parent f8efb929f4
commit d27bfd83d6
2 changed files with 39 additions and 6 deletions

View File

@ -18,6 +18,7 @@
package org.apache.commons.math3.optimization.linear;
import java.util.Collection;
import java.util.Collections;
import org.apache.commons.math3.exception.MathIllegalStateException;
import org.apache.commons.math3.exception.MaxCountExceededException;
@ -41,25 +42,25 @@ public abstract class AbstractLinearOptimizer implements LinearOptimizer {
* Linear objective function.
* @since 2.1
*/
protected LinearObjectiveFunction function;
private LinearObjectiveFunction function;
/**
* Linear constraints.
* @since 2.1
*/
protected Collection<LinearConstraint> linearConstraints;
private Collection<LinearConstraint> linearConstraints;
/**
* Type of optimization goal: either {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}.
* @since 2.1
*/
protected GoalType goal;
private GoalType goal;
/**
* Whether to restrict the variables to non-negative values.
* @since 2.1
*/
protected boolean nonNegative;
private boolean nonNegative;
/** Maximal number of iterations allowed. */
private int maxIterations;
@ -74,6 +75,34 @@ public abstract class AbstractLinearOptimizer implements LinearOptimizer {
setMaxIterations(DEFAULT_MAX_ITERATIONS);
}
/**
* @return {@code true} if the variables are restricted to non-negative values.
*/
protected boolean restrictToNonNegative() {
return nonNegative;
}
/**
* @return the optimization type.
*/
protected GoalType getGoalType() {
return goal;
}
/**
* @return the optimization type.
*/
protected LinearObjectiveFunction getFunction() {
return function;
}
/**
* @return the optimization type.
*/
protected Collection<LinearConstraint> getConstraints() {
return Collections.unmodifiableCollection(linearConstraints);
}
/** {@inheritDoc} */
public void setMaxIterations(int maxIterations) {
this.maxIterations = maxIterations;

View File

@ -185,8 +185,12 @@ public class SimplexSolver extends AbstractLinearOptimizer {
public PointValuePair doOptimize()
throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException {
final SimplexTableau tableau =
new SimplexTableau(function, linearConstraints, goal, nonNegative,
epsilon, maxUlps);
new SimplexTableau(getFunction(),
getConstraints(),
getGoalType(),
restrictToNonNegative(),
epsilon,
maxUlps);
solvePhase1(tableau);
tableau.dropPhase1Objective();