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

source

pub fn new(tax: f64, start_fortune: f64, players: usize) -> Economy

Creates a new economy.

source

pub fn add_player(&mut self) -> usize

Adds a player to the economy.

source

pub fn min_max(&self) -> (f64, f64)

Finds the minimum and maximum fortune.

source

pub fn gini(&self) -> f64

Find the Gini coefficient (see Wikipedia article).

source

pub fn transaction( &mut self, from: usize, to: usize, amount: f64 ) -> Result<(), ()>

Does a transaction between two people.

source

pub fn update(&mut self)

Updates the economy using the fixed tax rate. The Gini index can vary depending on economic activity.

source

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.

Trait Implementations§

source§

impl Clone for Economy

source§

fn clone(&self) -> Economy

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.