FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTSrModel.h
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
9#ifdef FMTWITHOSI
10
11#ifndef FMTsrmodel_Hm_included
12#define FMTsrmodel_Hm_included
13
14#include "FMTModel.h"
15#include <boost/serialization/export.hpp>
16#include <boost/serialization/split_member.hpp>
17#include "FMTLpSolver.h"
18#include "FMTVertexProperties.h"
19#include "FMTEdgeProperties.h"
20#include "FMTGraph.hpp"
21#include <memory>
22
23#if defined FMTWITHR
24 #include <Rcpp.h>
25#endif
26
27namespace Core
28{
29 class FMTSerie;
30}
31
32
33namespace Graph
34{
35 class FMTGraphVertexToYield;
36
37}
38
39namespace Models
40 {
41 // DocString: FMTSrModel
46 {
47 public:
48 // DocString: FMTSrModel::setNodeCacheSize
53 void setNodeCacheSize(const size_t& p_size);
54 // DocString: FMTSrModel::getGraphVertexToYield
61 // DocString: FMTSrModel::postSolve
66 virtual void postSolve(const FMTModel& originalbasemodel);
67 // DocString: FMTSrModel::setParallelLogger
73 void setParallelLogger(Logging::FMTLogger& logger) override;
74 // DocString: FMTSrModel(const FMTModel,FMTSolverInterface)
81 FMTSrModel(const FMTModel& base, FMTSolverInterface lsolvertype);
82 // DocString: FMTSrModel()
87 // DocString: FMTSrModel(const FMTSrModel)
93 // DocString: FMTSrModel(const FMTModel, const Graph::FMTGraph<Graph::FMTVertexProperties,Graph::FMTEdgeProperties>, const FMTLpSolver)
101 const FMTLpSolver& lsolver);
102 // DocString: FMTSrModel::operator=
108 FMTSrModel& operator = (const FMTSrModel& rhs);
109 // DocString: FMTSrModel(FMTSrModel&&)
114 FMTSrModel(FMTSrModel&& rhs) noexcept;
115 // DocString: FMTSrModel::operator=(FMTSrModel&& rhs)
121 FMTSrModel& operator =(FMTSrModel&& rhs) noexcept;
122 // DocString: ~FMTSrModel()
126 ~FMTSrModel() = default;
127 // DocString: FMTSrModel::operator==
133 bool operator == (const FMTSrModel& rhs) const;
134 // DocString: FMTSrModel::operator!=
140 bool operator != (const FMTSrModel& rhs) const;
141 // DocString: FMTSrModel::unboundSolution
147 bool unboundSolution(int period);
148 // DocString: FMTSrModel::isPeriodBounded
154 bool isPeriodBounded(int period) const;
155 // DocString: FMTSrModel::clearGraphDevelopments
160 // DocString: FMTSrModel::clearGraphCache
165 // DocString: FMTSrModel::setSolution
173 bool setSolution(int period, const Core::FMTSchedule& schedule, double tolerance = FMT_DBL_TOLERANCE);
174 // DocString: FMTSrModel::setSolutionByLp
183 bool setSolutionByLp(int period, const Core::FMTSchedule& schedule, double tolerance = FMT_DBL_TOLERANCE);
184 // DocString: FMTSrModel::forceSolution
192 bool forceSolution(int period, const Core::FMTSchedule& proportionschedulewithlock);
193 // DocString: FMTSrModel::getSolution
200 Core::FMTSchedule getSolution(int period, bool withlock = false) const final;
201 // DocString: FMTSrModel::getScheduleProportions
208 Core::FMTSchedule getScheduleProportions(int period, bool withlock) const;
209 // DocString: FMTSrModel::getStats
214 Graph::FMTGraphStats getStats() const;
215 // DocString: FMTSrModel::getGraphStats
221 Graph::FMTGraphStats getGraphStats(const Core::FMTMask& p_Subset) const;
222 // DocString: FMTSrModel::getCopy
229 virtual std::unique_ptr<FMTModel> getCopy(int period = 0) const;
230 // DocString: FMTSrModel::getOutput
239 virtual std::map<std::string, double> getOutput(const Core::FMTOutput& output,
240 int period, Core::FMToutputlevel level = Core::FMToutputlevel::standard) const;
241 #if defined FMTWITHR
242 // DocString: FMTSrModel::getOutputsDataFrame
250 Rcpp::DataFrame getOutputsDataFrame(const std::vector<Core::FMTOutput>& outputsdata, int firstPeriod, int lastPeriod) const;
251 #endif
252 // DocString: FMTSrModel::buildPeriod
262 bool forcepartialbuild = false, int compressageclassoperability = 1);
263 // DocString: FMTSrModel::getFirstActivePeriod
270 // DocString: FMTSrModel::getArea
278 virtual std::vector<Core::FMTActualDevelopment>getArea(int period = 0, bool beforegrowanddeath = false) const override;
279 // DocString: FMTSrModel::getPotentialArea
287 std::vector<Core::FMTActualDevelopment>getPotentialArea(int p_Period = 0, bool p_BeforeGrowAndDeath = false) const;
288
289
290 // DocString: FMTSrModel::getSolverPtr()
296 // DocString: FMTSrModel::getConstSolverPtr()
302 // DocString: FMTSrModel::clone
307 virtual std::unique_ptr<FMTModel>clone() const override;
308 // DocString: FMTSrModel::passInLogger
313 void passInLogger(const std::unique_ptr<Logging::FMTLogger>& logger) override;
314 // DocString: FMTSrModel::preSolve
320 virtual std::unique_ptr<FMTModel>preSolve(std::vector<Core::FMTActualDevelopment> optionaldevelopments = std::vector<Core::FMTActualDevelopment>()) const override;
321 // DocString: FMTSrModel::boundSolution
329 bool boundSolution(int period, double tolerance = FMT_DBL_TOLERANCE);
330 // DocString: FMTSrModel::setParameter(const FMTintmodelparameters, const int)
337 bool setParameter(const FMTintmodelparameters& key, const int& value) override;
338 // DocString: FMTSrModel::setParameter(const FMTboolmodelparameters, const bool)
345 bool setParameter(const FMTboolmodelparameters& key, const bool& value) override;
346 // DocString: FMTSrModel::getRotations
354 std::set<Core::FMTSerie>getRotations(const Core::FMTMask& mask, const std::string& aggregate) const;
355 // DocString: FMTSrModel::isOptimal
360 virtual bool isOptimal() const;
361 // DocString: FMTSrModel::getObjectiveValue
366 virtual double getObjectiveValue() const;
367 // DocString: FMTSrModel::getNoChoice
374 std::vector<const Core::FMTDevelopment*> getNoChoice(const Core::FMTMask& base_mask) const;
375 // DocString: FMTSrModel::getAllMasks
381 std::set<std::string> getAllMasks(const std::vector<Core::FMTTheme>& p_selectedThemes) const;
382 // DocString: FMTSrModel::SupportsMultiThreading
387 bool SupportsMultiThreading() const override;
388 protected:
389 // DocString: FMTSrModel::graph
391 std::unique_ptr<Graph::FMTGraph<Graph::FMTVertexProperties, Graph::FMTEdgeProperties>>m_graph;
392 // DocString: FMTSrModel::solver
395 // DocString: FMTSrModel::summarize
403 bool summarize(const std::map<int, double>& variables,
404 std::vector<int>& sumvariables, std::vector<double>& sumcoefficiants) const;
405 // DocString: FMTSrModel::initializeMatrix
411 // DocString: FMTSrModel::updateMatrix
420 const Graph::FMTGraphStats& newstats);
421 // DocString: FMTSrModel::getgraphlength
426 size_t getGraphSize() const;
427 // DocString: FMTSrModel::postSolveGraph
432 void postSolveGraph(const FMTModel& originalbasemodel);
433 // DocString: FMTSrModel::getActives
438 std::queue<Graph::FMTGraph<Graph::FMTVertexProperties, Graph::FMTEdgeProperties>::FMTvertex_descriptor> getActives();
439 private:
440 // DocString: FMTSrModel::save
447 friend class boost::serialization::access;
448 template<class Archive>
449 void save(Archive& ar, const unsigned int version) const
450 {
451 ar& boost::serialization::make_nvp("model", boost::serialization::base_object<FMTModel>(*this));
452 ar& BOOST_SERIALIZATION_NVP(solver);
453 ar& BOOST_SERIALIZATION_NVP(m_graph);
454 }
455 // DocString: FMTSrModel::load
462 template<class Archive>
463 void load(Archive& ar, const unsigned int version)
464 {
465 ar& boost::serialization::make_nvp("model", boost::serialization::base_object<FMTModel>(*this));
466 ar& BOOST_SERIALIZATION_NVP(solver);
467 ar& BOOST_SERIALIZATION_NVP(m_graph);
468 solver.passInMessageHandler(*_logger);
469 }
470 BOOST_SERIALIZATION_SPLIT_MEMBER()
471
472 };
473
474}
475
476BOOST_CLASS_EXPORT_KEY(Models::FMTSrModel)
477
478#endif
479#endif
#define FMT_DBL_TOLERANCE
Definition: FMTutility.h:11
#define FMTEXPORT
Definition: FMTutility.h:125
Core class holding, as a boost dynamic bitset, which theme attributes are part of a mask.
Definition: FMTMask.h:96
Spatially referenced schedule describing the area of developments for which an action can be operated...
Definition: FMTSchedule.h:29
Statistics about a FMTGraph and its FMTLpSolver: their size, elements and type of elements.
Definition: FMTGraphStats.h:28
Adapter pointing to a vertex of a line graph or a full graph and its model, used to answer a generic ...
Definition: FMTGraphVertexToYield.h:31
Definition: FMTGraphVertexToYield.h:20
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 passInMessageHandler(Logging::FMTLogger &logger)
Pass the FMTLogger to the solver interface.
Base class for the different models in FMT.
Definition: FMTModel.h:62
Base class holding the attributes and methods shared between the spatially referenced models (FMTLpMo...
Definition: FMTSrModel.h:46
virtual std::unique_ptr< FMTModel > preSolve(std::vector< Core::FMTActualDevelopment > optionaldevelopments=std::vector< Core::FMTActualDevelopment >()) const override
Return a presolved copy of the FMTSrModel.
std::unique_ptr< Graph::FMTGraph< Graph::FMTVertexProperties, Graph::FMTEdgeProperties > > m_graph
graph holding the FMTdevelopments for all the periods.
Definition: FMTSrModel.h:391
void passInLogger(const std::unique_ptr< Logging::FMTLogger > &logger) override
Pass in the logger, overridden for the osisolverinterface.
void clearGraphCache()
Clear the node caching in the graph.
bool SupportsMultiThreading() const override
Return true if the solver support multithreading.
FMTLpSolver * getSolverPtr()
Get a pointer to the solver behind the model.
void clearGraphDevelopments()
Clear the developments location by periods in the graph.
bool setParameter(const FMTboolmodelparameters &key, const bool &value) override
Override setter for bool model parameters.
virtual void postSolve(const FMTModel &originalbasemodel)
Postsolve the presolved model back into the original model, also postsolving the FMTGraph of the FMTS...
size_t getGraphSize() const
Return the size of the graph.
~FMTSrModel()=default
Default destructor for FMTSrModel.
std::set< std::string > getAllMasks(const std::vector< Core::FMTTheme > &p_selectedThemes) const
Get all masks in string format for a complete graph, only for the selected themes.
virtual std::vector< Core::FMTActualDevelopment > getArea(int period=0, bool beforegrowanddeath=false) const override
Return the area for a given period for a FMTSrModel.
virtual std::unique_ptr< FMTModel > clone() const override
Get a clone of the FMTSrModel.
bool boundSolution(int period, double tolerance=FMT_DBL_TOLERANCE)
Bound the primal variables to the primal solution present in the matrix for a given period and tolera...
const FMTLpSolver * getConstSolverPtr() const
Get a pointer to the const solver behind the model.
Graph::FMTGraphStats buildPeriod(Core::FMTSchedule schedule=Core::FMTSchedule(), bool forcepartialbuild=false, int compressageclassoperability=1)
Main function used to build the graph and the matrix, adding a period within the graph and the matrix...
std::vector< const Core::FMTDevelopment * > getNoChoice(const Core::FMTMask &base_mask) const
Return the period 0 developments of a base mask that have no actions assigned for the whole planning ...
std::set< Core::FMTSerie > getRotations(const Core::FMTMask &mask, const std::string &aggregate) const
Get all the unique rotations (in periods) taken to complete a serie of actions for a mask and an acti...
virtual double getObjectiveValue() const
Return the value of the solver objective.
FMTSrModel(const FMTModel &base, FMTSolverInterface lsolvertype)
Main constructor building a FMTSrModel from its base class and letting the user choose the solver typ...
Graph::FMTGraphStats initializeMatrix()
Initialize the solver interface, called once when the FMTGraph was empty after the first call of buil...
Core::FMTSchedule getSolution(int period, bool withlock=false) const final
Get the standard solution for a given period, without the natural growth solution.
bool setSolutionByLp(int period, const Core::FMTSchedule &schedule, double tolerance=FMT_DBL_TOLERANCE)
Set the solution on a partial graph using a schedule, changing the objective function,...
bool summarize(const std::map< int, double > &variables, std::vector< int > &sumvariables, std::vector< double > &sumcoefficiants) const
Summarize constraints stored in a map structure (key is the variable, element is the coefficient) int...
bool forceSolution(int period, const Core::FMTSchedule &proportionschedulewithlock)
Force a solution using a schedule based on proportions instead of area, placing only the parts of the...
FMTSrModel(const FMTSrModel &rhs)
Copy constructor for FMTSrModel.
std::vector< Core::FMTActualDevelopment > getPotentialArea(int p_Period=0, bool p_BeforeGrowAndDeath=false) const
Compute the potential (maximum) development area for a period by forcing all solver decision variable...
Graph::FMTGraphVertexToYield getGraphVertexToYield() const
Return a filled FMTGraphVertexToYield without a specific vertex selected.
bool unboundSolution(int period)
Unbound the primal bounds of a given period.
Graph::FMTGraphStats updateMatrix(const Graph::FMTGraph< Graph::FMTVertexProperties, Graph::FMTEdgeProperties >::FMTvertex_pair &targets, const Graph::FMTGraphStats &newstats)
Update the solver interface matrix after the graph has been updated with new development types during...
bool setParameter(const FMTintmodelparameters &key, const int &value) override
Override setter for int model parameters.
void setNodeCacheSize(const size_t &p_size)
Set the size of reserved memory used when caching output nodes during the build process and output re...
FMTSrModel(FMTSrModel &&rhs) noexcept
Default move constructor for FMTSrModel.
int getFirstActivePeriod() const
Return the first active period.
bool isPeriodBounded(int period) const
Check if the FMTDevelopment areas are bounded on their primal variables for a given period.
FMTSrModel(FMTModel &&base, const Graph::FMTGraph< Graph::FMTVertexProperties, Graph::FMTEdgeProperties > &lgraph, const FMTLpSolver &lsolver)
Constructor for FMTSrModel mainly used in postSolve.
FMTLpSolver solver
The lpsolver.
Definition: FMTSrModel.h:394
FMTSrModel()
Default constructor for FMTSrModel.
std::queue< Graph::FMTGraph< Graph::FMTVertexProperties, Graph::FMTEdgeProperties >::FMTvertex_descriptor > getActives()
Initialize the graph based on the area if it is not initialized, otherwise return the active vertices...
void postSolveGraph(const FMTModel &originalbasemodel)
Postsolve the graph, rebuilding each vertex and edge based on the original model.
virtual bool isOptimal() const
Return true if the solver considers the solution optimal.
bool setSolution(int period, const Core::FMTSchedule &schedule, double tolerance=FMT_DBL_TOLERANCE)
Set a solution for a given period to warmstart the model or to prepare to bound the model to that sol...
void setParallelLogger(Logging::FMTLogger &logger) override
Pass a logger owned by the thread to the solver so it does not work in concurrency.
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
Definition: FMTAreaParser.h:35
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
FMTintmodelparameters
Enumerator of the integer parameters of a FMTModel.
Definition: FMTModelParameters.h:28
FMTboolmodelparameters
Enumerator of the boolean parameters of a FMTModel.
Definition: FMTModelParameters.h:67
STL namespace.