broken
parent
e9f15c8a0a
commit
9226228a1d
|
@ -62,6 +62,8 @@
|
||||||
"stack": "cpp",
|
"stack": "cpp",
|
||||||
"numeric": "cpp",
|
"numeric": "cpp",
|
||||||
"array": "cpp",
|
"array": "cpp",
|
||||||
"map": "cpp"
|
"map": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"sstream": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,16 @@ execute_process(COMMAND bash ./scripts/setup-include.sh)
|
||||||
make_directory(bin)
|
make_directory(bin)
|
||||||
include_directories(include/)
|
include_directories(include/)
|
||||||
|
|
||||||
|
# fetch latest argparse
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
argparse
|
||||||
|
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(argparse)
|
||||||
|
|
||||||
add_executable(pop-simple pop-simple.cpp)
|
add_executable(pop-simple pop-simple.cpp)
|
||||||
|
target_link_libraries(pop-simple argparse)
|
||||||
# add_executable(./bin/fixed-simple fixed-simple.cpp)
|
# add_executable(./bin/fixed-simple fixed-simple.cpp)
|
||||||
# add_executable(./bin/wealth-flow wealth-flow.cpp)
|
# add_executable(./bin/wealth-flow wealth-flow.cpp)
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,21 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <argparse/argparse.hpp>
|
||||||
|
|
||||||
#include "econ.hpp"
|
#include "econ.hpp"
|
||||||
#include "io.hpp"
|
#include "io.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
|
||||||
std::map<std::string, std::string> config;
|
// std::map<std::string, std::string> config;
|
||||||
|
argparse::ArgumentParser program("pop-simple");
|
||||||
|
|
||||||
#define c(a) config[a]
|
#define arg(a) program[a]
|
||||||
#define ci(a) std::stoi(config[a])
|
#define iarg(a) std::stoi(program[a])
|
||||||
#define cf(a) std::stof(config[a])
|
#define farg(a) std::stof(program[a])
|
||||||
|
|
||||||
#define csets(k, v) config[k] = v
|
#define cset(k, v) config[k] = v
|
||||||
#define csetn(k, v) config[k] = std::to_string(v);
|
#define csetn(k, v) config[k] = std::to_string(v);
|
||||||
|
|
||||||
std::vector<int> ages;
|
std::vector<int> ages;
|
||||||
|
@ -71,7 +75,7 @@ void kill_inheritance(int id) {
|
||||||
void age_all(estate_mode mode) {
|
void age_all(estate_mode mode) {
|
||||||
for (int i = 0; i < ages.size(); i++) {
|
for (int i = 0; i < ages.size(); i++) {
|
||||||
ages.at(i) += 1;
|
ages.at(i) += 1;
|
||||||
if (ages.at(i) > ci("MAX_AGE")) {
|
if (ages.at(i) > iarg("MAX_AGE")) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case INHERITANCE:
|
case INHERITANCE:
|
||||||
kill_inheritance(i);
|
kill_inheritance(i);
|
||||||
|
@ -86,8 +90,8 @@ void age_all(estate_mode mode) {
|
||||||
|
|
||||||
int logistic_population_func(int year) {
|
int logistic_population_func(int year) {
|
||||||
// https://en.wikipedia.org//wiki/Logistic_function
|
// https://en.wikipedia.org//wiki/Logistic_function
|
||||||
return ci("N_o") + (ci("N_f") - ci("N_o")) /
|
return iarg("N_o") + (iarg("N_f") - iarg("N_o")) /
|
||||||
(1 + exp(-cf("GROWTH_RATE") * (year - ci("DURATION")/2)));
|
(1 + exp(-farg("GROWTH_RATE") * (year - ci("DURATION")/2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjust_population(int year) {
|
void adjust_population(int year) {
|
||||||
|
@ -95,16 +99,31 @@ void adjust_population(int year) {
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
ages.push_back(1);
|
ages.push_back(1);
|
||||||
balances.push_back(ci("STARTING_BALANCE_NEW"));
|
balances.push_back(iarg("STARTING_BALANCE_NEW"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char* argv[]) {
|
||||||
// set config - make configurable with params later
|
// set config via cli args
|
||||||
|
program.add_argument("estate", "-e")
|
||||||
|
.help("Estate distribution mode (redistribute, inheritance)")
|
||||||
|
.default_value(INHERITANCE);
|
||||||
|
|
||||||
|
program.add_argument("time", "-t")
|
||||||
|
.help("Duration in years of simulation.")
|
||||||
|
.default_value(1000);
|
||||||
|
|
||||||
|
try {
|
||||||
|
program.parse_args(argc, argv);
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error& err) {
|
||||||
|
std::cerr << err.what() << std::endl;
|
||||||
|
std::cerr << program;
|
||||||
|
std::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// model params
|
// model params
|
||||||
csetn("DURATION", 1000);
|
|
||||||
csetn("MAX_AGE", 81);
|
csetn("MAX_AGE", 81);
|
||||||
csetn("INIT_BALANCE_EACH", 5000);
|
csetn("INIT_BALANCE_EACH", 5000);
|
||||||
csetn("STARTING_BALANCE_NEW", 1000); // effectively inflation rate
|
csetn("STARTING_BALANCE_NEW", 1000); // effectively inflation rate
|
||||||
|
@ -158,7 +177,16 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::sort(balances.begin(), balances.end(), std::greater<int>());
|
// std::sort(balances.begin(), balances.end(), std::greater<int>());
|
||||||
dump_balances_and_ages_csv(balances, ages, "pop-balances-out");
|
std::string ext;
|
||||||
|
switch (emode) {
|
||||||
|
case EVEN_REDIST:
|
||||||
|
ext = "even";
|
||||||
|
break;
|
||||||
|
case INHERITANCE:
|
||||||
|
ext = "inheritance";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dump_balances_and_ages_csv(balances, ages, "pop-simple-results-"+ext);
|
||||||
std::cout << "Finished with " << balances.size() << " balances\n";
|
std::cout << "Finished with " << balances.size() << " balances\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ ! -f include/argparse/argparse.hpp ]; then
|
|
||||||
mkdir -p include/argparse
|
|
||||||
curl https://raw.githubusercontent.com/p-ranav/argparse/997da9255618311d1fcb0135ce86022729d1f1cb/include/argparse/argparse.hpp \
|
|
||||||
-o include/argparse/argparse.hpp
|
|
||||||
fi
|
|
|
@ -1,9 +1,20 @@
|
||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
with open("../pop-balances-out.csv", "r") as file:
|
with open("../pop-balances-out-inheritance.csv", "r") as file:
|
||||||
results = pd.read_csv(file)
|
pop_inheritance_results = pd.read_csv(file)
|
||||||
|
|
||||||
# balance avg
|
plt.hist(pop_inheritance_results.loc[:,"Balance"].sort_values(), bins=30)
|
||||||
plt.hist(results.loc[:,"Balance"].sort_values(), bins=30)
|
plt.title("Wealth distribution (Inheritance)")
|
||||||
|
plt.xlabel("dollarydoos")
|
||||||
|
plt.ylabel("participants")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
with open("../pop-balances-out-redist.csv", "r") as file:
|
||||||
|
pop_redist_results = pd.read_csv(file)
|
||||||
|
|
||||||
|
plt.hist(pop_redist_results.loc[:,"Balance"].sort_values(), bins=30)
|
||||||
|
plt.title("Wealth distribution (")
|
||||||
|
plt.xlabel("dollarydoos")
|
||||||
|
plt.ylabel("participants")
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
Loading…
Reference in New Issue