test-econ-model/v1/main.cpp

58 lines
1.2 KiB
C++
Raw Normal View History

2022-11-29 19:18:33 -08:00
#include <iostream>
#include <vector>
#include <cmath>
#include <random>
std::vector<float> ages;
std::vector<int> balances;
const int N = 10000;
const int DURATION = 1000;
const int MAX_AGE = 100;
const int LOGISTIC_CARRYING_CAPACITY = 100000;
const int LOGISTIC_GROWTH_RATE = 1;
const int LOGISTIC_MIDPOINT = DURATION / 2;
// state mutation funcs
void transfer_balance(int from, int to, int balance) {
balances[from] -= balance;
balances[to] += balance;
}
void kill_even_redist(int id) {
ages.erase(ages.begin()+id);
balances.erase(balances.begin()+id);
}
void kill_inheritance(int id) {
ages.erase(ages.begin()+id);
balances.erase(balances.begin()+id);
}
void frame_quarter() {
for (int i = 0; i < ages.size(); i++) {
ages[i] += 1;
if (ages[i] > MAX_AGE) {
kill_inheritance(i);
}
}
}
// modeling functions
float logistic_func(int year) {
// https://en.wikipedia.org//wiki/Logistic_function
return LOGISTIC_CARRYING_CAPACITY / (1 + (-LOGISTIC_GROWTH_RATE * exp(year - LOGISTIC_MIDPOINT)));
}
int main() {
// init state
for (int i = 0; i < 1000; i++) {
std::cout << logistic_func(i) << std::endl;
}
return 0;
}