9#ifndef FMTlpmodel_Hm_included
10#define FMTlpmodel_Hm_included
13#include <boost/serialization/export.hpp>
14#include <boost/serialization/split_member.hpp>
15#include <boost/serialization/unordered_map.hpp>
16#include <boost/serialization/vector.hpp>
17#include <boost/thread/recursive_mutex.hpp>
18#include <boost/thread/lock_guard.hpp>
24 class FMTOperatingAreaScheduler;
25 class FMTOperatingAreaClusterer;
26 class FMTOperatingAreaCluster;
27 class FMTOperatingAreaScheme;
137 virtual std::vector<Core::FMTConstraint>
getReplanningConstraints(
const std::string& modeltype,
const std::vector<Core::FMTConstraint>& localconstraints,
const int& period)
const;
193 std::map<std::string, std::vector<double>>
getVariabilities(
const std::vector<Core::FMTOutput>& outputs,
194 const int& periodStart,
const int& periodStop);
204 std::vector<double> tolerances)
const;
214 std::map<std::string, std::vector<double>>
getAreaVariabilities(
const std::vector<Core::FMTOutput>& localoutputs,
215 const std::vector<Core::FMTMask>& globalmasks,
216 std::vector<double> tolerances = std::vector<double>())
const;
236 size_t numberofheuristics=1,
237 bool copysolver=
true);
255 size_t numberofheuristics=1,
256 int minimalnumberofclusters = -1,
257 int maximalnumberofclusters = -1)
const;
308 virtual std::unique_ptr<FMTModel>
clone()
const;
315 virtual std::unique_ptr<FMTModel>
preSolve(std::vector<Core::FMTActualDevelopment> optionaldevelopments = std::vector<Core::FMTActualDevelopment>())
const;
323 virtual bool build(std::vector<Core::FMTSchedule> schedules=std::vector<Core::FMTSchedule>());
337 virtual std::unique_ptr<FMTModel>
getCopy(
int period = 0)
const;
339 class ConstraintIndex
347 bool operator < (
const ConstraintIndex& p_rhs)
const;
348 bool operator == (
const ConstraintIndex& p_rhs)
const;
351 size_t getHash()
const;
360 mutable std::allocator<int>m_rowsAllocator;
363 mutable std::allocator<ConstraintIndex>m_indexAllocator;
366 std::map<ConstraintIndex,std::vector<int>>m_indexes;
373 std::vector<Core::FMTConstraint>::const_iterator _getConstraintIndex(
const Core::FMTConstraint& p_constraint)
const;
380 std::vector<Core::FMTConstraint>::const_iterator _getSetConstraintIndex(
const Core::FMTConstraint& p_constraint);
387 int _getIndex(
const std::vector<Core::FMTConstraint>::const_iterator& p_it)
const;
393 void _setGraphCache(
bool p_noLength =
false);
398 void _setConstraintsCache();
406 friend class boost::serialization::access;
407 template<
class Archive>
408 void save(Archive& ar,
const unsigned int version)
const
410 ar& boost::serialization::make_nvp(
"model", boost::serialization::base_object<FMTSrModel>(*
this));
411 ar& BOOST_SERIALIZATION_NVP(m_indexes);
413 template<
class Archive>
414 void load(Archive& ar,
const unsigned int version)
416 ar& boost::serialization::make_nvp(
"model", boost::serialization::base_object<FMTSrModel>(*
this));
417 ar& BOOST_SERIALIZATION_NVP(m_indexes);
435 const std::vector<Heuristics::FMTOperatingAreaCluster>& initialcluster,
438 const int& period,
int minimalnumberofclusters = -1,
int maximalnumberofclusters = -1)
const;
450 int getsetMatrixElement(
const std::vector<Core::FMTConstraint>::const_iterator& p_constraintId,
451 const FMTmatrixelement& element_type,
const std::map<int, double>& indexes,
453 double lowerbound = std::numeric_limits<double>::min(),
454 double upperbound = std::numeric_limits<double>::max());
464 bool getGoals(
const std::vector<std::string>& goalsnames,
465 std::map<int, double>& index,
const double& sense)
const;
474 int getLevelFromLevelName(
const std::string& variable_level,
int period,
475 const std::vector<Core::FMTConstraint>::const_iterator& p_it)
const;
484 int getSetLevel(
const std::vector<Core::FMTConstraint>::const_iterator& p_it,
485 const std::string& variable_level,
int period);
494 const std::vector<int> getMatrixElement(
const std::vector<Core::FMTConstraint>::const_iterator& it,
496 FMTmatrixelement p_element)
const;
505 std::vector<int>& getMatrixElementRef(
const std::vector<Core::FMTConstraint>::const_iterator& it,
507 FMTmatrixelement p_element);
517 void locateLevels(
const std::vector<Core::FMTOutputNode>& nodes,
int period,
518 std::map<int, double>& variables,
const std::vector<Core::FMTConstraint>::const_iterator& p_it,
519 double multiplier = 1);
530 std::vector<std::map<int, double>> locateNodes(
const std::vector<Core::FMTOutputNode>& nodes,
int period, std::map<int, double>& variables,
double multiplier = 1)
const;
537 void updateMatrixElements(std::vector<int>& matrixelements,
const std::vector<int>& deletedelements)
const;
544 void updateConstraintsMapping(
const std::vector<int>& Dvariables,
const std::vector<int>& Dconstraints);
551 bool updateMatrixNGraph(
bool updategraph =
true);
565 bool isMatrixElement(
const std::vector<Core::FMTConstraint>::const_iterator& p_constraintId,
566 const FMTmatrixelement& element_type,
int period)
const;
574 bool containsMatrixElements(
const std::vector<Core::FMTConstraint>::const_iterator& p_constraintId,
int period)
const;
585 bool isSameMatrixElement(
const int& matrixindex,
const FMTmatrixelement& element_type,
586 const double& lowerb,
const double& upperb,
const std::map<int, double>& variables)
const;
596 std::vector<int>setObjectiveBounds(
bool dolower =
true,
bool doupper =
true,
double tolerance =
FMT_DBL_TOLERANCE);
601 void updateMatrixNaming();
608 void updateGeneralConstraintsNaming(std::vector<std::string>& colnames,
609 std::vector<std::string>& rownames)
const;
618 bool setPositiveOutputsInMatrix(
const std::vector<Core::FMTConstraint>::const_iterator& p_it,
619 const std::vector<std::map<int, double>>& strictlypositivesoutputs,
int period);
625 virtual void swapPtr(std::unique_ptr<FMTModel>& rhs);
631 FMTLpModel(
const FMTSrModel& rhs);
638 bool trySetSolution(
const std::vector<Core::FMTSchedule>& schedules);
#define FMT_DBL_TOLERANCE
Definition: FMTutility.h:11
#define FMTEXPORT
Definition: FMTutility.h:125
Representation of a line in the optimize section, an objective being considered a constraint.
Definition: FMTConstraint.h:52
Node of an output representing a set of developments in the graph, holding a source,...
Definition: FMTOutputNode.h:25
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
Statistics about a FMTGraph and its FMTLpSolver: their size, elements and type of elements.
Definition: FMTGraphStats.h:28
Heuristic to do spatial clustering of operating areas across a landscape from a shapefile.
Definition: FMTOperatingAreaClusterer.h:28
Type III LP forest planning model, with the graph divided per period.
Definition: FMTLpModel.h:54
virtual std::unique_ptr< FMTModel > preSolve(std::vector< Core::FMTActualDevelopment > optionaldevelopments=std::vector< Core::FMTActualDevelopment >()) const
Return a presolved copy of the model using a vector of developments and the actual transitions,...
FMTLpModel getLocalModel(FMTModel localmodel=FMTModel(), int period=0) const
Append a child local model to the subset of this general model generated by the selected period,...
std::map< std::string, std::vector< double > > getAreaVariabilities(const std::vector< Core::FMTOutput > &localoutputs, const std::vector< Core::FMTMask > &globalmasks, std::vector< double > tolerances=std::vector< double >()) const
Return the change in outputs resulting from a variation of the area of the model for a given global m...
Graph::FMTGraphStats eraseConstraint(const Core::FMTConstraint &constraint, int period=-1)
Erase a constraint in the matrix and in the model elements.
std::vector< Heuristics::FMTOperatingAreaScheduler > getOperatingAreaSchedulerHeuristics(const std::vector< Heuristics::FMTOperatingAreaScheme > &opareas, const Core::FMTOutputNode &node, size_t numberofheuristics=1, bool copysolver=true)
Return operating area scheduler heuristics using multiple operating areas and an output node with a M...
FMTLpModel getModelFromProportions(const std::vector< Core::FMTMask > &globalmasks, std::vector< double > tolerances) const
Return a new FMTLpModel with changes in the initial area based on the tolerances of each global mask.
void clearConstraintLocation()
Clear the constraint localisation in the matrix.
void setStrictlyPositivesOutputsMatrix()
Set the model parameter STRICTLY_POSITIVE to true.
Graph::FMTGraphStats setObjective(const Core::FMTConstraint &objective)
Set the objective of the matrix for the whole planning horizon (graph length).
virtual std::vector< Core::FMTConstraint > getReplanningConstraints(const std::string &modeltype, const std::vector< Core::FMTConstraint > &localconstraints, const int &period) const
Adjust local or global constraints to the global model during replanning, using the solution of this ...
virtual bool solve()
Call initialSolve on the solver.
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 matrix solution.
void writeLp(const std::string &location)
Write the solver interface matrix to a file using the LP formulation.
bool initialSolve()
Cold start of the LP solve of a simple LP model.
FMTLpModel()
Default constructor for FMTLpModel.
FMTLpModel(const FMTModel &base, FMTSolverInterface lsolvertype)
Main constructor building a FMTLpModel from its base class and letting the user choose the solver typ...
void clearCache()
Remove the cache to release memory.
void addScheduleToObjective(const Core::FMTSchedule &schedule, double weight=1000)
Add weight to the objective function for a given schedule.
double getObjValue() const
Get the objective value of the solved matrix.
virtual std::unique_ptr< FMTModel > clone() const
Get a clone of the FMTLpModel.
std::vector< Heuristics::FMTOperatingAreaClusterer > getOperatingAreaClustererHeuristics(const std::vector< Heuristics::FMTOperatingAreaCluster > &clusters, const Core::FMTOutput &statisticoutput, const Core::FMTOutput &areaoutput, const int &period, size_t numberofheuristics=1, int minimalnumberofclusters=-1, int maximalnumberofclusters=-1) const
Return operating area clusterer heuristics for solving the operating area clustering problem using mu...
void writeMps(const std::string &location)
Write the solver interface matrix to a file using the MPS formulation.
virtual bool build(std::vector< Core::FMTSchedule > schedules=std::vector< Core::FMTSchedule >())
Build the graph and set the solution if schedules are passed.
FMTLpModel(FMTLpModel &&rhs)
Default move constructor for FMTLpModel.
Graph::FMTGraphStats erasePeriod(bool constraintsonly=false)
Delete the first period (front) of the graph and the matrix, shrinking the planning length to the ori...
Graph::FMTGraphStats setConstraint(const Core::FMTConstraint &constraint)
Set a constraint in the matrix for the whole planning horizon (graph length).
~FMTLpModel()=default
Default destructor for FMTLpModel.
FMTLpModel(const FMTLpModel &rhs)
Constructor for FMTLpModel mainly used in postSolve to pass each attribute of the class.
virtual std::unique_ptr< FMTModel > getCopy(int period=0) const
Return a copy of the FMTModel for the selected period.
std::map< std::string, std::vector< double > > getVariabilities(const std::vector< Core::FMTOutput > &outputs, const int &periodStart, const int &periodStop)
Get the variability of multiple outputs for a given tolerance for each period between periodStart and...
bool resolve()
Call solverinterface->resolve when some changes are done to the model, avoiding a full initialSolve.
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
FMToutputlevel
Enumerator describing the level of detail of an output (standard, total only, development).
Definition: FMTutility.h:22
@ standard
Definition: FMTutility.h:23
Namespace regrouping all tools for solving LP/MIP problems using an heuristic.
Definition: FMTAreaParser.h:47
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
FMTmatrixelement
Enum for the matrix element types present within the matrix.
Definition: FMTLpModel.h:38
@ nr_items
Definition: FMTLpModel.h:44
@ strictlypositive
Definition: FMTLpModel.h:43
@ goalvariable
Definition: FMTLpModel.h:39
@ objectivevariable
Definition: FMTLpModel.h:41
@ levelvariable
Definition: FMTLpModel.h:40
@ constraint
Definition: FMTLpModel.h:42