vote-schulze 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +12 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +18 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -6
- data/Gemfile.lock +53 -19
- data/LICENSE.txt +17 -16
- data/README.md +22 -31
- data/Rakefile +4 -41
- data/bin/console +15 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/setup +8 -0
- data/exe/vote-schulze +57 -0
- data/lib/vote.rb +2 -4
- data/lib/vote/matrix.rb +5 -7
- data/lib/vote/schulze.rb +15 -0
- data/lib/vote/schulze/basic.rb +87 -0
- data/lib/vote/schulze/input.rb +70 -0
- data/lib/vote/schulze/version.rb +7 -0
- data/lib/vote_schulze.rb +3 -0
- data/vote-schulze.gemspec +29 -61
- metadata +114 -53
- data/.document +0 -5
- data/.rvmrc +0 -2
- data/VERSION +0 -1
- data/lib/vote-schulze.rb +0 -15
- data/lib/vote/condorcet.rb +0 -7
- data/lib/vote/condorcet/schulze.rb +0 -11
- data/lib/vote/condorcet/schulze/basic.rb +0 -117
- data/lib/vote/condorcet/schulze/input.rb +0 -89
- data/lib/vote/condorcet/schulze/win_and_lost.rb +0 -14
- data/spec/spec_helper.rb +0 -12
- data/spec/vote-schulze_spec.rb +0 -9
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 399759c49a38c8c50ce051e0a0af472c40b3cc106395a82d7000872a1e869c95
|
4
|
+
data.tar.gz: b51864add9c71ba7aab3ad2d7e694e18b0ee5e5701f60ebaaf8dd4e8231259a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8f5e1965631c33822f42c489c298789330c2d1c3d7c1fec71fccd5a9ed2b5e257b3e43c6bcd231936354770f59138312947756eff990e14fa1230a4869e9ffa
|
7
|
+
data.tar.gz: b3e2eacd9ba49a3d73175ab92dc2aab0aa557d090d991225b0d174a3065958df17c6ddaf58bffa8243b2ab951620fa2d97823d4c5db17641351cca06aa785ddf
|
data/.editorconfig
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# EditorConfig is awesome: https://EditorConfig.org
|
2
|
+
|
3
|
+
# top-most EditorConfig file
|
4
|
+
root = true
|
5
|
+
|
6
|
+
# Unix-style newlines with a newline ending every file
|
7
|
+
[*]
|
8
|
+
charset = utf-8
|
9
|
+
indent_style = space
|
10
|
+
indent_size = 2
|
11
|
+
end_of_line = lf
|
12
|
+
insert_final_newline = true
|
data/.gitignore
ADDED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
DisplayCopNames: true
|
8
|
+
TargetRubyVersion: 2.6
|
9
|
+
|
10
|
+
Style/Documentation:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# Current state is that we prefer the opposite (reduce/inject)
|
14
|
+
Style/EachWithObject:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Layout/LineLength:
|
18
|
+
Max: 120
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at asaaki@mannaz.cc. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
group :development do
|
3
|
-
gem "bundler", "~> 1.0.0"
|
4
|
-
gem "jeweler", "~> 1.6.0"
|
5
|
-
gem "rspec", "~> 2.3.0"
|
6
|
-
end
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in vote-schulze.gemspec
|
8
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
vote-schulze (0.3.0.pre.dev)
|
5
|
+
|
1
6
|
GEM
|
2
|
-
remote:
|
7
|
+
remote: https://rubygems.org/
|
3
8
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
rspec-
|
14
|
-
rspec-
|
15
|
-
|
16
|
-
rspec-
|
17
|
-
|
18
|
-
rspec-
|
9
|
+
ast (2.4.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
jaro_winkler (1.5.4)
|
12
|
+
parallel (1.19.1)
|
13
|
+
parser (2.7.0.2)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.9.0)
|
18
|
+
rspec-core (~> 3.9.0)
|
19
|
+
rspec-expectations (~> 3.9.0)
|
20
|
+
rspec-mocks (~> 3.9.0)
|
21
|
+
rspec-core (3.9.1)
|
22
|
+
rspec-support (~> 3.9.1)
|
23
|
+
rspec-expectations (3.9.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.9.0)
|
26
|
+
rspec-mocks (3.9.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-support (3.9.2)
|
30
|
+
rubocop (0.79.0)
|
31
|
+
jaro_winkler (~> 1.5.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.7.0.1)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
37
|
+
rubocop-performance (1.5.2)
|
38
|
+
rubocop (>= 0.71.0)
|
39
|
+
rubocop-rake (0.5.0)
|
40
|
+
rubocop
|
41
|
+
rubocop-rspec (1.37.1)
|
42
|
+
rubocop (>= 0.68.1)
|
43
|
+
ruby-progressbar (1.10.1)
|
44
|
+
unicode-display_width (1.6.1)
|
19
45
|
|
20
46
|
PLATFORMS
|
21
47
|
ruby
|
22
48
|
|
23
49
|
DEPENDENCIES
|
24
|
-
bundler (~> 1.
|
25
|
-
|
26
|
-
rspec (~>
|
50
|
+
bundler (~> 1.17)
|
51
|
+
rake (~> 10.0)
|
52
|
+
rspec (~> 3.0)
|
53
|
+
rubocop (~> 0.79)
|
54
|
+
rubocop-performance (~> 1.5)
|
55
|
+
rubocop-rake (~> 0.5)
|
56
|
+
rubocop-rspec (~> 1.37)
|
57
|
+
vote-schulze!
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
1.17.2
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
1
3
|
Copyright (c) 2011 Christoph Grabo
|
2
4
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
the following conditions:
|
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:
|
10
11
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
13
14
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
OF
|
20
|
-
|
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.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# vote-schulze
|
1
|
+
# vote-schulze ![https://travis-ci.com/asaaki/vote-schulze](https://travis-ci.com/asaaki/vote-schulze.svg?branch=master)
|
2
2
|
|
3
3
|
This gem is a Ruby implementation of the Schulze voting method (with help of the Floyd–Warshall algorithm), a type of the Condorcet voting methods.
|
4
4
|
|
@@ -21,13 +21,11 @@ gem install vote-schulze
|
|
21
21
|
|
22
22
|
``` ruby
|
23
23
|
require 'vote-schulze'
|
24
|
-
vs =
|
24
|
+
vs = Vote::Schulze::Basic.call(vote_list, candidate_count)
|
25
25
|
vs.ranks
|
26
|
-
vs.
|
26
|
+
vs.ranking_abc
|
27
27
|
```
|
28
28
|
|
29
|
-
`SchulzeBasic.do` - SchulzeBasic is a short term for `Vote::Condorcet::Schulze::Basic` and `.do` is a method of this class!
|
30
|
-
|
31
29
|
Input:
|
32
30
|
|
33
31
|
* `vote_list`
|
@@ -84,8 +82,8 @@ See it as an visual reminder while coding with this gem.
|
|
84
82
|
``` ruby
|
85
83
|
require 'vote-schulze'
|
86
84
|
vote_list_array = [[3,2,1],[1,3,2],[3,1,2]]
|
87
|
-
vs =
|
88
|
-
vs.
|
85
|
+
vs = Vote::Schulze::Basic.call(vote_list_array, 3)
|
86
|
+
vs.ranking_abc #=> result
|
89
87
|
```
|
90
88
|
|
91
89
|
#### String
|
@@ -99,16 +97,17 @@ A;C;B
|
|
99
97
|
A,C,B
|
100
98
|
4=C;A;B
|
101
99
|
EOF
|
102
|
-
vs =
|
103
|
-
vs.
|
100
|
+
vs = Vote::Schulze::Basic.call(vote_list_string, 3)
|
101
|
+
vs.ranking_abc #=> result
|
104
102
|
```
|
105
103
|
|
106
104
|
#### File
|
107
105
|
|
108
106
|
``` ruby
|
109
107
|
require 'vote-schulze'
|
110
|
-
|
111
|
-
vs
|
108
|
+
voting_list = File.open('path/to/vote.list')
|
109
|
+
vs = Vote::Schulze::Basic.call(voting_list)
|
110
|
+
vs.ranking_abc #=> result
|
112
111
|
```
|
113
112
|
|
114
113
|
### _preference order to weight_ example
|
@@ -127,18 +126,12 @@ D is on second position == 3
|
|
127
126
|
Later versions will have an automatic Preference-to-Weight algorithm.
|
128
127
|
(Internally only integers are used for calculation of ranking.)
|
129
128
|
|
130
|
-
###
|
131
|
-
|
132
|
-
It doesn't matter if you start counting at 0 (zero) or 1 (one).
|
129
|
+
### It doesn't matter if you start counting at 0 (zero) or 1 (one).
|
133
130
|
|
134
131
|
Also it's not important, if you use jumps (like `1 3 5 9`).
|
135
132
|
|
136
133
|
Internally it will only check if candidate X > candidate Y
|
137
134
|
|
138
|
-
Output:
|
139
|
-
|
140
|
-
* `.ranking_array` Array: numbers of total wins for each candidate `[candidate A, candidate B, candidate C, ...]`
|
141
|
-
|
142
135
|
## Example
|
143
136
|
|
144
137
|
Reference calculation: [Schulze Methode | blog.cgiesel.de (german)](http://blog.cgiesel.de/schulze-methode/)
|
@@ -146,9 +139,11 @@ Reference calculation: [Schulze Methode | blog.cgiesel.de (german)](http://blog.
|
|
146
139
|
Example file under `examples/vote4.list`
|
147
140
|
|
148
141
|
Result should be:
|
142
|
+
|
149
143
|
``` ruby
|
150
|
-
|
151
|
-
|
144
|
+
voting_list = File.open('examples/vote4.list')
|
145
|
+
voting = Vote::Schulze::Basic.call(voting_list)
|
146
|
+
voting.ranking_abc
|
152
147
|
#=> ["C:1", "D:2", "B:3", "A:4"]
|
153
148
|
```
|
154
149
|
|
@@ -156,18 +151,14 @@ which is the same result of the reference above.
|
|
156
151
|
|
157
152
|
The result strings are always in format `Candidate:Position`, because it's possible that multiple candidates can be on the same rank.
|
158
153
|
|
159
|
-
## Contributing
|
154
|
+
## Contributing
|
155
|
+
|
156
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/asaaki/vote-schulze. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
160
157
|
|
161
|
-
|
162
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
163
|
-
* Fork the project
|
164
|
-
* Use git-flow
|
165
|
-
* Start a feature/bugfix branch
|
166
|
-
* Commit and push until you are happy with your contribution
|
167
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
168
|
-
* 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.
|
158
|
+
## Code of Conduct
|
169
159
|
|
170
|
-
|
160
|
+
Everyone interacting in the vote-schulze project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/asaaki/vote-schulze/blob/master/CODE_OF_CONDUCT.md).
|
171
161
|
|
172
|
-
|
162
|
+
## License
|
173
163
|
|
164
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,45 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "vote-schulze"
|
18
|
-
gem.homepage = "http://github.com/asaaki/vote-schulze"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Schulze method implementation in Ruby (Condorcet voting method)}
|
21
|
-
gem.description = %Q{This gem is a Ruby implementation of the Schulze voting method (with help of the Floyd–Warshall algorithm), a type of the Condorcet voting methods.}
|
22
|
-
gem.email = "chris@dinarrr.com"
|
23
|
-
gem.authors = ["Christoph Grabo"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
28
|
-
require 'rspec/core'
|
3
|
+
require 'bundler/gem_tasks'
|
29
4
|
require 'rspec/core/rake_task'
|
30
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
-
end
|
33
|
-
|
34
|
-
task :default => :spec
|
35
|
-
|
36
|
-
require 'rake/rdoctask'
|
37
|
-
Rake::RDocTask.new do |rdoc|
|
38
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
5
|
|
40
|
-
|
41
|
-
rdoc.title = "vote-schulze #{version}"
|
42
|
-
rdoc.rdoc_files.include('README*')
|
43
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
-
end
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
45
7
|
|
8
|
+
task default: :spec
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'vote/schulze'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|