schulze-vote 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +178 -0
  4. metadata +48 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 221e6311ce305a77a33a9058a5ef6224c301315e
4
+ data.tar.gz: 076a63071dd29cad6aec5882a683ea1add159a2f
5
+ SHA512:
6
+ metadata.gz: 1fc77d9b40c113494e9b9a96f6febdef044d1a90d835247388874790b99f58b7c98b02f3bcfb436e12c257575b6fdd178a728f06d31b981cce0e44ebdc93e1ef
7
+ data.tar.gz: ac7f6916c5b290e623a299221b11fef0289200edd62a6025d9b9174db1e7cab017c90c73a874ddbd7318919a7e0cf62f49f8452a28792d1db6a0ff163daef65f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010-2015 Renuo GmbH. https://www.renuo.ch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,178 @@
1
+ # Schulze Vote
2
+
3
+ This gem is a Ruby implementation of the Schulze voting method (with help of the Floyd–Warshall algorithm),
4
+ a type of the Condorcet voting methods.
5
+
6
+
7
+ Wikipedia:
8
+
9
+ * [Schulze method](http://en.wikipedia.org/wiki/Schulze_method) ([deutsch](http://de.wikipedia.org/wiki/Schulze-Methode))
10
+ * [Floyd–Warshall algorithm](http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm)
11
+
12
+ ## Install
13
+
14
+ ``` bash
15
+ gem install schulze-vote
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ``` ruby
21
+ require 'schulze-vote'
22
+ vs = SchulzeBasic.do vote_list, candidate_count
23
+ vs.ranks
24
+ vs.ranks_abc
25
+ ```
26
+
27
+ `SchulzeBasic.do` - SchulzeBasic is a short term for `Vote::Condorcet::Schulze::Basic` and `.do` is a method of this class!
28
+
29
+ Input:
30
+
31
+ * `vote_list`
32
+ * Array of Arrays: votes of each voter as weights `[ [A,B,C,...],[A,B,C,...],[A,B,C,...] ]`
33
+ * String: "A;B;C\nA;B;C\n;3=A;B;C..."
34
+ * File: first line **must** be a single integer, following lines like vote_list type String (see vote lists under `examples` directory)
35
+ * `candidate_count` Integer: number of candidates
36
+ * **required** for vote_list types of Array and String
37
+ * _leave empty if vote_list is a File handle!_
38
+
39
+ ### String/File format:
40
+
41
+ A typical voters line looks like this:
42
+
43
+ ```
44
+ A;B;C;D;E;F
45
+ ```
46
+
47
+ You also can say that _n_ voters have the same preferences:
48
+
49
+ ```
50
+ n=F;E;D;C;B;A
51
+ ```
52
+
53
+ where _n_ is an integer value for the count.
54
+
55
+ Also it's possible to say that a voter has candidates equally weighted:
56
+
57
+ ```
58
+ A,B;C,D;E,F
59
+ ```
60
+
61
+ which means, that A + B, C + D and E + F are on the same weight level.
62
+
63
+ Here only 3 weight levels are used: (A,B) = 3, (C,D) = 2, (E,F) = 1
64
+
65
+ ### Why I must write the candidate count in the first line of the vote file?
66
+
67
+ _or: Why I must give a candidate count value for Array/String inputs?_
68
+
69
+ Very easy: The reason is, that voters can leave out candidates (they give no special preferences).
70
+
71
+ So, schulze-vote needs to know, how many real candidates are in the voting process.
72
+
73
+ Okay, for Array inputs it's currently a little bit overhead, because the voters array normally should have the size of the candidates count.
74
+ See it as an visual reminder while coding with this gem.
75
+
76
+ ### Examples
77
+
78
+ #### Array
79
+
80
+ (Only weight values, no letters here! See section "_preference order to weight_ example")
81
+
82
+ ``` ruby
83
+ require 'schulze-vote'
84
+ vote_list_array = [[3,2,1],[1,3,2],[3,1,2]]
85
+ vs = SchulzeBasic.do vote_list_array, 3
86
+ ```
87
+
88
+ #### String
89
+
90
+ ``` ruby
91
+ require 'schulze-vote'
92
+ vote_list_string = <<EOF
93
+ A;B;C
94
+ B;C;A
95
+ A;C;B
96
+ A,C,B
97
+ 4=C;A;B
98
+ EOF
99
+ vs = SchulzeBasic.do vote_list_string, 3
100
+ ```
101
+
102
+ #### File
103
+
104
+ ``` ruby
105
+ require 'schulze-vote'
106
+ vs = SchulzeBasic.do File.open('path/to/vote.list')
107
+ ```
108
+
109
+ ### _preference order to weight_ example
110
+
111
+ ```
112
+ voter => A D C B
113
+
114
+ weight => 4,1,2,3
115
+
116
+ A is on first position = highest prio == 4
117
+ B is on last position == 1
118
+ C is on third position == 2
119
+ D is on second position == 3
120
+ ```
121
+
122
+ Later versions will have an automatic Preference-to-Weight algorithm.
123
+ (Internally only integers are used for calculation of ranking.)
124
+
125
+ ### _SchulzeBasic_
126
+
127
+ It doesn't matter if you start counting at 0 (zero) or 1 (one).
128
+
129
+ Also it's not important, if you use jumps (like `1 3 5 9`).
130
+
131
+ Internally it will only check if candidate X > candidate Y
132
+
133
+ Output:
134
+
135
+ * `.ranks` Array: numbers of total wins for each candidate `[candidate A, candidate B, candidate C, ...]`
136
+ * `.winners_array` Array: set 1 if the candidate is a potential winner `[candidate A, candidate B, candidate C, ...]`
137
+
138
+ ## Example
139
+
140
+ Reference calculation: [Schulze Methode | blog.cgiesel.de (german)](http://blog.cgiesel.de/schulze-methode/)
141
+
142
+ Example file under `examples/vote4.list`
143
+
144
+ Result should be:
145
+
146
+ ``` ruby
147
+ sb = SchulzeBasic.do File.open('../examples/vote4.list')
148
+ sb.rank_abc
149
+ #=> ["C:1", "D:2", "B:3", "A:4"]
150
+ ```
151
+
152
+ which is the same result of the reference above.
153
+
154
+ The result strings are always in format `Candidate:Position`, because it's possible that multiple candidates can be on the same rank.
155
+
156
+ ## Contributing to schulze-vote
157
+
158
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
159
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
160
+ * Fork the project
161
+ * Use git-flow
162
+ * Start a feature/bugfix branch
163
+ * Commit and push until you are happy with your contribution
164
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
165
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
166
+
167
+ ## Problems? Questions?
168
+
169
+ ![Alessandro Rodi](http://www.gravatar.com/avatar/32d80da41830a6e6c1bb3eb977537e3e)
170
+
171
+ ## Thanks
172
+
173
+ Thanks to Christoph Grabo for providing the idea and base code of the gem
174
+
175
+ ## Copyright
176
+
177
+ See LICENSE for further details.
178
+
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schulze-vote
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Rodi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem is a Ruby implementation of the Schulze voting method (with
14
+ help of the Floyd-Warshall algorithm), a type of the Condorcet voting methods.
15
+ email: coorasse@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - LICENSE
20
+ - README.md
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ homepage: http://github.com/coorasse/schulze-vote
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.2.0
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Schulze method implementation in Ruby (Condorcet voting method)
48
+ test_files: []