FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
Models::FMTLpModel Class Reference

Type III LP forest planning model, with the graph divided per period. More...

#include <FMTLpModel.h>

Inheritance diagram for Models::FMTLpModel:
[legend]
Collaboration diagram for Models::FMTLpModel:
[legend]

Public Member Functions

void clearCache ()
 Remove the cache to release memory.
 
void clearConstraintLocation ()
 Clear the constraint localisation in the matrix.
 
 FMTLpModel (const FMTModel &base, FMTSolverInterface lsolvertype)
 Main constructor building a FMTLpModel from its base class and letting the user choose the solver type.
 
 FMTLpModel ()
 Default constructor for FMTLpModel.
 
 FMTLpModel (const FMTLpModel &rhs)
 Constructor for FMTLpModel mainly used in postSolve to pass each attribute of the class.
 
bool initialSolve ()
 Cold start of the LP solve of a simple LP model.
 
 FMTLpModel (FMTLpModel &&rhs)
 Default move constructor for FMTLpModel.
 
FMTLpModeloperator= (FMTLpModel &&rhs)
 Default move assignment for FMTLpModel.
 
void setStrictlyPositivesOutputsMatrix ()
 Set the model parameter STRICTLY_POSITIVE to true.
 
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.
 
virtual std::vector< Core::FMTConstraintgetReplanningConstraints (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 model to adjust the bounds.
 
void addScheduleToObjective (const Core::FMTSchedule &schedule, double weight=1000)
 Add weight to the objective function for a given schedule.
 
bool operator== (const FMTLpModel &rhs) const
 Comparison operator for FMTLpModel.
 
bool operator!= (const FMTLpModel &rhs) const
 Comparison operator for FMTLpModel.
 
Graph::FMTGraphStats setObjective (const Core::FMTConstraint &objective)
 Set the objective of the matrix for the whole planning horizon (graph length).
 
Graph::FMTGraphStats setConstraint (const Core::FMTConstraint &constraint)
 Set a constraint in the matrix for the whole planning horizon (graph length).
 
Graph::FMTGraphStats eraseConstraint (const Core::FMTConstraint &constraint, int period=-1)
 Erase a constraint in the matrix and in the model elements.
 
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 periodStop.
 
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.
 
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 mask.
 
Graph::FMTGraphStats erasePeriod (bool constraintsonly=false)
 Delete the first period (front) of the graph and the matrix, shrinking the planning length to the original size minus one.
 
std::vector< Heuristics::FMTOperatingAreaSchedulergetOperatingAreaSchedulerHeuristics (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 MIP formulation on the matrix of the FMTLpModel.
 
std::vector< Heuristics::FMTOperatingAreaClusterergetOperatingAreaClustererHeuristics (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 multiple operating areas.
 
bool resolve ()
 Call solverinterface->resolve when some changes are done to the model, avoiding a full initialSolve.
 
FMTLpModeloperator= (const FMTLpModel &rhs)
 Copy assignment operator for FMTLpModel.
 
 ~FMTLpModel ()=default
 Default destructor for FMTLpModel.
 
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, based on the model hierarchy.
 
double getObjValue () const
 Get the objective value of the solved matrix.
 
void writeLp (const std::string &location)
 Write the solver interface matrix to a file using the LP formulation.
 
void writeMps (const std::string &location)
 Write the solver interface matrix to a file using the MPS formulation.
 
virtual std::unique_ptr< FMTModelclone () const
 Get a clone of the FMTLpModel.
 
virtual std::unique_ptr< FMTModelpreSolve (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, reducing the model data if it is badly formulated.
 
virtual bool build (std::vector< Core::FMTSchedule > schedules=std::vector< Core::FMTSchedule >())
 Build the graph and set the solution if schedules are passed.
 
virtual bool solve ()
 Call initialSolve on the solver.
 
virtual std::unique_ptr< FMTModelgetCopy (int period=0) const
 Return a copy of the FMTModel for the selected period.
 
- Public Member Functions inherited from Models::FMTSrModel
void setNodeCacheSize (const size_t &p_size)
 Set the size of reserved memory used when caching output nodes during the build process and output requests.
 
Graph::FMTGraphVertexToYield getGraphVertexToYield () const
 Return a filled FMTGraphVertexToYield without a specific vertex selected.
 
virtual void postSolve (const FMTModel &originalbasemodel)
 Postsolve the presolved model back into the original model, also postsolving the FMTGraph of the FMTSrModel.
 
void setParallelLogger (Logging::FMTLogger &logger) override
 Pass a logger owned by the thread to the solver so it does not work in concurrency.
 
 FMTSrModel (const FMTModel &base, FMTSolverInterface lsolvertype)
 Main constructor building a FMTSrModel from its base class and letting the user choose the solver type.
 
 FMTSrModel ()
 Default constructor for FMTSrModel.
 
 FMTSrModel (const FMTSrModel &rhs)
 Copy constructor for FMTSrModel.
 
 FMTSrModel (FMTModel &&base, const Graph::FMTGraph< Graph::FMTVertexProperties, Graph::FMTEdgeProperties > &lgraph, const FMTLpSolver &lsolver)
 Constructor for FMTSrModel mainly used in postSolve.
 
FMTSrModeloperator= (const FMTSrModel &rhs)
 Copy assignment operator for FMTSrModel.
 
 FMTSrModel (FMTSrModel &&rhs) noexcept
 Default move constructor for FMTSrModel.
 
FMTSrModeloperator= (FMTSrModel &&rhs) noexcept
 Default move assignment for FMTSrModel.
 
 ~FMTSrModel ()=default
 Default destructor for FMTSrModel.
 
bool operator== (const FMTSrModel &rhs) const
 Comparison operator for FMTSrModel.
 
bool operator!= (const FMTSrModel &rhs) const
 Comparison operator for FMTSrModel.
 
bool unboundSolution (int period)
 Unbound the primal bounds of a given period.
 
bool isPeriodBounded (int period) const
 Check if the FMTDevelopment areas are bounded on their primal variables for a given period.
 
void clearGraphDevelopments ()
 Clear the developments location by periods in the graph.
 
void clearGraphCache ()
 Clear the node caching in the graph.
 
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 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, constraints and variable bounds.
 
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 solution possible with the model modifications.
 
Core::FMTSchedule getSolution (int period, bool withlock=false) const final
 Get the standard solution for a given period, without the natural growth solution.
 
Core::FMTSchedule getScheduleProportions (int period, bool withlock) const
 Same as getSolution but the schedule area represents the percentage of area of the development.
 
Graph::FMTGraphStats getStats () const
 Get the graph stats of the graph and matrix (number of columns, rows, edges, vertices).
 
Graph::FMTGraphStats getGraphStats (const Core::FMTMask &p_Subset) const
 Get the graph stats of the graph and matrix (number of columns, rows, edges, vertices) for a mask subset.
 
virtual std::unique_ptr< FMTModelgetCopy (int period=0) const
 Return a copy of the FMTModel for the selected period.
 
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.
 
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.
 
int getFirstActivePeriod () const
 Return the first active period.
 
virtual std::vector< Core::FMTActualDevelopmentgetArea (int period=0, bool beforegrowanddeath=false) const override
 Return the area for a given period for a FMTSrModel.
 
std::vector< Core::FMTActualDevelopmentgetPotentialArea (int p_Period=0, bool p_BeforeGrowAndDeath=false) const
 Compute the potential (maximum) development area for a period by forcing all solver decision variables to 1.0.
 
FMTLpSolvergetSolverPtr ()
 Get a pointer to the solver behind the model.
 
const FMTLpSolvergetConstSolverPtr () const
 Get a pointer to the const solver behind the model.
 
virtual std::unique_ptr< FMTModelclone () const override
 Get a clone of the FMTSrModel.
 
void passInLogger (const std::unique_ptr< Logging::FMTLogger > &logger) override
 Pass in the logger, overridden for the osisolverinterface.
 
virtual std::unique_ptr< FMTModelpreSolve (std::vector< Core::FMTActualDevelopment > optionaldevelopments=std::vector< Core::FMTActualDevelopment >()) const override
 Return a presolved copy 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 tolerance.
 
bool setParameter (const FMTintmodelparameters &key, const int &value) override
 Override setter for int model parameters.
 
bool setParameter (const FMTboolmodelparameters &key, const bool &value) override
 Override setter for bool model parameters.
 
std::set< Core::FMTSeriegetRotations (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 action aggregate.
 
virtual bool isOptimal () const
 Return true if the solver considers the solution optimal.
 
virtual double getObjectiveValue () const
 Return the value of the solver objective.
 
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 horizon.
 
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.
 
bool SupportsMultiThreading () const override
 Return true if the solver support multithreading.
 
- Public Member Functions inherited from Models::FMTModel
double getYieldValue (const std::string &p_mask, const std::string &p_yield, int p_age, int p_period) const
 Get yield value.
 
void setReplicate (size_t p_replicate, int p_ReplanningPeriod)
 Set the constraints to the specified Replanning Period.
 
bool gotReIgnore (const int &p_replanningPeriod) const
 Check if setReIgnore needs to be called.
 
bool gotReplicate (const int &p_replanningPeriod) const
 Check if setReplicate needs to be called.
 
FMTModel buildAction (const std::string &p_actionName, const std::string &p_Targetyield) const
 Build an action based on the positive value of a yield.
 
std::vector< Core::FMTSchedulebuildSchedule (const Core::FMTAction &p_action, const FMTModel &p_BaseModel, const std::string &p_Targetyield, const std::vector< Core::FMTSchedule > &p_schedules) const
 Build a schedule by looking at operability of the actual developments.
 
void pushTheme (const std::string &p_themeName, const std::string &p_yieldName, const std::vector< std::string > &p_attributes)
 Push a new theme and update the whole model with it.
 
Models::FMTModel aggregateAllActions (const std::vector< std::string > &p_Aggregates, std::vector< std::string > p_ActionOrdering) const
 Aggregate actions together and create a new model with new actions, transitions, outputs, constraints, yields and lifespan.
 
Models::FMTModel splitActions (const std::vector< std::string > &p_Actions, const std::vector< std::string > &p_masks) const
 Split actions using the provided masks, new actions are named action_mask and aggregated into the original action name.
 
std::vector< std::string > getSchedulesPriorities (const std::vector< Core::FMTSchedule > &p_schedules) const
 Return the action names in priority of area scheduled.
 
std::vector< Core::FMTScheduleaggregateSchedules (const std::vector< Core::FMTSchedule > &p_schedules) const
 Build a new schedule based on p_schedules with the corresponding aggregated actions.
 
std::vector< Core::FMTSchedulesplitSchedules (const std::vector< Core::FMTSchedule > &p_schedules) const
 Using the actions of the model change the actions of the schedule.
 
virtual void setParallelLogger (Logging::FMTLogger &logger)
 Set a thread owned logger so the solver does not work in concurrency.
 
virtual void clearCache ()
 Clear caching elements to reduce memory usage.
 
 FMTModel (const std::vector< Core::FMTActualDevelopment > &larea, const std::vector< Core::FMTTheme > &lthemes, const std::vector< Core::FMTAction > &lactions, const std::vector< Core::FMTTransition > &ltransitions, const Core::FMTYields &lyields, const Core::FMTLifespans &llifespan, const std::string &lname, const std::vector< Core::FMTOutput > &loutputs, std::vector< Core::FMTConstraint > lconstraints=std::vector< Core::FMTConstraint >(), FMTModelParameters lparameters=FMTModelParameters())
 Main constructor for FMTModel used in Parser::FMTModelParser, constraints and parameters are optional.
 
 FMTModel ()
 Default constructor of FMTModel.
 
virtual ~FMTModel ()=default
 Default virtual destructor of FMTModel.
 
 FMTModel (FMTModel &&rhs)
 Default move constructor for FMTModel.
 
FMTModeloperator= (FMTModel &&rhs)
 Default move assignment for FMTModel.
 
virtual std::vector< Core::FMTActualDevelopmentgetArea (int period=0, bool beforegrowanddeath=false) const
 Get the area of a given period as actual developments.
 
virtual std::unique_ptr< FMTModelgetCopy (int period=0) const
 Return a copy of the FMTModel for the selected period, cleaning the constraints and keeping the objective.
 
FMTModel basePreSolve () const
 Presolve the model using the existing area.
 
Core::FMTMaskFilter getPreSolveFilter (const std::vector< Core::FMTTheme > &originalthemes) const
 Get the preSolve filter.
 
Core::FMTMaskFilter getPostSolveFilter (const std::vector< Core::FMTTheme > &originalthemes, const Core::FMTMask &devmask) const
 Get the postsolve filter used by the preSolve, to turn a presolved mask into a postsolve mask.
 
Core::FMTMask getSelectedMask (const std::vector< Core::FMTTheme > &originalthemes) const
 Get the selection mask needed to preSolve a FMTMask when the model is presolved.
 
virtual std::unique_ptr< FMTModelpreSolve (std::vector< Core::FMTActualDevelopment > optionaldevelopments=std::vector< Core::FMTActualDevelopment >()) const
 Return a new presolved FMTModel using developments and the actual transitions of the model.
 
virtual void postSolve (const FMTModel &originalbasemodel)
 Postsolve the presolved model into the original model.
 
Core::FMTSchedule preSolveSchedule (const Core::FMTSchedule &originalbaseschedule, const FMTModel &originalbasemodel) const
 Return a new schedule with presolved development masks and actions.
 
FMTModelStats getModelStats () const
 Return the statistics of the model such as the number of themes, yields, actions and transitions.
 
void cleanActionsNTransitions ()
 Delete actions that have no defined transition and transitions that have no defined action, then sort them.
 
std::string getName () const
 Return the name of the FMTModel.
 
std::vector< Core::FMTThemegetThemes () const
 Return a copy of the themes of the model.
 
std::vector< Core::FMTActiongetActions () const
 Return a copy of the actions of the model.
 
std::vector< Core::FMTTransitiongetTransitions () const
 Return a copy of the transitions of the model.
 
Core::FMTYields getYields () const
 Return a copy of the yields of the model.
 
Core::FMTLifespans getLifespan () const
 Return a copy of the lifespan of the model.
 
std::vector< Core::FMTOutputgetOutputs () const
 Return a copy of the outputs of the model.
 
std::vector< Core::FMTConstraintgetConstraints () const
 Return a copy of the constraints of the model.
 
void addOutput (const std::string &name, const std::string &maskstring, Core::FMTotar outputtarget, std::string action=std::string(), std::string yield=std::string(), std::string description=std::string(), int targetTheme=-1)
 Add one output to the model based only on strings.
 
template<typename T >
void addYieldHandlers (const std::vector< T > &yieldhandlers)
 Add FMTYieldHandler from a vector to the yields.
 
void addYieldHandlersFromPtr (const std::vector< std::unique_ptr< Core::FMTYieldHandler > > &yieldhandlers)
 Add unique pointers of FMTYieldHandler from a vector to the yields.
 
bool operator== (const FMTModel &rhs) const
 Equality comparison operator of FMTModel.
 
bool operator< (const FMTModel &rhs) const
 Less than comparison operator of FMTModel.
 
void setArea (const std::vector< Core::FMTActualDevelopment > &ldevs)
 Setter for the initial actual developments (area section), replacing the originals.
 
void setThemes (const std::vector< Core::FMTTheme > &lthemes)
 Setter for the themes of the model, replacing the originals.
 
void setActions (const std::vector< Core::FMTAction > &lactions)
 Setter for the actions of the model, replacing the originals.
 
void setTransitions (const std::vector< Core::FMTTransition > &ltransitions)
 Setter for the transitions of the model, replacing the originals.
 
void setConstraints (const std::vector< Core::FMTConstraint > &lconstraint)
 Setter for the constraints of the model, replacing the original.
 
void setYields (const Core::FMTYields &lylds)
 Setter for the yields of the model, replacing the original.
 
void setLifespan (const Core::FMTLifespans &llifespan)
 Setter for the lifespan of the model, replacing the original.
 
void setName (const std::string &newname)
 Set the name of the FMTModel.
 
void setOutputs (const std::vector< Core::FMTOutput > &newoutputs)
 Setter for the outputs of the model.
 
bool isValid ()
 Validate the whole FMTModel through themes, actual developments, yields, actions, transitions, outputs and constraints.
 
std::vector< const Core::FMTTheme * > locateStaticThemes (const Core::FMTOutput &output, bool ignoreoutputvariables=false) const
 Return the themes that are not used in the transitions and in a given output (static themes).
 
std::vector< const Core::FMTTheme * > locateStaticThemes (const Core::FMTOutputNode &output, bool ignoreoutputvariables=false) const
 Return the themes that are not used in the transitions and in a given output node (static themes).
 
std::vector< const Core::FMTTheme * > locateDynamicThemes (const Core::FMTOutput &outpu, bool ignoreoutputvariables=false) const
 Return the themes used in the transition scheme.
 
Core::FMTMask getDynamicMask (const Core::FMTOutput &output, bool ignoreoutputvariables=false) const
 Return a mask where static attributes have a value of 0 and dynamic attributes a value of 1.
 
Core::FMTMask getDynamicMask (const Core::FMTOutputNode &node, bool ignoreoutputvariables=false) const
 Return a mask where static attributes have a value of 0 and dynamic attributes a value of 1.
 
virtual Core::FMTMask getStaticMask (const Core::FMTOutputNode &node, bool ignoreoutputvariables=false) const
 Return a mask where static attributes have a value of 1 and dynamic attributes a value of 0.
 
bool isStaticNode (const Core::FMTOutputNode &node, double ratioofset=0.1) const
 Return true if the node can be used in static mask functions.
 
std::vector< const Core::FMTTheme * > locateStaticTransitionsThemes () const
 Return the static themes based on the model transitions.
 
std::vector< const Core::FMTTheme * > locateNodeStaticThemes (const Core::FMTOutputNode &node, bool ignoreoutputvariables=false, std::vector< const Core::FMTTheme * > basethemes=std::vector< const Core::FMTTheme * >()) const
 Return the static themes of a node based on the model transitions.
 
 FMTModel (const FMTModel &rhs)
 Copy constructor of FMTModel.
 
FMTModeloperator= (const FMTModel &rhs)
 Copy assignment of FMTModel.
 
bool empty () const
 Return true if the FMTModel is empty.
 
void push_back (const FMTModel &rhs)
 Append a FMTModel to this FMTModel without overriding the objective of the base model.
 
double getInitialArea () const
 Return the sum of the area of the area vector.
 
void setAreaPeriod (const int &period)
 Change the initial area period to the targeted period.
 
int getAreaPeriod () const
 get the period of the area section.
 
Core::FMTSchedule getPotentialSchedule (std::vector< Core::FMTActualDevelopment > toRemove, std::vector< Core::FMTActualDevelopment > selection, bool withlock=true) const
 Test operability of a selection minus the developments to remove and return a schedule with an area of 1.0 for each operable development.
 
virtual std::vector< Core::FMTConstraintgetReplanningConstraints (const std::string &modeltype, const std::vector< Core::FMTConstraint > &localconstraints, const int &period) const
 Adjust the constraints that need to be set to a value of the global or local model and return all constraints.
 
virtual bool doPlanning (const bool &solve, std::vector< Core::FMTSchedule > schedules=std::vector< Core::FMTSchedule >())
 Build the model and do the initial solve or simulate, using the build and solve overridden functions of the different model types.
 
virtual std::map< std::string, double > getOutput (const Core::FMTOutput &output, int period, Core::FMToutputlevel level=Core::FMToutputlevel::standard) const
 Get the output value of an output for a given period using the spatial solution.
 
virtual Core::FMTSchedule getSolution (int period, bool withlock=false) const
 Get the standard solution for a given period, without the natural growth solution.
 
virtual std::map< std::string, std::vector< std::vector< double > > > getOutputsFromPeriods (const std::vector< Core::FMTOutput > &theoutputs, const int &firstPeriod, const int &lastPeriod, Core::FMToutputlevel level=Core::FMToutputlevel::standard) const
 For each output get a vector of output values from the first period to the last period.
 
virtual std::unique_ptr< FMTModelclone () const
 Get a clone of the FMTModel.
 
virtual bool setParameter (const FMTintmodelparameters &p_key, const int &p_value)
 set int parameters to nss model.
 
virtual bool setParameter (const FMTdblmodelparameters &key, const double &value)
 Setter for double model parameters. See FMTModelParameters.h.
 
virtual bool setParameter (const FMTboolmodelparameters &key, const bool &value)
 Setter for bool model parameters. See FMTModelParameters.h.
 
virtual bool setParameter (const FMTstrmodelparameters &p_key, const std::string &p_value)
 Setter forstr model parameters. See FMTModelParameters.h.
 
int getParameter (const FMTintmodelparameters &key) const
 Getter for int model parameters. See FMTModelParameters.h.
 
double getParameter (const FMTdblmodelparameters &key) const
 Getter for double model parameters. See FMTModelParameters.h.
 
bool getParameter (const FMTboolmodelparameters &key) const
 Getter for bool model parameters. See FMTModelParameters.h.
 
const std::string & getParameter (const FMTstrmodelparameters &p_key) const
 Getter for str model parameters. See FMTModelParameters.h.
 
bool setCompressTime (const int &periodStart, const int &periodStop, const int &value)
 Set the compresstime value for a range of periods. See FMTModelParameters.h.
 
std::vector< int > getCompressTime () const
 Return a vector with the compresstime value for each period, the first period being index 0. See FMTModelParameters.h.
 
std::vector< Core::FMTConstraintgoalConstraints (double penalty=999999) const
 Return all constraints and the objective with goals and penalty.
 
std::vector< Core::FMTConstraintgetTacticalConstraints (double penalty=999999, double scheduleweight=999999, double objective=0, double objectivefactor=1.0) const
 Get the constraints adapted for a tactical model.
 
virtual void showParameters (const bool &showhelp=false) const
 Show the parameter values.
 
virtual bool build (std::vector< Core::FMTSchedule > schedules=std::vector< Core::FMTSchedule >())
 Build the elements needed to solve the model, overridden by each type of model.
 
virtual bool solve ()
 Solve the model, overridden by each type of model.
 
virtual bool isOptimal () const
 Return true if the FMTModel is optimal.
 
virtual double getObjectiveValue () const
 Return the value of the global objective.
 
std::default_random_engine * getGeneratorPtr () const
 Get a pointer to the generator.
 
std::vector< size_t > getStaticTransitionThemes () const
 Locate the static transition themes.
 
virtual bool SupportsMultiThreading () const
 Some solver dont support multithreading.
 
- Public Member Functions inherited from Core::FMTObject
 FMTObject ()
 Default constructor for FMTObject.
 
virtual ~FMTObject ()
 Default virtual destructor for FMTObject.
 
 FMTObject (const std::unique_ptr< Exception::FMTExceptionHandler > exhandler)
 Construct a FMTObject passing in the exception handler of another FMTObject.
 
 FMTObject (const FMTObject &rhs)
 Copy constructor for FMTObject.
 
FMTObjectoperator= (const FMTObject &rhs)
 Copy assignment operator for FMTObject.
 
virtual void passInLogger (const std::unique_ptr< Logging::FMTLogger > &logger)
 Pass in the logger of another FMTObject.
 
void passInExceptionHandler (const std::unique_ptr< Exception::FMTExceptionHandler > &exhandler)
 Pass in the exception handler of another FMTObject.
 
void redirectLogToFile (const std::string &location)
 Redirect the log to a specific file, appending to it.
 
virtual void setDefaultLogger ()
 Create and set a default logger to the FMTObject.
 
virtual void setQuietLogger ()
 Create and set a quiet logger to the FMTObject.
 
virtual void setTaskLogger ()
 Create and set a task logger to the FMTObject.
 
virtual void setDebugLogger ()
 Create and set a debug logger to the FMTObject.
 
void setDefaultExceptionHandler ()
 Create and set a default exception handler to the FMTObject.
 
void setQuietExceptionHandler ()
 Create and set a quiet exception handler to the FMTObject.
 
void setDebugExceptionHandler ()
 Create and set a debug exception handler to the FMTObject.
 
void setFreeExceptionHandler ()
 Create and set a free exception handler to the FMTObject.
 
void disableNestedExceptions ()
 Disable the nested exception throw of the exception handler.
 
void enableNestedExceptions ()
 Enable the nested exception throw of the exception handler.
 
void setErrorsToWarnings (const std::vector< Exception::FMTexc > &errors)
 Set a list of errors to be cast to warnings on the exception handler.
 
void setMaxWarningsBeforeSilenced (const size_t &maxwarningcount)
 Set the number of warnings raised before being silenced.
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Friends

class boost::serialization::access
 Save and load functions used for serialization to do multiprocessing across multiple cpus (pickle in Python).
 

Additional Inherited Members

- Static Public Member Functions inherited from Models::FMTModel
static Core::FMTAction defaultDeathAction (const Core::FMTLifespans &llifespan, const std::vector< Core::FMTTheme > &lthemes)
 Return the default death action, based on the lifespan and themes, when not specified by the user.
 
static Core::FMTTransition defaultDeathTransition (const Core::FMTLifespans &llifespan, const std::vector< Core::FMTTheme > &lthemes)
 Return the default death transition, based on the lifespan and themes, when not specified by the user.
 
- Static Public Member Functions inherited from Core::FMTObject
static Logging::FMTLoggergetLogger ()
 get a pointer to the actual logger.
 
static Exception::FMTExceptionHandlergetExceptionHandler ()
 get a pointer to the actual exception handler.
 
static std::string getRuntimeLocation ()
 Return the location of the FMT shared library.
 
static unsigned long long getAvailableMemory ()
 Return the available memory in bytes.
 
static void setTerminateStack ()
 will write the stack in the log when terminate called and raise a function failed.
 
static void setAbortStack ()
 will write the stack in the log when abort called with SIGABRT and raise a function failed.
 
- Protected Member Functions inherited from Models::FMTSrModel
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) into a vector structure for the osisolverinterface.
 
Graph::FMTGraphStats initializeMatrix ()
 Initialize the solver interface, called once when the FMTGraph was empty after the first call of buildPeriod.
 
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 buildPeriod.
 
size_t getGraphSize () const
 Return the size of the graph.
 
void postSolveGraph (const FMTModel &originalbasemodel)
 Postsolve the graph, rebuilding each vertex and edge based on the original model.
 
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.
 
- Protected Member Functions inherited from Models::FMTModel
void setSeed (const int &p_seed)
 seed the random number generator
 
void setDefaultObjects ()
 Define the default _DEATH action and transition when they are not defined by the user.
 
Core::FMTMask getBaseMask (std::vector< Core::FMTActualDevelopment > optionaldevelopments) const
 Return a mask covering the actual bits used by the FMTModel and the optional developments.
 
std::vector< const Core::FMTTheme * > getStaticPreSolveThemes () const
 Return the themes that are not part of the model, using the transition themes, constraints, actions and yields.
 
void clearActionsCache ()
 Clear the cached actions data.
 
void clearYieldCache ()
 Clear the cached yields data.
 
void clearTransitionCache ()
 Clear the cached transitions data.
 
virtual void swapPtr (std::unique_ptr< FMTModel > &rhs)
 Swap this model for the element at the end of the rhs unique pointer.
 
std::vector< Core::FMTSchedulesetUpSchedulesForBuild (const std::vector< Core::FMTSchedule > &schedules) const
 Prepare the passed schedules for building based on FORCE_PARTIAL_BUILD, always returning a filled vector covering the whole length.
 
bool useActionSerie () const
 Return true if the model makes use of action series.
 
size_t getSeriesMaxSize () const
 Get the maximal serie size for the whole model.
 
- Protected Member Functions inherited from Core::FMTObject
template<class Archive >
void forceSave (Archive &ar, const unsigned int version) const
 Force the serialization to save useful information, which the default FMTObject serialization does not.
 
template<class Archive >
void forceLoad (Archive &ar, const unsigned int version)
 Force the serialization to load useful information, which the default FMTObject serialization does not.
 
void checkSignals () const
 Check if the user has sent a ctrl-c signal using boost::python to FMT.
 
void setCplHandler ()
 Pass the FMT exception handler to the GDAL exception handler (GDAL only).
 
- Static Protected Member Functions inherited from Core::FMTObject
static std::chrono::time_point< std::chrono::high_resolution_clock > getClock ()
 Return a clock of the current time.
 
template<class chrono >
static double getDuration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock as a double.
 
static std::string getDurationInSeconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock in seconds as a string.
 
static void _logStack ()
 Log the stack trace...
 
static void _terminate ()
 Raise an error with the boost stacktrace.
 
static void _abort (int p_signal)
 Raise an error with the boost stacktrace on abort.
 
- Protected Attributes inherited from Models::FMTSrModel
std::unique_ptr< Graph::FMTGraph< Graph::FMTVertexProperties, Graph::FMTEdgeProperties > > m_graph
 graph holding the FMTdevelopments for all the periods.
 
FMTLpSolver solver
 The lpsolver.
 
- Protected Attributes inherited from Models::FMTModel
std::default_random_engine m_generator
 Random number generator.
 
FMTModelParameters parameters
 
std::vector< Core::FMTActualDevelopmentarea
 Actualdevelopments for period 0, seen in the area section or the shapefile/raster.
 
std::vector< Core::FMTThemethemes
 Model themes of the landscape section file.
 
std::vector< Core::FMTActionactions
 Model actions from the action file and also the _death action.
 
std::vector< Core::FMTTransitiontransitions
 Model transitions from the transition file and also the _death transition.
 
Core::FMTYields yields
 Yields data comming from the yield file.
 
Core::FMTLifespans lifespan
 lifespan data comming from the lifespan file
 
std::vector< Core::FMTOutputoutputs
 Outputs comming from the ouput file.
 
std::vector< Core::FMTConstraintconstraints
 Outputs comming from the optimization file.
 
std::string name
 The name of the Model (name of the .pri file without extension)
 
std::vector< size_t > statictransitionthemes
 The location of the themes static from transitions.
 
- Static Protected Attributes inherited from Core::FMTObject
static std::unique_ptr< Exception::FMTExceptionHandler_exhandler
 A shared pointer to the exception handler.
 
static std::unique_ptr< Logging::FMTLogger_logger
 A shared pointer to the logger.
 

Detailed Description

Type III LP forest planning model, with the graph divided per period.

Made for replanning and simple forest planning LP optimization, it makes heavy use of FMTGraph to build the matrix. Being based on a list structure, the model can easily be extended (by the back) using buildPeriod or shrinked (by the front) using erasePeriod. The matrix is held within the solver interface pointer.

Constructor & Destructor Documentation

◆ FMTLpModel() [1/4]

Models::FMTLpModel::FMTLpModel ( const FMTModel base,
FMTSolverInterface  lsolvertype 
)

Main constructor building a FMTLpModel from its base class and letting the user choose the solver type.

See FMTSolverInterface.h for the supported solver types (CLP, MOSEK, GUROBI, CPLEX).

Parameters
[in]basethe base model.
[in]lsolvertypethe solver type.

◆ FMTLpModel() [2/4]

Models::FMTLpModel::FMTLpModel ( )

Default constructor for FMTLpModel.

◆ FMTLpModel() [3/4]

Models::FMTLpModel::FMTLpModel ( const FMTLpModel rhs)

Constructor for FMTLpModel mainly used in postSolve to pass each attribute of the class.

Copy constructor for FMTLpModel.

Parameters
[in]rhsthe FMTLpModel to copy.

◆ FMTLpModel() [4/4]

Models::FMTLpModel::FMTLpModel ( FMTLpModel &&  rhs)

Default move constructor for FMTLpModel.

Parameters
[in,out]rhsthe model to move from.

◆ ~FMTLpModel()

Models::FMTLpModel::~FMTLpModel ( )
default

Default destructor for FMTLpModel.

Member Function Documentation

◆ addScheduleToObjective()

void Models::FMTLpModel::addScheduleToObjective ( const Core::FMTSchedule schedule,
double  weight = 1000 
)

Add weight to the objective function for a given schedule.

Parameters
[in]schedulethe schedule.
[in]weightthe weight to add.

◆ build()

virtual bool Models::FMTLpModel::build ( std::vector< Core::FMTSchedule schedules = std::vector< Core::FMTSchedule >())
virtual

Build the graph and set the solution if schedules are passed.

If FORCE_PARTIAL_BUILD is true and schedules are passed, only a partial graph is built for the number of periods corresponding to the schedules.

Parameters
[in]schedulesthe schedules.
Returns
true if the build succeeded else false.

Reimplemented from Models::FMTModel.

◆ clearCache()

void Models::FMTLpModel::clearCache ( )
virtual

Remove the cache to release memory.

Reimplemented from Models::FMTModel.

◆ clearConstraintLocation()

void Models::FMTLpModel::clearConstraintLocation ( )

Clear the constraint localisation in the matrix.

This breaks the relation between the FMTModel constraints and the matrix constraints.

◆ clone()

virtual std::unique_ptr< FMTModel > Models::FMTLpModel::clone ( ) const
virtual

Get a clone of the FMTLpModel.

Returns
a unique pointer to the cloned model.

Reimplemented from Models::FMTSrModel.

◆ eraseConstraint()

Graph::FMTGraphStats Models::FMTLpModel::eraseConstraint ( const Core::FMTConstraint constraint,
int  period = -1 
)

Erase a constraint in the matrix and in the model elements.

If period is -1 the constraint is erased for the whole horizon, otherwise only for the specified period.

Parameters
[in]constraintthe constraint.
[in]periodthe period.
Returns
the graph stats.

◆ erasePeriod()

Graph::FMTGraphStats Models::FMTLpModel::erasePeriod ( bool  constraintsonly = false)

Delete the first period (front) of the graph and the matrix, shrinking the planning length to the original size minus one.

Parameters
[in]constraintsonlyif true only erases the constraints.
Returns
the graph stats.

◆ getAreaVariabilities()

std::map< std::string, std::vector< double > > Models::FMTLpModel::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 mask.

Uses the global masks as target; no map key is generated for infeasible variations.

Parameters
[in]localoutputsthe local outputs.
[in]globalmasksthe global masks.
[in]tolerancesthe tolerances.
Returns
a map of output names to value ranges.

◆ getCopy()

virtual std::unique_ptr< FMTModel > Models::FMTLpModel::getCopy ( int  period = 0) const
virtual

Return a copy of the FMTModel for the selected period.

For period 0 returns FMTModel::getCopy; for period greater than 0 returns a copy based on the developments of the FMTGraph. Needs a built graph with a solution.

Parameters
[in]periodthe period.
Returns
the copied model.

Reimplemented from Models::FMTSrModel.

◆ getLocalModel()

FMTLpModel Models::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, based on the model hierarchy.

Needs a built graph with a solution; the returned model is neither solved nor built.

Parameters
[in]localmodelthe local model.
[in]periodthe period.
Returns
the local model.

◆ getModelFromProportions()

FMTLpModel Models::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.

A tolerance greater than 0 increases the area, a tolerance lower than 0 decreases it.

Parameters
[in]globalmasksthe global masks.
[in]tolerancesthe tolerances.
Returns
the new model.

◆ getObjValue()

double Models::FMTLpModel::getObjValue ( ) const

Get the objective value of the solved matrix.

Returns
the objective value.

◆ getOperatingAreaClustererHeuristics()

std::vector< Heuristics::FMTOperatingAreaClusterer > Models::FMTLpModel::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 multiple operating areas.

The FMTLpModel has to be solved so the heuristic can use the value of the output for a given period as a statistic to perform clustering.

Parameters
[in]clustersthe operating area clusters.
[in]statisticoutputthe statistic output.
[in]areaoutputthe area output.
[in]periodthe period.
[in]numberofheuristicsthe number of heuristics.
[in]minimalnumberofclustersthe minimal number of clusters.
[in]maximalnumberofclustersthe maximal number of clusters.
Returns
the operating area clusterer heuristics.

◆ getOperatingAreaSchedulerHeuristics()

std::vector< Heuristics::FMTOperatingAreaScheduler > Models::FMTLpModel::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 MIP formulation on the matrix of the FMTLpModel.

The matrix can be copied within the heuristic or used directly (when numberofheuristics is 1 and copysolver is true).

Parameters
[in]opareasthe operating area schemes.
[in]nodethe output node.
[in]numberofheuristicsthe number of heuristics.
[in]copysolverif true copies the solver.
Returns
the operating area scheduler heuristics.

◆ getOutput()

virtual std::map< std::string, double > Models::FMTLpModel::getOutput ( const Core::FMTOutput output,
int  period,
Core::FMToutputlevel  level = Core::FMToutputlevel::standard 
) const
virtual

Get the output value for a period using the matrix solution.

The map key is the output name when level is standard or totalonly, or the development name when level is developpement; this function can also return the value of a variable output.

Parameters
[in]outputthe output.
[in]periodthe period.
[in]levelthe output level.
Returns
a map of names to values.

Reimplemented from Models::FMTSrModel.

◆ getReplanningConstraints()

virtual std::vector< Core::FMTConstraint > Models::FMTLpModel::getReplanningConstraints ( const std::string &  modeltype,
const std::vector< Core::FMTConstraint > &  localconstraints,
const int &  period 
) const
virtual

Adjust local or global constraints to the global model during replanning, using the solution of this model to adjust the bounds.

Parameters
[in]modeltypethe model type.
[in]localconstraintsthe local constraints.
[in]periodthe period.
Returns
the adjusted constraints.

Reimplemented from Models::FMTModel.

◆ getVariabilities()

std::map< std::string, std::vector< double > > Models::FMTLpModel::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 periodStop.

Must be called after initialSolve; the actual objective function is transformed into a constraint and each output is minimized and maximized to get its range. The map keys are the output name plus UB for the upper bound and LB for the lower bound.

Parameters
[in]outputsthe outputs.
[in]periodStartthe first period.
[in]periodStopthe last period.
Returns
a map of output names to value ranges.

◆ initialSolve()

bool Models::FMTLpModel::initialSolve ( )

Cold start of the LP solve of a simple LP model.

By default calls solverinterface->initialSolve, but based on the FMTSolverInterface it tries to use the best solver parameters for a type III forest planning model; interior point is considered the best algorithm for all solvers.

Returns
true if the initial solve succeeded else false.

◆ operator!=()

bool Models::FMTLpModel::operator!= ( const FMTLpModel rhs) const

Comparison operator for FMTLpModel.

Parameters
[in]rhsthe FMTLpModel to compare to.
Returns
true if both models are different else false.

◆ operator=() [1/2]

FMTLpModel & Models::FMTLpModel::operator= ( const FMTLpModel rhs)

Copy assignment operator for FMTLpModel.

Parameters
[in]rhsthe FMTLpModel to copy.
Returns
a reference to this FMTLpModel.

◆ operator=() [2/2]

FMTLpModel & Models::FMTLpModel::operator= ( FMTLpModel &&  rhs)

Default move assignment for FMTLpModel.

Parameters
[in,out]rhsthe model to move from.
Returns
a reference to this FMTLpModel.

◆ operator==()

bool Models::FMTLpModel::operator== ( const FMTLpModel rhs) const

Comparison operator for FMTLpModel.

Parameters
[in]rhsthe FMTLpModel to compare to.
Returns
true if both models are equal else false.

◆ preSolve()

virtual std::unique_ptr< FMTModel > Models::FMTLpModel::preSolve ( std::vector< Core::FMTActualDevelopment optionaldevelopments = std::vector< Core::FMTActualDevelopment >()) const
virtual

Return a presolved copy of the model using a vector of developments and the actual transitions, reducing the model data if it is badly formulated.

Parameters
[in]optionaldevelopmentsthe optional developments.
Returns
the presolved model.

Reimplemented from Models::FMTSrModel.

◆ resolve()

bool Models::FMTLpModel::resolve ( )

Call solverinterface->resolve when some changes are done to the model, avoiding a full initialSolve.

Returns
true if the resolve succeeded else false.

◆ setConstraint()

Graph::FMTGraphStats Models::FMTLpModel::setConstraint ( const Core::FMTConstraint constraint)

Set a constraint in the matrix for the whole planning horizon (graph length).

If the constraint already exists in the matrix it is not replaced; can be called after buildPeriod in replanning.

Parameters
[in]constraintthe constraint.
Returns
the graph stats.

◆ setObjective()

Graph::FMTGraphStats Models::FMTLpModel::setObjective ( const Core::FMTConstraint objective)

Set the objective of the matrix for the whole planning horizon (graph length).

The objective function is always the first constraint in the constraints vector of a FMTModel; a previously set objective is replaced.

Parameters
[in]objectivethe objective constraint.
Returns
the graph stats.

◆ setStrictlyPositivesOutputsMatrix()

void Models::FMTLpModel::setStrictlyPositivesOutputsMatrix ( )

Set the model parameter STRICTLY_POSITIVE to true.

◆ solve()

virtual bool Models::FMTLpModel::solve ( )
virtual

Call initialSolve on the solver.

Returns
true if the solve succeeded else false.

Reimplemented from Models::FMTModel.

◆ writeLp()

void Models::FMTLpModel::writeLp ( const std::string &  location)

Write the solver interface matrix to a file using the LP formulation.

Parameters
[in]locationthe file location.

◆ writeMps()

void Models::FMTLpModel::writeMps ( const std::string &  location)

Write the solver interface matrix to a file using the MPS formulation.

Parameters
[in]locationthe file location.

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Save and load functions used for serialization to do multiprocessing across multiple cpus (pickle in Python).

Template Parameters
Archivethe archive type.
Parameters
[in,out]arthe archive to serialize to or from.
[in]versionthe serialization version.

The documentation for this class was generated from the following file: