FFSM++  1.1.0
French Forest Sector Model ++
Pixel.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2015 by Laboratoire d'Economie Forestière *
3  * http://ffsm-project.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version, given the compliance with the *
9  * exceptions listed in the file COPYING that is distribued together *
10  * with this file. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 #ifndef PIXELS_H
23 #define PIXELS_H
24 
25 #include <string>
26 #include <vector>
27 #include <stdexcept>
28 #include <iostream>
29 #include <sstream>
30 
31 #include <Eigen/Dense>
32 
33 // regmas headers...
34 #include "BaseClass.h"
35 #include "ModelData.h"
36 
37 class Gis; //forward declaration
38 
39 using namespace Eigen;
40 
41 /// Pixel-level class
42 
43 /**
44 This class manage the info at the pixel level. A vector of pixel objects is owned by the class Gis.
45 @author Antonello Lobianco
46 */
47 class Pixel: public BaseClass{
48 
49 public:
50  Pixel(double ID_h, ThreadManager* MTHREAD_h);
51  ~Pixel();
52 
53  /// Return the value for a specific layer
54  double getDoubleValue (const string& layerName_h, const bool& returnZeroForNoValue = false) const;
55  double getDoubleValue (const string& parName, const string& forName, const string& dClass, const int& year, const bool& returnZeroForNoValue = false);
56  double getMultiplier (const string& multiplierName, const string& forName, int year=DATA_NOW);
57  double getPathMortality(const string& forType, const string& dC, int year=DATA_NOW); ///< Return the INCREASED mortality due to pathogen presence for a given ft and dc in a certain year (default the running year)
58  void correctInputMultiplier (const string& multiplierName, const string& forName, double coefficient=1); ///< It apply a given coefficient to all the multipliers layers of a given ft
59  void newYear();
60  double getPastRegArea(const int& ft_idx, const int& year);
61  void setPastRegArea(const double& value, const int& ft_idx, const int& year);
62  ModelRegion* getMyRegion(const int& rLevel = 2);
63  double getSTData(const string& parName, const string& forName, int year, const string& d2 ="", double naToReturn = RETNA); // Get spatio-temporal data from layers whose name follows a given pattern
64 
65 
66  // space..
67  double getID() const {return ID;} ;
68  int getX() const {return pxX;} ;
69  int getY() const {return pxY;};
70  /// Return a vector of pixels at the specified distance (in levels, not in physical units)
71  vector <Pixel *> getPixelsAtDistLevel (int distLevel_h) const;
72 
73  string getPxComments() const {return pxComments;};
74  double getCachedDouble() const {return cachedDouble;};
75 
76 
77  /// Insert a new layer and its value
78  void setValue ( const string& layerName_h, const double& value_h ){values.insert(pair<string, double>(layerName_h, value_h));}
79  //inline void setValue ( const string& parName, const string& forName, const string& dClass, const int& year, const double& value_h); // never used ???
80  /// Change the value of an existing layerMTHREAD->GIS->pack(parName, forName, dClass, year), value_h,
81  void changeValue (const string& layerName_h, const double& value_h, const bool& setNoValueForZero=false );
82  //void changeValue (const double& value_h, const string& parName, const string& forName, const string& dClass, const int& year, const bool& setNoValueForZero=false);
83  void setCoordinates ( int x_h, int y_h ) {pxX=x_h; pxY=y_h;};
84  void setPxComments ( std::string pxComments_h ) {pxComments = pxComments_h;};
85  void setCachedDouble(double cachedDouble_h){cachedDouble=cachedDouble_h;};
86  void clearCache(){cachedDouble=0;};
87  void setSpModifier(const double& value, const int& ftindex){spMods.at(ftindex)=value;};
88  double getSpModifier(const string& ft);
89  void swap(const int &swap_what); ///< Assign to the delayed value the current values, e.g. vol_l = vol
90  void setMyRegion(ModelRegion* region_h){l2region = region_h;};
91 
92  // matrices of (ft,dc)
93  /*MatrixXd vol;
94  MatrixXd area;
95  MatrixXd regArea;
96  MatrixXd hVol;
97  MatrixXd vol_l;
98  MatrixXd area_l;
99  MatrixXd regArea_l;
100  MatrixXd hVol_l;
101  MatrixXd beta;
102  MatrixXd mort;
103  MatrixXd tp;
104  MatrixXd cumTp;*/
105 
106  vector <vector <double> > vol; // by ft,dc
107  vector <vector <double> > area; // by ft,dc
108  vector <vector <double> > deltaArea; // by ft_in + "", ft_out + "" // delta areas, transiction matrix
109  vector <double> initialDc0Area; // by ft
110  vector <vector <double> > hArea; // by ft, dc // possibly in ha, but to be check for 100% sure
111  vector <vector <double> > hVol; // by ft.dc
112  vector <vector <double> > hProductivity; // by ft,dc
113  vector < vector <vector <double> > >hVol_byPrd; // by ft, dc, pp
114  map <int, vector <double> > regArea; // by year, ft
115  //vector <double> in; // by pp
116  //vector <double> hr; // by pp
117  vector <double> vReg; // by ft
118  vector <vector <double> > vMort; // by ft,dc
119  vector <double> expectedReturns; // by ft
120  vector <int> optDc; // The "optimal" diameter class chosen in project evaluation for the regeneration. By ft evaluated (not necessarily those then chosen)
121  vector <int> optFtChosen; // The ft (index) chosen as optimal in regeneration for each ft in input (harvested)
122  vector <int> optDcChosen; // The "optimal" diameter class of the ft chosen for regeneration. By ft in input (harvested)
123 
124  vector <double> expectedReturnsNotCorrByRa; ///< by ft. Attenction, reported expReturns at "forest" level (compared with those at forest type level) do NOT include ra
125 
126  vector <vector <double> > vol_l; ///< store the volumes of the previous year
127  vector <vector <double> > area_l; ///< store the areas of the previous year
128 
129  vector <vector <double> > beta;
130  vector <vector <double> > mort;
131  vector <vector <double> > tp;
132  vector <vector <double> > cumTp; ///< This is time of passage to REACH a diameter class (while the exogenous tp by diameter class is the time of passage to LEAVE to the next d class). By ft,dc
133  vector <vector <double> > vHa; ///< Volume at hectar by each diameter class [m^3/ha]
134  vector <vector <double> > cumAlive; ///< Cumulative prob of remaining alive at beginnin of a given diam class
135  vector <vector <double> > cumTp_exp; ///< This is the **expected** version of cumTp, used for calculating profits
136  vector <vector <double> > vHa_exp; ///< This is the **expected** version of vHa, used for calculating profits
137  vector <vector <double> > cumAlive_exp; ///< This is the **expected** version of cumAlive, used for calculating profits
138 
139  // management variables (pixel==agent)
140  double portfolioVarRa; ///< Sampling derived risk aversion on portfolio variance for of this agent
141  double expType; ///< Sampling derived expectation types of this agent (forest bilogical parameters: growth, mortality)
142  double expTypePrices; ///< Sampling derived expectation types of this agent (prices)
143  bool usePortfolio; ///< Sampling derived usage of portfolio management (false/true)
144  vector <double> avalCoef; ///< Availability (of wood resources) coefficient. A [0,1] coefficient (new: by forest type) that reduces avaiability of wood resources to exploitation due to local reasons (protected area, altimetry..)
145 
146 private:
147  map<string, double> values; ///< Map of values for each layer
148  mutable map<string, double>::const_iterator vIter; //< Iterator for the map of values
149  double ID;
150  int pxX;
151  int pxY;
152  string pxComments;
153  double cachedDouble; ///< Cachable double used in some optimized algorithms
154  vector<double> spMods; ///< The sampled spatial modifiers (by forest type)
155  ModelRegion* l2region; ///< Pointer to level 2 region where this pixel is
156 
157 };
158 
159 #endif
vector< vector< double > > deltaArea
Definition: Pixel.h:108
void setSpModifier(const double &value, const int &ftindex)
Definition: Pixel.h:87
The required data is for the current year.
Definition: BaseClass.h:73
double getCachedDouble() const
Definition: Pixel.h:74
void clearCache()
Definition: Pixel.h:86
vector< vector< double > > area
Definition: Pixel.h:107
vector< vector< double > > cumAlive_exp
This is the expected version of cumAlive, used for calculating profits.
Definition: Pixel.h:137
void setCachedDouble(double cachedDouble_h)
Definition: Pixel.h:85
Forest types (struct)
Definition: ModelData.h:293
int getX() const
Definition: Pixel.h:68
map< string, double >::const_iterator vIter
Definition: Pixel.h:148
double expType
Sampling derived expectation types of this agent (forest bilogical parameters: growth, mortality)
Definition: Pixel.h:141
double ID
Definition: Pixel.h:149
vector< double > avalCoef
Availability (of wood resources) coefficient. A [0,1] coefficient (new: by forest type) that reduces ...
Definition: Pixel.h:144
vector< vector< double > > mort
Definition: Pixel.h:130
vector< vector< double > > vMort
Definition: Pixel.h:118
ModelRegion * l2region
Pointer to level 2 region where this pixel is.
Definition: Pixel.h:155
vector< vector< double > > vol_l
store the volumes of the previous year
Definition: Pixel.h:126
void setValue(const string &layerName_h, const double &value_h)
Insert a new layer and its value.
Definition: Pixel.h:78
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
Definition: ThreadManager.h:65
vector< vector< double > > vHa_exp
This is the expected version of vHa, used for calculating profits.
Definition: Pixel.h:136
vector< double > initialDc0Area
Definition: Pixel.h:109
vector< vector< double > > cumAlive
Cumulative prob of remaining alive at beginnin of a given diam class.
Definition: Pixel.h:134
vector< vector< double > > vHa
Volume at hectar by each diameter class [m^3/ha].
Definition: Pixel.h:133
vector< double > spMods
The sampled spatial modifiers (by forest type)
Definition: Pixel.h:154
vector< int > optDcChosen
Definition: Pixel.h:122
string pxComments
Definition: Pixel.h:152
Pixel-level class.
Definition: Pixel.h:47
vector< vector< double > > hProductivity
Definition: Pixel.h:112
vector< vector< double > > vol
Definition: Pixel.h:90
vector< vector< double > > cumTp_exp
This is the expected version of cumTp, used for calculating profits.
Definition: Pixel.h:135
double expTypePrices
Sampling derived expectation types of this agent (prices)
Definition: Pixel.h:142
bool usePortfolio
Sampling derived usage of portfolio management (false/true)
Definition: Pixel.h:143
vector< vector< vector< double > > > hVol_byPrd
Definition: Pixel.h:113
Request the (scenario specific) NO VALUE to be returned.
Definition: BaseClass.h:79
vector< vector< double > > area_l
store the areas of the previous year
Definition: Pixel.h:127
double cachedDouble
Cachable double used in some optimized algorithms.
Definition: Pixel.h:153
void setCoordinates(int x_h, int y_h)
Definition: Pixel.h:83
vector< int > optFtChosen
Definition: Pixel.h:121
Base class for the regmas application.
Definition: BaseClass.h:239
vector< int > optDc
Definition: Pixel.h:120
map< string, double > values
Map of values for each layer.
Definition: Pixel.h:147
vector< double > expectedReturns
Definition: Pixel.h:119
string getPxComments() const
Definition: Pixel.h:73
vector< vector< double > > tp
Definition: Pixel.h:131
void setPxComments(std::string pxComments_h)
Definition: Pixel.h:84
Class to manage the spatial dimension.
Definition: Gis.h:67
vector< double > expectedReturnsNotCorrByRa
by ft. Attenction, reported expReturns at "forest" level (compared with those at forest type level) d...
Definition: Pixel.h:124
vector< vector< double > > hVol
Definition: Pixel.h:111
double portfolioVarRa
Sampling derived risk aversion on portfolio variance for of this agent.
Definition: Pixel.h:140
vector< vector< double > > cumTp
This is time of passage to REACH a diameter class (while the exogenous tp by diameter class is the ti...
Definition: Pixel.h:132
vector< vector< double > > hArea
Definition: Pixel.h:110
vector< double > vReg
Definition: Pixel.h:117
vector< vector< double > > beta
Definition: Pixel.h:129
int pxX
Definition: Pixel.h:150
This file is the header of BaseClass and it is included by ALL compiled code.
int getY() const
Definition: Pixel.h:69
double getID() const
Definition: Pixel.h:67
map< int, vector< double > > regArea
Definition: Pixel.h:114
int pxY
Definition: Pixel.h:151