Struct piston_mix_economy::Economy
source · pub struct Economy {
pub players: Vec<f64>,
pub tax: f64,
pub start_fortune: f64,
}
Expand description
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].
Implementations§
source§impl Economy
impl Economy
sourcepub fn add_player(&mut self) -> usize
pub fn add_player(&mut self) -> usize
Adds a player to the economy.
sourcepub fn gini(&self) -> f64
pub fn gini(&self) -> f64
Find the Gini coefficient (see Wikipedia article).
sourcepub fn transaction(
&mut self,
from: usize,
to: usize,
amount: f64
) -> Result<(), ()>
pub fn transaction( &mut self, from: usize, to: usize, amount: f64 ) -> Result<(), ()>
Does a transaction between two people.
sourcepub fn update(&mut self)
pub fn update(&mut self)
Updates the economy using the fixed tax rate. The Gini index can vary depending on economic activity.
sourcepub fn solve(&mut self, target_gini: f64, smooth_target: f64, min_tax: f64)
pub 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.