-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbehaviour.h
More file actions
367 lines (288 loc) · 9.71 KB
/
behaviour.h
File metadata and controls
367 lines (288 loc) · 9.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#ifndef BEHAVIOUR_H
#define BEHAVIOUR_H
#include <iostream>
#include <map>
#include <QObject>
#include <QVector>
#include <QtCharts/QLineSeries>
#include <QSettings>
#include <QMap>
class Account;
class Domain;
class Government;
class Worker;
class Firm;
class Bank;
QT_CHARTS_USE_NAMESPACE
// Only potentially conditional parameters are listed here
enum class ParamType {
procurement,
emp_rate,
prop_con,
inc_tax_rate,
inc_thresh,
sales_tax_rate,
firm_creation_prob,
recoup,
dedns,
unemp_ben_rate,
active_pop,
distrib,
prop_inv,
boe_int,
bus_int,
loan_prob,
};
class Behaviour : public QObject
{
Q_OBJECT
friend class MainWindow;
public:
static Behaviour *createBehaviour(QString name);
// List of all Behaviours. When a new Behaviour is created it is automatically
// added to this list.
static QList<Behaviour*> behaviours;
// Get the Behaviour having the given name, returning a pointer to it, and
// set it as current. Requires loadAllBehaviours() to have been called
// (which loads all the Behaviours into QList<Behaviour*> behaviours).
static Behaviour *getBehaviour(QString name);
static Behaviour *currentBehaviour;
inline static Behaviour *getDefaultBehaviour() {
return defaultBehaviour;
}
QString name();
// ----------------
// Practically everything from here on should go into the Domain class
// ----------------
void run(bool randomised = false);
void restart();
int getIters(); // number of iterations (periods)
int getStartPeriod();
// NEXT: Allow multi-domain behaviours
// We need to allow any number of Government instances (each owned by a
// different Domain), with each account directly or indirectly registered
// with the domain in which it pays its taxes. Later, we may allow an
// individual account to be associated with more than one domain, in which
// case it will need to include a mechanism for converting currencies.
// This may complicate things a lot and can be deferred for now.
Government *gov(); // the Government created and owned by the domain
Bank *bank(); // the central bank (generally owned by the Government)
int period();
int min_value(int);
int max_value(int);
int total(int);
Firm *createFirm(bool state_supported = false);
Firm *selectRandomFirm(Firm *exclude = nullptr);
enum class Status {any, employed, unemployed};
struct HireData {
int num;
int wages_due;
} hire_data;
double hireSome(Firm *employer, double wage, int period, int number_to_hire);
Worker *hire(Firm *employer, double wage, int period);
void fire(Worker *w, int period);
enum Reason {
for_benefits,
for_bonus
};
int getWageBill(Firm *employer, bool include_dedns = false);
int payWages(Firm *payer, int period);
bool randomCheck(int chances, int in);
double payWorkers(double amount, Account *source, Reason reason);
// ------------------------------------------------------------------------
// Properties
// ------------------------------------------------------------------------
enum class Property
{
current_period,
pop_size, // although constant, we treat this as a property
// as it's sometimes useful to show it on a graph
gov_exp,
bens_paid,
gov_exp_plus,
gov_recpts,
deficit,
deficit_pc,
gov_bal,
num_firms,
num_emps,
pc_emps,
num_unemps,
pc_unemps,
pc_active,
num_gov_emps,
num_hired,
num_fired,
prod_bal,
wages,
consumption,
bonuses,
dedns,
inc_tax,
sales_tax,
dom_bal,
amount_owed,
bus_size,
hundred,
zero,
procurement,
productivity,
rel_productivity,
unbudgeted,
investment,
gdp,
profit,
num_properties
};
Property getProperty(int); // return the property with the given value
QList<Property> prop_list; // to simplify iterations
// This gives us a set of pointers to line series, ordered by the Properties
// they are associated with. E.g., when iterating, the series for bens_paid
// will be encountered before the series for gov_recpts. Order is
// significant as it allows us to store values and use them in later
// composite properties (e,g, deficit).
QMap<Property, QLineSeries*> series;
QMap<Property, bool> scalable;
int _num_properties = static_cast<int>(Property::num_properties);
int min_val[static_cast<int>(Property::num_properties)];
int max_val[static_cast<int>(Property::num_properties)];
int sum[static_cast<int>(Property::num_properties)];
// Retrieve the current (periodic) value associated with a given Property
double getPropertyVal(Property p);
// These are the functions that actually interrogate the components of the
// model to evaluate its properties
int getNumEmployedBy(Firm *firm);
int getNumEmployed();
int getNumUnemployed(); // were employed but now unemployed
int getNumJustFired();
int getNumHired();
int getNumFired();
double getProdBal();
double getWagesPaid();
double getInvestment();
double getPurchasesMade();
double getSalesReceipts();
double getBonusesPaid();
double getDednsPaid();
double getIncTaxPaid();
double getSalesTaxPaid();
double getWorkersBal(Behaviour::Status status);
double getAmountOwed();
double getProcurementExpenditure();
int population();
// ------------------------------------------------------------------------
// Parameters
// ------------------------------------------------------------------------
int getActivePop(); // proportion of population that is economically active
double getProcurement(); //direct government expenditure
double getTargetEmpRate(); // target rate of employment (%)
double getStdWage(); // standard wage (currency units per employee per period)
double getPropCon(); // propensity to consume (%)
double getIncTaxRate(); // income tax rate (%)
double getIncomeThreshold(); // 100% of threshold is spent regardless of prop con
double getSalesTaxRate(); // sales tax rate (%)
double getPreTaxDedns(); // pre-tax deductions (%)
double getCapexRecoupTime(); // number of periods to recoup capex
double getFCP(); // firm creaton probability (%)
double getUBR(); // unemployment benefit rate (% of std wage)
double getPropInv(); // propensity to invest
double getDistributionRate(); // funds kept in reserve for next period (%)
double getBoeRate(); // BoE lending rate
double getBusRate(); // retail lending rate
double getLoanProb();
double getGini();
double getProductivity();
static int getId();
int num_hired;
int num_fired;
int num_just_fired;
private:
QVector<Firm*> firms;
QVector<Worker*> workers;
// We only need one bank
// QVector<Bank*> banks;
int _period;
Government *_gov;
Bank *_bank;
double _gini;
// Constants
QString _name;
QString _notes;
int _iterations;
int _population;
int _startups;
int _first_period;
double _scale;
double _std_wage;
// See getPropertyValue
int _num_firms, _num_emps, _num_unemps, _num_gov_emps, _num_hired,
_num_fired, _pop_size;
double _exp, _bens, _rcpts, _gov_bal, _prod_bal, _wages, _consumption,
_bonuses, _dedns, _inc_tax, _sales_tax, _dom_bal, _loan_prob,
_amount_owed, _deficit, _pc_active, _bus_size, _proc_exp,
_productivity, _rel_productivity, _investment, _gdp, _profit;
protected:
Behaviour(QString behaviourName);
double scale(Property p);
double gini();
double productivity();
enum class Opr
{
invalid_op = -1,
eq,
neq,
lt,
gt,
leq,
geq
};
struct Condition
{
// If property is set to zero the condition is deemed to
// apply regardless of the values of opr and val. This will be the
// case for the default parameter set but would be invalid otherwise.
Property property = Property::zero;
Opr opr;
int val; // possibly extend to allow expressions later
};
struct Pair
{
bool is_set = false;
int val;
};
struct Params
{
Condition condition;
Pair procurement;
Pair iters;
Pair count;
Pair emp_rate;
Pair prop_con;
Pair inc_tax_rate;
Pair inc_thresh;
Pair sales_tax_rate;
Pair firm_creation_prob;
Pair dedns;
Pair unemp_ben_rate;
Pair active_pop;
Pair distrib;
Pair prop_inv;
Pair boe_int;
Pair bus_int;
Pair loan_prob;
Pair recoup;
Pair invalid; // Just a marker -- value immaterial
};
bool applies(Condition);
bool compare(int lhs, int rhs, Opr op);
QVector<Params*> parameterSets;
int numParameterSets;
static QMap<ParamType,QString> parameterKeys;
// Params *default_parameters;
int getParameterVal(ParamType type);
bool isParamSet(ParamType t, int n);
void readParameters(); // get parameters for this Behaviour from settings
static Behaviour *createDefaultBehaviour();
static Behaviour *defaultBehaviour;
};
#endif // BEHAVIOUR_H