FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
Parser::FMTmodelparser Class Reference

#include <FMTmodelparser.hpp>

Inheritance diagram for Parser::FMTmodelparser:
[legend]
Collaboration diagram for Parser::FMTmodelparser:
[legend]

Public Member Functions

 FMTmodelparser ()
 
virtual ~FMTmodelparser ()=default
 
 FMTmodelparser (const FMTmodelparser &rhs)
 
FMTmodelparseroperator= (const FMTmodelparser &rhs)
 
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())
 
std::vector< Models::FMTmodelreadtemplates (const std::string &primary_location, const std::string &templatefolder)
 
std::vector< Models::FMTmodelreadproject (const std::string &primary_location, std::vector< std::string >scenarios=std::vector< std::string >(), bool readarea=true, bool readoutputs=true, bool readoptimize=true)
 
void writetoproject (const std::string &primary_location, const Models::FMTmodel &model)
 
std::vector< std::vector< Core::FMTschedule > > readschedules (const std::string &primary_location, const std::vector< Models::FMTmodel > &models)
 
std::vector< Core::FMTconstraintgetconstraintsfromstring (std::string constraintstr, const Models::FMTmodel &model, Core::FMTconstants constants=Core::FMTconstants())
 
void write (const Models::FMTmodel &model, const std::string &folder) const
 
OGRLayer * createresultslayer (const Models::FMTmodel &model, GDALDataset *dataset, std::vector< std::string > creationoptions=std::vector< std::string >()) const
 
void fillupinfeasibles (OGRLayer *layer, const std::vector< Core::FMToutput > &theoutputs, const int &iteration, const int &firstperiod, const int &lastperiod) const
 
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
 
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
 
- Public Member Functions inherited from Parser::FMTparser
 FMTparser ()
 
 FMTparser (const FMTparser &rhs)
 
FMTparseroperator= (const FMTparser &rhs)
 
virtual ~FMTparser ()=default
 
std::time_t getmostrecentfiletime () const
 
void setheader (const std::string &header)
 
bool tryopening (const std::ifstream &stream, const std::string &location) const
 
bool tryopening (std::ofstream &stream, const std::string &location) const
 
bool isvalidfile (const std::string &location) const
 
bool isvalid (const std::string &line) const
 
std::vector< std::string > regexloop (const boost::regex &cutregex, std::string &str) const
 
std::vector< std::string > spliter (std::string strmask, const boost::regex &xspliter) const
 
void clearcomments (std::string &line)
 
std::string upper (const std::string &lowercases) const
 
std::string getcleanline (std::ifstream &stream)
 
std::queue< std::string > tryinclude (const std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
std::string returninclude (const std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
bool getforloops (std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons, std::vector< std::string > &allvalues, std::string &target)
 
std::string getcleanlinewfor (std::ifstream &stream, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
bool isnum (std::string value) const
 
bool isnum (const std::string &value, const Core::FMTconstants &constant, bool throwerror=true) const
 
template<typename T >
getnum (const std::string &value, const Core::FMTconstants &constant, int period=0) const
 
template<typename T >
getnum (const std::string &value, bool omitnumtest=false) const
 
template<typename T >
bool tryfillnumber (T &number, const std::string &value, const Core::FMTconstants &constant, int period=0) const
 
template<typename T >
Core::FMTbounds< T > bounds (const Core::FMTconstants &constants, const std::string &value, const std::string &ope, Core::FMTsection section) const
 
GDALDataset * createOGRdataset (std::string location=std::string(), std::string gdaldrivername="CSV") const
 
OGRLayer * createlayer (GDALDataset *dataset, const std::string &name, std::vector< std::string > creationoptions=std::vector< std::string >()) const
 
std::vector< std::string > getGDALvectordrivernames (bool testcreation=true) const
 
std::vector< std::string > getGDALrasterdrivernames (bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALvectordriverextensions (bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALrasterdriverextensions (bool testcreation=true) const
 
- Public Member Functions inherited from Core::FMTobject
 FMTobject ()
 
virtual ~FMTobject ()
 
 FMTobject (const std::shared_ptr< Exception::FMTexceptionhandler > exhandler)
 
 FMTobject (const FMTobject &rhs)
 
FMTobjectoperator= (const FMTobject &rhs)
 
virtual void passinlogger (const std::shared_ptr< Logging::FMTlogger > &logger)
 
void passinexceptionhandler (const std::shared_ptr< Exception::FMTexceptionhandler > &exhandler)
 
void redirectlogtofile (const std::string &location)
 
virtual void setdefaultlogger ()
 
virtual void setquietlogger ()
 
virtual void settasklogger ()
 
virtual void setdebuglogger ()
 
void setdefaultexceptionhandler ()
 
void setquietexceptionhandler ()
 
void setdebugexceptionhandler ()
 
void setfreeexceptionhandler ()
 
void disablenestedexceptions ()
 
void enablenestedexceptions ()
 
void seterrorstowarnings (const std::vector< Exception::FMTexc > &errors)
 
void setmaxwarningsbeforesilenced (const size_t &maxwarningcount)
 

Protected Member Functions

std::map< std::string, std::vector< std::vector< double > > > getiterationsvalues (OGRLayer *layer) const
 
OGRLayer * createdriftlayer (GDALDataset *dataset, std::vector< std::string > creationoptions=std::vector< std::string >()) const
 
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
 
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
 
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
 
- Protected Member Functions inherited from Parser::FMTparser
void setsection (const Core::FMTsection &section) const
 
std::vector< GDALDriver * > getallGDALdrivers (const char *spatialtype, bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALextensions (const char *spatialtype, bool testcreation=true) const
 
void setcategories (GDALRasterBand *band, const std::vector< std::string > &categories) const
 
OGRCoordinateTransformation * getprojtransform (OGRLayer *baselayer, bool fittoforel=true) const
 
GDALDataset * gettransformmemlayercopy (OGRLayer *baselayer, const OGRSpatialReference *newreference, const std::string &fieldname) const
 
std::unique_ptr< OGRSpatialReference > getFORELspatialref () const
 
template<typename T >
GDALDataset * createdataset (const std::string &location, const Spatial::FMTlayer< T > &layer, const int datatypeid, std::string format="GTiff") const
 
GDALDataset * getdataset (const std::string &location) const
 
GDALDataset * getvectordataset (const std::string &location) const
 
OGRLayer * getlayer (GDALDataset *dataset, int id) const
 
GDALRasterBand * getband (GDALDataset *dataset, int bandid=1) const
 
GDALRasterBand * createband (GDALDataset *dataset, const std::vector< std::string > &categories, int bandid=1) const
 
std::vector< std::string > getcat (GDALDataset *dataset, int bandid=1) const
 
GDALRasterBand * getoverview (GDALRasterBand *band, int view=1) const
 
void getWSfields (OGRLayer *layer, std::map< int, int > &themes, int &age, int &area, int &lock, std::string agefield="", std::string areafield="", std::string lockfield="") const
 
GDALDataset * createvectormemoryds () const
 
std::array< std::string, 5 > getbaseoperators () const
 
std::vector< std::string > sameas (const std::string &allset) const
 
std::map< Core::FMTsection, std::string > getprimary (const std::string &primarylocation)
 
bool isyld (const Core::FMTyields &ylds, const std::string &value, Core::FMTsection section) const
 
bool isact (Core::FMTsection section, const std::vector< Core::FMTaction > &actions, std::string action) const
 
std::string setspecs (Core::FMTsection section, Core::FMTkwor key, const Core::FMTyields &ylds, const Core::FMTconstants &constants, std::vector< Core::FMTspec > &specs, const std::string &line)
 
std::string setspec (Core::FMTsection section, Core::FMTkwor key, const Core::FMTyields &ylds, const Core::FMTconstants &constants, Core::FMTspec &spec, const std::string &line)
 
Core::FMTsection from_extension (const std::string &ext) const
 
std::vector< std::vector< std::string > > readcsv (const std::string &location, const char &separator)
 
- Protected Member Functions inherited from Core::FMTobject
template<class Archive >
void forcesave (Archive &ar, const unsigned int version) const
 
template<class Archive >
void forceload (Archive &ar, const unsigned int version)
 
void checksignals () const
 
void setCPLhandler ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::FMTobject
static std::string getruntimelocation ()
 
static unsigned long long getavailablememory ()
 
- Static Public Attributes inherited from Parser::FMTparser
static const boost::regex rxseparator
 A regex for splitting general string.
 
- Static Protected Member Functions inherited from Core::FMTobject
static std::chrono::time_point< std::chrono::high_resolution_clock > getclock ()
 
template<class chrono >
static double getduration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 
static std::string getdurationinseconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 
- Protected Attributes inherited from Parser::FMTparser
boost::recursive_mutex mtx
 Mutex for multi-threading.
 
Core::FMTsection _section
 The section in which the child class is in.
 
int _constreplacement
 Number of constant replaced by a numerical number.
 
int _line
 Line id at which the parser is reading the values.
 
std::string _comment
 Comment found in the actual line read by the parser.
 
std::string _location
 File location of the section read by the parser.
 
std::time_t mostrecentfile
 The most recent file time read by this parser.
 
- Static Protected Attributes inherited from Parser::FMTparser
static const boost::regex rxayld
 A regex for capturing age/period/yield specification.
 
static const boost::regex rxaage
 A regex for capturing age specificaiton.
 
static const boost::regex rxayldage
 A regex for capturing age or yield specification.
 
static const boost::regex rxbounds
 A regex for capturing bounds for yield or age specification.
 
static const boost::regex rxoperators
 A regex for capturing simple operators.
 
static const boost::regex rxprimary
 A regex for capturing the primary file.
 
- Static Protected Attributes inherited from Core::FMTobject
static std::shared_ptr< Exception::FMTexceptionhandler_exhandler
 A shared pointer to the exception handler.
 
static std::shared_ptr< Logging::FMTlogger_logger
 A shared pointer to the logger.
 

Detailed Description

FMTmodelparser is the main parser class used for reading and writing models files. This class can read single model scenario and multiple model scenarios at the same time. The class make use of all other parser class of FMT to read and write a model.

Constructor & Destructor Documentation

◆ FMTmodelparser() [1/2]

Parser::FMTmodelparser::FMTmodelparser ( )

Default constructor for FMTmodelparser.

◆ ~FMTmodelparser()

virtual Parser::FMTmodelparser::~FMTmodelparser ( )
virtualdefault

Default destructor for FMTmodelparser.

◆ FMTmodelparser() [2/2]

Parser::FMTmodelparser::FMTmodelparser ( const FMTmodelparser rhs)

Default copy constructor for FMTmodelparser.

Member Function Documentation

◆ createdriftlayer()

OGRLayer * Parser::FMTmodelparser::createdriftlayer ( GDALDataset *  dataset,
std::vector< std::string >  creationoptions = std::vector< std::string >() 
) const
protected

Create a output drift layer.

◆ createresultslayer()

OGRLayer * Parser::FMTmodelparser::createresultslayer ( const Models::FMTmodel model,
GDALDataset *  dataset,
std::vector< std::string >  creationoptions = std::vector< std::string >() 
) const

Create a results layer on a dataset for a given model.

◆ fillupinfeasibles()

void Parser::FMTmodelparser::fillupinfeasibles ( OGRLayer *  layer,
const std::vector< Core::FMToutput > &  theoutputs,
const int &  iteration,
const int &  firstperiod,
const int &  lastperiod 
) const

Fill up the OGRlayer of infeasible values.

◆ getconstraintsfromstring()

std::vector< Core::FMTconstraint > Parser::FMTmodelparser::getconstraintsfromstring ( std::string  constraintstr,
const Models::FMTmodel model,
Core::FMTconstants  constants = Core::FMTconstants() 
)

Get constraints from string.

◆ getiterationsvalues()

std::map< std::string, std::vector< std::vector< double > > > Parser::FMTmodelparser::getiterationsvalues ( OGRLayer *  layer) const
protected

Go back in the layer and get all values per iteration and periods.

◆ operator=()

FMTmodelparser & Parser::FMTmodelparser::operator= ( const FMTmodelparser rhs)

Default copy assignment for FMTmodelparser.

◆ read()

Models::FMTmodel Parser::FMTmodelparser::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() 
)

This function aim at reading a single model and return it as a FMTmodel. using the path to the constants (cont), landscape (lan), lifespan(lif),area(are), yields(yld),actions(act),transitions(tr),outputs (out) and optional optimize (opt).

◆ readproject()

std::vector< Models::FMTmodel > Parser::FMTmodelparser::readproject ( const std::string &  primary_location,
std::vector< std::string >  scenarios = std::vector< std::string >(),
bool  readarea = true,
bool  readoutputs = true,
bool  readoptimize = true 
)

The readproject function reads multiple scenarios based on a primary file location (.pri). If the scenarios vector is provided then FMTmodelparser will only read the scenarios provied by the user. For reading the base scenario the user needs to add the string "ROOT" to the scenarios vector. If the scenarios vector is empty then all scenarios including the ROOT are going to be read. If readarea is false then the area section wont be read. If readoutputs is false then output section wont be read. If readoptimize is false then the optimize section wonht be read.

◆ readschedules()

std::vector< std::vector< Core::FMTschedule > > Parser::FMTmodelparser::readschedules ( const std::string &  primary_location,
const std::vector< Models::FMTmodel > &  models 
)

The readschedules function read the schedule files of the specified (models) based on a primary file (primary_location). It returns a vector of vector of FMTschedule ordered the same way as the models. If validate file date is true then it will validate that the parser most recent file is older than the schedule parser most recent file, if it is not it will return a empty schedule.

◆ readtemplates()

std::vector< Models::FMTmodel > Parser::FMTmodelparser::readtemplates ( const std::string &  primary_location,
const std::string &  templatefolder 
)

The readtemplate function read the base model from primary_location and then load all everything from templatefolder and use each folder in templatefolder has scenarios of the base model. Each folders within the templatefolder will will gave their names to the FMTmodel. So within a given subfolder it will read *._act, *._yld and so on...

◆ write()

void Parser::FMTmodelparser::write ( const Models::FMTmodel model,
const std::string &  folder 
) const

The write function write a FMTmodel (model) in to a folder (folder) all the files are going to be named based on the name of the FMTmodel.

◆ writedrift()

void Parser::FMTmodelparser::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
protected

Go back in the layer and get all values per iteration and periods.

◆ writefeatures()

void Parser::FMTmodelparser::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 (outputs)

◆ writemodel()

void Parser::FMTmodelparser::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
protected

Base function to write model section if string non empty then write the corresponding section of the model with the schedules also if not empty

◆ writeprimary()

void Parser::FMTmodelparser::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
protected

Write the primary file with all the other file name.

◆ writeresults()

void Parser::FMTmodelparser::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

The function writeresults for any kind of FMTmodel (optimized or simulated), starting from the first period to the last period, for a vector of outputs. Write the results down in a gdaldriver (gdaldrivername), You can also specify the iteration will be 0 by default.

◆ writetoproject()

void Parser::FMTmodelparser::writetoproject ( const std::string &  primary_location,
const Models::FMTmodel model 
)

The function will create a primary file if it does not exist and write the model in has a root scenario. If the primary file exist it will read the scenario writen and compare each section with the model and write the model has a new scenario...


The documentation for this class was generated from the following file: