Class: FeldtRuby::Optimize::SubQualitiesComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/feldtruby/optimize/sub_qualities_comparators.rb

Overview

A SubQualititesComparator can compare vectors of sub-qualitites for two individuals and rank the individuals based on if one is better (or dominates) the other.

Direct Known Subclasses

EpsilonNonDominance

Instance Method Summary collapse

Constructor Details

#initialize(objective) ⇒ SubQualitiesComparator

Returns a new instance of SubQualitiesComparator.



6
7
8
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 6

def initialize(objective)
  @objective = objective
end

Instance Method Details

#compare_candidates(candidate1, candidate2) ⇒ Object



18
19
20
21
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 18

def compare_candidates(candidate1, candidate2)
  sq1, sq2 = @objective.sub_qualities_of(candidate1), @objective.sub_qualities_of(candidate2)
  compare_sub_qualitites sq1, sq2
end

#compare_sub_qualitites(subQualitites1, subQualitites2) ⇒ Object

Compare two sub-quality vectors and return

-1 if the first one dominates the other one
 0 if none of them dominate the other
 1 if the second one dominates the first one

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 14

def compare_sub_qualitites(subQualitites1, subQualitites2)
  raise NotImplementedError
end

#first_dominates?(subQualitites1, subQualitites2) ⇒ Boolean

True iff the first dominates the second sub-quality vectors.

Returns:

  • (Boolean)


24
25
26
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 24

def first_dominates?(subQualitites1, subQualitites2)
  compare_sub_qualitites(subQualitites1, subQualitites2) == -1
end

#second_dominates?(subQualitites1, subQualitites2) ⇒ Boolean

True iff the second dominates the first sub-quality vectors.

Returns:

  • (Boolean)


29
30
31
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 29

def second_dominates?(subQualitites1, subQualitites2)
  compare_sub_qualitites(subQualitites1, subQualitites2) == 1
end