ecclesia
Version:
Framework for political and electoral simulations
26 lines • 1.1 kB
JavaScript
import { NumberCounter } from "@gouvernathor/python/collections";
import { createRandomObj } from "./utils";
/**
* Implements the most basic elections : combining a voting method and an attribution method.
*/
export function standardElection({ votingMethod, attributionMethod }) {
return (pool, candidates) => {
return attributionMethod(votingMethod(pool, candidates));
};
}
/**
* Implements a selection by lottery, directly among the population.
* Adds the supplementary constraint that the voter type and the candidate type must be the same.
*
* The pool of candidates and the pool of citizens must be the same.
* (Implementation detail : this is not enforced, and the pool of candidates is ignored.)
* Returns elements from the pool picked without replacement,
* so the pool must be at least nSeats in size.
*/
export function sortition({ nSeats, ...randomParam }) {
return (citizens) => {
const randomObj = createRandomObj(randomParam);
return NumberCounter.fromKeys(randomObj.shuffled(citizens, nSeats));
};
}
//# sourceMappingURL=election.js.map