declare module 'javascript-lp-solver' { interface Model { optimize: string opType: string constraints: Record variables: Record> ints?: Record } export function Solve(model: Model): Record } interface Ballot { ranking: string[][]; weight: number; } type Matrix = { candidates: string[]; array: number[][]; }; type ScoreObject = Record; declare enum VotingSystem { Approbation = "APPROBATION", AbsoluteMajority = "ABSOLUTE_MAJORITY", Baldwin = "BALDWIN", Borda = "BORDA", BottomTwoRunoff = "BOTTOM_TWO_RUNOFF", Coombs = "COOMBS", Copeland = "COPELAND", FirstPastThePost = "FIRST_PAST_THE_POST", Kemeny = "KEMENY", InstantRunoff = "INSTANT_RUNOFF", MajorityJudgment = "MAJORITY_JUDGEMENT", MaximalLotteries = "MAXIMAL_LOTTERIES", Minimax = "MINIMAX", MinimaxTD = "MINIMAX_TD", Nanson = "NANSON", RandomizedCondorcet = "RANDOMIZED_CONDORCET", RandomCandidates = "RANDOM_CANDIDATES", RandomDictator = "RANDOM_DICTATOR", RankedPairs = "RANKED_PAIRS", Schulze = "SCHULZE", Smith = "SMITH", TwoRoundRunoff = "TWO_ROUND_RUNOFF" } interface Ranker { ranking(): string[][]; } declare abstract class Method implements Ranker { readonly candidates: string[]; static readonly needsMatrix: boolean; static readonly needsBallot: boolean; static readonly isRandom: boolean; constructor(candidates: string[]); abstract ranking(): string[][]; tieBreak(rankingToTieBreak: string[][]): string[][]; } declare abstract class BallotMethod extends Method implements Ranker { static readonly needsBallot = true; protected readonly ballots: Ballot[]; private _matrix?; constructor({ ballots, candidates, }: { ballots: Ballot[]; candidates: string[]; }); get matrix(): Matrix; } type Round = { finished?: boolean; idx: number; candidates: string[]; roundResult: { eliminated: string[]; qualified: string[]; scores: ScoreObject; }; }; declare abstract class RoundBallotMethod extends BallotMethod implements Ranker { protected rounds: Round[]; computeRounds(): Round[]; ranking(): string[][]; protected abstract round(candidates: string[], idx?: number): { qualified: string[]; eliminated: string[]; scores: ScoreObject; }; private computeNextRound; private lastRoundQualified; } interface Scorer extends Ranker { scores(): ScoreObject; } declare abstract class ScoreMethod extends Method implements Scorer { abstract scores(): ScoreObject; ranking(): string[][]; } interface Matrixer { matrix: Matrix; } declare abstract class MatrixScoreMethod extends ScoreMethod implements Scorer, Matrixer { static readonly needsMatrix = true; private readonly _matrix; constructor(i: Matrix); get matrix(): Matrix; } declare abstract class BallotScoreMethod extends ScoreMethod implements Scorer, Matrixer { static readonly needsBallot = true; protected readonly ballots: Ballot[]; private _matrix?; constructor({ ballots, candidates, }: { ballots: Ballot[]; candidates: string[]; }); get matrix(): Matrix; } declare class AbsoluteMajority extends BallotScoreMethod { scores(): ScoreObject; } declare class Approbation extends BallotScoreMethod { scores(): ScoreObject; } declare class Baldwin extends RoundBallotMethod { protected round(candidates: string[]): { qualified: string[]; eliminated: string[]; scores: ScoreObject; }; } declare class Borda extends BallotScoreMethod { scores(): ScoreObject; } declare class BottomTwoRunoff extends RoundBallotMethod { private copeland; constructor(i: { ballots: Ballot[]; candidates: string[]; }); protected round(candidates: string[]): { qualified: string[]; eliminated: string[]; scores: ScoreObject; }; } declare class Coombs extends RoundBallotMethod { protected round(candidates: string[]): { eliminated: string[]; qualified: string[]; scores: ScoreObject; }; } declare class Copeland extends MatrixScoreMethod { scores(): ScoreObject; } declare class FirstPastThePost extends BallotScoreMethod { scores(): ScoreObject; } declare class InstantRunoff extends RoundBallotMethod { protected round(candidates: string[]): { qualified: string[]; eliminated: string[]; scores: ScoreObject; }; } declare class Kemeny extends MatrixScoreMethod { scores(): ScoreObject; } type Judgements = { [candidate: string]: [number, number, number, number, number, number]; }; declare class MajorityJudgment extends BallotMethod { judgements(): Judgements; medians(): ScoreObject; ranking(): string[][]; } declare abstract class RandomMethod extends Method implements Scorer { static readonly isRandom = true; protected readonly rng: () => number; constructor(i: { candidates: string[]; rng?: () => number; }); abstract scores(): ScoreObject; abstract ranking(): string[][]; } declare abstract class RandomMatrixMethod extends RandomMethod implements Scorer, Matrixer { static readonly needsMatrix = true; private readonly _matrix; constructor(i: Matrix & { rng?: () => number; }); get matrix(): Matrix; abstract scores(): ScoreObject; ranking(): string[][]; } declare class MaximalLotteries extends RandomMatrixMethod { scores(): ScoreObject; } declare enum MinimaxVariant { WinningVotes = "WINNING_VOTES", Margins = "MARGINS", PairwiseOpposition = "PAIRWISE_OPPOSITION" } declare class Minimax extends MatrixScoreMethod { minimaxVariant: MinimaxVariant; excludeTies: boolean; static Variants: typeof MinimaxVariant; constructor(i: Matrix & { variant?: MinimaxVariant; excludeTies?: boolean; }); scores(): ScoreObject; } declare class MinimaxTD extends Minimax { scores(): ScoreObject; } declare class Nanson extends RoundBallotMethod { protected round(candidates: string[]): { qualified: string[]; eliminated: string[]; scores: ScoreObject; }; } declare class RandomCandidates extends RandomMethod { ranking(): string[][]; scores(): ScoreObject; } declare abstract class RandomBallotMethod extends BallotMethod implements Ranker { static readonly isRandom = true; protected readonly rng: () => number; protected constructor(i: { candidates: string[]; ballots: Ballot[]; rng?: () => number; }); abstract ranking(): string[][]; } declare class RandomDictator extends RandomBallotMethod { constructor(i: { ballots: Ballot[]; candidates: string[]; rng?: () => number; }); ranking(): string[][]; } declare class RandomizedCondorcet extends RandomMatrixMethod { scores(): ScoreObject; } declare class RankedPairs extends MatrixScoreMethod { scores(): ScoreObject; } declare class Schulze extends MatrixScoreMethod { scores(): ScoreObject; } declare class Smith extends MatrixScoreMethod { scores(): ScoreObject; } declare class TwoRoundRunoff extends RoundBallotMethod { protected round(candidates: string[], idx: number): { eliminated: string[]; qualified: string[]; scores: ScoreObject; }; } declare const methods: { readonly ABSOLUTE_MAJORITY: typeof AbsoluteMajority; readonly APPROBATION: typeof Approbation; readonly BALDWIN: typeof Baldwin; readonly BORDA: typeof Borda; readonly BOTTOM_TWO_RUNOFF: typeof BottomTwoRunoff; readonly COOMBS: typeof Coombs; readonly COPELAND: typeof Copeland; readonly FIRST_PAST_THE_POST: typeof FirstPastThePost; readonly INSTANT_RUNOFF: typeof InstantRunoff; readonly KEMENY: typeof Kemeny; readonly MAJORITY_JUDGEMENT: typeof MajorityJudgment; readonly MAXIMAL_LOTTERIES: typeof MaximalLotteries; readonly MINIMAX: typeof Minimax; readonly MINIMAX_TD: typeof MinimaxTD; readonly NANSON: typeof Nanson; readonly RANDOM_CANDIDATES: typeof RandomCandidates; readonly RANDOM_DICTATOR: typeof RandomDictator; readonly RANDOMIZED_CONDORCET: typeof RandomizedCondorcet; readonly RANKED_PAIRS: typeof RankedPairs; readonly SCHULZE: typeof Schulze; readonly SMITH: typeof Smith; readonly TWO_ROUND_RUNOFF: typeof TwoRoundRunoff; }; type Methods = (typeof methods)[keyof typeof methods]; type Edge = { from: number; to: number; value: number; }; declare const generateAcyclicGraph: (graph: Edge[], edgesToAdd: Edge[]) => Edge[]; declare const findSmithSet: (_matrix: Matrix) => Matrix; declare const findCondorcet: (_matrix: Matrix) => Matrix; declare const matrixFromBallots: (ballots: Ballot[], candidates: string[]) => Matrix; declare const makeAntisymetric: (matrix: Matrix) => Matrix; declare const normalizeRankInput: (rankInput: (string | string[])[]) => string[][]; declare const groupBallots: (ballots: B[]) => B[]; declare const toWeightedBallots: (ballots: string[][][]) => Ballot[]; declare const checkDuplicatedCandidate: (ranking: string[][]) => void; declare const removeDuplicatedCandidates: (ranking: string[][]) => string[][]; declare const removeInvalidCandidates: (ranking: string[][], candidates: string[]) => string[][]; declare const normalizeRanking: (ranking: string[][], candidates: string[]) => string[][]; declare const normalizeBallot: (ballot: B, candidates: string[]) => B; declare const candidatesFromBallots: (ballots: Ballot[]) => string[]; declare const normalizeBallots: (ballots: B[], candidates?: string[]) => B[]; declare const scoresToRanking: (scores: { [candidate: string]: number; }) => string[][]; declare const index_candidatesFromBallots: typeof candidatesFromBallots; declare const index_checkDuplicatedCandidate: typeof checkDuplicatedCandidate; declare const index_findCondorcet: typeof findCondorcet; declare const index_findSmithSet: typeof findSmithSet; declare const index_generateAcyclicGraph: typeof generateAcyclicGraph; declare const index_groupBallots: typeof groupBallots; declare const index_makeAntisymetric: typeof makeAntisymetric; declare const index_matrixFromBallots: typeof matrixFromBallots; declare const index_normalizeBallot: typeof normalizeBallot; declare const index_normalizeBallots: typeof normalizeBallots; declare const index_normalizeRankInput: typeof normalizeRankInput; declare const index_normalizeRanking: typeof normalizeRanking; declare const index_removeDuplicatedCandidates: typeof removeDuplicatedCandidates; declare const index_removeInvalidCandidates: typeof removeInvalidCandidates; declare const index_scoresToRanking: typeof scoresToRanking; declare const index_toWeightedBallots: typeof toWeightedBallots; declare namespace index { export { index_candidatesFromBallots as candidatesFromBallots, index_checkDuplicatedCandidate as checkDuplicatedCandidate, index_findCondorcet as findCondorcet, index_findSmithSet as findSmithSet, index_generateAcyclicGraph as generateAcyclicGraph, index_groupBallots as groupBallots, index_makeAntisymetric as makeAntisymetric, index_matrixFromBallots as matrixFromBallots, index_normalizeBallot as normalizeBallot, index_normalizeBallots as normalizeBallots, index_normalizeRankInput as normalizeRankInput, index_normalizeRanking as normalizeRanking, index_removeDuplicatedCandidates as removeDuplicatedCandidates, index_removeInvalidCandidates as removeInvalidCandidates, index_scoresToRanking as scoresToRanking, index_toWeightedBallots as toWeightedBallots }; } type MethodsContaining = Method extends Methods ? Method[StaticProp] extends true ? Method : never : never; type SystemsBeing = System extends VotingSystem ? (typeof methods)[System] extends MethodType ? System : never : never; type RandomMethods = MethodsContaining<'isRandom', Methods>; type BallotMethods = MethodsContaining<'needsBallot', Methods>; type MatrixMethods = MethodsContaining<'needsMatrix', Methods>; type RandomSystem = SystemsBeing; type BallotSystem = SystemsBeing; type MatrixSystem = SystemsBeing; declare const isRandomMethod: (Method: Methods) => Method is RandomMethods; declare const isBallotMethod: (Method: Methods) => Method is BallotMethods; declare const isMatrixMethod: (Method: Methods) => Method is MatrixMethods; declare const isRandomSystem: (system: VotingSystem) => system is RandomSystem; declare const isBallotSystem: (system: VotingSystem) => system is BallotSystem; declare const isMatrixSystem: (system: VotingSystem) => system is MatrixSystem; export { AbsoluteMajority, Approbation, Baldwin, type Ballot, type BallotMethods, type BallotSystem, Borda, BottomTwoRunoff, Coombs, Copeland, FirstPastThePost, InstantRunoff, type Judgements, Kemeny, MajorityJudgment, type Matrix, type MatrixMethods, type MatrixSystem, MaximalLotteries, type Methods, Minimax, MinimaxTD, MinimaxVariant, Nanson, RandomCandidates, RandomDictator, type RandomMethods, type RandomSystem, RandomizedCondorcet, RankedPairs, type Round, Schulze, type ScoreObject, Smith, TwoRoundRunoff, VotingSystem, isBallotMethod, isBallotSystem, isMatrixMethod, isMatrixSystem, isRandomMethod, isRandomSystem, methods, index as utils };