    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements.  See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache License, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License.  You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the License for the specific language governing permissions and
    015     * limitations under the License.
    016     */
    017
    018    package org.apache.commons.math.optimization.linear;
    019
    020    import java.util.Collection;
    021
    022    import org.apache.commons.math.optimization.GoalType;
    023    import org.apache.commons.math.optimization.OptimizationException;
    024    import org.apache.commons.math.optimization.RealPointValuePair;
    025
    026    /**
    027     * This interface represents an optimization algorithm for linear problems.
    028     * <p>Optimization algorithms find the input point set that either {@link GoalType
    029     * maximize or minimize} an objective function. In the linear case the form of
    030     * the function is restricted to
    031     * <pre>
    032     * c<sub>1</sub>x<sub>1</sub> + ... c<sub>n</sub>x<sub>n</sub> = v
    033     * </pre>
    034     * and there may be linear constraints too, of one of the forms:
    035     * <ul>
    036     *   <li>c<sub>1</sub>x<sub>1</sub> + ... c<sub>n</sub>x<sub>n</sub> = v</li>
    037     *   <li>c<sub>1</sub>x<sub>1</sub> + ... c<sub>n</sub>x<sub>n</sub> &lt;= v</li>
    038     *   <li>c<sub>1</sub>x<sub>1</sub> + ... c<sub>n</sub>x<sub>n</sub> >= v</li>
    039     *   <li>l<sub>1</sub>x<sub>1</sub> + ... l<sub>n</sub>x<sub>n</sub> + l<sub>cst</sub> =
    040     *       r<sub>1</sub>x<sub>1</sub> + ... r<sub>n</sub>x<sub>n</sub> + r<sub>cst</sub></li>
    041     *   <li>l<sub>1</sub>x<sub>1</sub> + ... l<sub>n</sub>x<sub>n</sub> + l<sub>cst</sub> &lt;=
    042     *       r<sub>1</sub>x<sub>1</sub> + ... r<sub>n</sub>x<sub>n</sub> + r<sub>cst</sub></li>
    043     *   <li>l<sub>1</sub>x<sub>1</sub> + ... l<sub>n</sub>x<sub>n</sub> + l<sub>cst</sub> >=
    044     *       r<sub>1</sub>x<sub>1</sub> + ... r<sub>n</sub>x<sub>n</sub> + r<sub>cst</sub></li>
    045     * </ul>
    046     * where the c<sub>i</sub>, l<sub>i</sub> or r<sub>i</sub> are the coefficients of
    047     * the constraints, the x<sub>i</sub> are the coordinates of the current point and
    048     * v is the value of the constraint.
    049     * </p>
    050     * @version $Revision: 811685 $ $Date: 2009-09-05 19:36:48 +0200 (sam. 05 sept. 2009) $
    051     * @since 2.0
    052     */
    053    public interface LinearOptimizer {
    054
    055        /** Set the maximal number of iterations of the algorithm.
    056         * @param maxIterations maximal number of function calls
    057         */
    058        void setMaxIterations(int maxIterations);
    059
    060        /** Get the maximal number of iterations of the algorithm.
    061         * @return maximal number of iterations
    062         */
    063        int getMaxIterations();
    064
    065        /** Get the number of iterations realized by the algorithm.
    066         * <p>
    067         * The number of evaluations corresponds to the last call to the
    068         * {@link #optimize(LinearObjectiveFunction, Collection, GoalType, boolean) optimize}
    069         * method. It is 0 if the method has not been called yet.
    070         * </p>
    071         * @return number of iterations
    072         */
    073        int getIterations();
    074
    075        /** Optimizes an objective function.
    076         * @param f linear objective function
    077         * @param constraints linear constraints
    078         * @param goalType type of optimization goal: either {@link GoalType#MAXIMIZE}
    079         * or {@link GoalType#MINIMIZE}
    080         * @param restrictToNonNegative whether to restrict the variables to non-negative values
    081         * @return point/value pair giving the optimal value for objective function
    082         * @exception OptimizationException if no solution fulfilling the constraints
    083         * can be found in the allowed number of iterations
    084         */
    085       RealPointValuePair optimize(LinearObjectiveFunction f, Collection<LinearConstraint> constraints,
    086                                   GoalType goalType, boolean restrictToNonNegative)
    087            throws OptimizationException;
    088
    089    }