|
2 | 2 | import itertools as it
|
3 | 3 | import numpy as np
|
4 | 4 | from typing import Callable, Optional
|
| 5 | +from functools import lru_cache |
5 | 6 |
|
6 | 7 | from ..models import Election
|
7 | 8 | from ..election_state import ElectionState
|
|
18 | 19 | first_place_votes,
|
19 | 20 | )
|
20 | 21 |
|
| 22 | +# add ballots attribute // remove preference profile so the original profile is |
| 23 | +# not modified in place everytime? |
| 24 | + |
21 | 25 |
|
22 | 26 | class STV(Election):
|
23 | 27 | """
|
@@ -164,6 +168,7 @@ def run_step(self) -> ElectionState:
|
164 | 168 | )
|
165 | 169 | return self.state
|
166 | 170 |
|
| 171 | + @lru_cache |
167 | 172 | def run_election(self) -> ElectionState:
|
168 | 173 | """
|
169 | 174 | Runs complete STV election
|
@@ -278,6 +283,7 @@ def run_step(self) -> ElectionState:
|
278 | 283 | self.state = new_state
|
279 | 284 | return self.state
|
280 | 285 |
|
| 286 | + @lru_cache |
281 | 287 | def run_election(self) -> ElectionState:
|
282 | 288 | """
|
283 | 289 | Simulates a complete Limited election
|
@@ -340,6 +346,7 @@ def run_step(self) -> ElectionState:
|
340 | 346 | self.state = outcome
|
341 | 347 | return outcome
|
342 | 348 |
|
| 349 | + @lru_cache |
343 | 350 | def run_election(self) -> ElectionState:
|
344 | 351 | """
|
345 | 352 | Runs complete Bloc election
|
@@ -398,6 +405,7 @@ def run_step(self) -> ElectionState:
|
398 | 405 | self.state = outcome
|
399 | 406 | return outcome
|
400 | 407 |
|
| 408 | + @lru_cache |
401 | 409 | def run_election(self) -> ElectionState:
|
402 | 410 | """
|
403 | 411 | Runs complete SNTV election
|
@@ -513,6 +521,7 @@ def run_step(self, stage: str) -> ElectionState:
|
513 | 521 | self.state = new_state # type: ignore
|
514 | 522 | return new_state # type: ignore
|
515 | 523 |
|
| 524 | + @lru_cache |
516 | 525 | def run_election(self) -> ElectionState:
|
517 | 526 | """
|
518 | 527 | Runs complete SNTV_STV election
|
@@ -574,6 +583,7 @@ def run_step(self) -> ElectionState:
|
574 | 583 | self.state = outcome
|
575 | 584 | return outcome
|
576 | 585 |
|
| 586 | + @lru_cache |
577 | 587 | def run_election(self) -> ElectionState:
|
578 | 588 | """
|
579 | 589 | Simulates a complete TopTwo election
|
@@ -637,6 +647,7 @@ def run_step(self) -> ElectionState:
|
637 | 647 | self.state = new_state
|
638 | 648 | return new_state
|
639 | 649 |
|
| 650 | + @lru_cache |
640 | 651 | def run_election(self) -> ElectionState:
|
641 | 652 | """
|
642 | 653 | Simulates a complete DominatingSets election
|
@@ -709,6 +720,7 @@ def run_step(self) -> ElectionState:
|
709 | 720 | self.state = new_state
|
710 | 721 | return new_state
|
711 | 722 |
|
| 723 | + @lru_cache |
712 | 724 | def run_election(self) -> ElectionState:
|
713 | 725 | """
|
714 | 726 | Simulates a complete Conda-Borda election
|
@@ -784,6 +796,7 @@ def run_step(self, old_profile: PreferenceProfile) -> ElectionState:
|
784 | 796 | )
|
785 | 797 | return self.state
|
786 | 798 |
|
| 799 | + @lru_cache |
787 | 800 | def run_election(self) -> ElectionState:
|
788 | 801 | """
|
789 | 802 | Simulates a complete sequential RCV contest.
|
@@ -873,6 +886,7 @@ def run_step(self) -> ElectionState:
|
873 | 886 | self.state = new_state
|
874 | 887 | return new_state
|
875 | 888 |
|
| 889 | + @lru_cache |
876 | 890 | def run_election(self) -> ElectionState:
|
877 | 891 | """
|
878 | 892 | Simulates a complete Borda contest
|
|
0 commit comments