| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| LPSolver |
|
| 1.0;1 |
| 1 | /* | |
| 2 | This file is part of Combean. | |
| 3 | ||
| 4 | Combean is free software; you can redistribute it and/or modify | |
| 5 | it under the terms of the GNU General Public License as published by | |
| 6 | the Free Software Foundation; either version 2 of the License, or | |
| 7 | (at your option) any later version. | |
| 8 | ||
| 9 | Combean is distributed in the hope that it will be useful, | |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | GNU General Public License for more details. | |
| 13 | ||
| 14 | You should have received a copy of the GNU General Public License | |
| 15 | along with Combean; if not, write to the Free Software | |
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 17 | */ | |
| 18 | /* | |
| 19 | * Created on 22.04.2005 | |
| 20 | * | |
| 21 | */ | |
| 22 | package net.sourceforge.combean.interfaces.mathprog.lp; | |
| 23 | ||
| 24 | import net.sourceforge.combean.interfaces.mathprog.linalg.SparseVector; | |
| 25 | ||
| 26 | /** | |
| 27 | * An LP solver which allows a linear programming problem to be | |
| 28 | * constructed and solved. | |
| 29 | * | |
| 30 | * @author schickin | |
| 31 | * | |
| 32 | */ | |
| 33 | public interface LPSolver { | |
| 34 | ||
| 35 | /** | |
| 36 | * A hint to the memory management. Should be called before constructing | |
| 37 | * the LP. If the allocation stays within the given bounds, no further | |
| 38 | * memory allocation shall take place. | |
| 39 | * | |
| 40 | * @param numRows number of rows to be reserved. | |
| 41 | * @param numColumns number of columns to be reserved. | |
| 42 | */ | |
| 43 | public void setInitialDimensions(int numRows, int numColumns); | |
| 44 | ||
| 45 | /** | |
| 46 | * Add a variable to the LP problem. The corresponding column in the | |
| 47 | * constraint matrix is filled with zero values. | |
| 48 | * | |
| 49 | * @param variable the variable to be added. | |
| 50 | * @return the number of the corresponding column of the LP | |
| 51 | * (counting from zero) | |
| 52 | */ | |
| 53 | public int addVariable(LPVariable variable); | |
| 54 | ||
| 55 | /** | |
| 56 | * Add a constraint to the LP problem. The corresponding row in the | |
| 57 | * constraint matrix is filled with zero values. | |
| 58 | * | |
| 59 | * @param constraint the constraint to be added. | |
| 60 | * @return the number of the corresponding row of the LP | |
| 61 | * (counting from zero) | |
| 62 | */ | |
| 63 | public int addConstraint(LPConstraint constraint); | |
| 64 | ||
| 65 | /** | |
| 66 | * Add a row to the LP problem. | |
| 67 | * | |
| 68 | * @param constraint the constraint of the row to be added | |
| 69 | * @param rowVec the row vector of the constraint matrix to be added. | |
| 70 | * @return the number of the row in the LP (counting from zero). | |
| 71 | */ | |
| 72 | public int addRow(LPConstraint constraint, SparseVector rowVec); | |
| 73 | ||
| 74 | /** | |
| 75 | * Add a column to the LP problem. | |
| 76 | * | |
| 77 | * @param variable the variable of the column to be added | |
| 78 | * @param colVec the column vector of the constraint matrix to be added. | |
| 79 | * @return the number of the column in the LP (counting from zero). | |
| 80 | */ | |
| 81 | public int addColumn(LPVariable variable, SparseVector colVec); | |
| 82 | ||
| 83 | /** | |
| 84 | * @todo use an enum for that | |
| 85 | */ | |
| 86 | public static final byte LPOBJ_UNDEFINED = 0; | |
| 87 | public static final byte LPOBJ_MAX = 1; | |
| 88 | public static final byte LPOBJ_MIN = 2; | |
| 89 | public static final byte LPOBJ_COUNT = 3; | |
| 90 | ||
| 91 | /** | |
| 92 | * Set the objective of the LP (min or max). | |
| 93 | * | |
| 94 | * @param objective the objective | |
| 95 | */ | |
| 96 | public void setObjective(byte objective); | |
| 97 | ||
| 98 | /** | |
| 99 | * This method must be called after the LP has been constructed and | |
| 100 | * before the solver is called. This allows implementations to do | |
| 101 | * some cleanup of data structures which are only required during | |
| 102 | * the construction of the LP. | |
| 103 | */ | |
| 104 | public void freeze(); | |
| 105 | ||
| 106 | /** | |
| 107 | * The number of rows of the LP. | |
| 108 | * | |
| 109 | * @return number of rows. | |
| 110 | */ | |
| 111 | public int getNumRows(); | |
| 112 | ||
| 113 | /** | |
| 114 | * The number of columns of the LP. | |
| 115 | * | |
| 116 | * @return number of columns. | |
| 117 | */ | |
| 118 | public int getNumColumns(); | |
| 119 | ||
| 120 | /** | |
| 121 | * Solve the LP (usually from scratch). | |
| 122 | */ | |
| 123 | public void solve(); | |
| 124 | ||
| 125 | /** | |
| 126 | * @todo use an enum for that | |
| 127 | */ | |
| 128 | public static final byte LPSTAT_UNDEFINED = 0; | |
| 129 | public static final byte LPSTAT_SOLVED = 1; | |
| 130 | public static final byte LPSTAT_INFEASIBLE = 2; | |
| 131 | public static final byte LPSTAT_UNBOUNDED = 3; | |
| 132 | public static final byte LPSTAT_FAILURE = 4; | |
| 133 | public static final byte LPSTAT_COUNT = 5; | |
| 134 | ||
| 135 | /** | |
| 136 | * Return the status of the solver has attempted to solve the problem. | |
| 137 | * | |
| 138 | * @return status of the solution. | |
| 139 | */ | |
| 140 | public byte getSolutionStatus(); | |
| 141 | ||
| 142 | /** | |
| 143 | * Get value of objective function. | |
| 144 | * May only be called if status is LPSTAT_SOLVED. | |
| 145 | * | |
| 146 | * @return value of objective function. | |
| 147 | */ | |
| 148 | public double getSolutionValue(); | |
| 149 | ||
| 150 | /** | |
| 151 | * Get the primal solution vector of LP. | |
| 152 | * May only be called if status is LPSTAT_SOLVED. | |
| 153 | * | |
| 154 | * @return primal solution vector of LP. | |
| 155 | */ | |
| 156 | public SparseVector getSolution(); | |
| 157 | } |