Completed
Branch dev-2.0 (210bc7)
by Boudry
06:33
created

BasicUsageBench::benchPairwiseOptimization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace CondorcetPHP\Condorcet\Benchmarks;
5
6
use CondorcetPHP\Condorcet\Condorcet;
7
use CondorcetPHP\Condorcet\Election;
8
use CondorcetPHP\Condorcet\Candidate;
9
use CondorcetPHP\Condorcet\CondorcetUtil;
10
use CondorcetPHP\Condorcet\Vote;
11
12
13
class BasicUsageBench
14
{
15
    /**
16
     * @Iterations(2)
17
     * @Warmup(1)
18
     * @Revs(4)
19
     */
20
    public function benchSimpleManyVotes () : void
21
    {
22
       $election = new Election;
23
       $election->allowVoteWeight(true);
24
25
       $election->parseCandidates('A;B;C;D;E;F');
26
27
       $election->parseVotes('
28
       		Ultimate Question of Life || A>B>C ^42 * 42
29
          C=A>B ^2 * 200
30
          B>C
31
          E > B > C > A ^80 *50
32
          F > B > G > H > A* 250
33
          D = B = E > F ^6 * 48
34
       ');
35
36
       $election->getWinner();
37
       $election->getLoser();
38
39
       foreach (Condorcet::getAuthMethods() as $method) :
40
         $election->getResult($method);
41
       endforeach;
42
43
       $election->setImplicitRanking(false);
44
45
       foreach (Condorcet::getAuthMethods() as $method) :
46
         $election->getResult($method);
47
       endforeach;
48
49
       $election->allowVoteWeight(false);
50
51
       foreach (Condorcet::getAuthMethods() as $method) :
52
         $election->getResult($method);
53
       endforeach;
54
55
       $election->parseVotes('
56
          Ultimate Question of Life || C>B>A ^42 * 42
57
          C=A=B ^2 * 200
58
          B>C
59
          A > C >E ^80 *50
60
          G > B > G > H > F* 250
61
          C = B = E > A ^6 * 48
62
       ');
63
64
       foreach (Condorcet::getAuthMethods() as $method) :
65
         $election->getResult($method);
66
       endforeach;
67
    }
68
69
    /**
70
     * @Iterations(2)
71
     * @Warmup(1)
72
     * @Revs(4)
73
     */
74
    public function benchPairwiseOptimization () : void
75
    {
76
       $election = new Election;
77
78
       $election->parseCandidates('A;B;C;D;E;F;G');
79
80
       $election->parseVotes('
81
          E > B > C > A > G * 2500
82
          F > B > G > H > A * 2500
83
          H > B > G > E > A * 2500
84
          A = B = C > D > E = F > G * 2500
85
          G = E = C > F > A * 2500
86
          C > D = G > A > B * 2500
87
       ');
88
89
        $election->getWinner();
90
91
        $vote = $election->addVote('A>B>C');
92
93
        $election->removeVote($vote);
94
95
        $vote->setRanking('C>B>A');
96
97
        $election->getWinner();
98
    }
99
100
}