schulze-vote 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/lib/vote/condorcet/schulze/basic.rb +9 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54a125030f5f284e82f05d0a65c077e463a37ad0
|
4
|
+
data.tar.gz: cfa32855bdd40cd8ec4c92b1d96d17f81b635d68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84fb23bc8171ba68ea054785d85ac7215a0372327f55b26df9b305957b0172970faa97cfdfe9f24a63f52cf572d733294bb044628f63aec8322c1d2f27f09461
|
7
|
+
data.tar.gz: ed14fffb19e893095dbbd02e337dd4fabe8eb021ce0e7d5d0efa340278bf756afb993f79f4a831878be06cba74b16f4780445b98f4ff449bbfc934aa177f5a57
|
data/README.md
CHANGED
@@ -15,10 +15,16 @@ Wikipedia:
|
|
15
15
|
gem install schulze-vote
|
16
16
|
```
|
17
17
|
|
18
|
+
Gemfile
|
19
|
+
|
20
|
+
``` ruby
|
21
|
+
gem 'schulze-vote', require: 'schulze_vote'
|
22
|
+
```
|
23
|
+
|
18
24
|
## Usage
|
19
25
|
|
20
26
|
``` ruby
|
21
|
-
require '
|
27
|
+
require 'schulze_vote'
|
22
28
|
vs = SchulzeBasic.do vote_list, candidate_count
|
23
29
|
vs.ranks
|
24
30
|
vs.ranks_abc
|
@@ -80,7 +86,7 @@ See it as an visual reminder while coding with this gem.
|
|
80
86
|
(Only weight values, no letters here! See section "_preference order to weight_ example")
|
81
87
|
|
82
88
|
``` ruby
|
83
|
-
require '
|
89
|
+
require 'schulze_vote'
|
84
90
|
vote_list_array = [[3,2,1],[1,3,2],[3,1,2]]
|
85
91
|
vs = SchulzeBasic.do vote_list_array, 3
|
86
92
|
```
|
@@ -88,7 +94,7 @@ vs = SchulzeBasic.do vote_list_array, 3
|
|
88
94
|
#### String
|
89
95
|
|
90
96
|
``` ruby
|
91
|
-
require '
|
97
|
+
require 'schulze_vote'
|
92
98
|
vote_list_string = <<EOF
|
93
99
|
A;B;C
|
94
100
|
B;C;A
|
@@ -102,7 +108,7 @@ vs = SchulzeBasic.do vote_list_string, 3
|
|
102
108
|
#### File
|
103
109
|
|
104
110
|
``` ruby
|
105
|
-
require '
|
111
|
+
require 'schulze_vote'
|
106
112
|
vs = SchulzeBasic.do File.open('path/to/vote.list')
|
107
113
|
```
|
108
114
|
|
@@ -58,6 +58,10 @@ module Vote
|
|
58
58
|
@classifications ||= calculate_classifications(limit_results)
|
59
59
|
end
|
60
60
|
|
61
|
+
def beat_couples
|
62
|
+
@beat_couples ||= calculate_beat_couples
|
63
|
+
end
|
64
|
+
|
61
65
|
private
|
62
66
|
|
63
67
|
def play
|
@@ -123,22 +127,22 @@ module Vote
|
|
123
127
|
end
|
124
128
|
|
125
129
|
def calculate_beat_couples
|
126
|
-
|
130
|
+
beat_couples = []
|
127
131
|
ranks.each_with_index do |_val, idx|
|
128
132
|
ranks.each_with_index do |_val2, idx2|
|
129
133
|
next if idx == idx2
|
130
134
|
if play_matrix[idx, idx2] > play_matrix[idx2, idx]
|
131
|
-
|
135
|
+
beat_couples << [idx, idx2]
|
132
136
|
end
|
133
137
|
end
|
134
138
|
end
|
135
|
-
|
139
|
+
beat_couples
|
136
140
|
end
|
137
141
|
|
138
142
|
def rank_element(el)
|
139
143
|
rank = 0
|
140
144
|
rank -= 100 if @potential_winners.include?(el)
|
141
|
-
|
145
|
+
beat_couples.each do |b|
|
142
146
|
rank -= 1 if b[0] == el
|
143
147
|
end
|
144
148
|
rank
|
@@ -146,13 +150,12 @@ module Vote
|
|
146
150
|
|
147
151
|
def calculate_classifications(limit_results)
|
148
152
|
calculate_potential_winners
|
149
|
-
calculate_beat_couples
|
150
153
|
|
151
154
|
start_list = (0..ranks.length - 1).to_a
|
152
155
|
start_list.sort! { |e1, e2| rank_element(e1) <=> rank_element(e2) }
|
153
156
|
|
154
157
|
classifications = []
|
155
|
-
compute_classifications(classifications, [], @potential_winners,
|
158
|
+
compute_classifications(classifications, [], @potential_winners, beat_couples, start_list, limit_results)
|
156
159
|
classifications
|
157
160
|
end
|
158
161
|
|