FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTAction.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
9#ifndef FMTACT_Hm_included
10#define FMTACT_Hm_included
11
12#include "FMTExceptionHandler.h"
13#include "FMTList.hpp"
14#include "FMTBounds.hpp"
15#include "FMTSerie.h"
16#include <boost/serialization/string.hpp>
17#include <boost/serialization/serialization.hpp>
18#include <boost/serialization/nvp.hpp>
19#include <string>
20#include <vector>
21#include <unordered_set>
22#include <boost/serialization/export.hpp>
23#include <limits>
24
25
26#define FMTGCBMDEATHID 15
27#define FMTGCBMGROWTHID 16
28#define FMTGCBMUNKNOWNID 17
29#define FMTGCBMWILDFIREID 10
30#define FMTMaxNumberOfActions _I8_MAX + 1
31
32
33namespace Core
34{
35
37// DocString: FMTAction
42class FMTEXPORT FMTAction : public FMTList<FMTSpec>
43 {
44 friend class FMTActionComparator;
45 public:
46 // DocString: FMTAction::operator+=
52 FMTAction& operator+=(const FMTAction & OtherAction);
53 // DocString: FMTAction()
58 // DocString: ~FMTAction()
62 virtual ~FMTAction() = default;
63 // DocString: FMTAction(const std::string&)
68 FMTAction(const std::string& lname);
69 // DocString: FMTAction(const std::string&,const bool&,const bool&)
76 FMTAction(const std::string& lname, const bool& p_lock, const bool& p_reset);
77 // DocString: FMTAction::pushAggregate
82 void pushAggregate(const std::string& aggregate);
83 // DocString: FMTAction::pushPartials
88 void pushPartials(const std::string& yield);
89 // DocString: FMTAction(const FMTAction&)
94 FMTAction(const FMTAction& rhs);
95 // DocString: FMTAction::operator=
101 FMTAction& operator = (const FMTAction& rhs);
102 // DocString: FMTAction::update
106 void update() override;
107 // DocString: FMTAction::preSolve
117 const std::vector<FMTTheme>& originalthemes,
118 std::vector<FMTTheme>& newthemes, bool compressdata = false) const;
119 // DocString: FMTAction::preSolveRef
127 void preSolveRef(const FMTMaskFilter& p_filter,
128 const std::vector<FMTTheme>& p_originalthemes,
129 std::vector<FMTTheme>& p_newthemes, bool p_compressdata = false);
130 // DocString: FMTAction::getAgeLowerBound
135 inline const int& getAgeLowerBound() const
136 {
137 return m_agelowerbound;
138 }
139 // DocString: FMTAction::getAgeUpperBound
144 inline const int& getAgeUpperBound() const
145 {
146 return m_ageupperbound;
147 }
148 // DocString: FMTAction::getPeriodLowerBound
153 inline const int& getPeriodLowerBound() const
154 {
155 return m_periodlowerbound;
156 }
157 // DocString: FMTAction::getPeriodUpperBound
162 inline const int& getPeriodUpperBound() const
163 {
164 return m_periodupperbound;
165 }
166 // DocString: FMTAction::hash
171 inline size_t hash() const
172 {
173 return boost::hash<std::string>()(m_name);
174 }
175 // DocString: FMTAction::getName
180 inline std::string getName() const
181 {
182 return m_name;
183 }
184 // DocString: FMTAction::doRespectLock
189 inline bool doRespectLock() const
190 {
191 return m_lock;
192 }
193 // DocString: FMTAction::isResetAge
198 inline bool isResetAge() const
199 {
200 return m_reset;
201 }
202 // DocString: FMTAction::isPartOfASerie
207 inline bool isPartOfASerie() const
208 {
209 return !m_series.empty();
210 }
211 // DocString: FMTAction::isAllowedInSerie
217 bool isAllowedInSerie(const std::vector<std::string>& serie) const;
218 // DocString: FMTAction::getSerie
224 const FMTSerie* getSerie(const std::vector<std::string>& p_SerieMask) const;
225 // DocString: FMTAction::getSeries
230 const std::vector<FMTSerie>& getSeries() const;
231 // DocString: FMTAction::getSeriesNames
236 std::vector<std::string> getSeriesNames() const;
237 // DocString: FMTAction::getLargestSerieSize
242 size_t getLargestSerieSize() const;
243 // DocString: FMTAction::setSeries
248 void setSeries(std::vector<Core::FMTSerie> p_series);
249 // DocString: FMTAction::useYield
255 bool useYield(const std::string& yldname) const;
256 // DocString: FMTAction::getAggregates
261 std::vector<std::string> getAggregates() const;
262 // DocString: FMTAction::setAggregates
267 void setAggregates(const std::vector<std::string>& p_aggregates);
268 // DocString: FMTAction::getPartials
273 std::vector<std::string> getPartials() const;
274 // DocString: FMTAction::operator<
280 bool operator < (const FMTAction& rhs) const;
281 // DocString: FMTAction::operator==
287 bool operator == (const FMTAction& rhs) const;
288 // DocString: FMTAction::operator!=
294 bool operator != (const FMTAction& rhs) const;
295 // DocString: FMTAction::operator std::string
300 operator std::string() const;
301 // DocString: FMTAction::partial
307 bool partial(const std::string& yield) const;
308 // DocString: FMTAction::getGCBMActionId
313 int getGCBMActionId() const;
314 // DocString: FMTAction::getGCBMActionName
319 std::string getGCBMActionName() const;
320 // DocString: FMTAction::split
327 std::vector<Core::FMTAction>split(const std::vector<Core::FMTMask>& p_mask,
328 const std::vector<Core::FMTTheme>& p_themes) const;
329 // DocString: FMTAction::notUse
334 bool notUse() const;
335 // DocString: FMTAction::isPartOf
341 bool isPartOf(const std::string& p_name) const;
342 // DocString: FMTAction:: isInSeries
347 bool isInSeries() const;
348 protected:
349 // DocString: FMTAction::m_aggregates
351 std::vector<std::string> m_aggregates;
352 // DocString: FMTAction::m_partials
354 std::vector<std::string> m_partials;
355 // DocString: FMTAction::m_agelowerbound
358 int m_agelowerbound, m_ageupperbound, m_periodlowerbound, m_periodupperbound;
359 // DocString: FMTAction::m_name
361 std::string m_name;
362 // DocString: FMTAction::m_lock
364 bool m_lock;
365 // DocString: FMTAction::m_reset
368 // DocString: FMTAction::m_series
370 std::vector<FMTSerie> m_series;
371 // DocString: FMTAction::m_InSerie
374 // DocString: FMTAction::_setBounds
379 // DocString: FMTAction::_getGCBMActionDef
384 std::vector<std::string> _getGCBMActionDef() const;
385 private:
386 // DocString: FMTAction::serialize
393 friend class boost::serialization::access;
394 template<class Archive>
395 void serialize(Archive& ar, const unsigned int version)
396 {
397 try {
398 ar& boost::serialization::make_nvp("specs", boost::serialization::base_object<FMTList<FMTSpec>>(*this));
399 ar& boost::serialization::make_nvp("partials", m_partials);
400 ar& boost::serialization::make_nvp("agelowerbound", m_agelowerbound);
401 ar& boost::serialization::make_nvp("ageupperbound", m_ageupperbound);
402 ar& boost::serialization::make_nvp("periodlowerbound", m_periodlowerbound);
403 ar& boost::serialization::make_nvp("periodupperbound", m_periodupperbound);
404 ar& boost::serialization::make_nvp("name", m_name);
405 ar& boost::serialization::make_nvp("aggregates", m_aggregates);
406 ar& boost::serialization::make_nvp("lock", m_lock);
407 ar& boost::serialization::make_nvp("reset", m_reset);
408 }
409 catch (...)
410 {
411 _exhandler->printExceptions("", "FMTAction::serialize", __LINE__, __FILE__);
412 }
413 }
414 };
415
416// DocString: FMTActionComparator
421 {
422 public:
423 // DocString: FMTActionComparator(std::string,bool)
429 FMTActionComparator(std::string p_name, bool lcheckaggregate = false);
430 // DocString: FMTActionComparator::getAllAggregates
437 std::vector<const FMTAction*> getAllAggregates(const std::vector<FMTAction>&actions,bool aggregateonly = false) const;
438 // DocString: FMTActionComparator::getAllAggregatesSet
445 std::unordered_set<int> getAllAggregatesSet(const std::vector<FMTAction>&actions, bool aggregateonly = false) const;
446 // DocString: FMTActionComparator::operator()(const FMTAction&)
452 bool operator()(const FMTAction& action) const;
453 private:
454 // DocString: FMTActionComparator::m_actionName
456 std::string m_actionName;
457 // DocString: FMTActionComparator::m_checkAggregate
459 bool m_checkAggregate;
460 };
461}
462
463namespace boost {
464
468 template <>
469 struct hash<Core::FMTAction>
470 {
471 std::size_t operator()(const Core::FMTAction& act) const
472 {
473 return (act.hash());
474 }
475 };
476
477
478}
479BOOST_CLASS_EXPORT_KEY(Core::FMTAction)
480#endif // FMTACT_Hm_included
#define FMTEXPORT
Definition: FMTutility.h:125
Comparator used to check if an action name (or aggregate) already exists in a std container.
Definition: FMTAction.h:421
FMTActionComparator(std::string p_name, bool lcheckaggregate=false)
Construct the comparator from the action name to match.
std::unordered_set< int > getAllAggregatesSet(const std::vector< FMTAction > &actions, bool aggregateonly=false) const
Return the ids of the actions matching the action name, or only the matching aggregates.
bool operator()(const FMTAction &action) const
Matching test operator for the comparator.
std::vector< const FMTAction * > getAllAggregates(const std::vector< FMTAction > &actions, bool aggregateonly=false) const
Return the actions matching the action name, or only the matching aggregates.
List of specifications dictating the operability of a subset of developments to this action.
Definition: FMTAction.h:43
const FMTSerie * getSerie(const std::vector< std::string > &p_SerieMask) const
get the serie with the partial mask p_SerieMask
bool isResetAge() const
Return true if the development age is reset to 0 when operated by this action.
Definition: FMTAction.h:198
FMTAction preSolve(const FMTMaskFilter &filter, const std::vector< FMTTheme > &originalthemes, std::vector< FMTTheme > &newthemes, bool compressdata=false) const
Presolve the action by eliminating specifications and presolving the masks; the returned action can b...
bool partial(const std::string &yield) const
Check if the yield needs to be considered as partial for this action.
size_t hash() const
Return the hash of the action based on its name.
Definition: FMTAction.h:171
bool useYield(const std::string &yldname) const
Return true if the yield is used by the action to set operability.
void setAggregates(const std::vector< std::string > &p_aggregates)
Set a new vector of aggregates.
void pushPartials(const std::string &yield)
Push a partial yield name to the partials of the action.
int m_agelowerbound
Definition: FMTAction.h:358
void setSeries(std::vector< Core::FMTSerie > p_series)
Set the series of the action, checking which ones the action is part of and building them.
std::string getGCBMActionName() const
Return the corresponding GCBM action name.
FMTAction & operator+=(const FMTAction &OtherAction)
Append another action to this action; actions need to have the same age reset otherwise an exception ...
void pushAggregate(const std::string &aggregate)
Push an aggregate to the aggregates of the action.
bool isPartOfASerie() const
Return true if the action is part of a serie.
Definition: FMTAction.h:207
std::vector< std::string > getAggregates() const
Return the names of the aggregates the action is part of.
bool isInSeries() const
return true if you find this action first in a serie
std::vector< std::string > m_aggregates
An action can be part of a aggregate so this data member gets the name of all aggregate the action is...
Definition: FMTAction.h:351
bool m_lock
If lock is true the action is not _lockexempt when false the action is _LOCKEXEMPT.
Definition: FMTAction.h:364
bool notUse() const
Check if all specs are period lower == 0 and upper == 0.
const int & getPeriodUpperBound() const
Get the period upper bound for all specifications.
Definition: FMTAction.h:162
std::vector< std::string > getSeriesNames() const
Return the series names of the action.
std::vector< std::string > m_partials
Keeps the yields name for determining the amount of wood harvested in case of partial cut.
Definition: FMTAction.h:354
bool isAllowedInSerie(const std::vector< std::string > &serie) const
Return true if the serie mask is part of one serie of the action.
const int & getAgeLowerBound() const
Get the age lower bound for all specifications.
Definition: FMTAction.h:135
void preSolveRef(const FMTMaskFilter &p_filter, const std::vector< FMTTheme > &p_originalthemes, std::vector< FMTTheme > &p_newthemes, bool p_compressdata=false)
Presolve the action in place by eliminating specifications and presolving the masks; the action can b...
void _setBounds()
Set the age and period bounds member data by iterating on the specifications, for optimization.
bool doRespectLock() const
Return true if the action needs to respect the lock state of the development.
Definition: FMTAction.h:189
const int & getPeriodLowerBound() const
Get the period lower bound for all specifications.
Definition: FMTAction.h:153
bool isPartOf(const std::string &p_name) const
Check if action is part of action name or aggregate.
const int & getAgeUpperBound() const
Get the age upper bound for all specifications.
Definition: FMTAction.h:144
std::string m_name
The name of the action.
Definition: FMTAction.h:361
size_t getLargestSerieSize() const
Return the size of the largest serie of the action.
FMTAction(const FMTAction &rhs)
Copy constructor for FMTAction.
const std::vector< FMTSerie > & getSeries() const
get all series of the actions
std::vector< std::string > getPartials() const
Return the partial yield names of the action.
virtual ~FMTAction()=default
Default virtual destructor for FMTAction.
std::vector< FMTSerie > m_series
The action series that the action is part of.
Definition: FMTAction.h:370
FMTAction(const std::string &lname, const bool &p_lock, const bool &p_reset)
Construct an empty action with a given name, respect lock and reset age flags.
void update() override
Update the action by setting the bounds and shrinking the list, for optimization.
int getGCBMActionId() const
Return the corresponding GCBM action id.
FMTAction()
Default constructor for FMTAction.
std::vector< Core::FMTAction > split(const std::vector< Core::FMTMask > &p_mask, const std::vector< Core::FMTTheme > &p_themes) const
Split the action into different actions using the masks.
FMTAction(const std::string &lname)
Construct an empty action with a given name.
bool m_reset
If reset is true then the action is age reset Y else the action doen't reset age.
Definition: FMTAction.h:367
bool m_InSerie
True if the actions is in a serie.
Definition: FMTAction.h:373
std::string getName() const
Get the name of the action.
Definition: FMTAction.h:180
std::vector< std::string > _getGCBMActionDef() const
Return the corresponding GCBM action definition.
Definition: FMTAreaParser.h:32
Filter built from masks used to preSolve and postsolve FMTMask objects.
Definition: FMTMaskFilter.h:31
Class keeping the information of a serie of actions in a given order.
Definition: FMTSerie.h:23
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
Definition: FMTAction.h:463
std::size_t operator()(const Core::FMTAction &act) const
Definition: FMTAction.h:471