basic swig ver.
parent
239844d7e6
commit
340f21695e
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"cmake.sourceDirectory": "${workspaceFolder}/.",
|
||||
"files.associations": {
|
||||
"*.i": "swiglang",
|
||||
"*.hpp": "cpp",
|
||||
"vector": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"chrono": "cpp",
|
||||
|
@ -64,7 +66,13 @@
|
|||
"array": "cpp",
|
||||
"map": "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"
|
||||
}
|
|
@ -3,8 +3,8 @@
|
|||
#include <random>
|
||||
#include <cmath>
|
||||
|
||||
std::random_device econ_dev;
|
||||
std::mt19937 econ_rng(econ_dev());
|
||||
static std::random_device econ_dev;
|
||||
static std::mt19937 econ_rng(econ_dev());
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// -- Recipient Finders
|
||||
|
@ -16,7 +16,7 @@ std::mt19937 econ_rng(econ_dev());
|
|||
* @param balances Balance vec
|
||||
* @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
|
||||
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,balances.size()-1);
|
||||
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
|
||||
* @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
|
||||
int cutoff = percent_cutoff / 100 * balances.size();
|
||||
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
|
||||
* 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);
|
||||
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 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> &balances,
|
||||
int max_age,
|
||||
int id,
|
||||
float max_spend_ratio,
|
||||
int bump = 0.1
|
||||
float bump = 0.1
|
||||
) {
|
||||
int recipient_id = find_participant_random(balances);
|
||||
int spendable = round(
|
||||
|
@ -85,3 +85,8 @@ void economic_random_age_sin(
|
|||
balances.at(id) -= spendable;
|
||||
balances.at(recipient_id) += spendable;
|
||||
}
|
||||
|
||||
|
||||
static void economic_random_age_sin() {
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <iostream>
|
||||
#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";
|
||||
for (int i = 0; i < balances.size(); i++) {
|
||||
csv_data += std::to_string(i+1)+ "," +
|
||||
|
@ -16,7 +16,7 @@ void dump_balances_csv(std::vector<int> balances, std::string name) {
|
|||
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());
|
||||
std::string csv_data = "Id,Balance,Age\n";
|
||||
for (int i = 0; i < balances.size(); i++) {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* @param total_duration
|
||||
* @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
|
||||
return N_o + (N_f - N_o) /
|
||||
(1 + exp(-k * (year - total_duration/2)));
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#include <vector>
|
||||
#include <random>
|
||||
|
||||
std::random_device util_dev;
|
||||
std::mt19937 util_rng(util_dev());
|
||||
static std::random_device 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);
|
||||
int id = dist_len(util_rng);
|
||||
return get_id ? id : items[id];
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,7 @@
|
|||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <matplot/matplot.h>
|
||||
|
||||
#include "util.hpp"
|
||||
#include "population.hpp"
|
||||
|
@ -19,7 +20,7 @@ enum EstateMode {
|
|||
INHERITANCE
|
||||
};
|
||||
|
||||
PopSimpleResult pop_simple(
|
||||
static PopSimpleResult pop_simple(
|
||||
int duration,
|
||||
int max_age,
|
||||
int init_balance_each,
|
||||
|
|
Loading…
Reference in New Issue