# Module sp_npos_elections::balancing

source · ## Expand description

Balancing algorithm implementation.

Given a committee `A`

and an edge weight vector `w`

, a balanced solution is one that

- it maximizes the sum of member supports, i.e
`Argmax { sum(support(c)) }`

. for all`c`

in`A`

. - it minimizes the sum of supports squared, i.e
`Argmin { sum(support(c).pow(2)) }`

for all`c`

in`A`

.

See `balance`

for more information.

## Functions

- Balance the weight distribution of a given
`voters`

at most`iterations`

times, or up until the point where the biggest difference created per iteration of all stakes is`tolerance`

. If this is called with`tolerance = 0`

, then exactly`iterations`

rounds will be executed, except if no change has been made (`difference = 0`

).`tolerance`

and`iterations`

are part of the`BalancingConfig`

struct.