Added matrix to condorcet to draw a table of winners vs losers. Also added "points...
authorJustin Sharps <jlsharps@alum.mit.edu>
Wed, 15 Aug 2007 22:12:45 +0000 (22:12 +0000)
committerJustin Sharps <jlsharps@alum.mit.edu>
Wed, 15 Aug 2007 22:12:45 +0000 (22:12 +0000)
git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@38 1440c7f4-e209-0410-9a04-881b5eb134a8

lib/rubyvote/condorcet.rb
lib/rubyvote/election.rb
lib/rubyvote/positional.rb

index aaa504477373e07735b6eab9b7c847db0c68232a..bf4e548da45bcbb6d9c3ebfa57269d065bf09b6a 100644 (file)
@@ -32,7 +32,7 @@
 ## the CloneproofSSDVote classes but should not be used directly.
 
 class CondorcetVote < ElectionVote
-
+  
   attr_accessor :results
 
   def initialize(votes=nil)
@@ -144,15 +144,17 @@ end
 ## directly.
 
 class CondorcetResult < ElectionResult
+  attr_reader :matrix
+  
   def initialize(voteobj=nil)
     unless voteobj and voteobj.kind_of?( CondorcetVote )
       raise ArgumentError, "You must pass a CondorcetVote array.", caller
     end
     super(voteobj)
+    @matrix = voteobj.votes
   end
 
   protected
-
   def defeats(candidates=nil, votes=nil)
     candidates = @election.candidates unless candidates
     votes = @election.votes unless votes
index 42f18bb6c9fa7470e34c46051787573b377fdce2..ffd31c846e56400e9df945361d5a4c11ebb9df9d 100644 (file)
@@ -140,7 +140,8 @@ end
 
 class PluralityResult < ElectionResult
   attr_reader :ranked_candidates
-
+  attr_reader :points
+  
   def initialize(voteobj=nil)
     super(voteobj)
 
@@ -151,6 +152,8 @@ class PluralityResult < ElectionResult
       b[1] <=> a[1]
     end.collect {|a| a[0]}
     
+    @points = @election.votes
+    
     # winners are anyone who has the same number of votes as the
     # first person
     @winners = @ranked_candidates.find_all do |i|
index 3de3fb29ae6f20b0371eedacb41471ff73be279f..056194b519dc88f2a79adc3617bf95f250fa3310 100644 (file)
@@ -38,7 +38,7 @@ class BordaVote < ElectionVote
     end
     super(votes)
   end
-
+   
   def tally_vote(vote)
     points = candidates.length - 1
     vote.each do |candidate|
@@ -51,7 +51,7 @@ class BordaVote < ElectionVote
       points -= 1
     end
   end
-
+  
   def verify_vote(vote=nil)
     vote.instance_of?( Array ) and
       vote == vote.uniq
@@ -64,11 +64,12 @@ end
 
 class BordaResult < ElectionResult
   attr_reader :ranked_candidates
+  attr_reader :points
   
   def initialize(voteobj=nil)
     super(voteobj)
     votes = @election.votes
-
+    
     @ranked_candidates = votes.sort do |a, b|
       b[1] <=> a[1]
     end.collect {|i| i[0]}
@@ -76,6 +77,8 @@ class BordaResult < ElectionResult
     @winners = @ranked_candidates.find_all do |i|
       votes[i] == votes[@ranked_candidates[0]]
     end
+    
+    @points = @election.votes
   end
 
 end

Benjamin Mako Hill || Want to submit a patch?