Encapsulation of a linear program. More...
#include <LinearProgram.hh>
Public Member Functions | |
LinearProgram () | |
Constructor. | |
virtual | ~LinearProgram () |
Destructor. | |
void | readMps (const char *fileName) |
Read the problem instance from an MPS file. | |
void | randomizeObjective () |
Choose a random objective function. | |
void | setColLower (UndoManager &um, int col, double val) |
Set lower bound of a column. | |
void | setColUpper (UndoManager &um, int col, double val) |
Set upper bound of a column. | |
bool | solve () |
Find optimal solution to current linear program. | |
void | dumpSolution (std::ostream &out=std::cerr) const |
Dump the current solution for debugging purposes. | |
int | getNumRows () const |
Get the number of rows. | |
int | getNumCols () const |
Get the number of columns. | |
double | getColSolution (int index) const |
Get one variable of the solution. | |
double | getColLower (int col) const |
Get the current lower bound of a column. | |
double | getColUpper (int col) const |
Get the current upper bound of a column. | |
double | getRowLower (int row) const |
Get the current lower bound of a row. | |
double | getRowUpper (int row) const |
Get the current upper bound of a row. | |
std::string | getColName (int col) const |
Get the name of a column. | |
std::string | getRowName (int row) const |
Get the name of a row. | |
OsiSolverInterface * | getSolver () |
Access to the wrapped solver interface. | |
Protected Attributes | |
OsiSolverInterface * | solver |
The wrapped solver interface. | |
int | rows |
Number of rows. | |
int | cols |
Number of columns. | |
std::vector< std::string > | colNames |
Column names. | |
std::vector< std::string > | rowNames |
Row names. | |
bool | hasSolution |
Flag indicating a valid solution. | |
const double * | solution |
Solution values. |
Encapsulation of a linear program.
In the current implementation, this class encapsulates an LP solver through the OsiSolverInterface. It extends that interface by methods to access the row and column names and by registering modifications with an UndoManager.
Definition at line 37 of file LinearProgram.hh.
bande::LinearProgram::LinearProgram | ( | ) |
Constructor.
The current implementation uses OsiClpSolverInterface as the backend behind this wrapper. The model will be uninitialized, waiting to be read by readMps().
Definition at line 37 of file LinearProgram.cc.
References cols, hasSolution, rows, and solver.
void bande::LinearProgram::dumpSolution | ( | std::ostream & | out = std::cerr |
) | const |
Dump the current solution for debugging purposes.
out | the output stream to which the solution will be dumped. |
Definition at line 99 of file LinearProgram.cc.
References getColName(), getColSolution(), and getNumCols().
Referenced by bande::IntegerProgram::dumpSolution().
double bande::LinearProgram::getColLower | ( | int | col | ) | const [inline] |
Get the current lower bound of a column.
col | the index of the column. |
Definition at line 77 of file LinearProgram.hh.
References OsiSolverInterface::getColLower(), and solver.
Referenced by bande::IntegerProgram::readMps().
std::string bande::LinearProgram::getColName | ( | int | col | ) | const [inline] |
Get the name of a column.
This is also the name of the associated variable.
col | the index of the column. |
Definition at line 106 of file LinearProgram.hh.
References colNames.
Referenced by dumpSolution(), and bande::IntegerProgram::getColName().
double bande::LinearProgram::getColSolution | ( | int | index | ) | const [inline] |
Get one variable of the solution.
index | the index of the variable. |
Definition at line 70 of file LinearProgram.hh.
References solution.
Referenced by dumpSolution(), and bande::IntegerProgram::getColSolution().
double bande::LinearProgram::getColUpper | ( | int | col | ) | const [inline] |
Get the current upper bound of a column.
col | the index of the column. |
Definition at line 84 of file LinearProgram.hh.
References OsiSolverInterface::getColUpper(), and solver.
Referenced by bande::IntegerProgram::readMps().
int bande::LinearProgram::getNumCols | ( | ) | const [inline] |
Get the number of columns.
Each column corresponds to one variable of the solution.
Definition at line 63 of file LinearProgram.hh.
References cols.
Referenced by dumpSolution(), bande::IntegerProgram::getNumCols(), and randomizeObjective().
int bande::LinearProgram::getNumRows | ( | ) | const [inline] |
Get the number of rows.
Each row represents zero to two inequalities, depending on the row bounds.
Definition at line 56 of file LinearProgram.hh.
References rows.
Referenced by bande::IntegerProgram::getNumRows().
double bande::LinearProgram::getRowLower | ( | int | row | ) | const [inline] |
Get the current lower bound of a row.
row | the intex of the row. |
Definition at line 91 of file LinearProgram.hh.
References OsiSolverInterface::getRowLower(), and solver.
Referenced by bande::IntegerProgram::readMps().
std::string bande::LinearProgram::getRowName | ( | int | row | ) | const [inline] |
Get the name of a row.
row | the index of the row. |
Definition at line 113 of file LinearProgram.hh.
References rowNames.
Referenced by bande::IntegerProgram::getRowName().
double bande::LinearProgram::getRowUpper | ( | int | row | ) | const [inline] |
Get the current upper bound of a row.
row | the index of the row. |
Definition at line 98 of file LinearProgram.hh.
References OsiSolverInterface::getRowUpper(), and solver.
Referenced by bande::IntegerProgram::readMps().
OsiSolverInterface* bande::LinearProgram::getSolver | ( | ) | [inline] |
Access to the wrapped solver interface.
It is suggested that the returned object be used for read-only access, although this is not strictly required, as many methods of this wrapper simply call corresponding methods of the wrapped interface and thus will reflect changes. Notable Exceptions to this rules are the size of the matrix or the vector of solutions.
The returned pointer is the one used by this class, so it must not be deleted by the caller of this method.
Definition at line 131 of file LinearProgram.hh.
References solver.
Referenced by bande::IntegerProgram::readMps().
void bande::LinearProgram::randomizeObjective | ( | ) |
Choose a random objective function.
For enumeration purposes, the actual value of the objective function is irrelevant. However, a random objective function which most probably assigns different objective values to all feasible integral solutions will enhance numeric stability.
The implementation uses CoinDrand48() as randum number generator. As that generator is seeded to a fixed value in Settings::run(), consecutive runs of this program will yield the same results in the same order, making the process deterministic and any possible bugs reproducible.
Definition at line 152 of file LinearProgram.cc.
References CoinDrand48(), getNumCols(), OsiSolverInterface::setObjCoeff(), and solver.
Referenced by bande::IntegerProgram::randomizeObjective().
void bande::LinearProgram::readMps | ( | const char * | fileName | ) |
Read the problem instance from an MPS file.
If a different interface than OsiClpSolverInterface is used, then the file will be read twice, to provide names because access to names is not part of the generic OsiSolverInterface. In case of an error the program will exit with EXIT_FAILURE.
fileName | the name of the file to be read in. |
Definition at line 59 of file LinearProgram.cc.
References colNames, cols, OsiClpSolverInterface::getColName(), OsiSolverInterface::getNumCols(), OsiSolverInterface::getNumRows(), OsiClpSolverInterface::getRowName(), OsiSolverInterface::messageHandler(), OsiClpSolverInterface::readMps(), OsiSolverInterface::readMps(), rowNames, rows, CoinMessageHandler::setLogLevel(), and solver.
Referenced by bande::IntegerProgram::readMps().
void bande::LinearProgram::setColLower | ( | UndoManager & | um, | |
int | col, | |||
double | val | |||
) |
Set lower bound of a column.
This modification is registered with an undo manager so it can be rewound when switching to a different branch.
um | the undo manager to track the modification. | |
col | the index of the column to adjust. | |
val | the new lower bound on the specified column. |
Definition at line 118 of file LinearProgram.cc.
References OsiSolverInterface::getColLower(), bande::UndoManager::record(), OsiSolverInterface::setColLower(), and solver.
Referenced by bande::IntegerProgram::setColLower().
void bande::LinearProgram::setColUpper | ( | UndoManager & | um, | |
int | col, | |||
double | val | |||
) |
Set upper bound of a column.
This modification is registered with an undo manager so it can be rewound when switching to a different branch.
um | the undo manager to track the modification. | |
col | the index of the column to adjust. | |
val | the new upper bound on the specified column. |
Definition at line 132 of file LinearProgram.cc.
References OsiSolverInterface::getColUpper(), bande::UndoManager::record(), OsiSolverInterface::setColUpper(), and solver.
Referenced by bande::IntegerProgram::setColUpper().
bool bande::LinearProgram::solve | ( | ) |
Find optimal solution to current linear program.
Definition at line 86 of file LinearProgram.cc.
References OsiSolverInterface::getColSolution(), hasSolution, OsiSolverInterface::initialSolve(), OsiSolverInterface::isProvenOptimal(), OsiSolverInterface::resolve(), solution, and solver.
Referenced by bande::IntegerProgram::solve().