From d27bfd83d63a02fb8f313d528c0d265961174332 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Sat, 3 Mar 2012 01:52:06 +0000 Subject: [PATCH] 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 --- .../linear/AbstractLinearOptimizer.java | 37 +++++++++++++++++-- .../optimization/linear/SimplexSolver.java | 8 +++- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/optimization/linear/AbstractLinearOptimizer.java b/src/main/java/org/apache/commons/math3/optimization/linear/AbstractLinearOptimizer.java index 37254b651..deb7f3976 100644 --- a/src/main/java/org/apache/commons/math3/optimization/linear/AbstractLinearOptimizer.java +++ b/src/main/java/org/apache/commons/math3/optimization/linear/AbstractLinearOptimizer.java @@ -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 linearConstraints; + private Collection 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 getConstraints() { + return Collections.unmodifiableCollection(linearConstraints); + } + /** {@inheritDoc} */ public void setMaxIterations(int maxIterations) { this.maxIterations = maxIterations; diff --git a/src/main/java/org/apache/commons/math3/optimization/linear/SimplexSolver.java b/src/main/java/org/apache/commons/math3/optimization/linear/SimplexSolver.java index 13472a448..c3d90890f 100644 --- a/src/main/java/org/apache/commons/math3/optimization/linear/SimplexSolver.java +++ b/src/main/java/org/apache/commons/math3/optimization/linear/SimplexSolver.java @@ -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();