initial commit

master
michael 2022-11-30 12:18:33 +09:00
commit c31c8308d8
5 changed files with 86 additions and 0 deletions

16
.gitignore vendored Normal file
View File

@ -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

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"cmake.sourceDirectory": "${workspaceFolder}/v1",
"files.associations": {
"vector": "cpp"
}
}

5
v1/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*
!CMakeLists.txt
!*.cpp
!*.hpp
!.gitignore

2
v1/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
project(test_econ_model)
add_executable(main main.cpp)

57
v1/main.cpp Normal file
View 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;
}