@@ -0,0 +1,2924 @@
+/*%0A * The MIT License%0A *%0A * Copyright 2017 Y.K. Chan%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in%0A * all copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN%0A * THE SOFTWARE.%0A */%0A%0Apackage jacobi.core.linprog;%0A%0Aimport jacobi.api.Matrix;%0Aimport jacobi.api.annotations.Immutate;%0Aimport jacobi.core.util.Throw;%0Aimport java.util.Optional;%0A%0A/**%0A * Implementation class for Linear Programming problems.%0A * %0A * %3Cp%3EThe Linear Programming (LP) problem is standardize as follows:%3C/p%3E%0A * %0A * %3Cp%3EGiven column vector c, b, matrix a, find x &gt;= 0 s.t.&nbsp;c%5Et * x attains maximum and A * x &lt;= b.%3C/p%3E%0A * %0A * %3Cp%3E%0A * For minimization problems, user can simply negate c. %0A * For greater-than conditions, user can simply negate the equation. b here is allowed to be negative.%0A * %3C/p%3E%0A * %0A * @author Y.K. Chan%0A */%0A@Immutate%0Apublic class LinearProg %7B%0A%0A    /**%0A     * Constructor.%0A     */%0A    public LinearProg() %7B        %0A        this.simplexAlgo = new StandardSimplex(LIMIT, new DantzigsRule());%0A    %7D%0A    %0A    /**%0A     * Compute the LP max c%5Et * x s.t.&nbsp;A*x &lt;= b.%0A     * @param c  Coefficient to the linear objective function%0A     * @param a  Constraint matrix%0A     * @param b  Constraint boundary%0A     * @return  A solution to the LP problem, or empty if the constraint is unbounded/infeasible.%0A     */%0A    public Optional%3CMatrix%3E compute(Matrix c, Matrix a, Matrix b) %7B%0A        Throw.when().isNull(() -%3E c, () -%3E %22No objective function.%22)%0A                .isNull(() -%3E a, () -%3E %22No constraint matrix. Use an empty matrix for no constraint.%22)%0A                .isNull(() -%3E b, () -%3E %22No constraint boundary. Use an empty matrix for no boundary.%22);%0A        if(a.getRowCount() == 0 %7C%7C b.getRowCount() == 0)%7B%0A            // all LP problems are unbounded/infeasible if no constraint%0A            return Optional.empty(); %0A        %7D%0A        return this.simplexAlgo.compute(c, a, b);%0A    %7D%0A%0A    private StandardSimplex simplexAlgo;%0A    %0A    private static final long LIMIT = 65536L;%0A%7D%0A

Support linear programming