initial commit
This commit is contained in:
5
v1/.gitignore
vendored
Normal file
5
v1/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
*
|
||||
!CMakeLists.txt
|
||||
!*.cpp
|
||||
!*.hpp
|
||||
!.gitignore
|
||||
2
v1/CMakeLists.txt
Normal file
2
v1/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
project(test_econ_model)
|
||||
add_executable(main main.cpp)
|
||||
57
v1/main.cpp
Normal file
57
v1/main.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user