Schulze Method - Implementation

Implementation

The only difficult step in implementing the Schulze method is computing the strongest path strengths. However, this is a well-known problem in graph theory sometimes called the widest path problem. One simple way to compute the strengths therefore is a variant of the Floyd–Warshall algorithm. The following pseudocode illustrates the algorithm.

  1. # Input: d, the number of voters who prefer candidate i to candidate j.
  2. # Output: p, the strength of the strongest path from candidate i to candidate j.
  3. for i from 1 to C
  4. for j from 1 to C
  5. if (i ≠ j) then
  6. if (d > d) then
  7. p := d
  8. else
  9. p := 0
  10. for i from 1 to C
  11. for j from 1 to C
  12. if (i ≠ j) then
  13. for k from 1 to C
  14. if (i ≠ k and j ≠ k) then
  15. p := max ( p, min ( p, p ) )

This algorithm is efficient, and has running time proportional to C3 where C is the number of candidates. (This does not account for the running time of computing the d values, which if implemented in the most straightforward way, takes time proportional to C2 times the number of voters.)

Read more about this topic:  Schulze Method