iLand
scheduler.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 SCHEDULER_H
21#define SCHEDULER_H
22#include <QList>
23#include <QHash>
24
25#include "activity.h"
26class Expression;
27
28namespace ABE {
29class FMStand; // forward
30class FMUnit; // forward
31
45
46 void setup(QJSValue jsvalue);
47 static QStringList mAllowedProperties;
48};
49
56{
57public:
58 Scheduler(FMUnit* unit) { mUnit = unit; mExtraHarvest=0.; mFinalCutTarget=0.; mEnabled=false; }
60
61 void setEnabled(bool enabled) { mEnabled = enabled; }
62 bool enabled() const { return mEnabled; }
63
64
70 void addTicket(FMStand *stand, ActivityFlags *flags, double prob_schedule, double prob_execute);
71
74 int clearItemsOfStand(const FMStand *stand);
75
78 void run();
79
81 void resetHarvestCounter() { mExtraHarvest = 0.; }
82
85 bool forceHarvest(const FMStand *stand, const int max_years);
86
89 void addExtraHarvest(const FMStand *stand, const double volume, HarvestType type);
90
93 double plannedHarvests(double &rFinal, double &rThinning);
94
97 void setHarvestTarget(double target_m3_ha, double thinning_target_m3_ha) { mFinalCutTarget = std::max(target_m3_ha,0.01);
98 mThinningTarget = std::max(thinning_target_m3_ha,0.01); }
99 double harvestTarget() const { return mFinalCutTarget; }
100
103 double scoreOf(const int stand_id) const;
104 QStringList info(const int stand_id) const;
106 void dump() const;
107
108private:
109 void updateCurrentPlan();
110 class SchedulerItem {
111 public:
112 SchedulerItem(): stand(nullptr), score(0.), scheduledYear(-1) {}
113 bool operator<(const SchedulerItem &item);
114 void calculate();
115 FMStand *stand;
116 double harvest;
117 double harvestPerHa;
118 double scheduleScore;
119 double harvestScore;
120 double score;
121 HarvestType harvestType;
122 int enterYear;
123 int optimalYear;
124 int scheduledYear;
125 int forbiddenTo;
126 ActivityFlags *flags;
127 };
128 struct ItemComparator
129 {
130 bool operator()( const SchedulerItem *lx, const SchedulerItem *rx ) const;
131 };
132 QList<SchedulerItem*> mItems;
133 QMultiHash<int, SchedulerItem*> mSchedule;
135 SchedulerItem* item(const int stand_id) const;
136 FMUnit *mUnit;
137 double mExtraHarvest;
138 double mFinalCutTarget;
139 double mThinningTarget;
140 bool mEnabled;
141
142 static const int MAX_YEARS = 20;
143 friend class UnitOut;
144};
145
146
147
148} // namespace
149#endif // SCHEDULER_H
Activity meta data (enabled, active, ...) that need to be stored per stand.
Definition: activity.h:110
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
The Scheduler class schedules the forest management activities on a planning unit.
Definition: scheduler.h:56
Scheduler(FMUnit *unit)
Definition: scheduler.h:58
void resetHarvestCounter()
at the end of the year, reset the salvage harvests
Definition: scheduler.h:81
double harvestTarget() const
Definition: scheduler.h:99
double plannedHarvests(double &rFinal, double &rThinning)
return the total amount of planned harvests in the next planning period (10yrs) (total=false) if 'tot...
Definition: scheduler.cpp:293
int clearItemsOfStand(const FMStand *stand)
clear all items from the scheduler from a given stand returns the number of cleared items.
Definition: scheduler.cpp:70
QStringList info(const int stand_id) const
Definition: scheduler.cpp:325
void dump() const
write state of the scheduler to the console
Definition: scheduler.cpp:475
void run()
executes the scheduler for the planning unit.
Definition: scheduler.cpp:86
bool enabled() const
Definition: scheduler.h:62
void addExtraHarvest(const FMStand *stand, const double volume, HarvestType type)
tell the scheduler about extra harvests (that should be considered in the scheduling) volume: total v...
Definition: scheduler.cpp:287
bool forceHarvest(const FMStand *stand, const int max_years)
prepone a stand if in queue for the given stand.
Definition: scheduler.cpp:273
HarvestType
Definition: scheduler.h:59
@ EndHarvest
Definition: scheduler.h:59
@ Thinning
Definition: scheduler.h:59
@ Salvage
Definition: scheduler.h:59
void addTicket(FMStand *stand, ActivityFlags *flags, double prob_schedule, double prob_execute)
add an planned activity for a given stand.
Definition: scheduler.cpp:43
void setEnabled(bool enabled)
Definition: scheduler.h:61
double scoreOf(const int stand_id) const
get current score for stand 'id' return -1 if stand is invalid, 0..1 for probabilities,...
Definition: scheduler.cpp:310
void setHarvestTarget(double target_m3_ha, double thinning_target_m3_ha)
set the harvest target for the unit (m3/ha) for the current year.
Definition: scheduler.h:97
Definition: unitout.h:26
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
Definition: abegrid.h:22
SchedulerOptions store agent-specific options.
Definition: scheduler.h:34
void setup(QJSValue jsvalue)
Definition: scheduler.cpp:536
double useSustainableHarvest
scaling factor (0..1), 1 if scheduler used by agent (exclusively), 0: bottom up, linearly scaled in b...
Definition: scheduler.h:37
static QStringList mAllowedProperties
Definition: scheduler.h:47
double harvestIntensity
multiplier for the "sustainable" harvest level
Definition: scheduler.h:41
double scheduleRebounceDuration
number of years for which deviations from the planned volume are split into
Definition: scheduler.h:42
double deviationDecayRate
factor to reduce accumulated harvest deviation
Definition: scheduler.h:43
double maxHarvestLevel
multiplier to define the maximum overshoot over the planned volume (e.g. 1.2 -> 20% max....
Definition: scheduler.h:40
double maxAbsoluteHarvest
maximum harvest (only used if scheduler is disabled). Scheduler execution stops when level is surpass...
Definition: scheduler.h:44
SchedulerOptions()
Definition: scheduler.h:35
bool useScheduler
true, if the agent is using the scheduler at all
Definition: scheduler.h:36
double minScheduleHarvest
minimum amount of m3/ha*yr that should be scheduled
Definition: scheduler.h:38
double maxScheduleHarvest
the maximum number of m3/ha*yr that should be scheduled
Definition: scheduler.h:39