9#ifndef FMTsolve_Hm_included
10#define FMTsolve_Hm_included
11#include "FMTSolverInterface.h"
16#include <unordered_map>
18#include <boost/serialization/split_member.hpp>
19#include <boost/serialization/export.hpp>
20#include <boost/archive/binary_oarchive.hpp>
21#include <boost/archive/binary_iarchive.hpp>
24#if __has_include("OsiGlpkSolverInterface.hpp")
30#if __has_include("OsiClpSolverInterface.hpp")
37class OsiSolverInterface;
38class CoinPackedMatrix;
62 void passInLogger(
const std::unique_ptr<Logging::FMTLogger>& logger)
override;
119 const std::string& p_ColdStartParameters,
120 const std::string& p_WarmStartParameters,
121 const std::string& p_problemName);
287 int getRow(
int whichRow,
double &rowLower,
double &rowUpper,
288 std::vector<int>& indices, std::vector<double>&elements)
const;
300 int getCol(
int whichCol,
double &colLower,
double &colUpper,
double &objectiveValue,
301 std::vector<int>& indices, std::vector<double>&elements)
const;
330 void addRow(
int numberInRow,
const int * columns,
const double * elements,
331 double rowLower = -std::numeric_limits<double>::max(),
double rowUpper = std::numeric_limits<double>::max());
343 void addCol(
int numberInColumn,
const int * rows,
const double * elements,
double columnLower = 0.0,
344 double columnUpper = std::numeric_limits<double>::max(),
double objectiveValue = 0.0);
355 void addRows(
const int numrows,
const int* rowStarts,
const int* columns,
356 const double* elements,
const double* rowlb,
const double* rowub);
368 void addCols(
const int numcols,
const int* columnStarts,
const int* rows,
369 const double* elements,
const double* collb,
const double* colub,
const double* obj);
421 void setColSetBounds(
const int* indexFirst,
const int* indexLast,
const double* boundlist);
429 void setRowSetBounds(
const int* indexFirst,
const int* indexLast,
const double* boundlist);
455 void setColName(
const std::string& name,
const int& columnid)
const;
462 void setRowName(
const std::string& name,
const int& rowid)
const;
468 void writeLp(
const std::string& location)
const;
516 return matrixcache.getDeletedConstraints();
525 return matrixcache.getDeletedVariables();
625 static std::vector<std::pair<std::string, std::string>>strtoParams(
const std::string& p_params);
626 friend class boost::serialization::access;
634 template<
class Archive>
635 void save(Archive& ar,
const unsigned int version)
const
638 ar& boost::serialization::make_nvp(
"FMTobject", boost::serialization::base_object<Core::FMTObject>(*
this));
639 ar& BOOST_SERIALIZATION_NVP(usecache);
642 ar& BOOST_SERIALIZATION_NVP(solvertype);
643 ar& BOOST_SERIALIZATION_NVP(matrix);
647 _exhandler->raiseFromCatch(
"",
"FMTLpSolver::save", __LINE__, __FILE__);
657 template<
class Archive>
658 void load(Archive& ar,
const unsigned int version)
661 ar& boost::serialization::make_nvp(
"FMTobject", boost::serialization::base_object<FMTObject>(*
this));
662 ar& BOOST_SERIALIZATION_NVP(usecache);
664 FMTSerializableMatrix matrix;
665 ar& BOOST_SERIALIZATION_NVP(solvertype);
666 ar& BOOST_SERIALIZATION_NVP(matrix);
667 solverinterface = this->buildSolverInterface(solvertype);
668 matrix.setMatrix(solverinterface);
672 _exhandler->raiseFromCatch(
"",
"FMTLpSolver::load", __LINE__, __FILE__);
676 BOOST_SERIALIZATION_SPLIT_MEMBER()
679 std::shared_ptr<OsiSolverInterface>solverinterface;
685 std::vector<
std::pair<
std::
string,
std::
string>>m_ColdStartParameters;
688 std::vector<
std::pair<
std::
string,
std::
string>>m_WarmStartParameters;
694 int _mskOptimizeWithParameters();
700 int _mskOptimizeWithDefaultParameters();
706 void _setGlpkLogLevel(
Logging::FMTLogger& p_logger);
711 void _setClpOptions();
714BOOST_CLASS_EXPORT_KEY(
Models::FMTLpSolver)
#define FMTEXPORT
Definition: FMTutility.h:125
Base class of multiple FMT classes holding a shared exception handler pointer and logger.
Definition: FMTObject.h:49
Base class handling the level of information printed by FMT.
Definition: FMTLogger.h:37
Abstract class to ease the usage of the OsiSolverInterface in FMT for linear programming models.
Definition: FMTLpSolver.h:49
void writeLp(const std::string &location) const
Write the solver interface matrix to a file using the LP formulation.
double getObjValue() const
Get the objective value of the solved matrix.
void enableMatrixCaching()
Enable the rows and columns caching when adding or deleting a variable to the solver interface,...
void disableMatrixCaching()
Synchronize the matrix cache with the solver interface and turn off the matrix caching.
void clearRowCache()
Clear the row caching of the OsiSolverInterface if Mosek is used.
void setColSetBounds(const int *indexFirst, const int *indexLast, const double *boundlist)
Synchronize the matrix and set the lower and upper bounds of a set of columns.
const double * getRowActivity() const
Return the row activity of the solver interface, without synchronizing with the cache.
void setColSolution(const double *newsolution)
Set a solution for all columns of the solver interface, synchronizing the matrix first.
void swap(FMTLpSolver &rhs)
Swap this FMTLpSolver with another one.
void setInteger(const int &colindex)
Synchronize the matrix and set a given column as integer.
void updateRowsAndColsNames(bool shortformat=true)
Update the rows and columns names.
void deleteRows(int numberofrows, const int *rowindexes)
Delete multiple rows; if the cache is used the matrix is synchronized before deleting the rows.
virtual bool resolve()
Call solverinterface->resolve when some changes are done to the model, avoiding a full initialSolve.
const std::vector< int > & getCacheDeletedConstraints() const
Return the row ids that are in the cache and marked as deleted.
Definition: FMTLpSolver.h:514
bool stockResolve()
Call the plain OsiSolverInterface resolve, synchronizing the matrix first.
FMTSolverInterface solvertype
Solver type used maybe usefull for initialSolve or resolve to know what solver we are using to speed-...
Definition: FMTLpSolver.h:579
void synchronize()
Update the OsiSolverInterface using the cached matrix information (new or deleted rows and columns) w...
int getNumCols() const
Return the number of columns by looking in the solver interface and in the cache.
std::string getSolverName() const
Return the name of the solver used.
static std::string_view toString(Models::FMTSolverInterface p_solver)
return the string value of the solver
void writeMps(const std::string &location) const
Write the solver interface matrix to a file using the MPS formulation.
std::string getCacheElements() const
Return the constraints and variables sitting in the matrix cache to be added to the solver interface,...
const double * getColLower() const
Return the column lower bounds of the matrix, synchronizing the solver interface with the cache first...
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)
Add a column with its rows, elements, bounds and objective value.
bool isProvenOptimal() const
Return true if the program is optimal, synchronizing the matrix with the cache first.
double getObjSense() const
Return the objective sense of the solver interface, synchronizing with the cache first.
FMTLpSolver(const FMTLpSolver &rhs)
Default copy constructor for FMTLpSolver.
int getRow(int whichRow, double &rowLower, double &rowUpper, std::vector< int > &indices, std::vector< double > &elements) const
Fill the bounds, indices and elements of a given row, trying to synchronize the matrix as little as p...
const double * getColUpper() const
Return the column upper bounds of the matrix, synchronizing the solver interface with the cache first...
void setColName(const std::string &name, const int &columnid) const
Update the constraints and variables names.
void 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 its columns, elements and bounds.
virtual ~FMTLpSolver()=default
Default virtual destructor for FMTLpSolver.
void passInSolver(const FMTLpSolver &solver)
Share the solver interface pointer of another solver.
void setRowName(const std::string &name, const int &rowid) const
Set a row name.
static std::vector< Models::FMTSolverInterface > getAvailableSolverInterface()
Return the available solver interfaces.
const double * getObjCoefficients() const
Return the objective coefficients of the matrix, synchronizing the solver interface with the cache fi...
void passInMessageHandler(Logging::FMTLogger &logger)
Pass the FMTLogger to the solver interface.
void deleteRow(const int &rowindex)
Delete a given row; if the cache is used it is only deleted from the cache.
FMTMatrixBuild matrixcache
The matrix cache follow the constraints or variables that need to be added or removed to the problem.
Definition: FMTLpSolver.h:576
virtual bool initialSolve()
Cold start of the LP solve of a simple LP model.
void 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, synchronizing the matrix with the cache first.
std::string lowerNUpperToStr(const double &lower, const double &upper) const
Convert double bounds to string bounds (-inf, inf).
void mipParameters()
Set the mixed-integer optimizer parameters, including the way the feasibility pump heuristic is emplo...
void setObjective(const double *objectivevalues)
Set the objective values of the columns of the matrix.
void setOptimizerMaxTime(const double &time)
Set the maximum amount of time the optimizer is allowed to spend on the optimization.
FMTSolverInterface getSolverType() const
Return the solver type of the solver.
Definition: FMTLpSolver.h:495
void unmarkHotStart()
Clear all cached data in the OsiSolverInterface.
void setRowSetBounds(const int *indexFirst, const int *indexLast, const double *boundlist)
Synchronize the matrix and set the lower and upper bounds of a set of rows.
FMTLpSolver(FMTLpSolver &&rhs)=default
Default move constructor for FMTLpSolver.
int getNumRows() const
Return the number of rows by looking in the solver interface and in the cache.
void 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, synchronizing the matrix with the cache first.
bool canUpdateSource() const
Return true if the solver interface source can be updated.
void deleteCols(int numberofcols, const int *colindexes)
Delete multiple columns; if the cache is used the matrix is synchronized before deleting the columns.
void branchAndBound()
Synchronize the matrix cache and call the branch and bound MIP enumeration solver.
std::shared_ptr< OsiSolverInterface > buildSolverInterface(const FMTSolverInterface &lsolvertype) const
Build a shared pointer to a solver interface, passing the message handler to the pointer.
int getCol(int whichCol, double &colLower, double &colUpper, double &objectiveValue, std::vector< int > &indices, std::vector< double > &elements) const
Fill the bounds, objective, indices and elements of a given column, trying to synchronize the matrix ...
bool gotLicense() const
Return true if the license of the solver is available.
bool SupportsMultiThreading() const
Return true if the solver support multithreading.
const CoinPackedMatrix * getMatrixByRow() const
Return a CoinPackedMatrix by row of the problem, synchronizing the matrix first.
void setRowPrice(const double *rowprice)
Set a solution for all rows of the solver interface, synchronizing the matrix first.
const double * getRowPrice() const
Return the row price (dual solution) of the solver interface, without synchronizing with the cache.
void deleteCol(const int &colindex)
Delete a given column; if the cache is used it is only deleted from the cache.
FMTLpSolver(FMTSolverInterface lsolvertype, const std::string &p_ColdStartParameters, const std::string &p_WarmStartParameters, const std::string &p_problemName)
Main constructor for FMTLpSolver with a solver type, cold and warm start parameters and a problem nam...
std::string getMskErrorDesc(int error) const
Return the description of an error code from Mosek.
void setSolverType(FMTSolverInterface &lsolvertype) const
Setter of the solver type of the serializable matrix.
void setObjSense(const double &newsense)
Set the objective sense of the solver interface.
const double * getColSolution() const
Return the column solution of the solver interface, without synchronizing with the cache.
void setInteger(const int *indices, int len)
Synchronize the matrix and set multiple columns as integer variables.
const std::vector< int > & getCacheDeletedVariables() const
Return the column ids that are in the cache and marked as deleted.
Definition: FMTLpSolver.h:523
void setMipGapTolerance(const double &gap)
Set the tolerance between the relaxed optimal and the integer optimal.
const CoinPackedMatrix * getMatrixByCol() const
Return a CoinPackedMatrix by column of the problem, synchronizing the matrix first.
FMTLpSolver()
Default constructor for FMTLpSolver.
const double * getRowLower() const
Return the row lower bounds of the solver interface, synchronizing with the cache first.
void sortDeletedCache()
Sort and remove duplicates in the rows and columns to delete in the matrix cache.
void setNumberOfThreads(const size_t &nthread)
Set the maximum number of threads to be used by the solver.
std::shared_ptr< OsiSolverInterface > copySolverInterface(const std::shared_ptr< OsiSolverInterface > &solver_ptr, const FMTSolverInterface &lsolvertype) const
Copy a shared pointer to a solver interface into another shared pointer, passing the message handler ...
const double * getRowUpper() const
Return the row upper bounds of the solver interface, synchronizing with the cache first.
void passInLogger(const std::unique_ptr< Logging::FMTLogger > &logger) override
Pass in the logger, overridden for the OsiSolverInterface.
int getIterationCount() const
Get the number of iterations done by the solver.
Helper caching rows and columns to add to a solver matrix in batch for efficiency.
Definition: FMTMatrixBuild.h:32
void synchronize(std::shared_ptr< OsiSolverInterface > solver)
Synchronize the cached columns and rows with the solver matrix.
Helper for the serialization of an OSI solver interface matrix.
Definition: FMTSerializableMatrix.h:29
Namespace for the log management, provides different log handlers.
Definition: FMTDebugLogger.h:14
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
FMTSolverInterface
Enumerator used to specify the solver to use when solving the FMTLpModel.
Definition: FMTsolverinterface.h:21
void load(Ar &ar, dynamic_bitset< Block, Alloc > &bs, unsigned)
Definition: FMTMask.h:53