FMT 0.9.8
Forest management tools for forest planning
|
#include <FMTconstraint.hpp>
Public Member Functions | |
FMTconstraint () | |
FMTconstraint (FMTconstrainttype ltype, const FMToutput &loutput) | |
FMTconstraint (const FMTconstraint &rhs) | |
FMTconstraint & | operator= (const FMTconstraint &rhs) |
bool | operator== (const FMTconstraint &rhs) const |
bool | operator!= (const FMTconstraint &rhs) const |
bool | extravariables () const |
bool | isgoal () const |
bool | issetfrom (const std::string &modeltype) const |
bool | isreignore (const int &replanningperiod) const |
bool | dosupportrandom () const |
Core::FMTconstraint | setfrom (const std::string &modeltype, const double &value) const |
double | getscheduleweight () const |
Core::FMTconstraint | getiterationchange (const std::vector< double > &periodchanges, const int &targetperiod) const |
Core::FMTconstraint | getfromreplicate (const size_t &replicate, const int &period) const |
std::vector< std::string > | getpenalties (double &sense) const |
std::vector< std::string > | getvariablelevels () const |
void | getgoal (std::string &name, double &value) const |
void | setgoal (const std::string &goalname, const double &value) |
void | setpenalties (const std::string &penaltyoperator, const std::vector< std::string > &variables) |
bool | isobjective () const |
double | sense () const |
void | getbounds (double &lower, double &upper, int period=0) const |
void | setrhs (double lower, double upper) |
void | setlength (int firstperiod=1, int lastperiod=std::numeric_limits< int >::max()) |
void | getvariations (double &lower, double &upper) const |
bool | ismultiple () const |
bool | acrossperiod () const |
size_t | hash (bool hashrhs=true, bool hashoutputonly=false) const |
size_t | hashasoutput () const |
void | setoutput (const FMToutput &out) |
void | setconstrainttype (FMTconstrainttype ltype) |
FMTconstrainttype | getconstrainttype () const |
operator std::string () const | |
bool | isspatial () const |
bool | israndomaction () const |
size_t | getgroup () const |
size_t | outputempty () const |
FMTconstraint | presolve (const FMTmaskfilter &filter, const std::vector< FMTtheme > &originalthemes, const std::vector< FMTtheme > &selectedthemes, const std::vector< FMTtheme > &newthemes, const std::vector< FMTaction > &actions, const FMTyields &yields) const |
~FMTconstraint ()=default | |
double | evaluate (const std::vector< double > &temporalvalues) const |
std::vector< int > | getactionids (const std::vector< Core::FMTaction > &actions) const |
std::vector< bool > | isactionsused (const std::vector< Core::FMTaction > &actions) const |
bool | canbeturnedtoyieldsbasedontransitions () const |
void | turntoyieldsbasedontransition (const std::vector< Core::FMTtheme > &themes, const std::vector< Core::FMTtransition > &trans, std::vector< Core::FMTaction > &actions, Core::FMTyields &yields, const int &constraintid) const |
bool | canbeturnedtoyields () const |
void | turntoyieldsandactions (const std::vector< Core::FMTtheme > &themes, std::vector< Core::FMTaction > &actions, Core::FMTyields &yields, const int &constraintid) const |
Public Member Functions inherited from Core::FMToutput | |
FMToutput () | |
virtual | ~FMToutput ()=default |
FMToutput (const std::string &lname, const std::string &ldescription, const std::string &lgroup, const std::vector< FMToutputsource > &lsources, const std::vector< FMToperator > &loperators) | |
FMToutput (const std::string &lname) | |
FMToutput (const FMToutput &rhs) | |
FMToutput & | operator= (const FMToutput &rhs) |
bool | operator== (const FMToutput &rhs) const |
bool | operator!= (const FMToutput &rhs) const |
FMToutput & | operator+= (const FMToutput &rhs) |
FMToutput & | operator-= (const FMToutput &rhs) |
FMToutput & | operator*= (const double &rhs) |
FMToutput & | operator/= (const double &rhs) |
operator std::string () const | |
std::string | getname () const |
std::string | getdescription () const |
std::string | getgroup () const |
bool | empty () const |
size_t | size () const |
bool | islinear () const |
bool | canbenodesonly () const |
bool | islevel () const |
bool | isonlylevel () const |
bool | isconstantlevel () const |
bool | isconstant () const |
double | getconstantvalue () const |
bool | containslevel () const |
double | shuntingyard (const std::vector< double > &sourcevalues, const std::vector< FMToperator > &simple_operators) const |
FMToutput | boundto (const std::vector< FMTtheme > &themes, const FMTperbounds &bound, const std::string &specialbound, std::string attribute="") const |
std::vector< FMToutputnode > | getnodes (std::vector< std::string > &equation, double multiplier=1, bool orderbyoutputid=false, int period=1) const |
bool | issingleperiod () const |
bool | hasaverage () const |
int | gettargetperiod () const |
size_t | hash () const |
void | setsources (const std::vector< FMToutputsource > &p_sources) |
set new sources for this output | |
std::vector< FMToutputsource > | getsources () const |
const std::vector< FMToutputsource > & | getsourcesreference () const |
std::vector< FMToperator > | getopes () const |
FMTtheme | targettheme (const std::vector< FMTtheme > &themes) const |
int | targetthemeid () const |
std::vector< std::string > | getthemedecomposition (const FMTtheme &theme) const |
std::vector< std::string > | getdecomposition (const std::vector< FMTtheme > &themes) const |
FMToutput | intersectwithmask (const Core::FMTmask &mask, const std::vector< Core::FMTtheme > &themes) const |
FMTmask | getvariableintersect () const |
std::vector< Core::FMTtheme > | getstaticthemes (const std::vector< Core::FMTtheme > &themes, const Core::FMTyields &yields, bool ignoreoutputvariables=false) const |
FMToutput | presolve (const FMTmaskfilter &filter, const std::vector< FMTtheme > &originalthemes, const std::vector< FMTtheme > &selectedthemes, const std::vector< FMTtheme > &newthemes, const std::vector< FMTaction > &actions, const FMTyields &yields) const |
void | changesourcesid (const std::set< int > &newoutputsorigin, const std::set< int > &newthemeid) |
void | changesourcesid (const int &outid) |
Core::FMToutput | removeRHSvalue () const |
void | getRHSvalue (const int &period, double &lower, double &upper) const |
void | setperiod (const int &newperiod) |
bool | isactionbased () const |
bool | isvariablesizeof (const size_t &masksize) const |
bool | isinventory () const |
void | fillfromshuntingyard (const std::vector< std::string >baseeq, std::map< std::string, double > &results, const std::vector< Core::FMToutputnode > &nodes, std::map< std::string, std::vector< std::string > > &allequations) const |
Public Member Functions inherited from Core::FMTobject | |
FMTobject () | |
virtual | ~FMTobject () |
FMTobject (const std::shared_ptr< Exception::FMTexceptionhandler > exhandler) | |
FMTobject (const FMTobject &rhs) | |
FMTobject & | operator= (const FMTobject &rhs) |
virtual void | passinlogger (const std::shared_ptr< Logging::FMTlogger > &logger) |
void | passinexceptionhandler (const std::shared_ptr< Exception::FMTexceptionhandler > &exhandler) |
void | redirectlogtofile (const std::string &location) |
virtual void | setdefaultlogger () |
virtual void | setquietlogger () |
virtual void | settasklogger () |
virtual void | setdebuglogger () |
void | setdefaultexceptionhandler () |
void | setquietexceptionhandler () |
void | setdebugexceptionhandler () |
void | setfreeexceptionhandler () |
void | disablenestedexceptions () |
void | enablenestedexceptions () |
void | seterrorstowarnings (const std::vector< Exception::FMTexc > &errors) |
void | setmaxwarningsbeforesilenced (const size_t &maxwarningcount) |
Public Member Functions inherited from Core::FMTspec | |
FMTspec () | |
virtual | ~FMTspec ()=default |
FMTspec (const FMTspec &rhs) | |
FMTspec & | operator= (const FMTspec &rhs) |
bool | add (const FMTspec &rhs) |
bool | setbounds (const FMTperbounds &bound) |
bool | addbounds (const FMTagebounds &bound) |
bool | addbounds (const FMTyldbounds &bound) |
bool | addbounds (const FMTlockbounds &bound) |
bool | allowwithoutyield (const int &tperiod, const int &tage, const int &tlock) const |
const FMTyldbounds & | getyieldbound (const std::string &name) const |
bool | allowyields (const std::vector< double > &values) const |
bool | allow (const int &tperiod, const int &tage, const int &tlock, const std::vector< double > &values) const |
const std::vector< std::string > & | getylds () const |
const std::vector< FMTyldbounds > & | getyldbounds () const |
virtual | operator std::string () const |
bool | operator== (const FMTspec &rhs) const |
bool | operator< (const FMTspec &rhs) const |
size_t | hash () const |
bool | empty () const |
bool | emptyage () const |
bool | emptyylds () const |
bool | emptyperiod () const |
bool | emptylock () const |
int | getageupperbound () const |
int | getagelowerbound () const |
int | getperiodupperbound () const |
int | getperiodlowerbound () const |
int | getlockupperbound () const |
int | getlocklowerbound () const |
bool | issubsetof (const FMTspec &rhs) const |
Friends | |
class | boost::serialization::access |
Additional Inherited Members | |
Static Public Member Functions inherited from Core::FMTobject | |
static std::string | getruntimelocation () |
static unsigned long long | getavailablememory () |
Protected Member Functions inherited from Core::FMToutput | |
void | setproportions (std::map< std::string, std::vector< std::string > > &allequations, const std::vector< std::string > &baseequation) const |
bool | isdivision () const |
void | replacedivision (const double &bound) |
Protected Member Functions inherited from Core::FMTobject | |
template<class Archive > | |
void | forcesave (Archive &ar, const unsigned int version) const |
template<class Archive > | |
void | forceload (Archive &ar, const unsigned int version) |
void | checksignals () const |
void | setCPLhandler () |
Static Protected Member Functions inherited from Core::FMTobject | |
static std::chrono::time_point< std::chrono::high_resolution_clock > | getclock () |
template<class chrono > | |
static double | getduration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock) |
static std::string | getdurationinseconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock) |
Protected Attributes inherited from Core::FMToutput | |
std::vector< FMToutputsource > | sources |
outputsources data used to generate outputnodes | |
std::vector< FMToperator > | operators |
vector of simple operators like +-*/ | |
std::string | name |
Sometime output can specify multiple attributes of a given themes. | |
std::string | description |
This is description of the FMToutput has seen in the output section. | |
std::string | group |
This is the group of the output, if empty there's no group. | |
Protected Attributes inherited from Core::FMTspec | |
FMTperbounds | per |
Period bounds so lower >= period <= upper. | |
FMTagebounds | age |
Age bounds so lower >= age <= upper. | |
FMTlockbounds | lock |
Lock bounds so lower >= lock <= upper. | |
std::vector< std::string > | yieldnames |
The names of each yield in the vector of yieldbounds. | |
std::vector< FMTyldbounds > | yieldbounds |
the yields bounds vector lower>=y1<=upper,lower>=y2<=upper | |
Static Protected Attributes inherited from Core::FMTobject | |
static std::shared_ptr< Exception::FMTexceptionhandler > | _exhandler |
A shared pointer to the exception handler. | |
static std::shared_ptr< Logging::FMTlogger > | _logger |
A shared pointer to the logger. | |
FMTconstraint is a representation of a line in the optimize section. an objective is considered a constraint in FMT. So even for the object a FMTconstraint will be generated using a optimization section. A FMTconstraint is also a FMToutput with some specification (FMTspec). The main specification used is the period bounds (1.._LENGTH), RHS and variation (_GOAL).
Core::FMTconstraint::FMTconstraint | ( | ) |
Default constructor for FMTconstraint.
Core::FMTconstraint::FMTconstraint | ( | FMTconstrainttype | ltype, |
const FMToutput & | loutput | ||
) |
Partial constructor for FMTconstraint specifying the output and the constraint type.
Core::FMTconstraint::FMTconstraint | ( | const FMTconstraint & | rhs | ) |
Copy constructor for FMTconstraint.
|
default |
Default destructor for FMTconstraint
bool Core::FMTconstraint::acrossperiod | ( | ) | const |
Returns true if the FMTconstraint needs so be set across multiple periods like _EVEN,_SEQ,_NDY
bool Core::FMTconstraint::canbeturnedtoyields | ( | ) | const |
If the constraint can be turned to a simple action bound using a simple yield this function will returns true.
bool Core::FMTconstraint::canbeturnedtoyieldsbasedontransitions | ( | ) | const |
If the constraint can be turned to a simple action bound using a simple yield by checking the transitions before changing it, this function will returns true.
bool Core::FMTconstraint::dosupportrandom | ( | ) | const |
Return true if the constraint has only one source and only based on action area. So the contraint will support _RANDOM keywod.
double Core::FMTconstraint::evaluate | ( | const std::vector< double > & | temporalvalues | ) | const |
Given a vector of double this function will return a double value representing the quality of the solution. For a real constraint the more the value is close to 0 the better it is. For an objective smaller is better (can be negative).
bool Core::FMTconstraint::extravariables | ( | ) | const |
Returns true if the FMTconstraint need extravariables in the matrix formulation.
std::vector< int > Core::FMTconstraint::getactionids | ( | const std::vector< Core::FMTaction > & | actions | ) | const |
If the constraint is a spatial constraint it will return a vector of action ids to which the constraint apply to.
void Core::FMTconstraint::getbounds | ( | double & | lower, |
double & | upper, | ||
int | period = 0 |
||
) | const |
This function fills up the (lower) and (upper) bound for a given period, if the constraint can be applied to this (period). Use with osisolverinterfacer with rowsetbounds().
FMTconstrainttype Core::FMTconstraint::getconstrainttype | ( | ) | const |
Getter for the constrainttype.
Core::FMTconstraint Core::FMTconstraint::getfromreplicate | ( | const size_t & | replicate, |
const int & | period | ||
) | const |
If the constraint is build with a replicate tables it will gives a new constraint with the corresponding replicate value See keyword _REPLICATE in optimization seciton.
void Core::FMTconstraint::getgoal | ( | std::string & | name, |
double & | value | ||
) | const |
If the constraint has a goal this function fill up the name of the goal and it's weight.
size_t Core::FMTconstraint::getgroup | ( | ) | const |
Returns the group of the constraint (objective = 0,spatial = 1,other = 2 or userdefined)
Core::FMTconstraint Core::FMTconstraint::getiterationchange | ( | const std::vector< double > & | periodchanges, |
const int & | targetperiod | ||
) | const |
Based on constraint period it will set bounds to the double specified in the vector for the constraint period. The target period is only used if the constraint does not have a specific period.
std::vector< std::string > Core::FMTconstraint::getpenalties | ( | double & | sense | ) | const |
If the constraint is goal then you can get the name of the penalties of the constraint. like _GOAL(penaltyname,weight)
double Core::FMTconstraint::getscheduleweight | ( | ) | const |
If you are an objective and are a local model you can have a global schedule weight in the objective function.
std::vector< std::string > Core::FMTconstraint::getvariablelevels | ( | ) | const |
If the constraint is a level this function will return the level name of the constraint.
void Core::FMTconstraint::getvariations | ( | double & | lower, |
double & | upper | ||
) | const |
Get the variation for constraint like _EVEN _SEQ,_NDY etc... _EVEN(lowervariation,uppervariation).
size_t Core::FMTconstraint::hash | ( | bool | hashrhs = true , |
bool | hashoutputonly = false |
||
) | const |
Hasghing for FMTconstraint.
size_t Core::FMTconstraint::hashasoutput | ( | ) | const |
Hasghing for FMToutput.
std::vector< bool > Core::FMTconstraint::isactionsused | ( | const std::vector< Core::FMTaction > & | actions | ) | const |
If the constraint is a spatial constraint it will return a vector of action ids to which the constraint apply to.
bool Core::FMTconstraint::isgoal | ( | ) | const |
Returns true if the constraint have goal weight
bool Core::FMTconstraint::ismultiple | ( | ) | const |
Returns true if the FMTconstraint allow some sort of variability like _EVEN(lowervariation,uppervariation).
bool Core::FMTconstraint::isobjective | ( | ) | const |
Returns true if the constraint is an objective.
bool Core::FMTconstraint::israndomaction | ( | ) | const |
Returns true if spatial constraint
bool Core::FMTconstraint::isreignore | ( | const int & | replanningperiod | ) | const |
Returns true if we need to ignore the constraint from the replanning period
bool Core::FMTconstraint::issetfrom | ( | const std::string & | modeltype | ) | const |
Returns true if the constraint needs to be set from a specific model.
bool Core::FMTconstraint::isspatial | ( | ) | const |
Returns true if spatial constraint
|
virtual |
Get the string reprensentation like in the optimization section of a FMTconstraint.
Reimplemented from Core::FMTspec.
bool Core::FMTconstraint::operator!= | ( | const FMTconstraint & | rhs | ) | const |
FMTconstraint not equality operator check if FMTconstraint are not the same.
FMTconstraint & Core::FMTconstraint::operator= | ( | const FMTconstraint & | rhs | ) |
Copy assignment for FMTconstraint.
bool Core::FMTconstraint::operator== | ( | const FMTconstraint & | rhs | ) | const |
FMTconstraint equality operator check if FMTconstraint are the same.
size_t Core::FMTconstraint::outputempty | ( | ) | const |
Returns true if the FMTconstraint output is empty.
FMTconstraint Core::FMTconstraint::presolve | ( | const FMTmaskfilter & | filter, |
const std::vector< FMTtheme > & | originalthemes, | ||
const std::vector< FMTtheme > & | selectedthemes, | ||
const std::vector< FMTtheme > & | newthemes, | ||
const std::vector< FMTaction > & | actions, | ||
const FMTyields & | yields | ||
) | const |
Like FMToutput class this function presolve the FMTconstraint and can returns an empty FMTconstraint if based on a (basemask), the (originalthemes), the presolved themes, the presolved actions and presolved yields. See FMToutput presolve for more information.
double Core::FMTconstraint::sense | ( | ) | const |
If the constraint is an objective the function returns the sense of the objective, 1 = minimisation, -1 = maximisation.
void Core::FMTconstraint::setconstrainttype | ( | FMTconstrainttype | ltype | ) |
Setter for the FMTconstrainttype of FMTconstraint.
Core::FMTconstraint Core::FMTconstraint::setfrom | ( | const std::string & | modeltype, |
const double & | value | ||
) | const |
Using the value of the global model for the constraint output it will return a new constraints set with the model type value.
void Core::FMTconstraint::setgoal | ( | const std::string & | goalname, |
const double & | value | ||
) |
If the constraint is not an objective set a goal of goalname with a value
void Core::FMTconstraint::setlength | ( | int | firstperiod = 1 , |
int | lastperiod = std::numeric_limits< int >::max() |
||
) |
This functions sets the length of the FMTconstraint
void Core::FMTconstraint::setoutput | ( | const FMToutput & | out | ) |
Setter for the FMToutput of the FMTconstraint.
void Core::FMTconstraint::setpenalties | ( | const std::string & | penaltyoperator, |
const std::vector< std::string > & | variables | ||
) |
If the constraint is an objectif it will set penalties
void Core::FMTconstraint::setrhs | ( | double | lower, |
double | upper | ||
) |
This functions sets the RHS of this FMTconstraint with a row (lower) and (upper) bound.
void Core::FMTconstraint::turntoyieldsandactions | ( | const std::vector< Core::FMTtheme > & | themes, |
std::vector< Core::FMTaction > & | actions, | ||
Core::FMTyields & | yields, | ||
const int & | constraintid | ||
) | const |
This function will generate two yields handler from the constraint 1st: value = 0 for specific mask then the default handler. You need to specify the constraint id to generate a decent yield name. It will modify the actions in the action vectors. Then the yields will be included in the yields section. The constraint can be ignored after this. This will help reduce the size of the matrix.
void Core::FMTconstraint::turntoyieldsbasedontransition | ( | const std::vector< Core::FMTtheme > & | themes, |
const std::vector< Core::FMTtransition > & | trans, | ||
std::vector< Core::FMTaction > & | actions, | ||
Core::FMTyields & | yields, | ||
const int & | constraintid | ||
) | const |
This function check for
|
friend |
serialize function is for serialization, used to do multiprocessing across multiple cpus (pickle in Pyhton)