1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__serveur-vote-lalis/methods/schulzeResults.php

114 lines
1.5 KiB
PHP
Raw Normal View History

2022-09-23 00:52:56 +02:00
<?php
class schulze
{
public int $nvotant;
public int $ncandidats;
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
);
function matrix()
{
foreach($nvotes as $votes)
{
for ($i=1;$i<=$votes;$i++)
{
for ($j=1;$j<=$ncandidats;$j++)
{
2022-09-23 16:06:03 +02:00
void;
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)
{
$r[] = implode($vote);
}
return $r;
}
function votify($votes)
{
$r = array();
foreach($votes as $vote)
{
$r[] = explode($vote);
}
return $r;
}
2022-09-23 00:52:56 +02:00
function test($v)
{
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 18:59:08 +02:00
$v = stringify($v);
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
{
if ($i == 0)
{
2022-09-23 18:59:08 +02:00
$w[$j]["vote"] = $v[$i];
$w[$j]["n"] = 1;
2022-09-23 16:06:03 +02:00
$j += 1;
2022-09-23 15:33:28 +02:00
}
2022-09-23 18:59:08 +02:00
if ($v[$i] === $v[$i+1])
2022-09-23 15:33:28 +02:00
{
2022-09-23 18:59:08 +02:00
$x = array_search($v[$i], $w);
$w[$x]["n"] += 1;
2022-09-23 15:33:28 +02:00
}else
{
2022-09-23 18:59:08 +02:00
$w[$j]["vote"] = $v[$i+1];
$w[$j]["n"] = 1;
$j += 1;
2022-09-23 15:33:28 +02:00
}
}
2022-09-23 18:59:08 +02:00
$w = votify($w);
2022-09-23 16:06:03 +02:00
print_r($w);
2022-09-23 00:52:56 +02:00
}
function result()
{
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]));
}
}
}
return $p;
}
}
}
?>