Compare commits
3 Commits
158e406f7c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 239844d7e6 | |||
| e9ceb0c953 | |||
| e2573bc470 |
@@ -1,13 +1,20 @@
|
||||
# cmake_minimum_required(VERSION 3.25)
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(sim_econ_model)
|
||||
include_directories(include/)
|
||||
set(CMAKE_CXX_COMPILER /usr/bin/g++)
|
||||
|
||||
# if (APPLE)
|
||||
# set(CMAKE_CXX_COMPILER /usr/bin/clang++)
|
||||
# set(COMPILE_FLAGS "-Wl -export_dynamic")
|
||||
# else(LINUX)
|
||||
# set(CMAKE_CXX_COMPILER /usr/bin/g++)
|
||||
# endif()
|
||||
|
||||
find_package(SWIG 4.0 REQUIRED COMPONENTS python)
|
||||
include(UseSWIG)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# find_package(PythonLibs 3.10 EXACT REQUIRED)
|
||||
find_package(PythonLibs)
|
||||
include_directories(${PYTHON_INCLUDE_PATH})
|
||||
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user