1 | <?php |
||
19 | class KemenyYoung extends Method implements MethodInterface |
||
20 | { |
||
21 | // Method Name |
||
22 | public const METHOD_NAME = ['Kemeny–Young','Kemeny-Young','Kemeny Young','KemenyYoung','Kemeny rule','VoteFair popularity ranking','Maximum Likelihood Method','Median Relation']; |
||
23 | |||
24 | // Method Name |
||
25 | public const CONFLICT_WARNING_CODE = 42; |
||
26 | |||
27 | // Limits |
||
28 | /* 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. |
||
29 | Do not try to go to 10, it is not viable! */ |
||
30 | public static $_maxCandidates = 8; |
||
31 | |||
32 | // Cache |
||
33 | public static $useCache = true; |
||
34 | |||
35 | // Kemeny Young |
||
36 | protected $_PossibleRanking; |
||
37 | protected $_RankingScore; |
||
38 | |||
39 | |||
40 | |||
41 | /////////// PUBLIC /////////// |
||
42 | |||
43 | |||
44 | // Get the Kemeny ranking |
||
45 | 5 | public function getResult () : Result |
|
58 | |||
59 | |||
60 | 5 | protected function getStats () : array |
|
80 | |||
81 | 5 | protected function conflictInfos () : void |
|
82 | { |
||
83 | 5 | $max = max($this->_RankingScore); |
|
84 | |||
85 | 5 | $conflict = -1; |
|
86 | 5 | foreach ($this->_RankingScore as $value) : |
|
87 | 5 | if ($value === $max) : |
|
88 | 5 | $conflict++; |
|
89 | endif; |
||
90 | endforeach; |
||
91 | |||
92 | 5 | if ($conflict > 0) : |
|
93 | 1 | $this->_Result->addWarning(self::CONFLICT_WARNING_CODE, ($conflict + 1).';'.max($this->_RankingScore) ); |
|
94 | endif; |
||
95 | 5 | } |
|
96 | |||
97 | |||
98 | /////////// COMPUTE /////////// |
||
99 | |||
100 | |||
101 | //:: Kemeny-Young ALGORITHM. ::// |
||
102 | |||
103 | 5 | protected function calcPossibleRanking () : void |
|
125 | |||
126 | 1 | protected function doPossibleRanking (?string $path = null) |
|
136 | |||
137 | 5 | protected function calcRankingScore () : void |
|
158 | |||
159 | |||
160 | /* |
||
161 | I do not know how in the very unlikely event that several possible classifications have the same highest score. |
||
162 | In the current state, one of them is chosen arbitrarily. |
||
163 | |||
164 | See issue on Github : https://github.com/julien-boudry/Condorcet/issues/6 |
||
165 | */ |
||
166 | 5 | protected function makeRanking () : void |
|
170 | |||
171 | } |
||
172 |