FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTlpsolver.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifdef FMTWITHOSI
9#ifndef FMTsolve_H_INCLUDED
10#define FMTsolve_H_INCLUDED
12#include "FMTmatrixbuild.hpp"
14#include "FMTobject.hpp"
15#include <memory>
16#include <unordered_map>
17#include <boost/serialization/split_member.hpp>
18#include <boost/serialization/export.hpp>
19#include <boost/archive/binary_oarchive.hpp>
20#include <boost/archive/binary_iarchive.hpp>
22
23
24class OsiSolverInterface;
25class CoinPackedMatrix;
26
27namespace Models
28{
29
30// DocString: FMTlpsolver
39 {
40 friend class boost::serialization::access;
41 // DocString: FMTlpsolver::save
45 template<class Archive>
46 void save(Archive& ar, const unsigned int version) const
47 {
48 try {
49 ar& boost::serialization::make_nvp("FMTobject", boost::serialization::base_object<Core::FMTobject>(*this));
50 ar& BOOST_SERIALIZATION_NVP(usecache);
51 matrixcache.synchronize(solverinterface);
52 const FMTserializablematrix matrix(solverinterface);
53 ar& BOOST_SERIALIZATION_NVP(solvertype);
54 ar& BOOST_SERIALIZATION_NVP(matrix);
55 }
56 catch (...)
57 {
58 _exhandler->raisefromcatch("", "FMTlpsolver::save", __LINE__, __FILE__);
59 }
60 }
61 // DocString: FMTlpsolver::load
65 template<class Archive>
66 void load(Archive& ar, const unsigned int version)
67 {
68 try {
69 ar& boost::serialization::make_nvp("FMTobject", boost::serialization::base_object<FMTobject>(*this));
70 ar& BOOST_SERIALIZATION_NVP(usecache);
71 matrixcache.synchronize(solverinterface);
72 FMTserializablematrix matrix;
73 ar& BOOST_SERIALIZATION_NVP(solvertype);
74 ar& BOOST_SERIALIZATION_NVP(matrix);
75 solverinterface = this->buildsolverinterface(solvertype);
76 matrix.setmatrix(solverinterface);
77 }
78 catch (...)
79 {
80 _exhandler->raisefromcatch("", "FMTlpsolver::load", __LINE__, __FILE__);
81 }
82
83 }
84 BOOST_SERIALIZATION_SPLIT_MEMBER()
85 // DocString: FMTlpsolver::solverinterface
87 std::shared_ptr<OsiSolverInterface>solverinterface;
88 // DocString: FMTlpsolver::usecache
90 bool usecache;
91 protected:
92 // DocString: FMTlpsolver::matrixcache
94 mutable FMTmatrixbuild matrixcache;
95 // DocString: FMTlpsolver::solvertype
98 // DocString: FMTlpsolver::canupdatesource
102 bool canupdatesource() const;
103 // DocString: FMTlpsolver::buildsolverinterface
107 std::shared_ptr<OsiSolverInterface> buildsolverinterface(const FMTsolverinterface& lsolvertype) const;
108 // DocString: FMTlpsolver::copysolverinterface
112 std::shared_ptr<OsiSolverInterface> copysolverinterface(const std::shared_ptr<OsiSolverInterface>& solver_ptr, const FMTsolverinterface& lsolvertype) const;
113 // DocString: FMTlpsolver::clearrowcache
117 void clearrowcache();
118 // DocString: FMTlpsolver::getMatrixByRow
122 const CoinPackedMatrix* getMatrixByRow() const;
123 // DocString: FMTlpsolver::getMatrixByCol
127 const CoinPackedMatrix* getMatrixByCol() const;
128 public:
129 // DocString: FMTlpsolver::swap
133 void swap(FMTlpsolver& rhs);
134 // DocString: FMTlpsolver::passinlogger
138 void passinlogger(const std::shared_ptr<Logging::FMTlogger>& logger) override;
139 // DocString: FMTlpsolver::unmarkHotStart
143 void unmarkHotStart();
144 // DocString: FMTlpsolver::stockresolve
149 bool stockresolve();
150 // DocString: FMTlpsolver()
155 // DocString: ~FMTlpsolver()
159 virtual ~FMTlpsolver() = default;
160 // DocString: FMTlpsolver(const FMTlpsolver&)
165 // DocString: FMTlpsolver(FMTlpsolver&&)
169 FMTlpsolver(FMTlpsolver&& rhs)=default;
170 // DocString: FMTlpsolver::operator=
174 FMTlpsolver& operator =(const FMTlpsolver& rhs);
175 // DocString: FMTlpsolver::operator=
179 FMTlpsolver& operator =(FMTlpsolver&& rhs) =default;
180 // DocString: FMTlpsolver(FMTsolverinterface,Logging::FMTlogger&)
184 FMTlpsolver(FMTsolverinterface lsolvertype/*,Logging::FMTlogger& logger*/);
185 // DocString: FMTlpsolver::operator==
189 bool operator == (const FMTlpsolver& rhs) const;
190 // DocString: FMTlpsolver::operator==
194 bool operator != (const FMTlpsolver& rhs) const;
195 // DocString: FMTlpsolver::resolve
200 virtual bool resolve();
201 // DocString: FMTlpsolver::initialsolve
208 virtual bool initialsolve();
209 // DocString: FMTlpsolver::setnumberofthreads
214 void setnumberofthreads(const size_t& nthread);
215 // DocString: FMTlpsolver::setMIPgaptolerance
221 void setMIPgaptolerance(const double& gap);
222 // DocString: FMTlpsolver::setoptimizerMAXtime
226 void setoptimizerMAXtime(const double& time);
227 // DocString: FMTlpsolver::setFeasiblePumpImprovSol
231 void MIPparameters();
232 // DocString: FMTlpsolver::getObjValue
236 double getObjValue() const;
237 // DocString: FMTlpsolver::getiterationcount
241 int getiterationcount() const;
242 // DocString: FMTlpsolver::passinsolver
246 void passinsolver(const FMTlpsolver& solver);
247 // DocString: FMTlpsolver::passinmessagehandler
251 void passinmessagehandler(Logging::FMTlogger& logger);
252 // DocString: FMTlpsolver::setsolvertype
256 void setsolvertype(FMTsolverinterface& lsolvertype) const;
257 // DocString: FMTlpsolver::gotlicense
261 bool gotlicense() const;
262 // DocString: FMTlpsolver::getsolvername
266 std::string getsolvername() const;
267 // DocString: FMTlpsolver::getNumCols
271 int getNumCols() const;
272 // DocString: FMTlpsolver::getNumRows
276 int getNumRows() const;
277 // DocString: FMTlpsolver::getObjCoefficients
282 const double* getObjCoefficients() const;
283 // DocString: FMTlpsolver::getColLower
288 const double* getColLower() const;
289 // DocString: FMTlpsolver::getColUpper
294 const double* getColUpper() const;
295 // DocString: FMTlpsolver::getColSolution
299 const double* getColSolution() const;
300 // DocString: FMTlpsolver::getRowPrice
304 const double* getRowPrice() const;
305 // DocString: FMTlpsolver::getRowActivity
309 const double* getRowActivity() const;
310 // DocString: FMTlpsolver::getRowUpper
315 const double* getRowUpper() const;
316 // DocString: FMTlpsolver::getRowLower
321 const double* getRowLower() const;
322 // DocString: FMTlpsolver::getrow
328 int getrow(int whichRow, double &rowLower, double &rowUpper,
329 std::vector<int>& indices, std::vector<double>&elements) const;
330 // DocString: FMTlpsolver::getcol
336 int getcol(int whichCol, double &colLower, double &colUpper, double &objectiveValue,
337 std::vector<int>& indices, std::vector<double>&elements) const;
338 // DocString: FMTlpsolver::getObjSense
343 double getObjSense() const;
344 // DocString: FMTlpsolver::setObjective
348 void setObjective(const double* objectivevalues);
349 // DocString: FMTlpsolver::setObjSense
353 void setObjSense(const double& newsense);
354 // DocString: FMTlpsolver::addRow
360 void addRow(int numberInRow, const int * columns, const double * elements,
361 double rowLower = -std::numeric_limits<double>::max(), double rowUpper = std::numeric_limits<double>::max());
362 // DocString: FMTlpsolver::addCol
368 void addCol(int numberInColumn, const int * rows, const double * elements, double columnLower = 0.0,
369 double columnUpper = std::numeric_limits<double>::max(), double objectiveValue = 0.0);
370 // DocString: FMTlpsolver::addRows
374 void addRows(const int numrows, const int* rowStarts, const int* columns,
375 const double* elements, const double* rowlb, const double* rowub);
376 // DocString: FMTlpsolver::addCols
380 void addCols(const int numcols, const int* columnStarts, const int* rows,
381 const double* elements, const double* collb, const double* colub, const double* obj);
382 // DocString: FMTlpsolver::isProvenOptimal
386 bool isProvenOptimal() const;
387 // DocString: FMTlpsolver::deleteRow
391 void deleteRow(const int& rowindex);
392 // DocString: FMTlpsolver::deleteRow
396 void deleteCol(const int& colindex);
397 // DocString: FMTlpsolver::deleteRows
401 void deleteRows(int numberofrows,const int* rowindexes);
402 // DocString: FMTlpsolver::deleteCols
406 void deleteCols(int numberofcols, const int* colindexes);
407 // DocString: FMTlpsolver::setColSolution
412 void setColSolution(const double* newsolution);
413 // DocString: FMTlpsolver::setRowPrice
418 void setRowPrice(const double* rowprice);
419 // DocString: FMTlpsolver::setColSetBounds
424 void setColSetBounds(const int* indexFirst, const int* indexLast, const double* boundlist);
425 // DocString: FMTlpsolver::setRowSetBoundss
430 void setRowSetBounds(const int* indexFirst, const int* indexLast, const double* boundlist);
431 // DocString: FMTlpsolver::setInteger
436 void setInteger(const int& colindex);
437 // DocString: FMTlpsolver::setInteger
442 void setInteger(const int* indices,int len);
443 // DocString: FMTlpsolver::updatematrixnaming
447 //void updatematrixnaming(const std::unordered_map<int, std::string>& colsnames,
448 // const std::unordered_map<int, std::string>& rownames);
449 // DocString: FMTlpsolver::setcolname
453 void setcolname(const std::string& name, const int& columnid) const;
454 // DocString: FMTlpsolver::setrowname
458 void setrowname(const std::string& name, const int& rowid) const;
459 // DocString: FMTlpsolver::writeLP
463 void writeLP(const std::string& location) const;
464 // DocString: FMTlpsolver::writeMPS
468 void writeMPS(const std::string& location) const;
469 // DocString: FMTlpsolver::branchAndBound
473 void branchAndBound();
474 // DocString: FMTlpsolver::enablematrixcaching
479 void enablematrixcaching();
480 // DocString: FMTlpsolver::disablematrixcaching
485 void disablematrixcaching();
486 // DocString: FMTlpsolver::getsolvertype()
490 inline FMTsolverinterface getsolvertype() const
491 {
492 return solvertype;
493 }
494 // DocString: FMTlpsolver::synchronize
500 // DocString: FMTlpsolver::sortdeletedcache
505 // DocString: FMTlpsolver::getcachedeletedconstraints
509 inline const std::vector<int>& getcachedeletedconstraints() const
510 {
511 return matrixcache.getdeletedconstraints();
512 }
513 // DocString: FMTlpsolver::getcachedeletedvariable
517 inline const std::vector<int>& getcachedeletedvariables() const
518 {
519 return matrixcache.getdeletedvariables();
520 }
521 // DocString: FMTlpsolver::lowernuppertostr
525 std::string lowernuppertostr(const double& lower, const double& upper) const;
526 // DocString: FMTlpsolver::getcacheelements
531 std::string getcacheelements() const;
532 // DocString: FMTlpsolver::updaterowsandcolsnames
536 void updaterowsandcolsnames(bool shortformat = true);
537 #ifdef FMTWITHMOSEK
538 // DocString: FMTlpsolver::getmskerrordesc
542 std::string getmskerrordesc(int error) const;
543 #endif
544 };
545}
546BOOST_CLASS_EXPORT_KEY(Models::FMTlpsolver)
547#endif
548#endif
#define FMTEXPORT
Definition: FMTutility.hpp:92
Definition: FMTobject.hpp:50
Definition: FMTlpsolver.hpp:39
const std::vector< int > & getcachedeletedvariables() const
Definition: FMTlpsolver.hpp:517
void updaterowsandcolsnames(bool shortformat=true)
std::string getcacheelements() const
const std::vector< int > & getcachedeletedconstraints() const
Definition: FMTlpsolver.hpp:509
std::string lowernuppertostr(const double &lower, const double &upper) const
std::string getmskerrordesc(int error) const
Definition: FMTmatrixbuild.hpp:34
Definition: FMTserializablematrix.hpp:32
Namespace for the log management, provides different log handlers.
Definition: FMTdebuglogger.hpp:14
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTareaparser.hpp:50
FMTsolverinterface
Definition: FMTsolverinterface.hpp:21
void load(Ar &ar, dynamic_bitset< Block, Alloc > &bs, unsigned)
Definition: FMTmask.hpp:48