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
018package org.apache.commons.math3.optimization.linear;
019
020import java.util.Collection;
021
022import org.apache.commons.math3.exception.MathIllegalStateException;
023import org.apache.commons.math3.optimization.GoalType;
024import org.apache.commons.math3.optimization.PointValuePair;
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 * @deprecated As of 3.1 (to be removed in 4.0).
051 * @since 2.0
052 */
053@Deprecated
054public interface LinearOptimizer {
055
056    /**
057     * Set the maximal number of iterations of the algorithm.
058     * @param maxIterations maximal number of function calls
059     */
060    void setMaxIterations(int maxIterations);
061
062    /**
063     * Get the maximal number of iterations of the algorithm.
064     * @return maximal number of iterations
065     */
066    int getMaxIterations();
067
068    /**
069     * Get the number of iterations realized by the algorithm.
070     * <p>
071     * The number of evaluations corresponds to the last call to the
072     * {@link #optimize(LinearObjectiveFunction, Collection, GoalType, boolean) optimize}
073     * method. It is 0 if the method has not been called yet.
074     * </p>
075     * @return number of iterations
076     */
077    int getIterations();
078
079    /**
080     * Optimizes an objective function.
081     * @param f linear objective function
082     * @param constraints linear constraints
083     * @param goalType type of optimization goal: either {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}
084     * @param restrictToNonNegative whether to restrict the variables to non-negative values
085     * @return point/value pair giving the optimal value for objective function
086     * @exception MathIllegalStateException if no solution fulfilling the constraints
087     *   can be found in the allowed number of iterations
088     */
089   PointValuePair optimize(LinearObjectiveFunction f, Collection<LinearConstraint> constraints,
090                               GoalType goalType, boolean restrictToNonNegative) throws MathIllegalStateException;
091
092}