Struct piston_mix_economy::Economy
[−]
[src]
pub struct Economy { pub players: Vec<f64>, pub tax: f64, pub start_fortune: f64, }
Represents the whole economy.
Each player has a normalized fortune against an upper soft limit. The difference from the upper limit is charging the economy.
The tax tells how fast to burn money of fortunes above the soft limit, and how much to give each player below the soft limit per time interval.
The start fortune is given to new players.
Call Economy::update
at regular time intervals to distribute wealth,
using a fixed tax rate. The Gini index can vary depending on economic activity.
Call Economy::solve
at regular time intervals to distribute wealth,
using a target Gini coefficient.
The tax is automatically adjusted to meet the target.
Fields
players: Vec<f64>
The fortunes of the players.
tax: f64
The progressive tax factor, as the square root of fortune above 1.
start_fortune: f64
The initial fortune. Should be in the range [0, 1].
Methods
impl Economy
[src]
fn new(tax: f64, start_fortune: f64, players: usize) -> Economy
Creates a new economy.
fn add_player(&mut self) -> usize
Adds a player to the economy.
fn min_max(&self) -> (f64, f64)
Finds the minimum and maximum fortune.
fn gini(&self) -> f64
Find the Gini coefficient (see https://en.wikipedia.org/wiki/Gini_coefficient).
fn transaction(&mut self, from: usize, to: usize, amount: f64) -> Result<(), ()>
Does a transaction between two people.
fn update(&mut self)
Updates the economy using the fixed tax rate. The Gini index can vary depending on economic activity.
fn solve(&mut self, target_gini: f64, smooth_target: f64, min_tax: f64)
Updates the economy using a target Gini coefficient. The tax is automatically adjusted to meet the target. Uses convergent binary search to find the tax.
The solver is less accurate for high Gini (~0.5
or higher) in some cases.
A very low Gini (<0.1
) might not work at all, because the algorithm
is incentivizing (players that have more gets more below the upper soft limit).
The smooth_target
parameter is a value in range [0.5, 1)
.
0.5
gives binary search behavior, which assumes strict
monotonic Gini (tax should be lowered if target Gini is above).
Higher values weakens the assumption, interpreted as
the mix-algorithm "tends to have" monotonic Gini.
The min_tax
parameter is a value usually above 0,
to prevent the solver from getting stuck in 0% scenarios.
Trait Implementations
impl Clone for Economy
[src]
fn clone(&self) -> Economy
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more