FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTLineGraph.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 FMTLINEGRAPH_H
9#define FMTLINEGRAPH_H
10
11#include "FMTGraph.hpp"
12#include <boost/serialization/export.hpp>
13
14namespace Spatial
15{
16 class FMTEventContainer;
17}
18
19namespace Graph
20{
21// DocString: FMTLineGraph
26class FMTEXPORT FMTLineGraph : public FMTGraph<FMTBaseVertexProperties,FMTBaseEdgeProperties>
27{
28 public:
29 // DocString: FMTLineGraph()
34 // DocString: ~FMTLineGraph()
38 ~FMTLineGraph()=default;
39 // DocString: FMTLineGraph(const FMTgraphbuild)
44 FMTLineGraph(size_t p_LengthReserve);
45 // DocString: FMTLineGraph(const Core::FMTActualDevelopment&,size_t )
51 FMTLineGraph(size_t p_LengthReserve, const Core::FMTActualDevelopment& p_dev);
52 // DocString: FMTLineGraph(const FMTLineGraph&)
58 // DocString: FMTLineGraph(const FMTGraph<FMTBaseVertexProperties, FMTBaseEdgeProperties>&)
64 // DocString: FMTLineGraph::operator=
70 FMTLineGraph& operator = (const FMTLineGraph& rhs);
71 // DocString: FMTLineGraph::operator=
78 // DocString: FMTLineGraph::newPeriod
82 //void newPeriod();
83 // DocString: FMTLineGraph::setAction
90 void setAction( FMTvertex_descriptor active,const int& actionID,
91 const std::vector<Core::FMTDevelopmentPath>& paths);
92 // DocString: FMTLineGraph::operate
102 size_t operate( const Core::FMTAction& action, const int& action_id, const Core::FMTTransition& transition,
103 const Core::FMTYields& ylds, const std::vector<Core::FMTTheme>& themes);
104 // DocString: FMTLineGraph::grow
109 void grow(int p_Length=1);
110 // DocString: FMTLineGraph::getActiveVertex
115 FMTvertex_descriptor getActiveVertex() const;
116 // DocString: FMTLineGraph::getLastActionId
122 int getLastActionId(const int& period)const;
123 // DocString: FMTLineGraph::getPeriodActionIds
130 std::vector<int> getPeriodActionIds(const int& period, bool p_ordered = true)const;
131 // DocString: FMTLineGraph::getPeriodPredictors
141 std::vector<FMTPredictor>getPeriodPredictors(const int& period, const Models::FMTModel& model, const std::vector<std::string>& yieldnames,bool periodonevalues =false,bool withGCBMid = true) const;
142 // DocString: FMTLineGraph::getInEdgeActionId
148 int getInEdgeActionId(const FMTvertex_descriptor& vdesc)const;
149 // DocString: FMTLineGraph::getPeriodStartDev
155 const Core::FMTDevelopment& getPeriodStartDev(const int& period) const;
156 // DocString: FMTLineGraph::getPeriodStopDev
162 const Core::FMTDevelopment& getPeriodStopDev(const int& period) const;
163 // DocString: FMTLineGraph::randomBuildPeriod
172 std::vector<int> randomBuildPeriod(const Models::FMTModel& model,std::default_random_engine& generator,
173 boost::unordered_map<Core::FMTDevelopment, std::vector<int>>& operability,
174 bool dontchoosegrow=false);
175 // DocString: FMTLineGraph::getActions
183 std::vector<std::vector<bool>>getActions(const Models::FMTModel& model,const int& fromperiod,
184 std::map<Core::FMTDevelopment, std::vector<bool>>& operability) const;
185 // DocString: FMTLineGraph::getBaseDevelopment
191 // DocString: FMTLineGraph::getBaseHash
197 size_t getBaseHash(const Core::FMTMask& dynamicmask) const;
198 // DocString: FMTLineGraph::getBaseStr
204 std::string getBaseStr(const Core::FMTMask& dynamicmask) const;
205 // DocString: FMTLineGraph::getBaseMask
211 Core::FMTMask getBaseMask(const Core::FMTMask& dynamicmask) const;
212 // DocString: FMTLineGraph::setBaseMask
218 void setBaseMask(Core::FMTMask& p_dynamicmask,const int& p_period) const;
219 // DocString: FMTLineGraph::getEdgesHash
226 size_t getEdgesHash(const int& maximalperiod,bool& gotthewhole) const;
227 // DocString: FMTLineGraph::getEdgesStr
234 std::string getEdgesStr(const int& maximalperiod, bool& gotthewhole) const;
235 // DocString: FMTLineGraph::fillEdgesMask
241 void fillEdgesMask(Core::FMTMask& mask, const int& maximalperiod) const;
242 // DocString: FMTLineGraph::stringForConstraint
250 bool stringForConstraint(std::string& value, const int& stop, const Core::FMTMask& dynamicmask) const;
251 // DocString: FMTLineGraph::hashForConstraint
259 bool hashForConstraint(size_t& hashvalue,const int& stop,const Core::FMTMask& dynamicmask) const;
260 // DocString: FMTLineGraph::isOnlyGrow
266 bool isOnlyGrow(int period=0) const;
267 // DocString: FMTLineGraph::addFromEvents
271 //void addFromEvents(const Spatial::FMTCoordinate& localisation,const Models::FMTModel& model, Spatial::FMTEventContainer& events) const;
272 // DocString: FMTLineGraph::ismovable
280 bool isMovable(const Models::FMTModel& p_model, const int& period,
281 boost::unordered_map<Core::FMTDevelopment, std::vector<int>>&p_operability) const;
282 // DocString: FMTLineGraph::operator==
288 bool operator == (const FMTLineGraph& rhs) const;
289 // DocString: FMTLineGraph::operator<
295 bool operator < (const FMTLineGraph& rhs) const;
296 // DocString: FMTLineGraph::isLessPeriod
302 bool isLessPeriod(const FMTLineGraph& rhs) const;
303 // DocString: FMTLineGraph::isSameBase
309 bool isSameBase(const FMTLineGraph& rhs) const;
310 // DocString: FMTLineGraph::isNotDead
317 bool isNotDead(FMTvertex_descriptor p_Descriptor,int8_t p_DeathId) const;
318 // DocString: FMTLineGraph::clearNodeCache
323 // DocString: FMTLineGraph::anyUsageOf
331 std::vector<int> anyUsageOf(Core::FMTOutputNode output_node, const Models::FMTModel& model, const int& startingperiod) const;
332 // DocString: FMTLineGraph::getSetOperability
340 static const std::vector<int>& getSetOperability(
341 const Core::FMTDevelopment& p_development,
342 const Models::FMTModel& p_model,
343 boost::unordered_map<Core::FMTDevelopment, std::vector<int>>& p_Cache);
344 private:
345 friend class boost::serialization::access;
346 // DocString: FMTLineGraph::serialize
353 template<class Archive>
354 void serialize(Archive& ar, const unsigned int version)
355 {
356 ar& boost::serialization::make_nvp("Graph::FMTgraph<Graph::FMTbasevertexproperties,Graph::FMTbaseedgeproperties>", boost::serialization::base_object<FMTGraph<FMTBaseVertexProperties, FMTBaseEdgeProperties>>(*this));
357
358 }
359 // DocString: FMTLineGraph::isAnyActionOfEdge
366 bool isAnyActionOfEdge(const FMTBaseEdgeProperties& edgeproperty, const std::unordered_set<int>& actions) const;
367 // DocString: FMTLineGraph::isAnyVertexUsage
375 bool isAnyVertexUsage(const FMTBaseVertexProperties& vertexproperty, const Core::FMTOutputSource& source, const Core::FMTYields& yields) const;
376 // DocString: FMTLineGraph::_randomOperate
387 int _randomOperate(const std::vector<int>& operables, const Models::FMTModel& model,
388 FMTvertex_descriptor& front_vertex, std::default_random_engine& generator,
389 const Core::FMTDevelopment& active_development, bool dontchoosegrow = false);
390
391
392};
393}
394
395BOOST_CLASS_EXPORT_KEY(Graph::FMTLineGraph)
396
397#endif // FMTLINEGRAPH_H
#define FMTEXPORT
Definition: FMTutility.h:125
List of specifications dictating the operability of a subset of developments to this action.
Definition: FMTAction.h:43
Child class of FMTDevelopment representing an actual forest stand, holding the area of the stand.
Definition: FMTActualDevelopment.h:24
Base class of FMTActualDevelopment and FMTFuturDevelopment representing a forest stand.
Definition: FMTDevelopment.h:44
Core class holding, as a boost dynamic bitset, which theme attributes are part of a mask.
Definition: FMTMask.h:96
Node of an output representing a set of developments in the graph, holding a source,...
Definition: FMTOutputNode.h:25
Source of an output holding a mask, a target and values, used to compute an output.
Definition: FMTOutputSource.h:44
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
Base edge properties of a FMTGraph, holding the action of the edge.
Definition: FMTBaseEdgeProperties.h:31
Definition: FMTBaseVertexProperties.h:33
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
const Core::FMTDevelopment & getBaseDevelopment() const
Return a reference to the first development of the graph.
void clearNodeCache()
Clear the node cache used when getting outputs of the line graph.
FMTLineGraph(size_t p_LengthReserve, const Core::FMTActualDevelopment &p_dev)
Construct a FMTLineGraph from a base development, reserving memory for a given length.
FMTLineGraph()
Default constructor for FMTLineGraph.
bool isNotDead(FMTvertex_descriptor p_Descriptor, int8_t p_DeathId) const
Return true if a vertex descriptor did not get the death action.
bool stringForConstraint(std::string &value, const int &stop, const Core::FMTMask &dynamicmask) const
Fill a string used for the uniqueness of the line graph.
bool isMovable(const Models::FMTModel &p_model, const int &period, boost::unordered_map< Core::FMTDevelopment, std::vector< int > > &p_operability) const
Add actions (edges) and vertices to the graph based on an event.
void grow(int p_Length=1)
Grow the last active vertex of the line graph, generating a new edge and vertex.
bool hashForConstraint(size_t &hashvalue, const int &stop, const Core::FMTMask &dynamicmask) const
Fill a hash used for the uniqueness of the line graph.
std::string getEdgesStr(const int &maximalperiod, bool &gotthewhole) const
Return a string representing the edges of the line graph from period 0 to a maximal period.
std::vector< int > anyUsageOf(Core::FMTOutputNode output_node, const Models::FMTModel &model, const int &startingperiod) const
Return the periods at which the vertices fall within an output node description.
std::vector< int > randomBuildPeriod(const Models::FMTModel &model, std::default_random_engine &generator, boost::unordered_map< Core::FMTDevelopment, std::vector< int > > &operability, bool dontchoosegrow=false)
Randomly operate the active vertex to completely build the active period of the graph.
Core::FMTMask getBaseMask(const Core::FMTMask &dynamicmask) const
Return a filtered mask of the starting development mask of the line graph based on a dynamic mask fil...
FMTLineGraph(const FMTGraph< FMTBaseVertexProperties, FMTBaseEdgeProperties > &rhs)
Construct a FMTLineGraph from its parent FMTGraph.
void setBaseMask(Core::FMTMask &p_dynamicmask, const int &p_period) const
Set the base mask to the dynamic mask by intersection for a period.
FMTLineGraph(size_t p_LengthReserve)
Construct a FMTLineGraph reserving memory for a given length.
int getInEdgeActionId(const FMTvertex_descriptor &vdesc) const
Return the in edge action id of a vertex.
~FMTLineGraph()=default
Default destructor for FMTLineGraph.
void fillEdgesMask(Core::FMTMask &mask, const int &maximalperiod) const
Fill a unique mask based on the edges from period 0 to a maximal period.
FMTvertex_descriptor getActiveVertex() const
Return the last active vertex of the graph.
int getLastActionId(const int &period) const
Return the action id of the last edge of a period.
std::vector< int > getPeriodActionIds(const int &period, bool p_ordered=true) const
Return the action ids of every action done in a period, in order.
std::vector< FMTPredictor > getPeriodPredictors(const int &period, const Models::FMTModel &model, const std::vector< std::string > &yieldnames, bool periodonevalues=false, bool withGCBMid=true) const
Return the predictors of a period.
bool isLessPeriod(const FMTLineGraph &rhs) const
Return true if the other graph is the same graph with one less period.
bool isSameBase(const FMTLineGraph &rhs) const
Return true if the other graph has the same base development.
size_t getEdgesHash(const int &maximalperiod, bool &gotthewhole) const
Return a hash of the edges of the line graph from period 0 to a maximal period.
bool isOnlyGrow(int period=0) const
Return true if the graph is never operated by any action.
size_t getBaseHash(const Core::FMTMask &dynamicmask) const
Return a hash of the starting development of the line graph based on a dynamic mask filter.
const Core::FMTDevelopment & getPeriodStartDev(const int &period) const
Return a reference to the first development (vertex) of a period.
size_t operate(const Core::FMTAction &action, const int &action_id, const Core::FMTTransition &transition, const Core::FMTYields &ylds, const std::vector< Core::FMTTheme > &themes)
Operate the last active vertex and return the length of the generated development path.
std::vector< std::vector< bool > > getActions(const Models::FMTModel &model, const int &fromperiod, std::map< Core::FMTDevelopment, std::vector< bool > > &operability) const
Return, starting from a period, a vector of booleans per period indicating whether each action is ope...
std::string getBaseStr(const Core::FMTMask &dynamicmask) const
Return a string of the starting development of the line graph based on a dynamic mask filter.
static const std::vector< int > & getSetOperability(const Core::FMTDevelopment &p_development, const Models::FMTModel &p_model, boost::unordered_map< Core::FMTDevelopment, std::vector< int > > &p_Cache)
Return the operable action ids of a development, computing and caching them if needed.
const Core::FMTDevelopment & getPeriodStopDev(const int &period) const
Return a reference to the last development (vertex) of a period.
void setAction(FMTvertex_descriptor active, const int &actionID, const std::vector< Core::FMTDevelopmentPath > &paths)
Generate a new period container at the end of the line graph.
FMTLineGraph(const FMTLineGraph &rhs)
Copy constructor for FMTLineGraph.
Base class for the different models in FMT.
Definition: FMTModel.h:62
Definition: FMTAreaParser.h:35
Definition: FMTAreaParser.h:40