minor optimization
authorJoe Slag <joe@slagwerks.com>
Mon, 9 Apr 2007 18:36:35 +0000 (18:36 +0000)
committerJoe Slag <joe@slagwerks.com>
Mon, 9 Apr 2007 18:36:35 +0000 (18:36 +0000)
git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@23 1440c7f4-e209-0410-9a04-881b5eb134a8

lib/rubyvote/condorcet.rb

index b0471ec..4dd1745 100644 (file)
@@ -229,12 +229,15 @@ class CloneproofSSDResult < CondorcetResult
       candidates = [candidates] unless candidates.class == Array
       candidates.each do |cand1|
         candidates.each do |cand2|
-          candidates.each do |cand3|
-            if transitive_defeats.include?( [ cand2, cand1 ] ) and
-                transitive_defeats.include?( [ cand1, cand3 ] ) and
-                not transitive_defeats.include?( [ cand2, cand3 ] ) and
-                not cand2 == cand3
-              transitive_defeats << [ cand2, cand3 ]
+          unless cand1 == cand2
+            candidates.each do |cand3|
+              if not cand2 == cand3 and 
+                  not cand1 == cand3 and 
+                  transitive_defeats.include?( [ cand2, cand1 ] ) and
+                  transitive_defeats.include?( [ cand1, cand3 ] ) and
+                  not transitive_defeats.include?( [ cand2, cand3 ] )
+                transitive_defeats << [ cand2, cand3 ]
+              end
             end
           end
         end

Benjamin Mako Hill || Want to submit a patch?