Subversion Repositories public iLand

Rev

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

Rev Author Line No. Line
671 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
********************************************************************************************/
19
 
290 werner 20
#ifndef RANDOMTOOLS_H
21
#define RANDOMTOOLS_H
289 werner 22
 
23
#include <QtCore/QString>
24
 
25
// RandomIndex: get indicies in a random order
26
class RandomIndex
27
{
28
public:
29
        RandomIndex(int aCount); ///< creates a index with aCount entries.
30
        ~RandomIndex();
31
        bool next(); ///< retrieve next index. return false if all indices used.
32
        int index() const { return mIndex; } ///< retrieve (random) index
33
private:
34
        int mCount;
901 werner 35
        int mIndex; ///< currently selected
289 werner 36
        char *mField;
37
        int  mRemaining;
38
};
39
 
40
class RandomWeighted
41
{
42
public:
43
        RandomWeighted();
44
        ~RandomWeighted();
45
        void setup(const int gridSize);
46
        void setWeight(const int index, const int value);
47
        int get();
48
        double getRelWeight(const int index);
49
        double getRelWeight(const int from, const int to);
50
private:
51
        int *mGrid;
52
        int mSize;
53
        int mMemorySize;
54
        int mMaxVal;
55
        bool mUpdated;
56
        void updateValues();
57
 
58
};
290 werner 59
 
289 werner 60
class Expression;
61
class RandomCustomPDF
62
{
63
public:
64
        RandomCustomPDF();
65
        RandomCustomPDF(const QString &densityFunction){ mExpression=0; setup(densityFunction);}
66
        ~RandomCustomPDF();
67
        void setup(const QString &funcExpr, const double lowerBound=0., const double upperBound=1., const bool isSumFunc=false, const int stepCount=100);
290 werner 68
        // properties
69
        const QString &densityFunction() const { return mFunction; }
289 werner 70
        // operation
71
        double get(); ///< get a random number
72
        double getProbOfRange(const double lowerBound, const double upperBound); ///< get probability of random numbers between given bounds.
73
private:
290 werner 74
        QString mFunction;
289 werner 75
        RandomWeighted mRandomIndex;
76
        Expression *mExpression;
77
        int mSteps;
78
        double mLowerBound, mUpperBound;
79
        double mDeltaX;
80
        bool mSumFunction;
81
};
82
 
83
 
290 werner 84
#endif // RANDOMTOOLS_H