commit c31c8308d8920733d20fef2898f5113e7d6d2140 Author: turtlebasket Date: Wed Nov 30 12:18:33 2022 +0900 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07c6b6f --- /dev/null +++ b/.gitignore @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..304dc73 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cmake.sourceDirectory": "${workspaceFolder}/v1", + "files.associations": { + "vector": "cpp" + } +} \ No newline at end of file diff --git a/v1/.gitignore b/v1/.gitignore new file mode 100644 index 0000000..095be9b --- /dev/null +++ b/v1/.gitignore @@ -0,0 +1,5 @@ +* +!CMakeLists.txt +!*.cpp +!*.hpp +!.gitignore diff --git a/v1/CMakeLists.txt b/v1/CMakeLists.txt new file mode 100644 index 0000000..a77de4d --- /dev/null +++ b/v1/CMakeLists.txt @@ -0,0 +1,2 @@ +project(test_econ_model) +add_executable(main main.cpp) diff --git a/v1/main.cpp b/v1/main.cpp new file mode 100644 index 0000000..1107fbc --- /dev/null +++ b/v1/main.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +std::vector ages; +std::vector 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; +}