iLand
management.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19
20#ifndef MANAGEMENT_H
21#define MANAGEMENT_H
22
23#include <QObject>
24#include <QList>
25#include <QtCore/QVariantList>
26#include "scriptglobal.h"
27#include "scripttree.h"
28
29class Tree;
30class QJSEngine;
31class Management : public QObject //, protected QScriptable
32{
33 Q_OBJECT
34 Q_PROPERTY(int count READ count)
35 Q_PROPERTY(double removeFoliage READ removeFoliage WRITE setRemoveFoliage)
36 Q_PROPERTY(double removeBranch READ removeBranch WRITE setRemoveBranch)
37 Q_PROPERTY(double removeStem READ removeStem WRITE setRemoveStem)
38public:
39 Management();
41 void run();
42 void loadScript(const QString &fileName);
43 QString scriptFile() const { return mScriptFile; }
44
45 // property getter & setter for removal fractions
47 double removeFoliage() const { return mRemoveFoliage; }
49 double removeBranch() const { return mRemoveBranch; }
51 double removeStem() const { return mRemoveStem; }
52
53 void setRemoveFoliage(const double fraction) { mRemoveFoliage = fraction; }
54 void setRemoveBranch(const double fraction) { mRemoveBranch = fraction; }
55 void setRemoveStem(const double fraction) { mRemoveStem = fraction; }
56
57 int count() const {return mTrees.count();}
58
59public slots:
61 QJSValue tree(int index);
63 QJSValue treeObject(int index);
64
66 double mean(QString expression, QString filter=QString()) { return aggregate_function( expression, filter, "mean"); }
68 double sum(QString expression, QString filter=QString()) { return aggregate_function( expression, filter, "sum"); }
71 int remain(int number);
76 int killPct(int pctfrom, int pctto, int number);
77 int killAll();
85 int disturbanceKill(double stem_to_soil_fraction, double stem_to_snag_fraction, double branch_to_soil_fraction, double branch_to_snag_fraction, QString agent);
87 int kill(QString filter, double fraction);
88 // management
94 int managePct(int pctfrom, int pctto, int number);
95 int manageAll();
97 int manage(QString filter, double fraction);
99 void cutAndDrop();
100
101 double percentile(int pct);
102 int loadAll() { return load(QString()); }
103 int load(QString filter);
104 int loadResourceUnit(int ruindex);
105 void loadFromTreeList(QList<Tree*>tree_list);
106 void loadFromMap(const MapGrid *map_grid, int key);
107 int loadFromMap(MapGridWrapper *wrap, int key);
109 void killSaplings(MapGridWrapper *wrap, int key, QString filter=QString());
111 void killSaplingsResourceUnit(int ruindex);
114 void removeSoilCarbon(MapGridWrapper *wrap, int key, double SWDfrac, double DWDfrac, double litterFrac, double soilFrac);
118 void slashSnags(MapGridWrapper *wrap, int key, double slash_fraction);
119 void sort(QString statement);
120 int filter(QString filter);
121 int filterIdList(QVariantList idList);
122 void randomize();
123private:
124 QString executeScript(QString cmd="");
125 int remove_percentiles(int pctfrom, int pctto, int number, bool management);
126 int remove_trees(QString expression, double fraction, bool management);
127 double aggregate_function(QString expression, QString filter, QString type);
128 void throwError(const QString &errormessage);
129
130 // removal fractions
131 double mRemoveFoliage, mRemoveBranch, mRemoveStem;
132 QString mScriptFile;
133 QList<QPair<Tree*, double> > mTrees;
134 QJSEngine *mEngine;
135 int mRemoved;
136 QJSValue mTreeValue;
137 ScriptTree *mTree;
138};
139
140#endif // MANAGEMENT_H
management routines.
Definition: management.h:32
void sort(QString statement)
sort trees in the list according to a criterion
Definition: management.cpp:591
void setRemoveBranch(const double fraction)
Definition: management.h:54
double removeBranch() const
removal fraction branch biomass: 0: 0% will be removed, 1: 100% will be removed from the forest by ma...
Definition: management.h:49
void loadFromTreeList(QList< Tree * >tree_list)
load a previously present tree list
Definition: management.cpp:450
void loadFromMap(const MapGrid *map_grid, int key)
load all trees that are on the area denoted by 'key' of the given grid
Definition: management.cpp:571
int disturbanceKill(double stem_to_soil_fraction, double stem_to_snag_fraction, double branch_to_soil_fraction, double branch_to_snag_fraction, QString agent)
kill all trees (disturbance related)
Definition: management.cpp:107
void randomize()
random shuffle of all trees in the list
Definition: management.cpp:616
double removeFoliage() const
removal fraction foliage: 0: 0% will be removed, 1: 100% will be removed from the forest by managemen...
Definition: management.h:47
void setRemoveFoliage(const double fraction)
Definition: management.h:53
int managePct(int pctfrom, int pctto, int number)
kill "number" of stems in the percentile interval "from" - "to".
Definition: management.cpp:302
void slashSnags(MapGridWrapper *wrap, int key, double slash_fraction)
slash snags (SWD and otherWood-Pools) of polygon 'key' on the map 'wrap'.
Definition: management.cpp:550
int load(QString filter)
load all trees passing the filter in a list, return number of trees
Definition: management.cpp:425
~Management()
Definition: management.cpp:73
void loadScript(const QString &fileName)
Definition: management.cpp:334
double sum(QString expression, QString filter=QString())
calculate the sum for all trees in the internal list for the 'expression' (filtered by the filter cri...
Definition: management.h:68
void setRemoveStem(const double fraction)
Definition: management.h:55
void removeSoilCarbon(MapGridWrapper *wrap, int key, double SWDfrac, double DWDfrac, double litterFrac, double soilFrac)
hacky access function to resource units covered by a polygon.
Definition: management.cpp:522
double removeStem
Definition: management.h:37
int killPct(int pctfrom, int pctto, int number)
kill "number" of stems in the percentile interval "from" - "to".
Definition: management.cpp:296
int filter(QString filter)
apply a filter on the list of trees (expression), return number of remaining trees.
Definition: management.cpp:382
QJSValue treeObject(int index)
return a copy of a tree
Definition: management.cpp:349
int count
Definition: management.h:34
int count() const
return number of trees currently in list
Definition: management.h:57
int loadResourceUnit(int ruindex)
load all trees of a resource index
Definition: management.cpp:412
double removeFoliage
Definition: management.h:35
void killSaplingsResourceUnit(int ruindex)
kill all saplings that are on a given resource unit (given by 'ruindex')
Definition: management.cpp:504
int manageAll()
manage all trees in the list
Definition: management.cpp:307
int loadAll()
load all trees, return number of trees
Definition: management.h:102
int killAll()
kill all trees in the list
Definition: management.cpp:98
void killSaplings(MapGridWrapper *wrap, int key, QString filter=QString())
kill all saplings that are on the area denoted by 'key' of the given grid (script access)
Definition: management.cpp:468
QString scriptFile() const
Definition: management.h:43
void cutAndDrop()
kill trees, cut down to the ground
Definition: management.cpp:145
double removeStem() const
removal fraction stem biomass: 0: 0% will be removed, 1: 100% will be removed from the forest by mana...
Definition: management.h:51
void run()
Definition: management.cpp:320
int manage(QString filter, double fraction)
manage 'fraction' of all trees with 'filter'=true
Definition: management.cpp:140
double mean(QString expression, QString filter=QString())
calculate the mean value for all trees in the internal list for 'expression' (filtered by the filter ...
Definition: management.h:66
double percentile(int pct)
get value for the pct th percentile (1..100)
Definition: management.cpp:604
int kill(QString filter, double fraction)
kill 'fraction' of all trees with 'filter'=true
Definition: management.cpp:136
QJSValue tree(int index)
access to single trees (returns a reference)
Definition: management.cpp:340
int remain(int number)
remove randomly trees until only 'number' of trees remain.
Definition: management.cpp:78
Management()
Definition: management.cpp:55
double removeBranch
Definition: management.h:36
int filterIdList(QVariantList idList)
apply filter in form of a list of ids, return number of remaining trees
Definition: management.cpp:361
Definition: mapgrid.h:32
Definition: scriptglobal.h:31
Definition: scripttree.h:10
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44