-
Notifications
You must be signed in to change notification settings - Fork 0
/
schulze.py
35 lines (29 loc) · 889 Bytes
/
schulze.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from numpy import zeros, array
def winner(p: array) -> array:
results = []
for i in range(len(p)):
true = True
for j in range(len(p)):
if i != j:
true = p[i, j] >= p[j, i] and true
if not true:
break
if true:
results.append(i)
return results
def main(d: array) -> list:
p = zeros((len(d), len(d)))
for i in range(len(d)):
for j in range(len(d)):
if i != j:
if d[i, j] > d[j, i]:
p[i, j] = d[i, j]
else:
p[i, j] = 0
for i in range(len(d)):
for j in range(len(d)):
if i != j:
for k in range(len(d)):
if i != k and j != k:
p[j, k] = max(p[j, k], min(p[j, i], p[i, k]))
return winner(p)