2022-09-23 00:52:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class schulze
|
|
|
|
{
|
|
|
|
public int $nvotant;
|
2022-09-24 00:25:19 +02:00
|
|
|
public int $ncandidats = 5;
|
2022-09-23 00:52:56 +02:00
|
|
|
public array $nvotes;
|
|
|
|
|
2022-09-23 16:06:03 +02:00
|
|
|
public array $v = array(
|
2022-09-23 00:52:56 +02:00
|
|
|
array(5, 1, 3, 2, 4),
|
|
|
|
array(1, 5, 2, 4, 3),
|
|
|
|
array(5, 3, 2, 4, 1),
|
2022-09-23 15:33:28 +02:00
|
|
|
array(5, 1, 3, 2, 4),
|
|
|
|
array(5, 3, 2, 4, 1),
|
2022-09-23 00:52:56 +02:00
|
|
|
);
|
|
|
|
|
2022-09-23 18:59:08 +02:00
|
|
|
function stringify($votes)
|
|
|
|
{
|
|
|
|
$r = array();
|
|
|
|
foreach($votes as $vote)
|
|
|
|
{
|
2022-09-23 20:18:54 +02:00
|
|
|
$r[] = implode("/", $vote);
|
2022-09-23 18:59:08 +02:00
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
2022-09-23 21:46:09 +02:00
|
|
|
function votify(&$v)
|
2022-09-23 18:59:08 +02:00
|
|
|
{
|
2022-09-23 21:46:09 +02:00
|
|
|
$votes = array_flip($v);
|
2022-09-23 18:59:08 +02:00
|
|
|
foreach($votes as $vote)
|
|
|
|
{
|
2022-09-23 21:55:15 +02:00
|
|
|
$vote = explode("/", $vote);
|
2022-09-23 18:59:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-24 00:22:12 +02:00
|
|
|
function callBack($votes)
|
|
|
|
{
|
|
|
|
$mvotes = $this->matrix($votes);
|
|
|
|
$rvotes = $this->result($mvotes);
|
|
|
|
print_r($p);
|
|
|
|
}
|
|
|
|
|
|
|
|
function matrix($v)
|
2022-09-23 00:52:56 +02:00
|
|
|
{
|
2022-09-23 15:33:28 +02:00
|
|
|
$w = array();
|
2022-09-23 16:06:03 +02:00
|
|
|
$i = 0;
|
|
|
|
$j = 0;
|
2022-09-23 20:21:27 +02:00
|
|
|
$v = $this->stringify($v);
|
2022-09-23 18:59:08 +02:00
|
|
|
sort($v);
|
2022-09-23 15:33:28 +02:00
|
|
|
print_r($v);
|
2022-09-23 16:06:03 +02:00
|
|
|
for($i = 0;$i < count($v) - 1;$i++)
|
2022-09-23 15:33:28 +02:00
|
|
|
{
|
2022-09-23 20:18:54 +02:00
|
|
|
$s = $v[$i];
|
2022-09-23 22:13:42 +02:00
|
|
|
echo $i . " => " . $s . "==>" . $v[$i+1]; "\n";
|
2022-09-23 15:33:28 +02:00
|
|
|
if ($i == 0)
|
|
|
|
{
|
2022-09-23 20:59:12 +02:00
|
|
|
echo "i = 0\n";
|
2022-09-23 20:18:54 +02:00
|
|
|
$w[$s] = 1;
|
2022-09-23 15:33:28 +02:00
|
|
|
}
|
2022-09-23 20:18:54 +02:00
|
|
|
if ($s == $v[$i+1])
|
2022-09-23 15:33:28 +02:00
|
|
|
{
|
2022-09-23 20:41:50 +02:00
|
|
|
echo "egal\n";
|
2022-09-23 20:18:54 +02:00
|
|
|
$w[$s] += 1;
|
2022-09-23 22:17:10 +02:00
|
|
|
print_r($w);
|
|
|
|
|
2022-09-23 15:33:28 +02:00
|
|
|
}else
|
|
|
|
{
|
2022-09-23 20:41:50 +02:00
|
|
|
echo "non egal\n";
|
2022-09-23 21:38:23 +02:00
|
|
|
$w[$v[$i+1]] = 1;
|
2022-09-23 22:17:10 +02:00
|
|
|
print_r($w);
|
2022-09-23 15:33:28 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-23 20:21:27 +02:00
|
|
|
$w = $this->votify($w);
|
2022-09-23 16:06:03 +02:00
|
|
|
print_r($w);
|
2022-09-24 00:22:12 +02:00
|
|
|
return $w;
|
2022-09-23 00:52:56 +02:00
|
|
|
}
|
|
|
|
|
2022-09-25 13:50:22 +02:00
|
|
|
function paires($w)
|
|
|
|
{
|
|
|
|
foreach($w as $votes)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function result($d)
|
2022-09-23 00:52:56 +02:00
|
|
|
{
|
2022-09-24 00:25:19 +02:00
|
|
|
$ncandidats = $this->ncandidats;
|
2022-09-23 00:52:56 +02:00
|
|
|
for ($i=1;$i<=$ncandidats;$i++)
|
|
|
|
{
|
|
|
|
for ($j=1;$j<=$ncandidats;$j++)
|
|
|
|
{
|
|
|
|
if ($d[$i][$j] > $d[$j][$i])
|
|
|
|
{
|
|
|
|
$p[$i][$j] = $d[$i][$j];
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
$p[$i][$j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ($i=1;$i<=$ncandidats;$i++)
|
|
|
|
{
|
|
|
|
for ($j=1;$j<=$ncandidats;$j++)
|
|
|
|
{
|
|
|
|
for ($k=1;$k<=$ncandidats;$k++)
|
|
|
|
{
|
|
|
|
if ($j != $k)
|
|
|
|
{
|
|
|
|
$p[$j][$k] = max($p[$j][$k], min($p[$j][$i],$p[$i][$k]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-24 00:22:12 +02:00
|
|
|
return $p;
|
2022-09-23 00:52:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|