iLand
agenttype.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 AGENTTYPE_H
20#define AGENTTYPE_H
21#include <QHash>
22#include <QVector>
23#include <QJSValue>
24
25
26namespace ABE {
27
28
29class FMSTP; // forward
30class FMUnit; // forward
31class FMStand; // forward
32class Agent; // forward
33
35{
36public:
37 AgentUpdate(): mWhat(UpdateInvalid), mAge(-1), mYear(-1), mCounter(0) {}
39 static UpdateType label(const QString &name);
40 bool isValid() const { return mCounter>0; }
41 void setCounter(int n) { mCounter = n; }
42 void decrease() {--mCounter; }
43 QString dump();
44 // getters
45 UpdateType type() const { return mWhat; }
46 const QString &value() const { return mValue;}
47 const QString &afterActivity() const { return mAfterActivity; }
48 int age() const {return mAge; }
49 // setters
50 void setType(UpdateType type) { mWhat = type; }
51 void setValue(QString new_value) { mValue = new_value; }
52 void setTimeAge(int age) { mAge = age; }
53 void setTimeYear(int year) { mYear = year; }
54 void setTimeActivity(QString act) { mAfterActivity = act; }
55private:
56 UpdateType mWhat;
57 QString mValue;
58 int mAge;
59 int mYear;
60 QString mAfterActivity;
61
62 int mCounter;
63
64 friend class AgentType;
65};
66
72{
73public:
74
75 AgentType();
76 const QString &name() const {return mName; }
78 void setupSTP(QJSValue agent_code, const QString agent_name);
80 void addSTP(QString stp_name);
82 Agent *createAgent(QString agent_name=QString());
83
84 void addAgentUpdate(const AgentUpdate &update, FMUnit *unit);
85 bool agentUpdateForStand(FMStand *stand, QString after_activity, int age);
86
87
89 FMSTP *stpByName(const QString &name);
91 QJSValue &jsObject() { return mJSObj; }
92
94 int speciesCompositionIndex(const QString &key);
95 QString speciesCompositionName(const int index);
96
97private:
98 QString mName; // agent name
99 QJSValue mJSObj;
100 QHash<QString,FMSTP*> mSTP;
101 QVector<QString> mSpeciesCompositions;
102 QMultiHash<const FMUnit*, AgentUpdate> mAgentChanges;
103};
104
105} // namespace
106#endif // AGENTTYPE_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
void addAgentUpdate(const AgentUpdate &update, FMUnit *unit)
Definition: agenttype.cpp:117
QString speciesCompositionName(const int index)
Definition: agenttype.cpp:238
const QString & name() const
Definition: agenttype.h:76
AgentType()
Definition: agenttype.cpp:39
Agent * createAgent(QString agent_name=QString())
create an agent of the agent type
Definition: agenttype.cpp:78
QJSValue & jsObject()
access to the javascript object
Definition: agenttype.h:91
void addSTP(QString stp_name)
add a STP to the list of available STPs for the agent
Definition: agenttype.cpp:68
FMSTP * stpByName(const QString &name)
get stand treatment program by name; return 0 if the stp is not available.
Definition: agenttype.cpp:222
int speciesCompositionIndex(const QString &key)
return the index (0-based) of the species composition given by 'key'. Returns -1 if not found.
Definition: agenttype.cpp:230
void setupSTP(QJSValue agent_code, const QString agent_name)
setup the definition of STPs for the agent
Definition: agenttype.cpp:43
bool agentUpdateForStand(FMStand *stand, QString after_activity, int age)
Definition: agenttype.cpp:158
Definition: agenttype.h:35
void setTimeActivity(QString act)
Definition: agenttype.h:54
bool isValid() const
Definition: agenttype.h:40
void decrease()
Definition: agenttype.h:42
UpdateType type() const
Definition: agenttype.h:45
QString dump()
Definition: agenttype.cpp:253
void setCounter(int n)
Definition: agenttype.h:41
void setTimeYear(int year)
Definition: agenttype.h:53
const QString & afterActivity() const
Definition: agenttype.h:47
void setType(UpdateType type)
Definition: agenttype.h:50
UpdateType
Definition: agenttype.h:38
@ UpdateSpecies
Definition: agenttype.h:38
@ UpdateThinning
Definition: agenttype.h:38
@ UpdateU
Definition: agenttype.h:38
@ UpdateInvalid
Definition: agenttype.h:38
int age() const
Definition: agenttype.h:48
void setTimeAge(int age)
Definition: agenttype.h:52
static UpdateType label(const QString &name)
Definition: agenttype.cpp:245
const QString & value() const
Definition: agenttype.h:46
void setValue(QString new_value)
Definition: agenttype.h:51
AgentUpdate()
Definition: agenttype.h:37
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
The FMUnit represents a management unit, i.e.
Definition: fmunit.h:32
Definition: abegrid.h:22