FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTOutputSource.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 FMTOSR_Hm_included
9#define FMTOSR_Hm_included
10
11#include "FMTBounds.hpp"
12#include "FMTMask.h"
13#include <vector>
14#include <boost/serialization/serialization.hpp>
15#include <string>
16#include "FMTutility.h"
17#include <unordered_set>
18#include "FMTDevelopment.h"
19
20
21namespace Graph
22{
23 class FMTGraphVertexToYield;
24}
25
26namespace Parser
27{
28 class FMTOutputParser;
29}
30
31
32namespace Core
33{
34 class FMTAction;
35 class FMTYields;
36 class FMTActualDevelopment;
37 class FMTDevelopmentPath;
38 class FMTOperator;
39// DocString: FMTOutputSource
43class FMTEXPORT FMTOutputSource : public FMTSpec
44 {
45 public:
46 // DocString: FMTOutputSource()
51 // DocString: ~FMTOutputSource()
55 ~FMTOutputSource() = default;
56 // DocString: FMTOutputSource(const FMTotar,double,std::string,std::string,int,int)
66 FMTOutputSource(const FMTotar ltarget,double lvalue = 0,
67 std::string lyield= "", std::string laction = "",int origin=-1, int ttarget=-1);
68 // DocString: FMTOutputSource(const FMTotar,std::vector<double>,int,int,std::string)
77 FMTOutputSource(const FMTotar ltarget,
78 std::vector<double>lvalues, int origin = -1, int ttarget=-1, std::string llevelname = "");
79 // DocString: FMTOutputSource(const FMTSpec&,const FMTMask&,const FMTotar,std::string,std::string,int,int)
90 FMTOutputSource(const FMTSpec& spec,const FMTMask& lmask,
91 const FMTotar ltarget, std::string lyield= "",
92 std::string laction = "", int origin = -1, int ttarget=-1);
93 // DocString: FMTOutputSource(const FMTOutputSource&)
99 // DocString: FMTOutputSource::operator=
105 FMTOutputSource& operator = (const FMTOutputSource& rhs);
106 // DocString: FMTOutputSource::operator std::string
111 operator std::string() const override;
112 // DocString: FMTOutputSource::operator==
118 bool operator == (const FMTOutputSource& rhs) const;
119 // DocString: FMTOutputSource::operator!=
125 bool operator != (const FMTOutputSource& rhs) const;
126 // DocString: FMTOutputSource::operator<
132 bool operator < (const FMTOutputSource& rhs) const;
133 // DocString: FMTOutputSource::getOutputOrigin
138 inline int getOutputOrigin() const
139 {
140 return m_outputorigin;
141 }
142 // DocString: FMTOutputSource::getThemeTarget
147 inline int getThemeTarget() const
148 {
149 return m_themetarget;
150 }
151 // DocString: FMTOutputSource::isInAggregate
158 bool isInAggregate(const FMTOutputSource& rhs, const std::vector<Core::FMTAction>& actions) const;
159 // DocString: FMTOutputSource::isSubsetOf(const FMTOutputSource&, const std::vector<Core::FMTAction>&)
166 bool isSubsetOf(const FMTOutputSource& rhs, const std::vector<Core::FMTAction>& actions) const;
167 // DocString: FMTOutputSource::isSubsetOf(const FMTOutputSource&)
173 bool isSubsetOf(const FMTOutputSource& rhs) const;
174 // DocString: FMTOutputSource::isSameButDifferentAction
181 // DocString: FMTOutputSource::getMask
186 inline const FMTMask& getMask() const
187 {
188 return m_mask;
189 }
190 // DocString: FMTOutputSource::setMask
195 void setMask(const FMTMask& newmask);
196 // DocString: FMTOutputSource::setAction
201 void setAction(const std::string& actionname);
202 // DocString: FMTOutputSource::setTarget
207 void setTarget(const FMTotar& newtype);
208 // DocString: FMTOutputSource::setThemeTarget
213 void setThemeTarget(const int& newttarget);
214 // DocString: FMTOutputSource::setOutputOrigin
219 void setOutputOrigin(const int& neworigin);
220 // DocString: FMTOutputSource::resetValues
226 void resetValues(const FMTOperator& op,const FMTOutputSource& other);
227 // DocString: FMTOutputSource::getAction
232 inline const std::string& getAction() const
233 {
234 return m_action;
235 }
236 // DocString: FMTOutputSource::getYield
241 inline const std::string& getYield() const
242 {
243 return m_yield;
244 }
245 // DocString: FMTOutputSource::getTarget
250 inline const FMTotar& getTarget() const
251 {
252 return m_target;
253 }
254 // DocString: FMTOutputSource::getValue
260 double getValue(int period = 0) const;
261 // DocString: FMTOutputSource::isVariable
266 inline bool isVariable() const
267 {
268 return bool(m_mask);
269 }
270 // DocString: FMTOutputSource::isLevel
275 inline bool isLevel() const
276 {
277 return (m_target == FMTotar::level);
278 }
279 // DocString: FMTOutputSource::isConstant
284 inline bool isConstant() const
285 {
286 return (m_target == FMTotar::val);
287 }
288 // DocString: FMTOutputSource::isVariableLevel
293 inline bool isVariableLevel() const
294 {
295 return (!m_action.empty() && isLevel());
296 }
297 // DocString: FMTOutputSource::getLevel
302 inline const std::string& getLevel() const
303 {
304 return m_yield;
305 }
306 // DocString: FMTOutputSource::getValues
311 inline const std::vector<double>& getValues() const
312 {
313 return m_values;
314 }
315 // DocString: FMTOutputSource::isNull
321 bool isNull(const FMTYields& ylds) const;
322 // DocString: FMTOutputSource::isTimeYield
327 inline bool isTimeYield() const
328 {
329 return (m_target == FMTotar::timeyld);
330 }
331 // DocString: FMTOutputSource::targets
337 std::vector<const FMTAction*>targets(const std::vector<FMTAction>& actions) const;
338 // DocString: FMTOutputSource::targetsSet
344 std::unordered_set<int>targetsSet(const std::vector<FMTAction>& actions) const;
345 // DocString: FMTOutputSource::isInventory
350 inline bool isInventory() const
351 {
352 return (m_target == FMTotar::inventory);
353 }
354 // DocString: FMTOutputSource::useInEdges
359 inline bool useInEdges() const
360 {
361 return (m_target == FMTotar::inventory);
362 }
363 // DocString: FMTOutputSource::isNextPeriod
368 inline bool isNextPeriod() const
369 {
370 return (m_target == FMTotar::inventory && m_action.empty());
371 }
372 // DocString: FMTOutputSource::useOutEdges
377 inline bool useOutEdges() const
378 {
379 return (m_target == FMTotar::actual);
380 }
381 // DocString: FMTOutputSource::getCoef
391 double getCoef(const FMTDevelopment& development,
392 const FMTYields& yields,
393 const Graph::FMTGraphVertexToYield* graphinfo =nullptr,
394 std::vector<FMTDevelopmentPath> const * paths=nullptr,
395 FMTAction const * p_action=nullptr) const;
396 // DocString: FMTOutputSource::use
404 bool use(const FMTDevelopment& development, const FMTYields& ylds,
405 const Graph::FMTGraphVertexToYield* graphinfo = nullptr) const;
406 // DocString: FMTOutputSource::preSolve
413 FMTOutputSource preSolve(const FMTMaskFilter& filter,const std::vector<FMTTheme>& newthemes) const;
414 // DocString: FMTOutputSource::setAverage
419 // DocString: FMTOutputSource::isAverage
424 inline bool isAverage() const
425 {
426 return m_average;
427 }
428 // DocString: FMTOutputSource::setSum
432 void setSum();
433 // DocString: FMTOutputSource::isSum
438 inline bool isSum() const
439 {
440 return m_sum;
441 }
442 // DocString: FMTOutputSource::canBeDeducedToConstant
448 // DocString: FMTOutputSource::getConstantValue
456 double getConstantValue(const std::vector<Core::FMTActualDevelopment>& area,
457 const std::vector<Core::FMTAction>&actions, const FMTYields& yields) const;
458 // DocString: FMTOutputSource::hash
465 size_t hash(int period = -1,bool withyield = false) const;
466 // DocString: FMTOutputSource::fillHashMask
471 void fillHashMask(Core::FMTMask& baseMask) const;
472 // DocString: FMTOutputSource::fillHashSpec
477 void fillHashSpec(Core::FMTMask& baseMask) const;
478 // DocString: FMTOutputSource::isEqualByValue
484 bool isEqualByValue(const FMTOutputSource& rhs) const;
485 // DocString: FMTOutputSource::isAction
490 inline bool isAction() const
491 {
492 return !m_action.empty();
493 }
494 // DocString: FMTOutputSource::trimDouble
500 static std::string trimDouble(const std::string& string_number);
501 // DocString: FMTOutputSource::setYield
506 void setYield(const std::string& p_Yield);
507 private:
508 friend class boost::serialization::access;
510 // DocString: FMTOutputSource::serialize
517 template<class Archive>
518 void serialize(Archive& ar, const unsigned int version)
519 {
520 ar& boost::serialization::make_nvp("specification", boost::serialization::base_object<FMTSpec>(*this));
521 ar& boost::serialization::make_nvp("mask", m_mask);
522 ar& boost::serialization::make_nvp("target", m_target);
523 ar& boost::serialization::make_nvp("action", m_action);
524 ar& boost::serialization::make_nvp("yield", m_yield);
525 ar& boost::serialization::make_nvp("values", m_values);
526 ar& boost::serialization::make_nvp("themetarget", m_themetarget);
527 }
528 FMTMask m_mask;
529 FMTotar m_target;
530 std::string m_action, m_yield, m_levelname;//m_levelname is only for constant level...(for parsing)
531 std::vector<double>m_values;
532 bool m_average;
533 bool m_sum;
534 int m_outputorigin;
535 int m_themetarget;
536 //target =-1 or themetarget constructor
537 // DocString: FMTOutputSource::_pushValues
542 void _pushValues(const std::vector<double>& newvalues);
543 };
544
545// DocString: FMTOutputSourceComparator
550 {
551 public:
552 // DocString: FMTOutputSourceComparator(bool)
558 // DocString: FMTOutputSourceComparator::operator()
564 bool operator()(const FMTOutputSource& source) const;
565
566 private:
567 bool m_variable;
568 };
569}
570
571namespace boost {
575 template <>
576 struct hash<Core::FMTOutputSource>
577 {
578 std::size_t operator()(const Core::FMTOutputSource& p_source) const
579 {
580 return p_source.hash(-1, true);
581 }
582 };
583
584
585}
586
587
588
589#endif // FMTOSR_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
Base class of FMTActualDevelopment and FMTFuturDevelopment representing a forest stand.
Definition: FMTDevelopment.h:44
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
Mathematical operator usable in yield and output expressions.
Definition: FMTOperator.h:44
Comparator used to match output sources by whether they are variable.
Definition: FMTOutputSource.h:550
FMTOutputSourceComparator(bool lvariable)
Construct the comparator.
bool operator()(const FMTOutputSource &source) const
Matching test operator for the comparator.
Source of an output holding a mask, a target and values, used to compute an output.
Definition: FMTOutputSource.h:44
std::unordered_set< int > targetsSet(const std::vector< FMTAction > &actions) const
Return the ids of the actions targeted by the output source.
const std::vector< double > & getValues() const
Return a const reference to the values of the output source.
Definition: FMTOutputSource.h:311
void setAction(const std::string &actionname)
Set the action of the output source.
void fillHashSpec(Core::FMTMask &baseMask) const
Fill a base mask with the hash specification of the output source.
bool isNull(const FMTYields &ylds) const
Return true if the output source is null.
int getThemeTarget() const
Return the theme target.
Definition: FMTOutputSource.h:147
FMTOutputSource(const FMTotar ltarget, double lvalue=0, std::string lyield="", std::string laction="", int origin=-1, int ttarget=-1)
Construct an output source from a target and optional value, yield, action, origin and theme target.
FMTOutputSource(const FMTOutputSource &rhs)
Copy constructor for FMTOutputSource.
bool useOutEdges() const
Return true if the output source uses the out edges.
Definition: FMTOutputSource.h:377
int getOutputOrigin() const
Return the output origin.
Definition: FMTOutputSource.h:138
bool isNextPeriod() const
Return true if the output source targets the next period.
Definition: FMTOutputSource.h:368
void resetValues(const FMTOperator &op, const FMTOutputSource &other)
Reset the values of the output source using an operator and another output source.
const std::string & getAction() const
Return a const reference to the action of the output source.
Definition: FMTOutputSource.h:232
bool isVariable() const
Return true if the output source is a variable.
Definition: FMTOutputSource.h:266
bool useInEdges() const
Return true if the output source uses the in edges.
Definition: FMTOutputSource.h:359
bool isSum() const
Return true if the output source is a sum.
Definition: FMTOutputSource.h:438
bool isSameButDifferentAction(const FMTOutputSource &rhs) const
Return true if this output source is the same as another but with a different action.
double getConstantValue(const std::vector< Core::FMTActualDevelopment > &area, const std::vector< Core::FMTAction > &actions, const FMTYields &yields) const
Return the constant value of the output source.
bool isAverage() const
Return true if the output source is an average.
Definition: FMTOutputSource.h:424
void setMask(const FMTMask &newmask)
Set the mask of the output source.
void fillHashMask(Core::FMTMask &baseMask) const
Fill a base mask with the hash mask of the output source.
void setYield(const std::string &p_Yield)
set Yield to the output source.
const FMTotar & getTarget() const
Return a const reference to the target of the output source.
Definition: FMTOutputSource.h:250
~FMTOutputSource()=default
Default destructor for FMTOutputSource.
bool isLevel() const
Return true if the output source is a level.
Definition: FMTOutputSource.h:275
bool isVariableLevel() const
Return true if the output source is a variable level.
Definition: FMTOutputSource.h:293
double getCoef(const FMTDevelopment &development, const FMTYields &yields, const Graph::FMTGraphVertexToYield *graphinfo=nullptr, std::vector< FMTDevelopmentPath > const *paths=nullptr, FMTAction const *p_action=nullptr) const
Return the coefficient of the output source for a development based on the yields.
static std::string trimDouble(const std::string &string_number)
Trim the trailing zeros of a number in string format, for example 1400.0000 to 1400 or 14....
bool isTimeYield() const
Return true if the output source is a time yield.
Definition: FMTOutputSource.h:327
double getValue(int period=0) const
Return the value of the output source for a given period.
void setThemeTarget(const int &newttarget)
Set the theme target of the output source.
bool isSubsetOf(const FMTOutputSource &rhs) const
Return true if this output source is a subset of another.
bool isInventory() const
Return true if the output source targets the inventory.
Definition: FMTOutputSource.h:350
void setAverage()
Set the output source as an average.
bool isSubsetOf(const FMTOutputSource &rhs, const std::vector< Core::FMTAction > &actions) const
Return true if this output source is a subset of another considering the actions.
FMTOutputSource(const FMTSpec &spec, const FMTMask &lmask, const FMTotar ltarget, std::string lyield="", std::string laction="", int origin=-1, int ttarget=-1)
Construct an output source from a specification, a mask and a target.
const std::string & getYield() const
Return a const reference to the yield of the output source.
Definition: FMTOutputSource.h:241
void setSum()
Set the output source as a sum.
const FMTMask & getMask() const
Return a const reference to the mask of the output source.
Definition: FMTOutputSource.h:186
FMTOutputSource(const FMTotar ltarget, std::vector< double >lvalues, int origin=-1, int ttarget=-1, std::string llevelname="")
Construct an output source from a target and a vector of values.
bool isEqualByValue(const FMTOutputSource &rhs) const
Return true if this output source is equal by value to another.
bool use(const FMTDevelopment &development, const FMTYields &ylds, const Graph::FMTGraphVertexToYield *graphinfo=nullptr) const
Return true if the output source is used by a development based on the yields.
FMTOutputSource preSolve(const FMTMaskFilter &filter, const std::vector< FMTTheme > &newthemes) const
Return a presolved copy of the output source.
FMTOutputSource()
Default constructor for FMTOutputSource.
bool isAction() const
Return true if the output source is an action.
Definition: FMTOutputSource.h:490
size_t hash(int period=-1, bool withyield=false) const
Return the hash of the output source.
std::vector< const FMTAction * > targets(const std::vector< FMTAction > &actions) const
Return the actions targeted by the output source.
void setTarget(const FMTotar &newtype)
Set the target of the output source.
void setOutputOrigin(const int &neworigin)
Set the output origin of the output source.
bool isConstant() const
Return true if the output source is a constant.
Definition: FMTOutputSource.h:284
bool isInAggregate(const FMTOutputSource &rhs, const std::vector< Core::FMTAction > &actions) const
Return true if this output source is in the same aggregate as another.
bool canBeDeducedToConstant() const
Return true if the output source can be deduced to a constant.
const std::string & getLevel() const
Return a const reference to the level of the output source.
Definition: FMTOutputSource.h:302
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
Parser reading and writing a vector of FMTOutput from or into a file.
Definition: FMTOutputParser.h:35
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
FMTotar
Enumerator describing the target of an output (inventory, actual, value, time yield,...
Definition: FMTutility.h:101
Definition: FMTAreaParser.h:35
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTActionParser.h:27
Definition: FMTAction.h:463
std::size_t operator()(const Core::FMTOutputSource &p_source) const
Definition: FMTOutputSource.h:578