Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created July 30, 2010 00:16
Show Gist options
  • Select an option

  • Save Vaguery/499569 to your computer and use it in GitHub Desktop.

Select an option

Save Vaguery/499569 to your computer and use it in GitHub Desktop.
# encoding: UTF-8
module Machine::Nudge
class SplitTournament < Machine
def process (answers)
@criteria ||= []
@tournament_size ||= 20
winners = []
losers = []
until answers.empty?
answers.shuffle!
some = answers.slice!(0..@tournament_size)
indices_of_best = []
some.each_with_index do |a, index|
nondominated = true
some.each do |b|
nondominated_vs_b = true
@criteria.each do |score_name|
a_score = a.score(score_name)
b_score = b.score(score_name)
if a_score < b_score
nondominated_vs_b = true
break
elsif nondominated_vs_b
nondominated_vs_b &&= (a_score == b_score)
end
end
break unless nondominated &&= nondominated_vs_b
end
indices_of_best << index if nondominated
end
indices_of_best.reverse.each do |i|
winners << some.delete_at(i)
end
left = some.length
left.times {losers << some.pop}
end
return :winners => winners,
:losers => losers
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment