FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTModel.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Qu�bec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTMODEL_Hm_included
9#define FMTMODEL_Hm_included
10
11#include "FMTTheme.h"
12#include "FMTAction.h"
13#include "FMTTransition.h"
14#include "FMTYields.h"
15#include "FMTLifespans.h"
17#include "FMTOutput.h"
18#include "FMTConstraint.h"
19#include "FMTList.hpp"
20#include "FMTModelParameters.h"
21#include <boost/serialization/vector.hpp>
22#include <boost/serialization/map.hpp>
23#include <boost/serialization/unordered_map.hpp>
24#include <boost/serialization/export.hpp>
25#include "FMTOutputNode.h"
26#include "FMTSchedule.h"
27#include <random>
28
29
30namespace Graph
31{
32 template<class T1, class T2>
33 class FMTGraph;
34 class FMTLineGraph;
35 class FMTGraphVertexToYield;
36}
37
38namespace Parser
39{
40 class FMTModelParser;
41}
42
43namespace Spatial
44{
45 class FMTSpatialSchedule;
46 class FMTSpatialNodesCache;
47 class FMTSpatialGraphs;
48}
50namespace Models
51{
52 class FMTModelStats;
53 // DocString: FMTModel
62 {
63 template<class T1,class T2>
64 friend class Graph::FMTGraph;
65 friend class Graph::FMTLineGraph;
67 friend class Spatial::FMTSpatialNodesCache;
71 public:
72 // DocString: FMTModel::getYieldValue
81 double getYieldValue(const std::string& p_mask, const std::string& p_yield, int p_age, int p_period) const;
82 // DocString: FMTModel::setReplicate
88 void setReplicate(size_t p_replicate,int p_ReplanningPeriod);
89 // DocString: FMTModel::gotReIgnore
95 bool gotReIgnore(const int& p_replanningPeriod) const;
96 // DocString: FMTModel::gotReplicate
102 bool gotReplicate(const int& p_replanningPeriod) const;
103 // DocString: FMTModel::buildAction
110 FMTModel buildAction(const std::string& p_actionName,
111 const std::string& p_Targetyield) const;
112 // DocString: FMTModel::buildSchedule
121 std::vector<Core::FMTSchedule> buildSchedule(const Core::FMTAction& p_action,
122 const FMTModel& p_BaseModel,
123 const std::string& p_Targetyield,
124 const std::vector<Core::FMTSchedule>& p_schedules) const;
125
126 // DocString: FMTModel::pushTheme
133 void pushTheme(const std::string& p_themeName,
134 const std::string& p_yieldName,
135 const std::vector<std::string>& p_attributes);
136 // DocString: FMTModel::aggregateAllActions
143 Models::FMTModel aggregateAllActions(const std::vector<std::string>& p_Aggregates,
144 std::vector<std::string> p_ActionOrdering) const;
145 // DocString: FMTModel::splitActions
152 Models::FMTModel splitActions(const std::vector<std::string>& p_Actions,
153 const std::vector<std::string>& p_masks) const;
154 // DocString: FMTSchedule::getPriorities
160 std::vector<std::string>getSchedulesPriorities(const std::vector<Core::FMTSchedule>& p_schedules) const;
161 // DocString: FMTModel::aggregateSchedules
167 std::vector<Core::FMTSchedule> aggregateSchedules(const std::vector<Core::FMTSchedule>& p_schedules) const;
168 // DocString: FMTModel::splitSchedules
174 std::vector<Core::FMTSchedule> splitSchedules(const std::vector<Core::FMTSchedule>& p_schedules) const;
175 // DocString: FMTModel::setParallelLogger
181 // DocString: FMTModel::clearCache
185 virtual void clearCache();
186 // DocString: FMTModel(const std::vector<Core::FMTActualDevelopment>& larea, const std::vector<Core::FMTTheme>, const std::vector<Core::FMTAction>, const std::vector<Core::FMTTransition>, const Core::FMTYields, const Core::FMTLifespans, const std::string, const std::vector<Core::FMTOutput>, std::vector<Core::FMTConstraint>,FMTModelParameters)
200 FMTModel(const std::vector<Core::FMTActualDevelopment>& larea, const std::vector<Core::FMTTheme>& lthemes,
201 const std::vector<Core::FMTAction>& lactions,
202 const std::vector<Core::FMTTransition>& ltransitions, const Core::FMTYields& lyields, const Core::FMTLifespans& llifespan,
203 const std::string& lname, const std::vector<Core::FMTOutput>& loutputs, std::vector<Core::FMTConstraint> lconstraints = std::vector<Core::FMTConstraint>(),
204 FMTModelParameters lparameters = FMTModelParameters());
205 // DocString: FMTModel()
210 // DocString: ~FMTModel
214 virtual ~FMTModel() = default;
215 // DocString: FMTModel(FMTModel&&)
221 // DocString: FMTModel::operator=(FMTModel&&)
227 FMTModel& operator =(FMTModel&& rhs);
228 // DocString: FMTModel::getArea
235 virtual std::vector<Core::FMTActualDevelopment>getArea(int period = 0, bool beforegrowanddeath = false) const;
236 // DocString: FMTModel::getCopy
242 virtual std::unique_ptr<FMTModel> getCopy(int period = 0) const;
243 // DocString: FMTModel::basePreSolve
250 // DocString: FMTModel::getPreSolveFilter
256 Core::FMTMaskFilter getPreSolveFilter(const std::vector<Core::FMTTheme>& originalthemes) const;
257 // DocString: FMTModel::getPostSolveFilter
264 Core::FMTMaskFilter getPostSolveFilter(const std::vector<Core::FMTTheme>& originalthemes, const Core::FMTMask& devmask) const;
265 // DocString: FMTModel::getSelectedMask
271 Core::FMTMask getSelectedMask(const std::vector<Core::FMTTheme>& originalthemes) const;
272 // DocString: FMTModel::preSolve
279 virtual std::unique_ptr<FMTModel>preSolve(std::vector<Core::FMTActualDevelopment> optionaldevelopments = std::vector<Core::FMTActualDevelopment>()) const;
280 // DocString: FMTModel::postSolve
285 virtual void postSolve(const FMTModel& originalbasemodel);
286 // DocString: FMTModel::preSolveSchedule
294 const FMTModel& originalbasemodel) const;
295 // DocString: FMTModel::getModelStats
301 // DocString: FMTModel::cleanActionsNTransitions
306 // DocString: FMTModel::getName
311 inline std::string getName() const
312 {
313 return name;
314 }
315 // DocString: FMTModel::getThemes
320 inline std::vector<Core::FMTTheme>getThemes() const
321 {
322 return themes;
323 }
324 // DocString: FMTModel::getActions
329 inline std::vector<Core::FMTAction>getActions() const
330 {
331 return actions;
332 }
333 // DocString: FMTModel::getTransitions
338 inline std::vector<Core::FMTTransition>getTransitions() const
339 {
340 return transitions;
341 }
342 // DocString: FMTModel::getYields
348 {
349 return yields;
350 }
351 // DocString: FMTModel::getLifespan
357 {
358 return lifespan;
359 }
360 // DocString: FMTModel::getOutputs
365 inline std::vector<Core::FMTOutput> getOutputs() const
366 {
367 return outputs;
368 }
369 // DocString: FMTModel::getConstraints
374 inline std::vector<Core::FMTConstraint>getConstraints() const
375 {
376 return constraints;
377 }
378 // DocString: FMTModel::defaultDeathAction
386 const std::vector<Core::FMTTheme>& lthemes);
387 // DocString: FMTModel::defaultDeathTransition
395 const std::vector<Core::FMTTheme>& lthemes);
396 // DocString: FMTModel::addOutput
407 void addOutput(const std::string& name, const std::string& maskstring, Core::FMTotar outputtarget,
408 std::string action = std::string(), std::string yield = std::string(), std::string description = std::string(), int targetTheme = -1);
409 // DocString: FMTModel::addYieldHandlers
416 template<typename T>
417 void addYieldHandlers(const std::vector<T>& yieldhandlers)
418 {
419 try {
420 yields.unShrink(themes);
421 for (const auto& yldhandler : yieldhandlers)
422 {
423 std::unique_ptr<Core::FMTYieldHandler> yldhandlerptr = yldhandler.clone();
424 yields.push_back(yldhandlerptr->getMask(), yldhandlerptr);
425 }
426 yields.update();
427 }
428 catch (...) {
429 _exhandler->printExceptions("", "FMTModel:::addyieldhandlers", __LINE__, __FILE__);
430 }
431 }
432 // DocString: FMTModel::addYieldHandlersFromPtr
437 void addYieldHandlersFromPtr(const std::vector<std::unique_ptr<Core::FMTYieldHandler>>& yieldhandlers);
438 // DocString: FMTModel::operator==
444 bool operator == (const FMTModel& rhs) const;
445 // DocString: FMTModel::operator<
451 bool operator < (const FMTModel& rhs) const;
452 // DocString: FMTModel::setArea
458 void setArea(const std::vector<Core::FMTActualDevelopment>& ldevs);
459 // DocString: FMTModel::setThemes
464 void setThemes(const std::vector<Core::FMTTheme>& lthemes);
465 // DocString: FMTModel::setActions
470 void setActions(const std::vector<Core::FMTAction>& lactions);
471 // DocString: FMTModel::setTransitions
476 void setTransitions(const std::vector<Core::FMTTransition>& ltransitions);
477 // DocString: FMTModel::setConstraints
482 void setConstraints(const std::vector<Core::FMTConstraint>& lconstraint);
483 // DocString: FMTModel::setYields
488 void setYields(const Core::FMTYields& lylds);
489 // DocString: FMTModel::setLifespan
494 void setLifespan(const Core::FMTLifespans& llifespan);
495 // DocString: FMTModel::setName
500 void setName(const std::string& newname);
501 // DocString: FMTModel::setOutputs
506 void setOutputs(const std::vector<Core::FMTOutput>& newoutputs);
507 // DocString: FMTModel::isValid
512 bool isValid();
513 // DocString: FMTModel::locateStaticThemes(const Core::FMTOutput, bool ignoreoutputvariables)
520 std::vector<const Core::FMTTheme*> locateStaticThemes(const Core::FMTOutput& output, bool ignoreoutputvariables = false) const;
521 // DocString: FMTModel::locateStaticThemes(const Core::FMTOutputNode, bool ignoreoutputvariables)
528 std::vector<const Core::FMTTheme*> locateStaticThemes(const Core::FMTOutputNode& output, bool ignoreoutputvariables = false) const;
529 // DocString: FMTModel::locateDynamicThemes
536 std::vector<const Core::FMTTheme*> locateDynamicThemes(const Core::FMTOutput& outpu, bool ignoreoutputvariables = false) const;
537 // DocString: FMTModel::getDynamicMask(const Core::FMTOutput, bool ignoreoutputvariables)
544 Core::FMTMask getDynamicMask(const Core::FMTOutput& output, bool ignoreoutputvariables = false) const;
545 // DocString: FMTModel::getDynamicMask(const Core::FMTOutputNode, bool ignoreoutputvariables)
552 Core::FMTMask getDynamicMask(const Core::FMTOutputNode& node, bool ignoreoutputvariables = false) const;
553 // DocString: FMTModel::getStaticMask
560 virtual Core::FMTMask getStaticMask(const Core::FMTOutputNode& node, bool ignoreoutputvariables = false) const;
561 // DocString: FMTModel::isStaticNode
569 bool isStaticNode(const Core::FMTOutputNode& node, double ratioofset = 0.1) const;
570 // DocString: FMTModel::locateStaticTransitionsThemes
575 std::vector<const Core::FMTTheme*>locateStaticTransitionsThemes() const;
576 // DocString: FMTModel::locatenotestaticthemes
584 std::vector<const Core::FMTTheme*>locateNodeStaticThemes(const Core::FMTOutputNode& node,
585 bool ignoreoutputvariables = false,
586 std::vector<const Core::FMTTheme*> basethemes = std::vector<const Core::FMTTheme*>()) const;
587 // DocString: FMTModel(FMTModel)
592 FMTModel(const FMTModel& rhs);
593 // DocString: FMTModel::operator=
599 FMTModel& operator = (const FMTModel& rhs);
600 // DocString: FMTModel::empty
605 bool empty() const;
606 // DocString: FMTModel::append
611 void push_back(const FMTModel& rhs);
612 // DocString: FMTModel::getInitialArea
617 double getInitialArea() const;
618 // DocString: FMTModel::setAreaPeriod
623 void setAreaPeriod(const int& period);
624 // DocString: FMTModel::getAreaPeriod
629 int getAreaPeriod() const;
630 // DocString: FMTModel::getPotentialSchedule
638 Core::FMTSchedule getPotentialSchedule(std::vector<Core::FMTActualDevelopment> toRemove,
639 std::vector<Core::FMTActualDevelopment> selection, bool withlock = true) const;
640 // DocString: FMTModel::getReplanningConstraints
648 virtual std::vector<Core::FMTConstraint> getReplanningConstraints(const std::string& modeltype, const std::vector<Core::FMTConstraint>& localconstraints, const int& period) const;
649 // DocString: FMTModel::doPlanning
656 virtual bool doPlanning(const bool& solve, std::vector<Core::FMTSchedule> schedules = std::vector<Core::FMTSchedule>());
657 // DocString: FMTModel::getOutput
666 virtual std::map<std::string, double> getOutput(const Core::FMTOutput& output,
667 int period, Core::FMToutputlevel level = Core::FMToutputlevel::standard) const;
668 // DocString: FMTModel::getSolution
675 virtual Core::FMTSchedule getSolution(int period, bool withlock = false) const;
676 // DocString: FMTModel::getOutputsFromPeriods
685 virtual std::map<std::string, std::vector<std::vector<double>>>getOutputsFromPeriods(const std::vector<Core::FMTOutput>& theoutputs,
686 const int& firstPeriod, const int& lastPeriod, Core::FMToutputlevel level = Core::FMToutputlevel::standard) const;
687 // DocString: FMTModel::clone
692 virtual std::unique_ptr<FMTModel>clone() const;
693 // DocString: FMTModel::setParameter(const FMTintmodelparameters,const int&)
694 // DocString: FMTNssModel::setParameter
701 virtual bool setParameter(const FMTintmodelparameters& p_key, const int& p_value);
702 // DocString: FMTModel::setParameter(const FMTdblmodelparameters,const double)
709 virtual bool setParameter(const FMTdblmodelparameters& key, const double& value);
710 // DocString: FMTModel::setParameter(const FMTboolmodelparameters,const bool)
717 virtual bool setParameter(const FMTboolmodelparameters& key, const bool& value);
718 // DocString: FMTModel::setParameter(const FMTboolstrparameters,const std::string)
725 virtual bool setParameter(const FMTstrmodelparameters& p_key, const std::string& p_value);
726 // DocString: FMTModel::getParameter(const FMTintmodelparameters)
732 int getParameter(const FMTintmodelparameters& key) const;
733 // DocString: FMTModel::getParameter(const FMTdblmodelparameters)
739 double getParameter(const FMTdblmodelparameters& key) const;
740 // DocString: FMTModel::getParameter(const FMTboolmodelparameters)
746 bool getParameter(const FMTboolmodelparameters& key) const;
747 // DocString: FMTModel::getParameter(const FMTstrmodelparameters)
753 const std::string& getParameter(const FMTstrmodelparameters& p_key) const;
754 // DocString: FMTModel::setCompressTime
762 bool setCompressTime(const int& periodStart, const int& periodStop, const int& value);
763 // DocString: FMTModel::getCompressTime
768 std::vector<int> getCompressTime() const;
769 // DocString: FMTModel::goalConstraints
775 std::vector<Core::FMTConstraint>goalConstraints(double penalty = 999999) const;
776 // DocString: FMTModel::getTacticalConstraints
785 std::vector<Core::FMTConstraint>getTacticalConstraints(double penalty = 999999, double scheduleweight = 999999, double objective = 0, double objectivefactor = 1.0) const;
786 // DocString: FMTModel::showParameters
791 virtual void showParameters(const bool& showhelp = false)const;
792 // DocString: FMTModel::build
798 virtual bool build(std::vector<Core::FMTSchedule> schedules = std::vector<Core::FMTSchedule>())
799 {
800 //Mettre message warning
801 return false;
802 }
803 // DocString: FMTModel::solve
808 virtual bool solve()//Only for optimisation
809 {
810 //Mettre message warning
811 return false;
812 }
813 // DocString: FMTModel::isOptimal
818 virtual bool isOptimal() const;
819 // DocString: FMTModel::getObjectiveValue
824 virtual double getObjectiveValue() const;
825 // DocString: FMTModel::getGeneratorPtr
830 std::default_random_engine* getGeneratorPtr() const;
831 // DocString: FMTModel::getStaticTransitionThemes
836 std::vector<size_t>getStaticTransitionThemes() const;
837 // DocString: FMTModel::SupportsMultiThreading
842 virtual bool SupportsMultiThreading() const;
843 protected:
844 // DocString: FMTModel::m_generator
846 mutable std::default_random_engine m_generator;
847 // DocString: FMTModel::parameters
851 // DocString: FMTModel::area
853 std::vector<Core::FMTActualDevelopment>area;
854 // DocString: FMTModel::themes
856 std::vector<Core::FMTTheme>themes;
857 // DocString: FMTModel::actions
859 std::vector<Core::FMTAction>actions;
860 // DocString: FMTModel::transitions
862 std::vector<Core::FMTTransition>transitions;
863 // DocString: FMTModel::yields
866 // DocString: FMTModel::lifespan
869 // DocString: FMTModel::outputs
871 std::vector<Core::FMTOutput> outputs;
872 // DocString: FMTModel::constraints
874 std::vector<Core::FMTConstraint>constraints;
875 // DocString: FMTModel::name
877 std::string name;
878 // DocString: FMTModel::statictransitionthemes
880 std::vector<size_t>statictransitionthemes;
881 // DocString: FMTModel::setSeed
886 void setSeed(const int& p_seed);
887 // DocString: FMTModel::setDefaultObjects
892 // DocString: FMTModel::getBaseMask
898 Core::FMTMask getBaseMask(std::vector<Core::FMTActualDevelopment> optionaldevelopments) const;
899
900 // DocString: FMTModel::getStaticPreSolveThemes
905 std::vector<const Core::FMTTheme*>getStaticPreSolveThemes() const;
906 // DocString: FMTModel::clearActionsCache
911 // DocString: FMTModel::clearYieldCache
916 // DocString: FMTModel::clearTransitionCache
921 // DocString: FMTModel::swapPtr
926 virtual void swapPtr(std::unique_ptr<FMTModel>& rhs);
927 // DocString: FMTModel::setUpSchedulesForBuild
933 std::vector<Core::FMTSchedule>setUpSchedulesForBuild(const std::vector<Core::FMTSchedule>& schedules) const;
934 // DocString: FMTModel::useActionSerie
939 bool useActionSerie() const;
940 // DocString: FMTModel::getSeriesMaxSize
945 size_t getSeriesMaxSize() const;
946
947 private:
948 // DocString: FMTModel::save
955 friend class boost::serialization::access;
956 template<class Archive>
957 void save(Archive& ar, const unsigned int version) const
958 {
959 ar& boost::serialization::make_nvp("FMTobject", boost::serialization::base_object<FMTObject>(*this));
960 FMTObject::forceSave(ar, version);
961 std::stringstream basegenerator;
962 basegenerator << m_generator;
963 const std::string baseGeneratorString(basegenerator.str());
964 ar& BOOST_SERIALIZATION_NVP(baseGeneratorString);
965 ar& BOOST_SERIALIZATION_NVP(parameters);
966 ar& BOOST_SERIALIZATION_NVP(area);
967 ar& BOOST_SERIALIZATION_NVP(themes);
968 ar& BOOST_SERIALIZATION_NVP(actions);
969 ar& BOOST_SERIALIZATION_NVP(transitions);
970 ar& BOOST_SERIALIZATION_NVP(yields);
971 ar& BOOST_SERIALIZATION_NVP(lifespan);
972 ar& BOOST_SERIALIZATION_NVP(outputs);
973 ar& BOOST_SERIALIZATION_NVP(constraints);
974 ar& BOOST_SERIALIZATION_NVP(name);
975 }
976 // DocString: FMTModel::load
983 template<class Archive>
984 void load(Archive& ar, const unsigned int version)
985 {
986 ar& boost::serialization::make_nvp("FMTobject", boost::serialization::base_object<FMTObject>(*this));
987 FMTObject::forceLoad(ar, version);//get the object information for the global object
988 std::string baseGeneratorString;
989 ar& BOOST_SERIALIZATION_NVP(baseGeneratorString);
990 std::stringstream(baseGeneratorString) >> m_generator;
991 ar& BOOST_SERIALIZATION_NVP(parameters);
992 ar& BOOST_SERIALIZATION_NVP(area);
993 ar& BOOST_SERIALIZATION_NVP(themes);
994 ar& BOOST_SERIALIZATION_NVP(actions);
995 ar& BOOST_SERIALIZATION_NVP(transitions);
996 ar& BOOST_SERIALIZATION_NVP(yields);
997 ar& BOOST_SERIALIZATION_NVP(lifespan);
998 ar& BOOST_SERIALIZATION_NVP(outputs);
999 ar& BOOST_SERIALIZATION_NVP(constraints);
1000 ar& BOOST_SERIALIZATION_NVP(name);
1001 //this->passinobject(*this);//Distribute global object to local object
1002 }
1003 BOOST_SERIALIZATION_SPLIT_MEMBER()
1004 // DocString: FMTModel::validateListMasks
1011 template<class T>
1012 void validateListMasks(const Core::FMTList<T>& container) const
1013 {
1014 try {
1015 for (const auto& listobject : container)
1016 {
1017 std::string name = std::string(listobject.first);
1018 Core::FMTTheme::validate(themes, name);
1019 }
1020 }
1021 catch (...)
1022 {
1023 _exhandler->raiseFromCatch("", "FMTModel::validateListMasks", __LINE__, __FILE__);
1024 }
1025 }
1026 // DocString: FMTModel::validateListSpec
1032 void validateListSpec(const Core::FMTSpec& specifier) const;
1033 // DocString: FMTModel::aggregateActions
1039 std::map<std::string, std::pair<std::string,Core::FMTMask>> aggregateActions(std::vector<std::string> p_ActionsMapping);
1040 // DocString: FMTModel::aggregateTransitions
1045 void aggregateTransitions(const std::map<std::string, std::pair<std::string, Core::FMTMask>>& p_Filters);
1046 // DocString: FMTModel::aggregateOutputs
1053 void aggregateOutputs(const std::map<std::string, std::pair<std::string, Core::FMTMask>>& p_Filters,
1054 std::vector<Core::FMTOutput*>& p_Outputs, const std::vector<std::string>& p_ActionOrdering);
1055 // DocString: FMTModel::addNewMask
1061 Core::FMTMask addNewMask(const Core::FMTMask& p_incompleteMask);
1062 // DocString: FMTModel::extendSchedule
1068 std::vector<Core::FMTSchedule> extendSchedule(const std::vector<Core::FMTSchedule>& p_schedules) const;
1069 // DocString: FMTModel::_gutsOfConstructor
1074 void _gutsOfConstructor(const std::vector<Core::FMTActualDevelopment>& p_area);
1075 // DocString: FMTModel::_cleanVector
1082 template<class T>
1083 static void _cleanVector(std::vector<T>& p_toClean, const std::vector<bool>& p_whichtoKeep)
1084 {
1085 size_t Id = p_toClean.size();
1086 while (Id != 0)
1087 {
1088 --Id;
1089 if (!p_whichtoKeep[Id])
1090 {
1091 p_toClean.erase(p_toClean.begin() + Id);
1092 }
1093 }
1094 }
1095 // DocString: FMTModel::_getYieldsStraticAggregates
1101 std::set<std::string>_getYieldsStraticAggregates(const std::string& p_yieldName) const;
1102 // DocString: FMTModel::_getAggregatesWrap
1109 std::string _getAggregatesWrap(const Core::FMTMask& p_mask,
1110 const std::vector<size_t>& p_themes) const;
1111 // DocString: FMTModel::_getAggregatesThemes
1117 std::vector<size_t> _getAggregatesThemes(const std::string& p_yieldName) const;
1118 // DocString: FMTModel::_getYieldAttribute
1126 std::string _getYieldAttribute(const Core::FMTMask& p_devMask,
1127 const std::string& p_yieldName, const std::vector<size_t>& p_AggregatedThemes) const;
1128 };
1129// DocString: FMTModelComparator
1134{
1135public:
1136 // DocString: FMTModelComparator(std::string)
1141 FMTModelComparator(std::string p_name);
1142 // DocString: FMTModelComparator::operator()
1148 bool operator()(const FMTModel& model) const;
1149
1150private:
1151 // DocString: FMTModelComparator::m_modelName
1153 std::string m_modelName;
1154};
1155
1156}
1157
1158BOOST_CLASS_EXPORT_KEY(Models::FMTModel)
1159
1160#endif // FMTMODEL_Hm_included
#define FMTEXPORT
Definition: FMTutility.h:125
List of specifications dictating the operability of a subset of developments to this action.
Definition: FMTAction.h:43
List holding the maximum age of aggregates of developments.
Definition: FMTLifespans.h:23
Filter built from masks used to preSolve and postsolve FMTMask objects.
Definition: FMTMaskFilter.h:31
Core class holding, as a boost dynamic bitset, which theme attributes are part of a mask.
Definition: FMTMask.h:96
Base class of multiple FMT classes holding a shared exception handler pointer and logger.
Definition: FMTObject.h:49
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
static bool validate(const std::vector< Core::FMTTheme > &p_themes, std::string &p_mask, std::string p_otherinformation=std::string())
Validate the construction of a valid mask string based on the themes, trimming the mask if there are ...
List of FMTFork describing the transition of an action, disturbing a development to generate new deve...
Definition: FMTTransition.h:35
FMTList containing multiple yield handlers as seen in the yield section, holding the information rela...
Definition: FMTYields.h:44
Adapter pointing to a vertex of a line graph or a full graph and its model, used to answer a generic ...
Definition: FMTGraphVertexToYield.h:31
Definition: FMTGraphVertexToYield.h:20
Simple graph where each action generates a single new vertex (0-—0-—0-—0), used with FMTLayer to simu...
Definition: FMTLineGraph.h:27
Base class handling the level of information printed by FMT.
Definition: FMTLogger.h:37
Comparator used to compare FMTModel with std::find_if when models are in a stl container.
Definition: FMTModel.h:1134
FMTModelComparator(std::string p_name)
Constructor of the comparator.
bool operator()(const FMTModel &model) const
Return true if the given model matches the name held by the comparator.
Class containing all the parameters a model needs to be solved by the different types of FMTModel.
Definition: FMTModelParameters.h:97
Class reporting the statistics of a FMTModel, used with the preSolve and postsolve functions.
Definition: FMTModelStats.h:24
Base class for the different models in FMT.
Definition: FMTModel.h:62
virtual bool setParameter(const FMTboolmodelparameters &key, const bool &value)
Setter for bool model parameters. See FMTModelParameters.h.
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.
Definition: FMTModel.h:798
virtual Core::FMTSchedule getSolution(int period, bool withlock=false) const
Get the standard solution for a given period, without the natural growth solution.
FMTModelParameters parameters
Definition: FMTModel.h:850
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.
std::string name
The name of the Model (name of the .pri file without extension)
Definition: FMTModel.h:877
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.
std::vector< Core::FMTTheme > themes
Model themes of the landscape section file.
Definition: FMTModel.h:856
std::vector< const Core::FMTTheme * > locateDynamicThemes(const Core::FMTOutput &outpu, bool ignoreoutputvariables=false) const
Return the themes used in the transition scheme.
std::vector< const Core::FMTTheme * > getStaticPreSolveThemes() const
Return the themes that are not part of the model, using the transition themes, constraints,...
Core::FMTMask getSelectedMask(const std::vector< Core::FMTTheme > &originalthemes) const
Get the selection mask needed to preSolve a FMTMask when the model is presolved.
FMTModel basePreSolve() const
Presolve the model using the existing area.
Core::FMTYields yields
Yields data comming from the yield file.
Definition: FMTModel.h:865
std::vector< std::string > getSchedulesPriorities(const std::vector< Core::FMTSchedule > &p_schedules) const
Return the action names in priority of area scheduled.
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.
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.
std::vector< size_t > statictransitionthemes
The location of the themes static from transitions.
Definition: FMTModel.h:880
std::vector< Core::FMTOutput > getOutputs() const
Return a copy of the outputs of the model.
Definition: FMTModel.h:365
void addYieldHandlersFromPtr(const std::vector< std::unique_ptr< Core::FMTYieldHandler > > &yieldhandlers)
Add unique pointers of FMTYieldHandler from a vector to the yields.
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< Core::FMTTheme > getThemes() const
Return a copy of the themes of the model.
Definition: FMTModel.h:320
std::vector< int > getCompressTime() const
Return a vector with the compresstime value for each period, the first period being index 0....
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 ...
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.
int getParameter(const FMTintmodelparameters &key) const
Getter for int model parameters. See FMTModelParameters.h.
std::vector< Core::FMTSchedule > buildSchedule(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.
std::vector< Core::FMTConstraint > constraints
Outputs comming from the optimization file.
Definition: FMTModel.h:874
FMTModel(FMTModel &&rhs)
Default move constructor for FMTModel.
double getParameter(const FMTdblmodelparameters &key) const
Getter for double model parameters. See FMTModelParameters.h.
std::vector< Core::FMTConstraint > goalConstraints(double penalty=999999) const
Return all constraints and the objective with goals and penalty.
Core::FMTSchedule preSolveSchedule(const Core::FMTSchedule &originalbaseschedule, const FMTModel &originalbasemodel) const
Return a new schedule with presolved development masks and actions.
bool getParameter(const FMTboolmodelparameters &key) const
Getter for bool model parameters. See FMTModelParameters.h.
std::vector< Core::FMTOutput > outputs
Outputs comming from the ouput file.
Definition: FMTModel.h:871
virtual bool setParameter(const FMTdblmodelparameters &key, const double &value)
Setter for double model parameters. See FMTModelParameters.h.
size_t getSeriesMaxSize() const
Get the maximal serie size for the whole model.
Core::FMTMaskFilter getPreSolveFilter(const std::vector< Core::FMTTheme > &originalthemes) const
Get the preSolve filter.
virtual void setParallelLogger(Logging::FMTLogger &logger)
Set a thread owned logger so the solver does not work in concurrency.
bool gotReplicate(const int &p_replanningPeriod) const
Check if setReplicate needs to be called.
Core::FMTYields getYields() const
Return a copy of the yields of the model.
Definition: FMTModel.h:347
int getAreaPeriod() const
get the period of the area section.
void push_back(const FMTModel &rhs)
Append a FMTModel to this FMTModel without overriding the objective of the base model.
void setOutputs(const std::vector< Core::FMTOutput > &newoutputs)
Setter for the outputs of the model.
FMTModel(const FMTModel &rhs)
Copy constructor of FMTModel.
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...
void cleanActionsNTransitions()
Delete actions that have no defined transition and transitions that have no defined action,...
void setConstraints(const std::vector< Core::FMTConstraint > &lconstraint)
Setter for the constraints of the model, replacing the original.
std::vector< Core::FMTSchedule > setUpSchedulesForBuild(const std::vector< Core::FMTSchedule > &schedules) const
Prepare the passed schedules for building based on FORCE_PARTIAL_BUILD, always returning a filled vec...
std::vector< Core::FMTTransition > getTransitions() const
Return a copy of the transitions of the model.
Definition: FMTModel.h:338
virtual void swapPtr(std::unique_ptr< FMTModel > &rhs)
Swap this model for the element at the end of the rhs unique pointer.
double getInitialArea() const
Return the sum of the area of the area vector.
virtual void postSolve(const FMTModel &originalbasemodel)
Postsolve the presolved model into the original model.
FMTModel buildAction(const std::string &p_actionName, const std::string &p_Targetyield) const
Build an action based on the positive value of a yield.
virtual bool isOptimal() const
Return true if the FMTModel is optimal.
void setAreaPeriod(const int &period)
Change the initial area period to the targeted period.
virtual bool solve()
Solve the model, overridden by each type of model.
Definition: FMTModel.h:808
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.
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.
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...
void clearActionsCache()
Clear the cached actions data.
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,...
std::vector< Core::FMTAction > actions
Model actions from the action file and also the _death action.
Definition: FMTModel.h:859
bool empty() const
Return true if the FMTModel is empty.
std::vector< Core::FMTSchedule > splitSchedules(const std::vector< Core::FMTSchedule > &p_schedules) const
Using the actions of the model change the actions of the schedule.
void setReplicate(size_t p_replicate, int p_ReplanningPeriod)
Set the constraints to the specified Replanning Period.
void setArea(const std::vector< Core::FMTActualDevelopment > &ldevs)
Setter for the initial actual developments (area section), replacing the originals.
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 o...
bool useActionSerie() const
Return true if the model makes use of action series.
std::vector< Core::FMTAction > getActions() const
Return a copy of the actions of the model.
Definition: FMTModel.h:329
Core::FMTMask getBaseMask(std::vector< Core::FMTActualDevelopment > optionaldevelopments) const
Return a mask covering the actual bits used by the FMTModel and the optional developments.
virtual bool SupportsMultiThreading() const
Some solver dont support multithreading.
std::vector< size_t > getStaticTransitionThemes() const
Locate the static transition themes.
virtual bool setParameter(const FMTintmodelparameters &p_key, const int &p_value)
set int parameters to nss model.
virtual ~FMTModel()=default
Default virtual destructor of FMTModel.
std::default_random_engine m_generator
Random number generator.
Definition: FMTModel.h:846
const std::string & getParameter(const FMTstrmodelparameters &p_key) const
Getter for str model parameters. See FMTModelParameters.h.
void setYields(const Core::FMTYields &lylds)
Setter for the yields of the model, replacing the original.
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 * > 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.
Core::FMTLifespans getLifespan() const
Return a copy of the lifespan of the model.
Definition: FMTModel.h:356
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).
virtual double getObjectiveValue() const
Return the value of the global objective.
void setLifespan(const Core::FMTLifespans &llifespan)
Setter for the lifespan of the model, replacing the original.
std::vector< Core::FMTTransition > transitions
Model transitions from the transition file and also the _death transition.
Definition: FMTModel.h:862
bool gotReIgnore(const int &p_replanningPeriod) const
Check if setReIgnore needs to be called.
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< Core::FMTActualDevelopment > area
Actualdevelopments for period 0, seen in the area section or the shapefile/raster.
Definition: FMTModel.h:853
void setName(const std::string &newname)
Set the name of the FMTModel.
virtual std::unique_ptr< FMTModel > preSolve(std::vector< Core::FMTActualDevelopment > optionaldevelopments=std::vector< Core::FMTActualDevelopment >()) const
Return a new presolved FMTModel using developments and the actual transitions of the model.
void addYieldHandlers(const std::vector< T > &yieldhandlers)
Add FMTYieldHandler from a vector to the yields.
Definition: FMTModel.h:417
FMTModelStats getModelStats() const
Return the statistics of the model such as the number of themes, yields, actions and transitions.
void setDefaultObjects()
Define the default _DEATH action and transition when they are not defined by the user.
std::string getName() const
Return the name of the FMTModel.
Definition: FMTModel.h:311
void setSeed(const int &p_seed)
seed the random number generator
Core::FMTLifespans lifespan
lifespan data comming from the lifespan file
Definition: FMTModel.h:868
virtual bool setParameter(const FMTstrmodelparameters &p_key, const std::string &p_value)
Setter forstr model parameters. See FMTModelParameters.h.
virtual void showParameters(const bool &showhelp=false) const
Show the parameter values.
void setTransitions(const std::vector< Core::FMTTransition > &ltransitions)
Setter for the transitions of the model, replacing the originals.
virtual std::vector< Core::FMTActualDevelopment > getArea(int period=0, bool beforegrowanddeath=false) const
Get the area of a given period as actual developments.
std::vector< Core::FMTSchedule > aggregateSchedules(const std::vector< Core::FMTSchedule > &p_schedules) const
Build a new schedule based on p_schedules with the corresponding aggregated actions.
virtual std::vector< Core::FMTConstraint > getReplanningConstraints(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 con...
void setThemes(const std::vector< Core::FMTTheme > &lthemes)
Setter for the themes of the model, replacing the originals.
virtual std::unique_ptr< FMTModel > getCopy(int period=0) const
Return a copy of the FMTModel for the selected period, cleaning the constraints and keeping the objec...
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 ori...
virtual std::unique_ptr< FMTModel > clone() const
Get a clone of the FMTModel.
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 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.
std::vector< Core::FMTConstraint > getTacticalConstraints(double penalty=999999, double scheduleweight=999999, double objective=0, double objectivefactor=1.0) const
Get the constraints adapted for a tactical model.
std::vector< const Core::FMTTheme * > locateStaticTransitionsThemes() const
Return the static themes based on the model transitions.
bool isValid()
Validate the whole FMTModel through themes, actual developments, yields, actions, transitions,...
double getYieldValue(const std::string &p_mask, const std::string &p_yield, int p_age, int p_period) const
Get yield value.
void clearTransitionCache()
Clear the cached transitions data.
std::vector< Core::FMTConstraint > getConstraints() const
Return a copy of the constraints of the model.
Definition: FMTModel.h:374
FMTModel()
Default constructor of FMTModel.
void setActions(const std::vector< Core::FMTAction > &lactions)
Setter for the actions of the model, replacing the originals.
std::default_random_engine * getGeneratorPtr() const
Get a pointer to the generator.
virtual void clearCache()
Clear caching elements to reduce memory usage.
void clearYieldCache()
Clear the cached yields data.
Main parser reading and writing model files, for single or multiple scenarios, using all the other FM...
Definition: FMTModelParser.h:48
Container of the line graphs of a spatially explicit model, organized by constraint family,...
Definition: FMTSpatialGraphs.h:52
Map containing a line graph for each cell, representing the stand, the action and the transition at e...
Definition: FMTSpatialSchedule.h:50
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
FMToutputlevel
Enumerator describing the level of detail of an output (standard, total only, development).
Definition: FMTutility.h:22
@ standard
Definition: FMTutility.h:23
FMTotar
Enumerator describing the target of an output (inventory, actual, value, time yield,...
Definition: FMTutility.h:101
Definition: FMTAreaParser.h:35
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
FMTdblmodelparameters
Enumerator of the double parameters of a FMTModel.
Definition: FMTModelParameters.h:54
FMTstrmodelparameters
Enumerator of the string parameters of a FMTModel.
Definition: FMTModelParameters.h:84
FMTintmodelparameters
Enumerator of the integer parameters of a FMTModel.
Definition: FMTModelParameters.h:28
FMTboolmodelparameters
Enumerator of the boolean parameters of a FMTModel.
Definition: FMTModelParameters.h:67
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTActionParser.h:27
Definition: FMTAreaParser.h:40