FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTSeModel.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#ifndef FMTSEM_Hm_included
9#define FMTSEM_Hm_included
10
11#include "FMTModel.h"
12#include "FMTSpatialSchedule.h"
13#include <boost/serialization/vector.hpp>
14#include <boost/serialization/serialization.hpp>
15#include <boost/serialization/nvp.hpp>
16#include <boost/serialization/export.hpp>
17#include "FMTSpatialGraphs.h"
18
19namespace Spatial
20{
21 template <typename T>
22 class FMTLayer;
23}
24
25namespace Models
26{
27// DocString: FMTSeModel
33 {
34 public:
35 // DocString: FMTSeModel()
40 // DocString: ~FMTSeModel()
44 virtual ~FMTSeModel() = default;
45 // DocString: FMTSeModel(const FMTSeModel)
51 // DocString: FMTSeModel(const FMTModel, const FMTForest)
57 FMTSeModel(const FMTModel& rhs,const Spatial::FMTForest& forest);
58 // DocString: FMTSeModel(const FMTModel, const FMTForest)
63 FMTSeModel(const FMTModel& rhs);
64 // DocString: FMTSeModel::operator=
70 FMTSeModel& operator = (const FMTSeModel& rhs);
71 // DocString: FMTSeModel::getMapping
77 // DocString: FMTSeModel::getSpSchedule
83 {
84 return m_BestSolution;
85 }
86 // DocString: FMTSeModel::getDisturbanceStats
91 std::string getDisturbanceStats() const;
92 // DocString: FMTSeModel::getSchedule
98 std::vector<Core::FMTSchedule> getSchedule(bool withlock=false) const;
99 // DocString: FMTSeModel::setInitialMapping
106 // DocString: FMTSeModel::logConstraintsInfeasibilities
111 // DocString: FMTSeModel::logConstraintsFactors
116 // DocString: FMTSeModel::preSolve
122 virtual std::unique_ptr<FMTModel>preSolve(
123 std::vector<Core::FMTActualDevelopment> optionaldevelopments = std::vector<Core::FMTActualDevelopment>()) const;
124 // DocString: FMTSeModel::postSolve
129 virtual void postSolve(const FMTModel& originalbasemodel);
130 // DocString: FMTSeModel::getOutput
139 virtual std::map<std::string, double> getOutput(const Core::FMTOutput& output,
140 int period, Core::FMToutputlevel level = Core::FMToutputlevel::standard) const;
141 // DocString: FMTSeModel::getOutput
148 virtual Spatial::FMTLayer<double> getSpatialOutput(const Core::FMTOutput& output,int period) const;
149 // DocString: FMTSeModel::getSolution
156 virtual Core::FMTSchedule getSolution(int period, bool withlock = false) const;
157
158
159 // DocString: FMTSeModel::clone
164 virtual std::unique_ptr<FMTModel>clone() const;
165 // DocString: FMTSeModel::getArea
172 virtual std::vector<Core::FMTActualDevelopment>getArea(int period = 0, bool beforegrowanddeath = false) const;
173 // DocString: FMTSeModel::getCopy
179 virtual std::unique_ptr<FMTModel> getCopy(int period = 0) const;
180 // DocString: FMTModel::getObjectiveValue
185 virtual double getObjectiveValue() const;
186 // DocString: FMTSeModel::getSchedules
193 std::vector<Core::FMTSchedule> getSchedules(const Spatial::FMTSpatialSchedule& p_SpatialSchedule,
194 bool withlock = false) const;
195 // DocString: FMTSeModel::getSolutionStatus
205 void getSolutionStatus(const Spatial::FMTSpatialSchedule& p_SpatialSchedule,
206 double& p_Objective, double& p_PrimalInFeasibility,
207 bool withsense = true, bool withfactorization = false, bool withspatial = true) const;
208 // DocString: FMTSeModel::getConstraintEvaluation
214 double getConstraintEvaluation(size_t p_Constraint) const;
215
216 protected:
217 // DocString: FMTSeModel::spschedule
220 // DocString: FMTSeModel::FMTSpatialGraphs
223
224 // DocString: FMTSeModel::_getGlobalObjective
230 double _getGlobalObjective(const Spatial::FMTSpatialSchedule& p_Schedule) const;
231
232 // DocString: FMTSeModel::_getConstraintsValues
238 std::vector<double> _getConstraintsValues(const Spatial::FMTSpatialSchedule& p_SpatialSchedule) const;
239
240 // DocString: FMTSeModel::_doRefactorization
245 void _doRefactorization(Spatial::FMTSpatialSchedule& p_SpatialSchedule) const;
246 // DocString: FMTSeModel::_getNewSolution
253 // DocString: FMTSeModel::greedyReferenceBuild
264 std::map<std::string, double> greedyReferenceBuild(
265 Spatial::FMTSpatialSchedule& p_SpatialSchedule,
266 const Core::FMTSchedule& schedule,
267 const size_t& randomiterations,
268 unsigned int seed = 0,
269 double tolerance = FMT_DBL_TOLERANCE,
270 bool log = true) const;
271 // DocString: FMTSeModel::_getConstraintFactor
278 double _getConstraintFactor(size_t p_constraint, double p_GrossValue) const;
279 // DocString: FMTSeModel::_isValidFactor
285 bool _isValidFactor(double p_GrossValue)const;
286 private:
287 // DocString: FMTSeModel::Serialize
294 friend class boost::serialization::access;
295 template<class Archive>
296 void serialize(Archive& ar, const unsigned int version)
297 {
298 ar& boost::serialization::make_nvp("model", boost::serialization::base_object<FMTModel>(*this));
299 //ar& BOOST_SERIALIZATION_NVP(m_BestSolution);
300 }
301 // DocString: FMTSeModel::swapPtr
306 virtual void swapPtr(std::unique_ptr<FMTModel>& rhs);
307 // DocString: FMTSeModel::_buildArea
312 void _buildArea(const Spatial::FMTForest& p_Forest);
313 // DocString: FMTSeModel::_buildGraphs
318 void _buildGraphs(double p_cellSize);
319 // DocString: FMTSeModel::_buildSolution
324 void _buildSolution(const Spatial::FMTForest& p_Forest);
325 // DocString: FMTSeModel::_copyGraphs
330 void _copyGraphs(const Spatial::FMTSpatialGraphs& pToCopy);
331 // DocString: FMTSeModel::_copySolution
336 void _copySolution(const Spatial::FMTSpatialSchedule& pToCopy);
337 // DocString: FMTSeModel::_getConstraintNumerator
343 double _getConstraintNumerator(size_t p_constraint) const;
344 static const double MAX_FACTOR;
345
346 };
347
348}
349
350BOOST_CLASS_EXPORT_KEY(Models::FMTSeModel)
351
352#endif // FMTSEM_Hm_included
#define FMT_DBL_TOLERANCE
Definition: FMTutility.h:11
#define FMTEXPORT
Definition: FMTutility.h:125
Class letting the user formulate a constraint in the optimize section or collect data across the grap...
Definition: FMTOutput.h:37
Spatially referenced schedule describing the area of developments for which an action can be operated...
Definition: FMTSchedule.h:29
Base class for the different models in FMT.
Definition: FMTModel.h:62
Abstract class for spatially explicit models, parent of FMTSesModel and FMTSaModel.
Definition: FMTSeModel.h:33
double _getGlobalObjective(const Spatial::FMTSpatialSchedule &p_Schedule) const
Return the global objective of a spatial schedule.
std::vector< Core::FMTSchedule > getSchedule(bool withlock=false) const
Return a copy of the operated schedules of the model, which can differ from the potential schedule.
Spatial::FMTSpatialSchedule m_BestSolution
Contains the builded spatialsolution latest or best one.
Definition: FMTSeModel.h:219
virtual double getObjectiveValue() const
Return the global objective value of the actual solution.
virtual std::vector< Core::FMTActualDevelopment > getArea(int period=0, bool beforegrowanddeath=false) const
Get the area of a period based on the solution.
FMTSeModel(const FMTModel &rhs)
Construct a FMTSeModel from a model.
FMTSeModel(const FMTModel &rhs, const Spatial::FMTForest &forest)
Construct a FMTSeModel from a model and a forest.
Spatial::FMTSpatialSchedule _getNewSolution(const Spatial::FMTSpatialSchedule &p_FromSolution) const
Return a new solution from an existing one.
std::string getDisturbanceStats() const
Return a string of patch statistics (area, perimeter) of the disturbances stack.
virtual std::map< std::string, double > getOutput(const Core::FMTOutput &output, int period, Core::FMToutputlevel level=Core::FMToutputlevel::standard) const
Get the output value for a period using the spatial solution.
virtual Core::FMTSchedule getSolution(int period, bool withlock=false) const
Get the standard solution for a period, without the natural growth solution.
virtual std::unique_ptr< FMTModel > clone() const
Get a clone of the FMTSeModel.
Spatial::FMTSpatialGraphs m_SpatialGraphs
Contains all the SpatialGraphs.
Definition: FMTSeModel.h:222
void getSolutionStatus(const Spatial::FMTSpatialSchedule &p_SpatialSchedule, double &p_Objective, double &p_PrimalInFeasibility, bool withsense=true, bool withfactorization=false, bool withspatial=true) const
Get the status of a spatial solution.
double getConstraintEvaluation(size_t p_Constraint) const
Evaluate a constraint with the actual solution.
std::map< std::string, double > greedyReferenceBuild(Spatial::FMTSpatialSchedule &p_SpatialSchedule, const Core::FMTSchedule &schedule, const size_t &randomiterations, unsigned int seed=0, double tolerance=FMT_DBL_TOLERANCE, bool log=true) const
Find the best spatialization for a schedule using random draws.
Spatial::FMTForest getMapping() const
Return a copy of the actual spatial forest state of each development.
virtual std::unique_ptr< FMTModel > preSolve(std::vector< Core::FMTActualDevelopment > optionaldevelopments=std::vector< Core::FMTActualDevelopment >()) const
Return a presolved copy of the model, presolving the forest map and the spatial actions.
std::vector< double > _getConstraintsValues(const Spatial::FMTSpatialSchedule &p_SpatialSchedule) const
Return the constraint values of a spatial schedule.
FMTSeModel()
Default constructor for FMTSeModel.
void _doRefactorization(Spatial::FMTSpatialSchedule &p_SpatialSchedule) const
Refactorize a spatial schedule.
bool setInitialMapping(const Spatial::FMTForest &forest)
Set the initial forest state, to be set before greedyReferenceBuild is called.
virtual Spatial::FMTLayer< double > getSpatialOutput(const Core::FMTOutput &output, int period) const
Get the spatial output value based on the spatial solution.
virtual void postSolve(const FMTModel &originalbasemodel)
Postsolve the model back into a complete model using the original model.
std::vector< Core::FMTSchedule > getSchedules(const Spatial::FMTSpatialSchedule &p_SpatialSchedule, bool withlock=false) const
Get the schedules of a spatial solution.
FMTSeModel(const FMTSeModel &rhs)
Copy constructor for FMTSeModel.
virtual std::unique_ptr< FMTModel > getCopy(int period=0) const
Return a copy of the model for a period, cleaning the constraints and keeping the objective.
double _getConstraintFactor(size_t p_constraint, double p_GrossValue) const
Return the factor of a constraint for a gross value.
void logConstraintsFactors() const
Log the constraint factors.
virtual ~FMTSeModel()=default
Default virtual destructor for FMTSeModel.
bool _isValidFactor(double p_GrossValue) const
Return true if a gross value is a valid factor.
Spatial::FMTSpatialSchedule getSpSchedule() const
Return a copy of the spatially explicit solution.
Definition: FMTSeModel.h:82
void logConstraintsInfeasibilities() const
Log the constraint infeasibilities, spatial or not.
Spatially referenced layer of Core::FMTDevelopment representing the forest.
Definition: FMTForest.h:33
Definition: FMTParser.h:54
Container of the line graphs of a spatially explicit model, organized by constraint family,...
Definition: FMTSpatialGraphs.h:52
Map containing a line graph for each cell, representing the stand, the action and the transition at e...
Definition: FMTSpatialSchedule.h:50
FMToutputlevel
Enumerator describing the level of detail of an output (standard, total only, development).
Definition: FMTutility.h:22
@ standard
Definition: FMTutility.h:23
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
Definition: FMTAreaParser.h:40