Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1033 werner 1
/********************************************************************************************
2
**    iLand - an individual based forest landscape and disturbance model
3
**    http://iland.boku.ac.at
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
********************************************************************************************/
807 werner 19
#ifndef FORESTMANAGEMENTENGINE_H
20
#define FORESTMANAGEMENTENGINE_H
811 werner 21
#include <QMultiMap>
870 werner 22
#include <QVector>
808 werner 23
 
909 werner 24
#include "abegrid.h"
870 werner 25
 
26
class QJSEngine; // forward
873 werner 27
class MapGrid; // forward
1070 werner 28
class ResourceUnit; // forward
904 werner 29
class Tree; // forward
870 werner 30
 
904 werner 31
 
907 werner 32
namespace ABE {
870 werner 33
 
811 werner 34
class FMUnit; // forward
35
class FMStand; // forward
870 werner 36
class FMSTP; // forward
811 werner 37
class Agent; // forward
38
class AgentType; // forward
815 werner 39
class FomeScript; // forward
40
 
807 werner 41
/// the FOrestManagementEngine is the container for the agent based forest management engine.
42
class ForestManagementEngine
43
{
44
public:
808 werner 45
    // life cycle
807 werner 46
    ForestManagementEngine();
815 werner 47
    ~ForestManagementEngine();
884 werner 48
    // engine instance (singleton)
815 werner 49
    static ForestManagementEngine *instance() { if (singleton_fome_engine) return singleton_fome_engine; singleton_fome_engine = new ForestManagementEngine; return singleton_fome_engine; }
884 werner 50
    /// link to stand grid
873 werner 51
    static const MapGrid *standGrid();
934 werner 52
 
53
    // setup
54
    void setup(); ///< setup data structures
55
    void initialize(); ///< run initial stp
811 werner 56
    void clear(); ///< delete all objects and free memory
901 werner 57
    void abortExecution(const QString &message);
58
    bool isCancel() const { return mCancel; }
1089 werner 59
    void runOnInit(bool before_init); ///< run javascript code that can be used to initialize forest stands
875 werner 60
 
61
    // main function
876 werner 62
    void run(int debug_year=-1);
875 werner 63
 
808 werner 64
    // properties
875 werner 65
    int currentYear() { return mCurrentYear; }
815 werner 66
    /// access to the "global" Javascript engine
67
    static QJSEngine *scriptEngine();
68
    FomeScript *scriptBridge() const {return mScriptBridge; }
808 werner 69
 
914 werner 70
    // setting up agents and stps
938 werner 71
    /// add a stand treatment programme to the list of programs.
870 werner 72
    void addSTP(FMSTP* stp) { mSTP.push_back(stp);}
938 werner 73
    /// add an agent type (called from JS)
74
    void addAgentType(AgentType* at) { mAgentTypes.append(at);}
75
    /// add an agent (called from JS)
76
    void addAgent(Agent *agent) { mAgents.append(agent);}
77
    /// return the agent type with the name 'name' or NULL
78
    AgentType *agentType(const QString &name);
79
    /// return the Agent with the name 'name' or NULL
80
    Agent *agent(const QString &name);
914 werner 81
 
938 werner 82
 
873 werner 83
    /// retrieve pointer to stand treatment programme. return 0-pointer if not available.
84
    FMSTP *stp(QString stp_name) const;
884 werner 85
    /// get stand with id 'stand_id'. Return 0 if not found.
86
    FMStand *stand(int stand_id) const;
875 werner 87
    //QVector<FMStand*> stands() const {return mStands; }
977 werner 88
    const QMultiMap<FMUnit*, FMStand*> &stands() const {return mUnitStandMap; }
89
    const QVector<FMUnit*> &units() const { return mUnits; }
1059 werner 90
    QStringList standIds() const;
808 werner 91
    // functions
904 werner 92
 
93
    /// called by iLand for every tree that is removed/harvested/died due to disturbance.
1064 werner 94
    void notifyTreeRemoval(Tree* tree, int reason);
1070 werner 95
    /// called when bark beetle are likely going to spread
1157 werner 96
    bool notifyBarkbeetleAttack(const ResourceUnit *ru, const double generations, int n_infested_px);
904 werner 97
 
914 werner 98
    ///
99
    FMStand *splitExistingStand(FMStand *stand);
100
 
815 werner 101
    /// evalaute forest management activities and select fitting activities for each forest stand
808 werner 102
    void test();
896 werner 103
    QStringList evaluateClick(const QPointF coord, const QString &grid_name);
808 werner 104
 
867 werner 105
 
808 werner 106
private:
914 werner 107
    static int mMaxStandId;
873 werner 108
    void setupScripting();
903 werner 109
    void prepareRun();
904 werner 110
    void finalizeRun();
915 werner 111
    void setupOutputs();
958 werner 112
    void runJavascript();
903 werner 113
 
815 werner 114
    static ForestManagementEngine *singleton_fome_engine;
875 werner 115
    int mCurrentYear; ///< current year of the simulation (=year of the model)
811 werner 116
 
870 werner 117
    QVector<FMSTP*> mSTP;
118
 
815 werner 119
    // scripting bridge (accessing model properties from javascript)
120
    FomeScript *mScriptBridge;
121
 
811 werner 122
    // forest management units
123
    QVector<FMUnit*> mUnits; ///< container for forest management units
124
    // mapping of stands to units
125
    QMultiMap<FMUnit*, FMStand*> mUnitStandMap;
873 werner 126
    QVector<FMStand*> mStands;
914 werner 127
    QHash<int, FMStand*> mStandHash;
811 werner 128
 
129
    // agents
130
    QVector<AgentType*> mAgentTypes; ///< collection of agent types
131
    QVector<Agent*> mAgents; ///< collection of all agents (individuals)
873 werner 132
 
133
    // grids, visuals, etc.
882 werner 134
    Grid<FMStand*> mFMStandGrid;
909 werner 135
    ABELayers mStandLayers;
901 werner 136
 
137
    bool mCancel;
914 werner 138
    bool mStandLayoutChanged;
901 werner 139
    QString mLastErrorMessage;
915 werner 140
 
141
    //
142
    friend class UnitOut;
807 werner 143
};
144
 
870 werner 145
 
146
} // namespace
807 werner 147
#endif // FORESTMANAGEMENTENGINE_H