Table des codes de règles¶
All rules expose a cowinners_ attribute. They are integrated via the rule_codes key in config/simulation.toml.
SVVAMP Rules¶
| code | rule | doc SVVAMP | status |
|---|---|---|---|
| AP_T | Approval (threshold 0.7) | rule_approval | Tested & validated |
| AP_K | K-Approval (k=2) |
rule_k_approval | Tested & validated |
| BALD | Baldwin | rule_baldwin | Tested & validated |
| BLAC | Black | rule_black | Tested & validated |
| BORD | Borda | rule_borda | Tested & validated |
| BUCK_I | Iterated Bucklin | rule_iterated_bucklin | Tested & validated |
| BUCK_R | Bucklin | rule_bucklin | Tested & validated |
| CAIR | Condorcet Abs IRV | rule_condorcet_abs_irv | Tested & validated |
| COOM | Coombs | rule_coombs | Tested & validated |
| COPE | Copeland | rule_copeland | Tested & validated |
| CSUM | Condorcet Sum Defeats | rule_condorcet_sum_defeats | Tested & validated |
| CVIR | Condorcet Vtb IRV | rule_condorcet_vtb_irv | Tested & validated |
| DODG_C | Dodgson (C) | ❌ Not implemented | |
| DODG_S | Dodgson (S) | rule_dodgson | may be nan |
| EXHB | Exhaustive Ballot | rule_exhaustive_ballot | Tested & validated |
| HARE | IRV / Hare | rule_irv | Tested & validated |
| ICRV | ICRV | rule_icrv | ⚠️ No dedicated test |
| IRV | IRV (alias de HARE) |
see HARE | |
| IRVA | IRV Average | rule_irv_average | ⚠️ No dedicated test |
| IRVD | IRV Duels | rule_irv_duels | ⚠️ No dedicated test |
| KEME | Kemeny | rule_kemeny | ⚠️ No dedicated test — high computational time |
| KIMR | Kim-Roush | rule_kim_roush | Tested & validated |
| L4VD | L4VD | — | ❌ Not implemented |
| MJ | Majority Judgment | rule_majority_judgment | Tested & validated |
| MMAX | Maximin | rule_maximin | Tested & validated |
| NANS | Nanson | rule_nanson | Tested & validated |
| PLU1 | Plurality | rule_plurality | Tested & validated |
| PLU2 | Two-Round | rule_two_round | Tested & validated |
| RPAR | Ranked Pairs | rule_ranked_pairs | Tested & validated |
| RV | Range Voting | rule_range_voting | Tested & validated |
| SCHU | Schulze | rule_schulze | Tested & validated |
| SIRV | Smith IRV | rule_smith_irv | Tested & validated |
| SLAT | Slater | rule_slater | ⚠️ No dedicated test -- computational time too long |
| SPCY | Split Cycle | rule_split_cycle | Tested & validated |
| STAR | STAR | rule_star | Tested & validated |
| TIDE | Tideman | rule_tideman | Tested & validated |
| VETO | Veto (Anti-plurality) | rule_veto | Tested & validated |
| WOOD | Woodall | rule_woodall | Tested & validated |
| YOUN | Young | rule_young | Tested & validated |
How to add a rule¶
Use the public registry helpers to add custom rules :
from svvamp import RuleApproval
from vote_simulation.models.rules import get_rule_builder, make_rule_builder, register_rule
register_rule(
"AP_T8",
make_rule_builder(lambda profile: RuleApproval(approval_threshold=0.8)(profile)),
)
ballots = [
{"Alice": 1.0, "Bob": 0.9, "Chloe": 0.2},
{"Alice": 0.85, "Bob": 0.7, "Chloe": 0.9},
]
result = get_rule_builder("AP_T8")(ballots)
print(result.cowinners_)
See demo/adding_rule.py for a already built example.
Rule index for mapping short codes to svvamp rule factories.
RuleResult
¶
Bases: Protocol
Protocol for rule results that have been post-processed to include co-winners.
Source code in src/vote_simulation/models/rules/registry.py
get_all_rules_codes()
¶
get_rule_builder(code)
¶
Return rule builder from code
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
rule encoding (detailed index in documentation) |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if wrong code |
Returns:
| Name | Type | Description |
|---|---|---|
RuleBuilder |
RuleBuilder
|
rule applied |
Source code in src/vote_simulation/models/rules/registry.py
make_rule_builder(rule_factory)
¶
Create a public RuleBuilder from a Profile -> rule result factory.
This helper is intended for external users who want to register custom rules while reusing the registry's profile conversion and co-winner post-processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_factory
|
Callable[[Profile], Any]
|
Callable that takes a |
required |
Returns:
| Type | Description |
|---|---|
RuleBuilder
|
A |
Source code in src/vote_simulation/models/rules/registry.py
register_rule(code, builder)
¶
Register a rule builder under a short code.