iLand
random.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 RANDOMTOOLS_H
21#define RANDOMTOOLS_H
22
23#include <QtCore/QString>
24
25// RandomIndex: get indicies in a random order
27{
28public:
29 RandomIndex(int aCount);
31 bool next();
32 int index() const { return mIndex; }
33private:
34 int mCount;
35 int mIndex;
36 char *mField;
37 int mRemaining;
38};
39
41{
42public:
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);
50private:
51 int *mGrid;
52 int mSize;
53 int mMemorySize;
54 int mMaxVal;
55 bool mUpdated;
56 void updateValues();
57
58};
59
60class Expression;
62{
63public:
65 RandomCustomPDF(const QString &densityFunction){ mExpression=0; setup(densityFunction);}
67 void setup(const QString &funcExpr, const double lowerBound=0., const double upperBound=1., const bool isSumFunc=false, const int stepCount=100);
68 // properties
69 const QString &densityFunction() const { return mFunction; }
70 // operation
71 double get();
72 double getProbOfRange(const double lowerBound, const double upperBound);
73private:
74 QString mFunction;
75 RandomWeighted mRandomIndex;
76 Expression *mExpression;
77 int mSteps;
78 double mLowerBound, mUpperBound;
79 double mDeltaX;
80 bool mSumFunction;
81};
82
83
84#endif // RANDOMTOOLS_H
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
numbers with a user defined probaility density function.
Definition: random.h:62
~RandomCustomPDF()
Definition: random.cpp:189
RandomCustomPDF(const QString &densityFunction)
Definition: random.h:65
double getProbOfRange(const double lowerBound, const double upperBound)
get probability of random numbers between given bounds.
Definition: random.cpp:252
const QString & densityFunction() const
Definition: random.h:69
RandomCustomPDF()
Definition: random.cpp:185
void setup(const QString &funcExpr, const double lowerBound=0., const double upperBound=1., const bool isSumFunc=false, const int stepCount=100)
setup of the properites of the RandomCustomPDF.
Definition: random.cpp:202
double get()
get a random number
Definition: random.cpp:238
index of a given size in a random order.
Definition: random.h:27
~RandomIndex()
Definition: random.cpp:47
int index() const
retrieve (random) index
Definition: random.h:32
RandomIndex(int aCount)
creates a index with aCount entries.
Definition: random.cpp:34
bool next()
retrieve next index. return false if all indices used.
Definition: random.cpp:53
Definition: random.h:41
int get()
Definition: random.cpp:115
RandomWeighted()
Definition: random.cpp:78
void setup(const int gridSize)
Definition: random.cpp:85
~RandomWeighted()
Definition: random.cpp:101
double getRelWeight(const int index)
Definition: random.cpp:129
void setWeight(const int index, const int value)
Definition: random.cpp:107