basic swig ver.
parent
239844d7e6
commit
340f21695e
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"cmake.sourceDirectory": "${workspaceFolder}/.",
|
"cmake.sourceDirectory": "${workspaceFolder}/.",
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
|
"*.i": "swiglang",
|
||||||
|
"*.hpp": "cpp",
|
||||||
"vector": "cpp",
|
"vector": "cpp",
|
||||||
"algorithm": "cpp",
|
"algorithm": "cpp",
|
||||||
"chrono": "cpp",
|
"chrono": "cpp",
|
||||||
|
@ -64,7 +66,13 @@
|
||||||
"array": "cpp",
|
"array": "cpp",
|
||||||
"map": "cpp",
|
"map": "cpp",
|
||||||
"list": "cpp",
|
"list": "cpp",
|
||||||
"sstream": "cpp"
|
"sstream": "cpp",
|
||||||
|
"__hash_table": "cpp",
|
||||||
|
"__node_handle": "cpp",
|
||||||
|
"__tree": "cpp",
|
||||||
|
"complex": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"unordered_map": "cpp"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "Enabled"
|
"C_Cpp.errorSquiggles": "Enabled"
|
||||||
}
|
}
|
|
@ -3,8 +3,8 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
std::random_device econ_dev;
|
static std::random_device econ_dev;
|
||||||
std::mt19937 econ_rng(econ_dev());
|
static std::mt19937 econ_rng(econ_dev());
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
// -- Recipient Finders
|
// -- Recipient Finders
|
||||||
|
@ -16,7 +16,7 @@ std::mt19937 econ_rng(econ_dev());
|
||||||
* @param balances Balance vec
|
* @param balances Balance vec
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
int find_participant_random(std::vector<int> &balances) {
|
static int find_participant_random(std::vector<int> &balances) {
|
||||||
// random spend ratio is too costly
|
// random spend ratio is too costly
|
||||||
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,balances.size()-1);
|
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,balances.size()-1);
|
||||||
return dist_len(econ_rng);
|
return dist_len(econ_rng);
|
||||||
|
@ -29,7 +29,7 @@ int find_participant_random(std::vector<int> &balances) {
|
||||||
* @param percent_cutoff Upper N% to decide among
|
* @param percent_cutoff Upper N% to decide among
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
int find_participant_random_wealthy(std::vector<int> &balances, float percent_cutoff = 10) {
|
static int find_participant_random_wealthy(std::vector<int> &balances, float percent_cutoff = 10) {
|
||||||
// random spend ratio is too costly
|
// random spend ratio is too costly
|
||||||
int cutoff = percent_cutoff / 100 * balances.size();
|
int cutoff = percent_cutoff / 100 * balances.size();
|
||||||
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,balances.size()-1);
|
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,balances.size()-1);
|
||||||
|
@ -48,7 +48,7 @@ int find_participant_random_wealthy(std::vector<int> &balances, float percent_cu
|
||||||
* @param spend_ratio Proportion of savings they are willing
|
* @param spend_ratio Proportion of savings they are willing
|
||||||
* to spend
|
* to spend
|
||||||
*/
|
*/
|
||||||
void economic_decision_simple(std::vector<int> &balances, int id, float spend_ratio) {
|
static void economic_decision_simple(std::vector<int> &balances, int id, float spend_ratio) {
|
||||||
// assert(spend_ratio > 0 && spend_ratio <= 1);
|
// assert(spend_ratio > 0 && spend_ratio <= 1);
|
||||||
int total_bal = balances.at(id);
|
int total_bal = balances.at(id);
|
||||||
|
|
||||||
|
@ -68,13 +68,13 @@ void economic_decision_simple(std::vector<int> &balances, int id, float spend_ra
|
||||||
* @param max_spend_ratio max/peak spend ratio
|
* @param max_spend_ratio max/peak spend ratio
|
||||||
* @param bump how much to bump min spend amount from 0
|
* @param bump how much to bump min spend amount from 0
|
||||||
*/
|
*/
|
||||||
void economic_random_age_sin(
|
static void economic_random_age_sin(
|
||||||
std::vector<int> &ages,
|
std::vector<int> &ages,
|
||||||
std::vector<int> &balances,
|
std::vector<int> &balances,
|
||||||
int max_age,
|
int max_age,
|
||||||
int id,
|
int id,
|
||||||
float max_spend_ratio,
|
float max_spend_ratio,
|
||||||
int bump = 0.1
|
float bump = 0.1
|
||||||
) {
|
) {
|
||||||
int recipient_id = find_participant_random(balances);
|
int recipient_id = find_participant_random(balances);
|
||||||
int spendable = round(
|
int spendable = round(
|
||||||
|
@ -85,3 +85,8 @@ void economic_random_age_sin(
|
||||||
balances.at(id) -= spendable;
|
balances.at(id) -= spendable;
|
||||||
balances.at(recipient_id) += spendable;
|
balances.at(recipient_id) += spendable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void economic_random_age_sin() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
void dump_balances_csv(std::vector<int> balances, std::string name) {
|
static void dump_balances_csv(std::vector<int> balances, std::string name) {
|
||||||
std::string csv_data = "Id,Balance\n";
|
std::string csv_data = "Id,Balance\n";
|
||||||
for (int i = 0; i < balances.size(); i++) {
|
for (int i = 0; i < balances.size(); i++) {
|
||||||
csv_data += std::to_string(i+1)+ "," +
|
csv_data += std::to_string(i+1)+ "," +
|
||||||
|
@ -16,7 +16,7 @@ void dump_balances_csv(std::vector<int> balances, std::string name) {
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_balances_and_ages_csv(std::vector<int> balances, std::vector<int> ages, std::string name) {
|
static void dump_balances_and_ages_csv(std::vector<int> balances, std::vector<int> ages, std::string name) {
|
||||||
assert(balances.size() == ages.size());
|
assert(balances.size() == ages.size());
|
||||||
std::string csv_data = "Id,Balance,Age\n";
|
std::string csv_data = "Id,Balance,Age\n";
|
||||||
for (int i = 0; i < balances.size(); i++) {
|
for (int i = 0; i < balances.size(); i++) {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* @param total_duration
|
* @param total_duration
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
int logistic_population_func(int year, int N_o, int N_f, int k, int total_duration) {
|
static int logistic_population_func(int year, int N_o, int N_f, int k, int total_duration) {
|
||||||
// https://en.wikipedia.org//wiki/Logistic_function
|
// https://en.wikipedia.org//wiki/Logistic_function
|
||||||
return N_o + (N_f - N_o) /
|
return N_o + (N_f - N_o) /
|
||||||
(1 + exp(-k * (year - total_duration/2)));
|
(1 + exp(-k * (year - total_duration/2)));
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
std::random_device util_dev;
|
static std::random_device util_dev;
|
||||||
std::mt19937 util_rng(util_dev());
|
static std::mt19937 util_rng(util_dev());
|
||||||
|
|
||||||
int random_item(std::vector<int> items, bool get_id) {
|
static int random_item(std::vector<int> items, bool get_id) {
|
||||||
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,items.size()-1);
|
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,items.size()-1);
|
||||||
int id = dist_len(util_rng);
|
int id = dist_len(util_rng);
|
||||||
return get_id ? id : items[id];
|
return get_id ? id : items[id];
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <matplot/matplot.h>
|
||||||
|
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
#include "population.hpp"
|
#include "population.hpp"
|
||||||
|
@ -19,7 +20,7 @@ enum EstateMode {
|
||||||
INHERITANCE
|
INHERITANCE
|
||||||
};
|
};
|
||||||
|
|
||||||
PopSimpleResult pop_simple(
|
static PopSimpleResult pop_simple(
|
||||||
int duration,
|
int duration,
|
||||||
int max_age,
|
int max_age,
|
||||||
int init_balance_each,
|
int init_balance_each,
|
||||||
|
|
Loading…
Reference in New Issue