more stuff
parent
e9ceb0c953
commit
239844d7e6
|
@ -1,10 +1,45 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
|
||||
std::random_device econ_dev;
|
||||
std::mt19937 econ_rng(econ_dev());
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// -- Recipient Finders
|
||||
// ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Find & return random participant
|
||||
*
|
||||
* @param balances Balance vec
|
||||
* @return int
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find & return random participant
|
||||
*
|
||||
* @param balances Balance vec
|
||||
* @param percent_cutoff Upper N% to decide among
|
||||
* @return int
|
||||
*/
|
||||
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);
|
||||
return dist_len(econ_rng);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// -- Spend Decisions
|
||||
// ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Simple random economic spend decision
|
||||
*
|
||||
|
@ -17,24 +52,36 @@ void economic_decision_simple(std::vector<int> &balances, int id, float spend_ra
|
|||
// assert(spend_ratio > 0 && spend_ratio <= 1);
|
||||
int total_bal = balances.at(id);
|
||||
|
||||
// random spend ratio is too costly
|
||||
// std::uniform_int_distribution<std::mt19937::result_type> dist_spend_ratios(0,10000 * spend_ratio);
|
||||
std::uniform_int_distribution<std::mt19937::result_type> dist_len(0,balances.size()-1);
|
||||
|
||||
int spendable = spend_ratio * total_bal;
|
||||
int recipient_id = dist_len(econ_rng);
|
||||
int recipient_id = find_participant_random(balances);
|
||||
balances.at(id) -= spendable;
|
||||
balances.at(recipient_id) += spendable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief balances vec
|
||||
* @brief Sin-based varying spend output based on age. Peaks in midlife
|
||||
*
|
||||
* @param ages Ages vec
|
||||
* @param balances Balances vec
|
||||
* @param id ID of participant making decision
|
||||
* @param id ID of participant making decision
|
||||
* @param max_spend_ratio max/peak spend ratio
|
||||
* @param bump how much to bump min spend amount from 0
|
||||
*/
|
||||
void economic_decision_tiered(std::vector<int> &balances, int id, float max_spend_ratio) {
|
||||
|
||||
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
|
||||
) {
|
||||
int recipient_id = find_participant_random(balances);
|
||||
int spendable = round(
|
||||
max_spend_ratio *
|
||||
sin(ages[id] / max_age) +
|
||||
bump)
|
||||
;
|
||||
balances.at(id) -= spendable;
|
||||
balances.at(recipient_id) += spendable;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue