initial commit
commit
c31c8308d8
|
@ -0,0 +1,16 @@
|
|||
# output output
|
||||
build/
|
||||
|
||||
# cmake general
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
Footer
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"cmake.sourceDirectory": "${workspaceFolder}/v1",
|
||||
"files.associations": {
|
||||
"vector": "cpp"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
*
|
||||
!CMakeLists.txt
|
||||
!*.cpp
|
||||
!*.hpp
|
||||
!.gitignore
|
|
@ -0,0 +1,2 @@
|
|||
project(test_econ_model)
|
||||
add_executable(main main.cpp)
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue