FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Models::FMTlpsolver Class Reference

#include <FMTlpsolver.hpp>

Inheritance diagram for Models::FMTlpsolver:
[legend]
Collaboration diagram for Models::FMTlpsolver:
[legend]

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
 
FMTlpsolveroperator= (const FMTlpsolver &rhs)
 
FMTlpsolveroperator= (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)
 
FMTobjectoperator= (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FMTlpsolver() [1/4]

Models::FMTlpsolver::FMTlpsolver ( )

Default constructor for FMTlpsolver.

◆ ~FMTlpsolver()

virtual Models::FMTlpsolver::~FMTlpsolver ( )
virtualdefault

Default virtual destructor for FMTlpsolver.

◆ FMTlpsolver() [2/4]

Models::FMTlpsolver::FMTlpsolver ( const FMTlpsolver rhs)

Default copy constructor for FMTlpsolver.

◆ FMTlpsolver() [3/4]

Models::FMTlpsolver::FMTlpsolver ( FMTlpsolver &&  rhs)
default

Default move constructor for FMTlpsolver.

◆ FMTlpsolver() [4/4]

Models::FMTlpsolver::FMTlpsolver ( FMTsolverinterface  lsolvertype)

Constructor for FMTlpsolver with a (lsolvertype) and a (logger). It's the main constructor used.

Member Function Documentation

◆ addCol()

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.

◆ addCols()

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.

◆ addRow()

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.

◆ addRows()

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.

◆ branchAndBound()

void Models::FMTlpsolver::branchAndBound ( )

Synchronize the matrix cache and then calls the branch and bound MIP enumeration solver.

◆ buildsolverinterface()

std::shared_ptr< OsiSolverInterface > Models::FMTlpsolver::buildsolverinterface ( const FMTsolverinterface lsolvertype) const
protected

Function used to build a shared pointer of a solverinterface passing the message handler to the pointer.

◆ canupdatesource()

bool Models::FMTlpsolver::canupdatesource ( ) const
protected

◆ clearrowcache()

void Models::FMTlpsolver::clearrowcache ( )
protected

Clears the row caching of the osisolverinterface if Mosek is used.

◆ copysolverinterface()

std::shared_ptr< OsiSolverInterface > Models::FMTlpsolver::copysolverinterface ( const std::shared_ptr< OsiSolverInterface > &  solver_ptr,
const FMTsolverinterface lsolvertype 
) const
protected

Function used to copy a shared pointer of a solverinterface passing the message handler to the pointer to a other shared pointer.

◆ deleteCol()

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.

◆ deleteCols()

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.

◆ deleteRow()

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.

◆ deleteRows()

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.

◆ disablematrixcaching()

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.

◆ enablematrixcaching()

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.

◆ getcachedeletedconstraints()

const std::vector< int > & Models::FMTlpsolver::getcachedeletedconstraints ( ) const
inline

It will returns rows ids that are in the cache and marked as deleted.

◆ getcachedeletedvariables()

const std::vector< int > & Models::FMTlpsolver::getcachedeletedvariables ( ) const
inline

It will returns the cols ids that are in the cache and marked as deleted.

◆ getcacheelements()

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.

◆ getcol()

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.

◆ getColLower()

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.

◆ getColSolution()

const double * Models::FMTlpsolver::getColSolution ( ) const

Returns the columns solution of the solverinterface. The function wont synchronize the solverinterface with the cache.

◆ getColUpper()

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.

◆ getiterationcount()

int Models::FMTlpsolver::getiterationcount ( ) const

Get the number of iterations done by the solver.

◆ getMatrixByCol()

const CoinPackedMatrix * Models::FMTlpsolver::getMatrixByCol ( ) const
protected

Returns a Coinpackedmatrix by column of the problem. A synchronization will be done when calling this function.

◆ getMatrixByRow()

const CoinPackedMatrix * Models::FMTlpsolver::getMatrixByRow ( ) const
protected

Returns a Coinpackedmatrix by row of the problem. A synchronization will be done when calling this function.

◆ getmskerrordesc()

std::string Models::FMTlpsolver::getmskerrordesc ( int  error) const

Return description of error code from Mosek.

◆ getNumCols()

int Models::FMTlpsolver::getNumCols ( ) const

Returns the number of columns by looking in the solverinterface and in the cache.

◆ getNumRows()

int Models::FMTlpsolver::getNumRows ( ) const

Returns the number of rows by looking in the solverinterface and in the cache.

◆ getObjCoefficients()

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.

◆ getObjSense()

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.

◆ getObjValue()

double Models::FMTlpsolver::getObjValue ( ) const

Get the objective value of the solved matrix.

◆ getrow()

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.

◆ getRowActivity()

const double * Models::FMTlpsolver::getRowActivity ( ) const

Returns the rows solution of the solverinterface. The function wont synchronize the solverinterface with the cache.

◆ getRowLower()

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.

◆ getRowPrice()

const double * Models::FMTlpsolver::getRowPrice ( ) const

Returns the rows solution of the solverinterface. The function wont synchronize the solverinterface with the cache.

◆ getRowUpper()

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.

◆ getsolvername()

std::string Models::FMTlpsolver::getsolvername ( ) const

Returns the name of the solver used.

◆ getsolvertype()

FMTsolverinterface Models::FMTlpsolver::getsolvertype ( ) const
inline

Return the solver type of the solver.

◆ gotlicense()

bool Models::FMTlpsolver::gotlicense ( ) const

Returns true if the license of the solver is available.

◆ initialsolve()

virtual bool Models::FMTlpsolver::initialsolve ( )
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.

◆ isProvenOptimal()

bool Models::FMTlpsolver::isProvenOptimal ( ) const

Returns true if the program is optimal but first will synchronize the matrix with the matrix cache.

◆ lowernuppertostr()

std::string Models::FMTlpsolver::lowernuppertostr ( const double &  lower,
const double &  upper 
) const

Function to convert double bounds to string bounds (-inf,inf).

◆ MIPparameters()

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

◆ operator!=()

bool Models::FMTlpsolver::operator!= ( const FMTlpsolver rhs) const

FMTlpsolver nonequality operator.

◆ operator=() [1/2]

FMTlpsolver & Models::FMTlpsolver::operator= ( const FMTlpsolver rhs)

Default copy assignment for FMTlpsolver.

◆ operator=() [2/2]

FMTlpsolver & Models::FMTlpsolver::operator= ( FMTlpsolver &&  rhs)
default

Default move assignment for FMTlpsolver.

◆ operator==()

bool Models::FMTlpsolver::operator== ( const FMTlpsolver rhs) const

Comparison operator of FMTlpsolver

◆ passinlogger()

void Models::FMTlpsolver::passinlogger ( const std::shared_ptr< Logging::FMTlogger > &  logger)
overridevirtual

We need to override the passinlogger for the osisolverinterface

Reimplemented from Core::FMTobject.

◆ passinmessagehandler()

void Models::FMTlpsolver::passinmessagehandler ( Logging::FMTlogger logger)

This will pass the FMTlogger to the solverinterface.

◆ passinsolver()

void Models::FMTlpsolver::passinsolver ( const FMTlpsolver solver)

This will share the solverinterface pointer of (solver).

◆ resolve()

virtual bool Models::FMTlpsolver::resolve ( )
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.

◆ setcolname()

void Models::FMTlpsolver::setcolname ( const std::string &  name,
const int &  columnid 
) const

Update constraints and variables names. set column name.

◆ setColSetBounds()

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)

◆ setColSolution()

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.

◆ setInteger() [1/2]

void Models::FMTlpsolver::setInteger ( const int &  colindex)

It synchronize the matrix and then sets a given column (colindex) integer.

◆ setInteger() [2/2]

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.

◆ setMIPgaptolerance()

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...

◆ setnumberofthreads()

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.

◆ setObjective()

void Models::FMTlpsolver::setObjective ( const double *  objectivevalues)

Sets the objective values of the columns of the matrix.

◆ setObjSense()

void Models::FMTlpsolver::setObjSense ( const double &  newsense)

Sets the objective sense (newsense) of the solverinterface.

◆ setoptimizerMAXtime()

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.

◆ setrowname()

void Models::FMTlpsolver::setrowname ( const std::string &  name,
const int &  rowid 
) const

set row name.

◆ setRowPrice()

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.

◆ setRowSetBounds()

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)

◆ setsolvertype()

void Models::FMTlpsolver::setsolvertype ( FMTsolverinterface lsolvertype) const

Setter of the solvertype of the serializable matrix.

◆ sortdeletedcache()

void Models::FMTlpsolver::sortdeletedcache ( )

Sorts and remove replicates present in the rows and columns to delete matrix cache.

◆ stockresolve()

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.

◆ swap()

void Models::FMTlpsolver::swap ( FMTlpsolver rhs)

Swap a FMTlpsolver.

◆ synchronize()

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).

◆ unmarkHotStart()

void Models::FMTlpsolver::unmarkHotStart ( )

Clear all cached data in osisolverinterface.

◆ updaterowsandcolsnames()

void Models::FMTlpsolver::updaterowsandcolsnames ( bool  shortformat = true)

Update the rows and columns names

◆ writeLP()

void Models::FMTlpsolver::writeLP ( const std::string &  location) const

Write the solverinterface matrix to a file (location) using the lp formulation.

◆ writeMPS()

void Models::FMTlpsolver::writeMPS ( const std::string &  location) const

Write the solverinterface matrix to a file (location) using the MPS formulation.

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Member Data Documentation

◆ matrixcache

FMTmatrixbuild Models::FMTlpsolver::matrixcache
mutableprotected

The matrix cache follow the constraints or variables that need to be added or removed to the problem.

◆ solvertype

FMTsolverinterface Models::FMTlpsolver::solvertype
protected

Solver type used maybe usefull for initialsolve or resolve to know what solver we are using to speed-up the process.


The documentation for this class was generated from the following file: