Package nl.tue.astar.util.ilp
Interface LPMatrix<S>
-
- Type Parameters:
S-
- All Known Implementing Classes:
LPMatrix.DENSE.GUROBI,LPMatrix.DENSE.LPSOLVE,LPMatrix.SPARSE.GUROBI,LPMatrix.SPARSE.LPSOLVE
public interface LPMatrix<S>This interface represents an LP matrix, consisting of an objective function, an internal matrix, a right-hand-side vector, row- and column names, variable types, constraint types and lower and upper bound. The type parameterrefers to the type of the external solver used for solving the MIP represented by this object. The interface is borrowed mainly from LpSolve, with the distinct difference that all rows and columns start from 0, i.e. there are [0 .. getNRows()-1] rows and [0 .. getNColumns()-1] columns. The constants GE (greater or equal), LE (less or equal), and EQ (equal) represent the constraint types The constants REAL, INTEGER and BINARY represent the variable types. INFINITE = 1E30 defines infinity. A call to solve(double[] vars) will push the internal structure to the solver, call the external solve function (currently provided for LpSolve and Gurobi) and return OPTIMAL, in case an optimal solution is found, INFEASIBLE, if the model is infeasible or unbounded, or OTHER, if the external solver returned another result. If the solve() call returns OPTIMAL, the array vars is filled with the solution for all variables, i.e. vars needs to be dimensioned [0..getNColumns()-1] by the caller. If the solve() call returns INFEASIBLE or OTHER, the vars array is not touched. The exact result of the external solver can be obtained by a call to getLastSolverResult(). An LPMatrixException is thrown in all methods that are pushed to the external solver and the exception typically wraps the exception thrown by the external solver. The SPARSE and DENSE implementations provided by this interface differ in the way the internal matrix is stored. The SPARSE variants use considerably less memory at the expense of slightly higher time to set elements in the matrix. Additional to an esay solve() method, the interface also provides a toSolver() method, that returns an object of type S, which is a translation of the matrix into the external solver. This method is for more advanced use only. Note that the getOffset() method is to be used in conjunction to make sure that rows and columns are adressed properly in the external representation.- Author:
- bfvdonge
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classLPMatrix.DENSEStatic class wrapping DENSE variants of LPMatrixThe dense variants of LPMatrixrepresent the internal MIP matrix explicitly, i.e.static classLPMatrix.SPARSEStatic class wrapping SPARSE variants of LPMatrixThe internal MIP matrix is represented by a hashmap from a pair of coordinates to a value.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadjustMat(int row, int column, double value)adjusts the value at index row, column in the matrix.java.lang.StringgetColName(int column)Gets the name of a column, or null if there is none.java.lang.String[]getColNames()Returns the column names or null if there are none.bytegetConstrType(int r)intgetLastSolverResult()returns the last result returned by the external solver.doublegetlowBo(int c)doublegetMat(int row, int column)Return the value at index row, column in the MIP matrix.intgetNcolumns()intgetNrows()doublegetObjective(int column)intgetOffset()doublegetRh(int row)java.lang.StringgetRowName(int r)java.lang.String[]getRowNames()doublegetUpBo(int c)bytegetVarType(int c)doubleobjectiveValue(double[] vars)voidprintLp(java.io.OutputStreamWriter writer, java.lang.String sep)prints the LP to the given outputWriter using the given separator character as separator.voidprintLpToCSV(java.lang.String fileName)Prints the MIP to a CSV file using ";" as a separator character.doubleproduct(double[] vars, int fromIncluding, int toExcluding, int row)voidsetBinary(int c, boolean b)voidsetColName(int column, java.lang.String name)Sets the name of a column.voidsetConstrType(int row, byte type)voidsetInt(int column, boolean isInt)voidsetLowbo(int column, double value)voidsetMat(int row, int column, double value)set the value at index row, column in the matrix.voidsetMaxim()voidsetMinim()voidsetObjective(int column, double value)voidsetRh(int row, double value)voidsetRhVec(double[] rhs)voidsetRowName(int row, java.lang.String name)Sets the name of a row.voidsetUpbo(int column, double value)intsolve(double[] vars)Constructs the solver and solves the MIP represented by this problem.StoSolver()Constructs the solver in its external representation
-
-
-
Field Detail
-
INFEASIBLE
static final int INFEASIBLE
- See Also:
- Constant Field Values
-
OPTIMAL
static final int OPTIMAL
- See Also:
- Constant Field Values
-
OTHER
static final int OTHER
- See Also:
- Constant Field Values
-
REAL
static final byte REAL
- See Also:
- Constant Field Values
-
INTEGER
static final byte INTEGER
- See Also:
- Constant Field Values
-
BINARY
static final byte BINARY
- See Also:
- Constant Field Values
-
GE
static final byte GE
- See Also:
- Constant Field Values
-
LE
static final byte LE
- See Also:
- Constant Field Values
-
EQ
static final byte EQ
- See Also:
- Constant Field Values
-
INFINITE
static final double INFINITE
- See Also:
- Constant Field Values
-
-
Method Detail
-
toSolver
S toSolver() throws LPMatrixException
Constructs the solver in its external representation- Returns:
- Throws:
LPMatrixException
-
solve
int solve(double[] vars) throws LPMatrixException
Constructs the solver and solves the MIP represented by this problem. The returned value is either OPTIMAL, INFEASIBLE or OTHER. The external solver's result can be obtained through getLastSolverResult()- Parameters:
vars- an array dimensioned in the number of columns, i.e. vars.length == getNColumns(). This is not checked!- Returns:
- Throws:
LPMatrixException- if the external solver throws an exception
-
getLastSolverResult
int getLastSolverResult()
returns the last result returned by the external solver. This method only makes sense after a call to solve() that did not throw an exception.- Returns:
-
getMat
double getMat(int row, int column)Return the value at index row, column in the MIP matrix.- Parameters:
row-column-- Returns:
-
setMat
void setMat(int row, int column, double value)set the value at index row, column in the matrix.- Parameters:
row-column-value-
-
adjustMat
void adjustMat(int row, int column, double value)adjusts the value at index row, column in the matrix.- Parameters:
row-column-value-
-
setInt
void setInt(int column, boolean isInt)
-
setUpbo
void setUpbo(int column, double value)
-
setLowbo
void setLowbo(int column, double value)
-
setColName
void setColName(int column, java.lang.String name)Sets the name of a column. Setting names is not required and no memory is reserved for column names until the first name is set on a column.- Parameters:
column-
-
setRowName
void setRowName(int row, java.lang.String name)Sets the name of a row. Setting names is not required and no memory is reserved for row names until the first name is set on a row.- Parameters:
row-
-
setConstrType
void setConstrType(int row, byte type)
-
setMaxim
void setMaxim()
-
setMinim
void setMinim()
-
getNrows
int getNrows()
-
setRhVec
void setRhVec(double[] rhs)
-
getNcolumns
int getNcolumns()
-
setRh
void setRh(int row, double value)
-
setObjective
void setObjective(int column, double value)
-
getRh
double getRh(int row)
-
getColName
java.lang.String getColName(int column)
Gets the name of a column, or null if there is none.- Parameters:
column-- Returns:
-
getObjective
double getObjective(int column)
-
getColNames
java.lang.String[] getColNames()
Returns the column names or null if there are none.- Parameters:
column-- Returns:
-
product
double product(double[] vars, int fromIncluding, int toExcluding, int row)
-
setBinary
void setBinary(int c, boolean b)
-
getOffset
int getOffset()
-
printLpToCSV
void printLpToCSV(java.lang.String fileName) throws java.io.IOExceptionPrints the MIP to a CSV file using ";" as a separator character. If row and column names are provided they are printed, otherwise, they are numbered- Parameters:
fileName-- Throws:
java.io.IOException
-
printLp
void printLp(java.io.OutputStreamWriter writer, java.lang.String sep) throws java.io.IOExceptionprints the LP to the given outputWriter using the given separator character as separator. The output of this method on System.out, with "\t" as the separator returns the same representation as LpSolve's printLp() method.- Parameters:
writer-sep-- Throws:
java.io.IOException
-
getRowNames
java.lang.String[] getRowNames()
-
getVarType
byte getVarType(int c)
-
getlowBo
double getlowBo(int c)
-
getUpBo
double getUpBo(int c)
-
getConstrType
byte getConstrType(int r)
-
getRowName
java.lang.String getRowName(int r)
-
objectiveValue
double objectiveValue(double[] vars)
-
-