FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTModelParser.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 FMTmodelparser_Hm_included
9#define FMTmodelparser_Hm_included
10
11
12#include <map>
13#include <string>
14#include <vector>
15#include "FMTParser.h"
16#include "FMTOutputNode.h"
17#include "FMTConstants.h"
18
19
20namespace Models {
21 class FMTModel;
22}
23
24
25namespace Core {
26 class FMTSchedule;
27 class FMTConstraint;
28 class FMTOutput;
29}
30
31
32namespace Parser
33{
34class FMTConstantParser;
35class FMTLandscapeParser;
36class FMTAreaParser;
37class FMTYieldParser;
38class FMTActionParser;
39class FMTLifespanParser;
40class FMTOutputParser;
41class FMTOptimizationParser;
42class FMTScheduleParser;
43// DocString: FMTModelParser
48 {
49 public:
50 // DocString: FMTModelParser()
55 // DocString: ~FMTModelParser()
59 virtual ~FMTModelParser() = default;
60 // DocString: FMTModelParser(const FMTModelParser&)
66 // DocString: FMTModelParser::operator=
72 FMTModelParser& operator = (const FMTModelParser& rhs);
73 // DocString: FMTModelParser::read
87 Models::FMTModel read(const std::string& con,const std::string& lan,
88 const std::string& lif,const std::string& are,const std::string& yld,
89 const std::string& act,const std::string& tr,const std::string& out,
90 std::string opt = std::string());
91 // DocString: FMTModelParser::readtemplate
98 std::vector<Models::FMTModel>readTemplates(const std::string& primarym_location,const std::string& templatefolder);
99 // DocString: FMTModelParser::readproject
109 std::vector<Models::FMTModel>readproject(const std::string& primarym_location,
110 std::vector<std::string>scenarios = std::vector<std::string>(),
111 bool readarea = true,bool readoutputs = true, bool readoptimize = true);
112 // DocString: FMTModelParser::writeToProject
118 void writeToProject(const std::string& primarym_location,
119 const Models::FMTModel& model);
120 // DocString: FMTModelParser::readSchedules
127 std::vector<std::vector<Core::FMTSchedule>>readSchedules(const std::string& primarym_location,
128 const std::vector<Models::FMTModel>& models);
129 // DocString: FMTModelParser::getConstraintsFromString
137 std::vector<Core::FMTConstraint>getConstraintsFromString(std::string constraintstr,
138 const Models::FMTModel& model,Core::FMTConstants constants = Core::FMTConstants());
139 // DocString: FMTModelParser::write
145 void write(const Models::FMTModel& model,const std::string& folder) const;
146 #ifdef FMTWITHGDAL
147 // DocString: FMTModelParser::createResultsLayer
156 const std::string& p_modelName,
157 GDALDataset* p_dataset,
158 std::vector<std::string> p_creationOptions = std::vector<std::string>()) const;
159 // DocString: FMTModelParser::fillUpInfeasibles
168 void fillUpInfeasibles(OGRLayer* layer,
169 const std::vector<Core::FMTOutput>&theoutputs,
170 const int& iteration,const int& firstPeriod, const int&lastPeriod) const;
171 // DocString: FMTModelParser::writeFeatures
181 void writeFeatures(OGRLayer* layer,const int& firstPeriod, const int& iteration,
182 const std::vector<Core::FMTOutput>&theoutputs,
183 const std::map<std::string,std::vector<std::vector<double>>>& values, bool writeNaN = false)const;
184 // DocString: FMTModelParser::writeResults
196 const std::vector<Core::FMTOutput>&theoutputs,
197 const int& firstPeriod, const int& lastPeriod,
198 const std::string& location,
200 std::string gdaldrivername= "CSV") const;
201 #endif
202 protected:
203 #ifdef FMTWITHGDAL
204 // DocString: FMTModelParser::getIterationsValues()
210 std::map<std::string, std::vector<std::vector<double>>>getIterationsValues(OGRLayer* layer) const;
211 // DocString: FMTModelParser::createDriftLayer()
218 OGRLayer* createDriftLayer(GDALDataset* dataset, std::vector<std::string> creationoptions = std::vector<std::string>()) const;
219 // DocString: FMTModelParser::writedriftr()
226 void writeDrift(OGRLayer* layer, const std::map<std::string, std::map<double, std::vector<double>>>& lowervalues,
227 const std::map<std::string, std::map<double, std::vector<double>>>& uppervalues) const;
228 #endif
229 // DocString: FMTModelParser::writePrimary()
244 const std::string& location,
245 const std::string& lanfile,
246 const std::string& arefile,
247 const std::string& yldfile,
248 const std::string& actfile,
249 const std::string& trnfile,
250 const std::string& outfile,
251 const std::string& optfile,
252 const std::string& liffile,
253 std::string seqfile = std::string()) const;
254 // DocString: FMTModelParser::writeModel
268 void writeModel(const Models::FMTModel& model,
269 const std::string& lanfile,
270 const std::string& arefile,
271 const std::string& yldfile,
272 const std::string& actfile,
273 const std::string& trnfile,
274 const std::string& outfile,
275 const std::string& optfile,
276 const std::string& liffile,
277 const std::string& seqfile) const;
278 private:
279 // DocString: FMTModelParser::referenceRead
296 Models::FMTModel referenceRead(std::map<std::string, std::vector<int>>& commonm_sections,
297 std::vector<Models::FMTModel>& models,
298 const std::string& con, const std::string& lan,
299 const std::string& lif, const std::string& are, const std::string& yld,
300 const std::string& act, const std::string& tr, const std::string& out,
301 std::string opt = std::string(), bool allow_mapping = false);
302 // DocString: FMTModelParser::readFromFolder
314 std::vector<Models::FMTModel>readFromFolder(const std::string& primarym_location,
315 const std::string& folder,
316 std::vector<std::string>scenarios,
317 bool validatescenarioname,
318 bool readarea = true, bool readoutputs = true, bool readoptimize = true);
319 // DocString: FMTModelParser::setSolverParameters
325 void setSolverParameters(Models::FMTModel& p_model, const std::string& p_optimize_file) const;
326 };
327}
328
329#endif // FMTmodelparser_Hm_included
#define FMTEXPORT
Definition: FMTutility.h:125
Class holding the constants defined in the constants section of a model, used by the parsers.
Definition: FMTConstants.h:28
Base class for the different models in FMT.
Definition: FMTModel.h:62
Main parser reading and writing model files, for single or multiple scenarios, using all the other FM...
Definition: FMTModelParser.h:48
std::vector< Core::FMTConstraint > getConstraintsFromString(std::string constraintstr, const Models::FMTModel &model, Core::FMTConstants constants=Core::FMTConstants())
Get constraints from a string.
FMTModelParser()
Default constructor for FMTModelParser.
FMTModelParser(const FMTModelParser &rhs)
Copy constructor for FMTModelParser.
OGRLayer * createDriftLayer(GDALDataset *dataset, std::vector< std::string > creationoptions=std::vector< std::string >()) const
Create an output drift layer.
void writePrimary(const std::string &location, const std::string &lanfile, const std::string &arefile, const std::string &yldfile, const std::string &actfile, const std::string &trnfile, const std::string &outfile, const std::string &optfile, const std::string &liffile, std::string seqfile=std::string()) const
Write the primary file with the section file names.
std::vector< Models::FMTModel > readTemplates(const std::string &primarym_location, const std::string &templatefolder)
Read the base model then load each folder in the template folder as a scenario of the base model.
void writeResults(const Models::FMTModel &model, const std::vector< Core::FMTOutput > &theoutputs, const int &firstPeriod, const int &lastPeriod, const std::string &location, Core::FMToutputlevel level=Core::FMToutputlevel::standard, std::string gdaldrivername="CSV") const
Write the results of a model from the first to the last period for a vector of outputs into a GDAL dr...
void writeDrift(OGRLayer *layer, const std::map< std::string, std::map< double, std::vector< double > > > &lowervalues, const std::map< std::string, std::map< double, std::vector< double > > > &uppervalues) const
Write the drift lower and upper values to a layer.
std::vector< std::vector< Core::FMTSchedule > > readSchedules(const std::string &primarym_location, const std::vector< Models::FMTModel > &models)
Read the schedule files of the models based on a primary file.
std::map< std::string, std::vector< std::vector< double > > > getIterationsValues(OGRLayer *layer) const
Return all the values per iteration and period from a layer.
void write(const Models::FMTModel &model, const std::string &folder) const
Write a model into a folder, naming the files based on the model name.
Models::FMTModel read(const std::string &con, const std::string &lan, const std::string &lif, const std::string &are, const std::string &yld, const std::string &act, const std::string &tr, const std::string &out, std::string opt=std::string())
Read a single model and return it as a FMTModel.
virtual ~FMTModelParser()=default
Default virtual destructor for FMTModelParser.
OGRLayer * createResultsLayer(const std::string &p_modelName, GDALDataset *p_dataset, std::vector< std::string > p_creationOptions=std::vector< std::string >()) const
Create a results layer on a dataset for a given model name.
void fillUpInfeasibles(OGRLayer *layer, const std::vector< Core::FMTOutput > &theoutputs, const int &iteration, const int &firstPeriod, const int &lastPeriod) const
Fill up an OGR layer with infeasible values.
std::vector< Models::FMTModel > readproject(const std::string &primarym_location, std::vector< std::string >scenarios=std::vector< std::string >(), bool readarea=true, bool readoutputs=true, bool readoptimize=true)
Read multiple scenarios based on a primary file location.
void writeModel(const Models::FMTModel &model, const std::string &lanfile, const std::string &arefile, const std::string &yldfile, const std::string &actfile, const std::string &trnfile, const std::string &outfile, const std::string &optfile, const std::string &liffile, const std::string &seqfile) const
Write the sections of a model, and the schedules if the schedule file is not empty.
void writeToProject(const std::string &primarym_location, const Models::FMTModel &model)
Create a primary file if needed and write the model as a root scenario, or as a new scenario if the p...
void writeFeatures(OGRLayer *layer, const int &firstPeriod, const int &iteration, const std::vector< Core::FMTOutput > &theoutputs, const std::map< std::string, std::vector< std::vector< double > > > &values, bool writeNaN=false) const
Write multiple features to a layer.
Main parent class of all the parsers in FMT.
Definition: FMTParser.h:72
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
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTActionParser.h:27