iLand
forestmanagementengine.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#ifndef FORESTMANAGEMENTENGINE_H
20#define FORESTMANAGEMENTENGINE_H
21#include <QMultiMap>
22#include <QVector>
23
24#include "abegrid.h"
25
26class QJSEngine; // forward
27class MapGrid; // forward
28class ResourceUnit; // forward
29class Tree; // forward
30
31
32namespace ABE {
33
34class FMUnit; // forward
35class FMStand; // forward
36class FMSTP; // forward
37class Agent; // forward
38class AgentType; // forward
39class FomeScript; // forward
40
43{
44public:
45 // life cycle
48 // engine instance (singleton)
49 static ForestManagementEngine *instance() { if (singleton_fome_engine) return singleton_fome_engine; singleton_fome_engine = new ForestManagementEngine; return singleton_fome_engine; }
51 static const MapGrid *standGrid();
52
53 // setup
54 void setup();
55 void initialize();
56 void clear();
57 void abortExecution(const QString &message);
58 bool isCancel() const { return mCancel; }
59 void runOnInit(bool before_init);
60
61 // main function
62 void run(int debug_year=-1);
65 void yearEnd();
66
67 // properties
68 int currentYear() { return mCurrentYear; }
69 bool enabled() const { return mEnabled; }
70 void setEnabled(bool enable) {mEnabled=enable; }
72 static QJSEngine *scriptEngine();
73 FomeScript *scriptBridge() const {return mScriptBridge; }
74
75 // setting up agents and stps
77 void addSTP(FMSTP* stp) { mSTP.push_back(stp);}
79 void addAgentType(AgentType* at) { mAgentTypes.append(at);}
81 void addAgent(Agent *agent) { mAgents.append(agent);}
83 AgentType *agentType(const QString &name);
85 Agent *agent(const QString &name);
86
87
89 FMSTP *stp(QString stp_name) const;
91 FMStand *stand(int stand_id) const;
92 //QVector<FMStand*> stands() const {return mStands; }
93 const QMultiMap<FMUnit*, FMStand*> &stands() const {return mUnitStandMap; }
94 const QVector<FMUnit*> &units() const { return mUnits; }
95 QVariantList standIds() const;
96
97 FMStand *standAt(QPointF coord) const { return mFMStandGrid.constValueAt(coord); }
98 // functions
99
101 void notifyTreeRemoval(Tree* tree, int reason);
103 bool notifyBarkbeetleAttack(const ResourceUnit *ru, const double generations, int n_infested_px);
104
107
109 void test();
110 QStringList evaluateClick(const QPointF coord, const QString &grid_name);
111
112
113private:
114 static int mMaxStandId;
115 void setupScripting();
116 void prepareRun();
117 void finalizeRun();
118 void setupOutputs();
119 void runJavascript(bool after_processing);
120
121 static ForestManagementEngine *singleton_fome_engine;
122 int mCurrentYear;
123
124 QVector<FMSTP*> mSTP;
125
126 // scripting bridge (accessing model properties from javascript)
127 FomeScript *mScriptBridge;
128
129 // forest management units
130 QVector<FMUnit*> mUnits;
131 // mapping of stands to units
132 QMultiMap<FMUnit*, FMStand*> mUnitStandMap;
133 QVector<FMStand*> mStands;
134 QHash<int, FMStand*> mStandHash;
135
136 // agents
137 QVector<AgentType*> mAgentTypes;
138 QVector<Agent*> mAgents;
139
140 // grids, visuals, etc.
141 Grid<FMStand*> mFMStandGrid;
142 ABELayers mStandLayers;
143
144 bool mCancel;
145 bool mEnabled;
146 bool mStandLayoutChanged;
147 QString mLastErrorMessage;
148
149 //
150 friend class UnitOut;
151};
152
153
154} // namespace
155#endif // FORESTMANAGEMENTENGINE_H
The Agent is the core element of the agent based forest management model and simulates a foresters de...
Definition: agent.h:35
AgentType is the archtype agent including the agents decision logic.
Definition: agenttype.h:72
The FMSTP class encapsulates a stand treatment program, which is defined in Javascript.
Definition: fmstp.h:39
FMStand encapsulates a forest stand for the forest management engine.
Definition: fmstand.h:49
FomeScript provides general helping functions for the Javascript world.
Definition: fomescript.h:45
the ForestManagementEngine is the container for the agent based forest management engine.
Definition: forestmanagementengine.h:43
bool isCancel() const
Definition: forestmanagementengine.h:58
Agent * agent(const QString &name)
return the Agent with the name 'name' or NULL
Definition: forestmanagementengine.cpp:224
~ForestManagementEngine()
Definition: forestmanagementengine.cpp:93
static ForestManagementEngine * instance()
Definition: forestmanagementengine.h:49
void addSTP(FMSTP *stp)
add a stand treatment programme to the list of programs.
Definition: forestmanagementengine.h:77
QStringList evaluateClick(const QPointF coord, const QString &grid_name)
Definition: forestmanagementengine.cpp:708
void addAgentType(AgentType *at)
add an agent type (called from JS)
Definition: forestmanagementengine.h:79
QVariantList standIds() const
Definition: forestmanagementengine.cpp:745
bool enabled() const
Definition: forestmanagementengine.h:69
void addAgent(Agent *agent)
add an agent (called from JS)
Definition: forestmanagementengine.h:81
void yearEnd()
write outputs, finalize the current year should be called at the end of the year (after all disturban...
Definition: forestmanagementengine.cpp:603
void setup()
setup data structures
Definition: forestmanagementengine.cpp:292
int currentYear()
Definition: forestmanagementengine.h:68
ForestManagementEngine()
Definition: forestmanagementengine.cpp:83
void abortExecution(const QString &message)
Definition: forestmanagementengine.cpp:534
void clear()
delete all objects and free memory
Definition: forestmanagementengine.cpp:515
FMStand * splitExistingStand(FMStand *stand)
Definition: forestmanagementengine.cpp:786
static QJSEngine * scriptEngine()
access to the "global" Javascript engine
Definition: forestmanagementengine.cpp:718
void runOnInit(bool before_init)
run javascript code that can be used to initialize forest stands
Definition: forestmanagementengine.cpp:540
void setEnabled(bool enable)
Definition: forestmanagementengine.h:70
void initialize()
run initial stp
Definition: forestmanagementengine.cpp:479
bool notifyBarkbeetleAttack(const ResourceUnit *ru, const double generations, int n_infested_px)
called when bark beetle are likely going to spread
Definition: forestmanagementengine.cpp:767
void notifyTreeRemoval(Tree *tree, int reason)
called by iLand for every tree that is removed/harvested/died due to disturbance.
Definition: forestmanagementengine.cpp:753
void test()
evalaute forest management activities and select fitting activities for each forest stand
Definition: forestmanagementengine.cpp:648
FMStand * stand(int stand_id) const
get stand with id 'stand_id'. Return 0 if not found.
Definition: forestmanagementengine.cpp:732
FMStand * standAt(QPointF coord) const
Definition: forestmanagementengine.h:97
static const MapGrid * standGrid()
link to stand grid
Definition: forestmanagementengine.cpp:102
FMSTP * stp(QString stp_name) const
retrieve pointer to stand treatment programme. return 0-pointer if not available.
Definition: forestmanagementengine.cpp:724
const QMultiMap< FMUnit *, FMStand * > & stands() const
Definition: forestmanagementengine.h:93
FomeScript * scriptBridge() const
Definition: forestmanagementengine.h:73
const QVector< FMUnit * > & units() const
Definition: forestmanagementengine.h:94
AgentType * agentType(const QString &name)
return the agent type with the name 'name' or NULL
Definition: forestmanagementengine.cpp:216
void run(int debug_year=-1)
this is the main function of the forest management engine.
Definition: forestmanagementengine.cpp:556
Definition: unitout.h:26
ABELayers is a helper class for spatial visualization of ABE data.
Definition: abegrid.h:30
Grid class (template).
Definition: grid.h:44
Definition: mapgrid.h:32
ResourceUnit is the spatial unit that encapsulates a forest stand and links to several environmental ...
Definition: resourceunit.h:49
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
Definition: abegrid.h:22