1 | <?php |
||
22 | class KemenyYoung extends Method implements MethodInterface |
||
23 | { |
||
24 | // Method Name |
||
25 | public const METHOD_NAME = ['Kemeny–Young','Kemeny-Young','Kemeny Young','KemenyYoung','Kemeny rule','VoteFair popularity ranking','Maximum Likelihood Method','Median Relation']; |
||
26 | |||
27 | // Method Name |
||
28 | public const CONFLICT_WARNING_CODE = 42; |
||
29 | |||
30 | // Limits |
||
31 | /* If you need to put it on 9, You must use ini_set('memory_limit','1024M'); before. The first use will be slower because Kemeny-Young will work without pre-calculated data of Permutations. |
||
32 | Do not try to go to 10, it is not viable! */ |
||
33 | public static $_maxCandidates = 8; |
||
34 | |||
35 | // Cache |
||
36 | public static $useCache = true; |
||
37 | public static $devWriteCache = false; |
||
38 | |||
39 | // Kemeny Young |
||
40 | protected $_PossibleRanking; |
||
41 | protected $_RankingScore; |
||
42 | |||
43 | |||
44 | |||
45 | /////////// PUBLIC /////////// |
||
46 | |||
47 | |||
48 | // Get the Kemeny ranking |
||
49 | 6 | public function getResult () : Result |
|
62 | |||
63 | |||
64 | 6 | protected function getStats () : array |
|
85 | |||
86 | 6 | protected function conflictInfos () : void |
|
101 | |||
102 | |||
103 | /////////// COMPUTE /////////// |
||
104 | |||
105 | |||
106 | //:: Kemeny-Young ALGORITHM. ::// |
||
107 | |||
108 | 6 | protected function calcPossibleRanking () : void |
|
130 | |||
131 | 2 | protected function doPossibleRanking (?string $path = null) |
|
132 | { |
||
133 | 2 | $permutation = new Permutation ($this->_selfElection->countCandidates()); |
|
134 | |||
135 | 2 | if ($path === null) : |
|
136 | 1 | return $permutation->getResults(true); |
|
137 | else : |
||
138 | 1 | $permutation->writeResults($path); |
|
139 | 1 | return $permutation->getResults(true); |
|
140 | endif; |
||
141 | } |
||
142 | |||
143 | 6 | protected function calcRankingScore () : void |
|
164 | |||
165 | |||
166 | /* |
||
167 | I do not know how in the very unlikely event that several possible classifications have the same highest score. |
||
168 | In the current state, one of them is chosen arbitrarily. |
||
169 | |||
170 | See issue on Github : https://github.com/julien-boudry/Condorcet/issues/6 |
||
171 | */ |
||
172 | 6 | protected function makeRanking () : void |
|
176 | } |
||
177 |