FMT 0.9.8
Forest management tools for forest planning
|
#include <FMTlpsolver.hpp>
Public Member Functions | |
void | swap (FMTlpsolver &rhs) |
void | passinlogger (const std::shared_ptr< Logging::FMTlogger > &logger) override |
void | unmarkHotStart () |
bool | stockresolve () |
FMTlpsolver () | |
virtual | ~FMTlpsolver ()=default |
FMTlpsolver (const FMTlpsolver &rhs) | |
FMTlpsolver (FMTlpsolver &&rhs)=default | |
FMTlpsolver & | operator= (const FMTlpsolver &rhs) |
FMTlpsolver & | operator= (FMTlpsolver &&rhs)=default |
FMTlpsolver (FMTsolverinterface lsolvertype) | |
bool | operator== (const FMTlpsolver &rhs) const |
bool | operator!= (const FMTlpsolver &rhs) const |
virtual bool | resolve () |
virtual bool | initialsolve () |
void | setnumberofthreads (const size_t &nthread) |
void | setMIPgaptolerance (const double &gap) |
void | setoptimizerMAXtime (const double &time) |
void | MIPparameters () |
double | getObjValue () const |
int | getiterationcount () const |
void | passinsolver (const FMTlpsolver &solver) |
void | passinmessagehandler (Logging::FMTlogger &logger) |
void | setsolvertype (FMTsolverinterface &lsolvertype) const |
bool | gotlicense () const |
std::string | getsolvername () const |
int | getNumCols () const |
int | getNumRows () const |
const double * | getObjCoefficients () const |
const double * | getColLower () const |
const double * | getColUpper () const |
const double * | getColSolution () const |
const double * | getRowPrice () const |
const double * | getRowActivity () const |
const double * | getRowUpper () const |
const double * | getRowLower () const |
int | getrow (int whichRow, double &rowLower, double &rowUpper, std::vector< int > &indices, std::vector< double > &elements) const |
int | getcol (int whichCol, double &colLower, double &colUpper, double &objectiveValue, std::vector< int > &indices, std::vector< double > &elements) const |
double | getObjSense () const |
void | setObjective (const double *objectivevalues) |
void | setObjSense (const double &newsense) |
void | addRow (int numberInRow, const int *columns, const double *elements, double rowLower=-std::numeric_limits< double >::max(), double rowUpper=std::numeric_limits< double >::max()) |
void | addCol (int numberInColumn, const int *rows, const double *elements, double columnLower=0.0, double columnUpper=std::numeric_limits< double >::max(), double objectiveValue=0.0) |
void | addRows (const int numrows, const int *rowStarts, const int *columns, const double *elements, const double *rowlb, const double *rowub) |
void | addCols (const int numcols, const int *columnStarts, const int *rows, const double *elements, const double *collb, const double *colub, const double *obj) |
bool | isProvenOptimal () const |
void | deleteRow (const int &rowindex) |
void | deleteCol (const int &colindex) |
void | deleteRows (int numberofrows, const int *rowindexes) |
void | deleteCols (int numberofcols, const int *colindexes) |
void | setColSolution (const double *newsolution) |
void | setRowPrice (const double *rowprice) |
void | setColSetBounds (const int *indexFirst, const int *indexLast, const double *boundlist) |
void | setRowSetBounds (const int *indexFirst, const int *indexLast, const double *boundlist) |
void | setInteger (const int &colindex) |
void | setInteger (const int *indices, int len) |
void | setcolname (const std::string &name, const int &columnid) const |
void | setrowname (const std::string &name, const int &rowid) const |
void | writeLP (const std::string &location) const |
void | writeMPS (const std::string &location) const |
void | branchAndBound () |
void | enablematrixcaching () |
void | disablematrixcaching () |
FMTsolverinterface | getsolvertype () const |
void | synchronize () |
void | sortdeletedcache () |
const std::vector< int > & | getcachedeletedconstraints () const |
const std::vector< int > & | getcachedeletedvariables () const |
std::string | lowernuppertostr (const double &lower, const double &upper) const |
std::string | getcacheelements () const |
void | updaterowsandcolsnames (bool shortformat=true) |
std::string | getmskerrordesc (int error) const |
Public Member Functions inherited from Core::FMTobject | |
FMTobject () | |
virtual | ~FMTobject () |
FMTobject (const std::shared_ptr< Exception::FMTexceptionhandler > exhandler) | |
FMTobject (const FMTobject &rhs) | |
FMTobject & | operator= (const FMTobject &rhs) |
virtual void | passinlogger (const std::shared_ptr< Logging::FMTlogger > &logger) |
void | passinexceptionhandler (const std::shared_ptr< Exception::FMTexceptionhandler > &exhandler) |
void | redirectlogtofile (const std::string &location) |
virtual void | setdefaultlogger () |
virtual void | setquietlogger () |
virtual void | settasklogger () |
virtual void | setdebuglogger () |
void | setdefaultexceptionhandler () |
void | setquietexceptionhandler () |
void | setdebugexceptionhandler () |
void | setfreeexceptionhandler () |
void | disablenestedexceptions () |
void | enablenestedexceptions () |
void | seterrorstowarnings (const std::vector< Exception::FMTexc > &errors) |
void | setmaxwarningsbeforesilenced (const size_t &maxwarningcount) |
Protected Member Functions | |
bool | canupdatesource () const |
std::shared_ptr< OsiSolverInterface > | buildsolverinterface (const FMTsolverinterface &lsolvertype) const |
std::shared_ptr< OsiSolverInterface > | copysolverinterface (const std::shared_ptr< OsiSolverInterface > &solver_ptr, const FMTsolverinterface &lsolvertype) const |
void | clearrowcache () |
const CoinPackedMatrix * | getMatrixByRow () const |
const CoinPackedMatrix * | getMatrixByCol () const |
Protected Member Functions inherited from Core::FMTobject | |
template<class Archive > | |
void | forcesave (Archive &ar, const unsigned int version) const |
template<class Archive > | |
void | forceload (Archive &ar, const unsigned int version) |
void | checksignals () const |
void | setCPLhandler () |
Protected Attributes | |
FMTmatrixbuild | matrixcache |
The matrix cache follow the constraints or variables that need to be added or removed to the problem. | |
FMTsolverinterface | solvertype |
Solver type used maybe usefull for initialsolve or resolve to know what solver we are using to speed-up the process. | |
Friends | |
class | boost::serialization::access |
Additional Inherited Members | |
Static Public Member Functions inherited from Core::FMTobject | |
static std::string | getruntimelocation () |
static unsigned long long | getavailablememory () |
Static Protected Member Functions inherited from Core::FMTobject | |
static std::chrono::time_point< std::chrono::high_resolution_clock > | getclock () |
template<class chrono > | |
static double | getduration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock) |
static std::string | getdurationinseconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock) |
Static Protected Attributes inherited from Core::FMTobject | |
static std::shared_ptr< Exception::FMTexceptionhandler > | _exhandler |
A shared pointer to the exception handler. | |
static std::shared_ptr< Logging::FMTlogger > | _logger |
A shared pointer to the logger. | |
This class is an abstract class to make the usage of osisolverinterface more easy in FMT. Usefull stuff if dealing with linear programming model. the FMTlpsolver class was needed to reduce the overhead caused by the addrow / addcol osisolverinterface during recurrent calls. All calls related to add/remove columns or rows checking for primal or dual solution getting the number of rows or columns dont need synchronization with the cache. So those calls are going to be faster when usecache = true.
Models::FMTlpsolver::FMTlpsolver | ( | ) |
Default constructor for FMTlpsolver.
|
virtualdefault |
Default virtual destructor for FMTlpsolver.
Models::FMTlpsolver::FMTlpsolver | ( | const FMTlpsolver & | rhs | ) |
Default copy constructor for FMTlpsolver.
|
default |
Default move constructor for FMTlpsolver.
Models::FMTlpsolver::FMTlpsolver | ( | FMTsolverinterface | lsolvertype | ) |
Constructor for FMTlpsolver with a (lsolvertype) and a (logger). It's the main constructor used.
void Models::FMTlpsolver::addCol | ( | int | numberInColumn, |
const int * | rows, | ||
const double * | elements, | ||
double | columnLower = 0.0 , |
||
double | columnUpper = std::numeric_limits< double >::max() , |
||
double | objectiveValue = 0.0 |
||
) |
Add a col, with a number of rows (numberInColumn),with rows indexes (rows), with (elements) with a given lower bound (colLower), and a given column upper bound (colUpper) and an objective value (objectiveValue).If usecache is true then it will be only added to the matrix cache else it will be added to the solverinterface.
void Models::FMTlpsolver::addCols | ( | const int | numcols, |
const int * | columnStarts, | ||
const int * | rows, | ||
const double * | elements, | ||
const double * | collb, | ||
const double * | colub, | ||
const double * | obj | ||
) |
Add multiple columns directly to the matrix but first will synchronize the matrix with the matrix cache.
void Models::FMTlpsolver::addRow | ( | int | numberInRow, |
const int * | columns, | ||
const double * | elements, | ||
double | rowLower = -std::numeric_limits< double >::max() , |
||
double | rowUpper = std::numeric_limits< double >::max() |
||
) |
Add a row, with a number of columns (numberInRow),with columns indexes (columns), with (elements) with a given lower bound (rowLower), and a given row upper bound (rowUpper).If usecache is true then it will be only added to the matrix cache else it will be added to the solverinterface.
void Models::FMTlpsolver::addRows | ( | const int | numrows, |
const int * | rowStarts, | ||
const int * | columns, | ||
const double * | elements, | ||
const double * | rowlb, | ||
const double * | rowub | ||
) |
Add multiple rows directly to the matrix but first will synchronize the matrix with the matrix cache.
void Models::FMTlpsolver::branchAndBound | ( | ) |
Synchronize the matrix cache and then calls the branch and bound MIP enumeration solver.
|
protected |
Function used to build a shared pointer of a solverinterface passing the message handler to the pointer.
|
protected |
|
protected |
Clears the row caching of the osisolverinterface if Mosek is used.
|
protected |
Function used to copy a shared pointer of a solverinterface passing the message handler to the pointer to a other shared pointer.
void Models::FMTlpsolver::deleteCol | ( | const int & | colindex | ) |
Delete's a given column (colindex), if usecache is true then it will only delete it from the cache.
void Models::FMTlpsolver::deleteCols | ( | int | numberofcols, |
const int * | colindexes | ||
) |
Delete's multiple Cols, if usecache is true then it will synchronize first the matrix befores deleting the columns.
void Models::FMTlpsolver::deleteRow | ( | const int & | rowindex | ) |
Delete's a given row (rowindex), if usecache is true then it will only delete it from the cache.
void Models::FMTlpsolver::deleteRows | ( | int | numberofrows, |
const int * | rowindexes | ||
) |
Delete's multiple Rows, if usecache is true then it will synchronize first the matrix befores deleting the rows.
void Models::FMTlpsolver::disablematrixcaching | ( | ) |
First it will synchronize the matrix cache with the solverinterface and then turn off the matrix caching, the number of calls made to osisolverinterface will be greater.
void Models::FMTlpsolver::enablematrixcaching | ( | ) |
Enable the rows and columns caching when adding or deleting a variable to the solverinterface. It reduces the number of calls made to the osisolverinterface.
|
inline |
It will returns rows ids that are in the cache and marked as deleted.
|
inline |
It will returns the cols ids that are in the cache and marked as deleted.
std::string Models::FMTlpsolver::getcacheelements | ( | ) | const |
This function is for debugging it returns the constraints and variables to add to the solverinterface sitting in the matrixcache.
int Models::FMTlpsolver::getcol | ( | int | whichCol, |
double & | colLower, | ||
double & | colUpper, | ||
double & | objectiveValue, | ||
std::vector< int > & | indices, | ||
std::vector< double > & | elements | ||
) | const |
Given a col (whichCol) the function will fill up the column lower bound (colLower), the column upper bound (colUpper), the column's objective (objectiveValue), the column's (indicies) and the column's elements. The function will try to not synchronize the matrix has much has possible.
const double * Models::FMTlpsolver::getColLower | ( | ) | const |
Returns columns lower bounds of the matrix. The function will synchronize the solverinterface with the matrix cache before getting the bounds.
const double * Models::FMTlpsolver::getColSolution | ( | ) | const |
Returns the columns solution of the solverinterface. The function wont synchronize the solverinterface with the cache.
const double * Models::FMTlpsolver::getColUpper | ( | ) | const |
Returns columns upper bounds of the matrix. The function will synchronize the solverinterface with the matrix cache before getting the bounds.
int Models::FMTlpsolver::getiterationcount | ( | ) | const |
Get the number of iterations done by the solver.
|
protected |
Returns a Coinpackedmatrix by column of the problem. A synchronization will be done when calling this function.
|
protected |
Returns a Coinpackedmatrix by row of the problem. A synchronization will be done when calling this function.
std::string Models::FMTlpsolver::getmskerrordesc | ( | int | error | ) | const |
Return description of error code from Mosek.
int Models::FMTlpsolver::getNumCols | ( | ) | const |
Returns the number of columns by looking in the solverinterface and in the cache.
int Models::FMTlpsolver::getNumRows | ( | ) | const |
Returns the number of rows by looking in the solverinterface and in the cache.
const double * Models::FMTlpsolver::getObjCoefficients | ( | ) | const |
Returns the objective coefficients of the matrix. The function will synchronize the solverinterface with the matrix cache before getting the coefficients.
double Models::FMTlpsolver::getObjSense | ( | ) | const |
The function returns the objective sense of the solverinterface.The function will synchronize the solverinterface with the matrix cache before getting the objective sense.
double Models::FMTlpsolver::getObjValue | ( | ) | const |
Get the objective value of the solved matrix.
int Models::FMTlpsolver::getrow | ( | int | whichRow, |
double & | rowLower, | ||
double & | rowUpper, | ||
std::vector< int > & | indices, | ||
std::vector< double > & | elements | ||
) | const |
Given a g row (whichRow) the function will fill up the row lower bound (rowLower), the row upper bound (rowUpper), the row's (indicies) and the row's elements. The function will try to not synchronize the matrix has much has possible. It will returns the number of variables within the row.
const double * Models::FMTlpsolver::getRowActivity | ( | ) | const |
Returns the rows solution of the solverinterface. The function wont synchronize the solverinterface with the cache.
const double * Models::FMTlpsolver::getRowLower | ( | ) | const |
Returns rows lower bounds of the solverinterface. The function will synchronize the solverinterface with the matrix cache before getting the bounds.
const double * Models::FMTlpsolver::getRowPrice | ( | ) | const |
Returns the rows solution of the solverinterface. The function wont synchronize the solverinterface with the cache.
const double * Models::FMTlpsolver::getRowUpper | ( | ) | const |
Returns rows upper bounds of the solverinterface. The function will synchronize the solverinterface with the matrix cache before getting the bounds.
std::string Models::FMTlpsolver::getsolvername | ( | ) | const |
Returns the name of the solver used.
|
inline |
Return the solver type of the solver.
bool Models::FMTlpsolver::gotlicense | ( | ) | const |
Returns true if the license of the solver is available.
|
virtual |
Cold start of the LPsolve of a simple LP model. By default initialsolve will call solverinterface->initialsolve() but using the FMTsolverinterface enum this function will try to use the best solver parameters for a Type III Forest planning model. For all solvers interior point is considered the best algorith.
Reimplemented in Heuristics::FMToperatingareaclusterer, and Heuristics::FMToperatingareascheduler.
bool Models::FMTlpsolver::isProvenOptimal | ( | ) | const |
Returns true if the program is optimal but first will synchronize the matrix with the matrix cache.
std::string Models::FMTlpsolver::lowernuppertostr | ( | const double & | lower, |
const double & | upper | ||
) | const |
Function to convert double bounds to string bounds (-inf,inf).
void Models::FMTlpsolver::MIPparameters | ( | ) |
Controls the way the Feasibility Pump heuristic is employed by the mixed-integer optimizer.The Feasibility Pump is enabled with an effort to improve solution quality. And others
bool Models::FMTlpsolver::operator!= | ( | const FMTlpsolver & | rhs | ) | const |
FMTlpsolver nonequality operator.
FMTlpsolver & Models::FMTlpsolver::operator= | ( | const FMTlpsolver & | rhs | ) |
Default copy assignment for FMTlpsolver.
|
default |
Default move assignment for FMTlpsolver.
bool Models::FMTlpsolver::operator== | ( | const FMTlpsolver & | rhs | ) | const |
Comparison operator of FMTlpsolver
|
overridevirtual |
We need to override the passinlogger for the osisolverinterface
Reimplemented from Core::FMTobject.
void Models::FMTlpsolver::passinmessagehandler | ( | Logging::FMTlogger & | logger | ) |
This will pass the FMTlogger to the solverinterface.
void Models::FMTlpsolver::passinsolver | ( | const FMTlpsolver & | solver | ) |
This will share the solverinterface pointer of (solver).
|
virtual |
By default call solverinterface->resolve() when some changes are done to the model. The user dont necessery need the call initialsolve every time the matrix has changed a call to resolve maybe enought.
void Models::FMTlpsolver::setcolname | ( | const std::string & | name, |
const int & | columnid | ||
) | const |
Update constraints and variables names. set column name.
void Models::FMTlpsolver::setColSetBounds | ( | const int * | indexFirst, |
const int * | indexLast, | ||
const double * | boundlist | ||
) |
It synchronize the matrix and then set the columns index (indexFirst) to (indexlast) lower and upper bounds (boundlist)
void Models::FMTlpsolver::setColSolution | ( | const double * | newsolution | ) |
The function will set a solution for all columns of the solverinterface, it will synchronize the matrix before setting the new column solution.
void Models::FMTlpsolver::setInteger | ( | const int & | colindex | ) |
It synchronize the matrix and then sets a given column (colindex) integer.
void Models::FMTlpsolver::setInteger | ( | const int * | indices, |
int | len | ||
) |
It synchronize the matrix and then sets multiple columns (indices) with a given size (len) integer variable.
void Models::FMTlpsolver::setMIPgaptolerance | ( | const double & | gap | ) |
set The tolerance between the relaxed optimal and the integer optimal. Default it 1.0-4...might be better to use a larger gap like 0.01 (1%) or even 5%... Not all solver can have the MIPgap set...
void Models::FMTlpsolver::setnumberofthreads | ( | const size_t & | nthread | ) |
set the maximum number of threads to be used by the solver. Not all solver can have numberof threads sets.
void Models::FMTlpsolver::setObjective | ( | const double * | objectivevalues | ) |
Sets the objective values of the columns of the matrix.
void Models::FMTlpsolver::setObjSense | ( | const double & | newsense | ) |
Sets the objective sense (newsense) of the solverinterface.
void Models::FMTlpsolver::setoptimizerMAXtime | ( | const double & | time | ) |
Maximum amount of time the optimizer is allowed to spent on the optimization. A negative number means infinity.
void Models::FMTlpsolver::setrowname | ( | const std::string & | name, |
const int & | rowid | ||
) | const |
set row name.
void Models::FMTlpsolver::setRowPrice | ( | const double * | rowprice | ) |
The function will set a solution for all rows of the solverinterface, it will synchronize the matrix before setting the new row solution.
void Models::FMTlpsolver::setRowSetBounds | ( | const int * | indexFirst, |
const int * | indexLast, | ||
const double * | boundlist | ||
) |
It synchronize the matrix and then set the rows index (indexFirst) to (indexlast) lower and upper bounds (boundlist)
void Models::FMTlpsolver::setsolvertype | ( | FMTsolverinterface & | lsolvertype | ) | const |
Setter of the solvertype of the serializable matrix.
void Models::FMTlpsolver::sortdeletedcache | ( | ) |
Sorts and remove replicates present in the rows and columns to delete matrix cache.
bool Models::FMTlpsolver::stockresolve | ( | ) |
Returns true if the solving result in a optimal solution. It calls the plain old osisolverinterface->resolve(). A synchronization will be done when calling this function.
void Models::FMTlpsolver::swap | ( | FMTlpsolver & | rhs | ) |
Swap a FMTlpsolver.
void Models::FMTlpsolver::synchronize | ( | ) |
If the users as added or deleted constraints or variables this function is going to update the Osisolverinterface using the cachedmatrix informations (new or deleted rows and columns).
void Models::FMTlpsolver::unmarkHotStart | ( | ) |
Clear all cached data in osisolverinterface.
void Models::FMTlpsolver::updaterowsandcolsnames | ( | bool | shortformat = true | ) |
Update the rows and columns names
void Models::FMTlpsolver::writeLP | ( | const std::string & | location | ) | const |
Write the solverinterface matrix to a file (location) using the lp formulation.
void Models::FMTlpsolver::writeMPS | ( | const std::string & | location | ) | const |
Write the solverinterface matrix to a file (location) using the MPS formulation.
|
friend |
|
mutableprotected |
The matrix cache follow the constraints or variables that need to be added or removed to the problem.
|
protected |
Solver type used maybe usefull for initialsolve or resolve to know what solver we are using to speed-up the process.