你可以找到a pseudo implementation on Wikipedia:
# Input: d[i,j], the number of voters who prefer candidate i to candidate j.
# Output: p[i,j], the strength of the strongest path from candidate i to candidate j.
for i from 1 to C
for j from 1 to C
if (i ≠ j) then
if (d[i,j] > d[j,i]) then
p[i,j] := d[i,j]
else
p[i,j] := 0
for i from 1 to C
for j from 1 to C
if (i ≠ j) then
for k from 1 to C
if (i ≠ k and j ≠ k) then
p[j,k] := max (p[j,k], min (p[j,i], p[i,k]))
翻译这SciLab的需要使用functions,for-loops,if-else constructs,max,min。
下面我将伪码简单地翻译成Scilab代码。我没有测试过,你必须找出调用它的参数。
function p = schulzeMethod(d, C)
// Initialize a zero matrix p of the same size as d
p = zeros(size(d))
for i = 1:C
for j = 1:C
if i ~= j then
if d(i,j) > d(j,i) then
p(i,j) = d(i,j)
else
p(i,j) = 0
end
end
end
end
for i = 1:C
for j = 1:C
if i ~= j then
for k = 1:C
if (i ~= k) & (j ~= k) then
p(j,k) = max(p(j,k), min(p(j,i), p(i,k)))
end
end
end
end
end
endfunction
// Create some random values
C = 10
d = rand(C, C)
// Call the function above
p = schulzeMethod(d, C)
disp(p)
祝你好运,希望它有帮助!如果能够帮助他人,请给予一些反馈。
谢谢,我们将在周末尝试一下并提供反馈。 –
我已经设法写了一些似乎可行的东西。我更新了这篇文章,并给出了一段代码链接。我不确定这是最好的解决方案,但它的工作原理。 –