8#ifndef FMTconstraint_Hm_included
9#define FMTconstraint_Hm_included
15#include "FMTBounds.hpp"
16#include <boost/serialization/serialization.hpp>
17#include <boost/serialization/nvp.hpp>
18#include <boost/serialization/export.hpp>
182 void getGoal(std::string& name,
double& value)
const;
189 void setGoal(
const std::string& goalname,
const double& value);
196 void setPenalties(
const std::string& penaltyoperator,
const std::vector<std::string>& variables);
216 void getBounds(
double& lower,
double& upper,
int period = 0)
const;
230 void setLength(
int firstPeriod = 1,
int lastPeriod = std::numeric_limits<int>::max());
257 size_t hash(
bool hashrhs =
true,
bool hashoutputonly =
false)
const;
287 operator std::string()
const;
325 const std::vector<FMTTheme>& originalthemes,
326 const std::vector<const FMTTheme*>& selectedthemes,
327 const std::vector<FMTTheme>& newthemes,
328 const std::vector<FMTAction>& actions,
329 const std::vector<bool>& p_valideActions,
343 const std::vector<FMTTheme>& p_originalThemes,
344 const std::vector<const FMTTheme*>& p_selectedThemes,
345 const std::vector<FMTTheme>& p_newThemes,
346 const std::vector<FMTAction>& p_actions,
347 const std::vector<bool>& p_valideActions,
361 double evaluate(
const std::vector<double>& temporalvalues)
const;
368 std::vector<int>
getActionIds(
const std::vector<Core::FMTAction>& actions)
const;
375 std::vector<bool>
isActionsused(
const std::vector<Core::FMTAction>& actions)
const;
386 const std::vector<Core::FMTTransition>& p_trans,
387 const std::vector<Core::FMTAction>& p_actions,
388 const std::vector<bool>& p_valideActions)
const;
400 const std::vector<Core::FMTTransition>& trans,
401 std::vector<Core::FMTAction>&actions,
402 const std::vector<bool>& p_valideActions,
404 const int& constraintid)
const;
421 std::vector<Core::FMTAction>&actions,
422 const std::vector<bool>& p_valideActions,
424 const int& constraintid)
const;
446 friend class boost::serialization::access;
447 template<
class Archive>
448 void serialize(Archive& ar,
const unsigned int version)
450 ar& boost::serialization::make_nvp(
"output", boost::serialization::base_object<FMTOutput>(*
this));
451 ar& boost::serialization::make_nvp(
"specification", boost::serialization::base_object<FMTSpec>(*
this));
452 ar& boost::serialization::make_nvp(
"type", m_type);
466 void _standardString(std::string& line, std::string& period_bounds,
467 std::string& goal, std::string& global,
bool asInt =
false)
const;
475 void _getMaxAndMin(
const std::vector<double>& values,
double& min,
double& max)
const;
482 double _getSum(
const std::vector<double>& values)
const;
490 double _getPeriodicVariationCost(
const std::vector<double>& values,
bool evaluateupper =
false)
const;
499 double _getVariability(
const std::vector<double>& values,
const double& var,
const double& lowarvar)
const;
508 bool _getReplicateValue(
size_t p_replicate,
int p_period,
double& p_bound)
const;
515 void _setIterationChange(
double p_bound);
#define FMTEXPORT
Definition: FMTutility.h:125
Representation of a line in the optimize section, an objective being considered a constraint.
Definition: FMTConstraint.h:52
void getGoal(std::string &name, double &value) const
Fill up the name and weight of the goal of the constraint.
FMTconstrainttype getConstraintType() const
Return the type of the constraint.
bool isObjective() const
Return true if the constraint is an objective.
size_t hasHasOutput() const
Return the hash of the output of the constraint.
double sense() const
Return the sense of the objective, 1 for minimisation and -1 for maximisation.
size_t hash(bool hashrhs=true, bool hashoutputonly=false) const
Return the hash of the constraint.
double getScheduleWeight() const
Return the global schedule weight of the objective for a local model.
double getWeight() const
Return the weight of the constraint.
Core::FMTConstraint getFromReplicate(const size_t &replicate, const int &period) const
Return a new constraint with the replicate value, if the constraint is built with a replicate table....
bool isReIgnore(const int &replanningperiod) const
Return true if the constraint must be ignored from the replanning period.
bool canBeTurnedToYieldsBasedOnTransitions(const std::vector< Core::FMTTheme > &p_themes, const std::vector< Core::FMTTransition > &p_trans, const std::vector< Core::FMTAction > &p_actions, const std::vector< bool > &p_valideActions) const
Return true if the constraint can be turned to a simple action bound using a simple yield,...
void setOutput(const FMTOutput &out)
Set the output of the constraint.
bool acrossPeriod() const
Return true if the constraint needs to be set across multiple periods like _EVEN, _SEQ or _NDY.
void setGoal(const std::string &goalname, const double &value)
Set a goal with a name and a value if the constraint is not an objective.
void setPenalties(const std::string &penaltyoperator, const std::vector< std::string > &variables)
Set the penalties if the constraint is an objective.
size_t outputEmpty() const
Return true if the output of the constraint is empty.
FMTConstraint()
Default constructor for FMTConstraint.
void setConstraintType(FMTconstrainttype ltype)
Set the type of the constraint.
std::vector< bool > isActionsused(const std::vector< Core::FMTAction > &actions) const
Return a vector of booleans, true for the actions to which the spatial constraint applies.
FMTConstraint(FMTconstrainttype ltype, const FMTOutput &loutput)
Partial constructor specifying the output and the constraint type.
bool isMultiple() const
Return true if the constraint allows some variability like _EVEN.
bool isSpatial() const
Return true if the constraint is a spatial constraint.
std::vector< std::string > getPenalties(double &sense) const
Return the names of the penalties of the constraint if it is a goal, like _GOAL(penaltyname,...
bool gotReplicate(const int &p_period) const
Check if the constraint contains a replicate.
bool isSetFrom(const std::string &modeltype) const
Return true if the constraint needs to be set from a specific model.
FMTConstraint preSolve(const FMTMaskFilter &filter, const std::vector< FMTTheme > &originalthemes, const std::vector< const FMTTheme * > &selectedthemes, const std::vector< FMTTheme > &newthemes, const std::vector< FMTAction > &actions, const std::vector< bool > &p_valideActions, const FMTYields &yields) const
Presolve the constraint, potentially returning an empty constraint. See FMTOutput::preSolve.
bool doSupportRandom() const
Return true if the constraint has only one source based on action area and supports the _RANDOM keywo...
std::vector< int > getActionIds(const std::vector< Core::FMTAction > &actions) const
Return the action ids to which the spatial constraint applies.
FMTConstraint(const FMTConstraint &rhs)
Copy constructor for FMTConstraint.
void preSolveRef(const FMTMaskFilter &p_filter, const std::vector< FMTTheme > &p_originalThemes, const std::vector< const FMTTheme * > &p_selectedThemes, const std::vector< FMTTheme > &p_newThemes, const std::vector< FMTAction > &p_actions, const std::vector< bool > &p_valideActions, const FMTYields &p_yields)
Presolve the constraint in place. See FMTOutput::preSolve.
void getVariations(double &lower, double &upper) const
Get the variation for constraints like _EVEN, _SEQ or _NDY.
bool isGoal() const
Return true if the constraint has a goal weight.
std::vector< std::string > getVariableLevels() const
Return the level names of the constraint if it is a level.
void setRhs(double lower, double upper)
Set the RHS of the constraint with a lower and upper bound.
Core::FMTConstraint setFrom(const std::string &modeltype, const double &value) const
Return a new constraint set with the value of the given model type.
void turnToYieldsBasedOnTransition(const std::vector< Core::FMTTheme > &themes, const std::vector< Core::FMTTransition > &trans, std::vector< Core::FMTAction > &actions, const std::vector< bool > &p_valideActions, Core::FMTYields &yields, const int &constraintid) const
Turn the constraint to yields and actions based on the transitions.
bool isRandomAction() const
Return true if the constraint is a random action constraint.
~FMTConstraint()=default
Default destructor for FMTConstraint.
void turnToYieldsAndActions(const std::vector< Core::FMTTheme > &themes, std::vector< Core::FMTAction > &actions, const std::vector< bool > &p_valideActions, Core::FMTYields &yields, const int &constraintid) const
Generate two yield handlers from the constraint and include them in the yields, modifying the actions...
void getBounds(double &lower, double &upper, int period=0) const
Fill up the lower and upper bound for a given period if the constraint applies to it.
void setLength(int firstPeriod=1, int lastPeriod=std::numeric_limits< int >::max())
Set the length of the constraint.
void setFromReplicate(size_t p_replicate, int p_period)
If the constraint is build with a replicate tables it will gives a new constraint with the correspond...
double evaluate(const std::vector< double > &temporalvalues) const
Return a value representing the quality of the solution for the constraint.
bool extraVariables() const
Return true if the constraint needs extra variables in the matrix formulation.
bool canBeTurnedToYields() const
Return true if the constraint can be turned to a simple action bound using a simple yield.
int getThemeTarget() const
Return the theme target of the constraint.
size_t getGroup() const
Return the group of the constraint (objective = 0, spatial = 1, other = 2 or user defined).
Filter built from masks used to preSolve and postsolve FMTMask objects.
Definition: FMTMaskFilter.h:31
Class letting the user formulate a constraint in the optimize section or collect data across the grap...
Definition: FMTOutput.h:37
FMTList containing multiple yield handlers as seen in the yield section, holding the information rela...
Definition: FMTYields.h:44
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
FMTconstrainttype
Enumerator of the constraint and objective types found in an optimization section,...
Definition: FMTConstraint.h:31
@ FMTsequence
Definition: FMTConstraint.h:38
@ FMTspatialadjacency
Definition: FMTConstraint.h:41
@ FMTrandomaction
Definition: FMTConstraint.h:44
@ FMTstandard
Definition: FMTConstraint.h:39
@ FMTMINMAXobjective
Definition: FMTConstraint.h:35
@ FMTSpatialGroup
Definition: FMTConstraint.h:43
@ FMTnondeclining
Definition: FMTConstraint.h:37
@ FMTMAXMINobjective
Definition: FMTConstraint.h:34
@ FMTspatialsize
Regular constraint m_type like output = 1...
Definition: FMTConstraint.h:40
@ FMTMAXobjective
Definition: FMTConstraint.h:32
@ FMTMINobjective
Definition: FMTConstraint.h:33
@ FMTevenflow
Definition: FMTConstraint.h:36
@ FMTspatialgreenup
Definition: FMTConstraint.h:42