Class: AnswerFactory::Machines::SelectNondominated

Inherits:
Machine
  • Object
show all
Defined in:
lib/machines/select_nondominated.rb

Instance Attribute Summary

Attributes inherited from Machine

#options

Instance Method Summary collapse

Methods inherited from Machine

#initialize

Constructor Details

This class inherits a constructor from AnswerFactory::Machines::Machine

Instance Method Details

#screen(batch, overriden_options = {}) ⇒ Object Also known as: generate

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/machines/select_nondominated.rb', line 9

def screen(batch, overriden_options={})
  raise ArgumentError, "SelectNondominated#screen cannot process class #{batch.class}" unless
    batch.kind_of?(Batch)
  all_options = @options.merge(overriden_options)
  
  criteria = all_options[:comparison_criteria]
  result = Batch.new
  
  batch.each do |a|
    if criteria.nil?
      winner = batch.inject(true) {|anded, b| anded && (!a.dominated_by?(b))}
    else
      winner = batch.inject(true) {|anded, b| anded && (!a.dominated_by?(b, criteria))}
    end
    result << a if winner
  end
  
  return result
end