Class: FeldtRuby::Optimize::EpsilonNonDominance

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

Overview

Epsilon-distance non-dominance comparator. Default epsilon is 0.0 which gives the standard non-dominance comparator.

Instance Method Summary collapse

Methods inherited from SubQualitiesComparator

#compare_candidates, #first_dominates?, #second_dominates?

Constructor Details

#initialize(objective, epsilon = 0.0) ⇒ EpsilonNonDominance

Returns a new instance of EpsilonNonDominance.



37
38
39
40
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 37

def initialize(objective, epsilon = 0.0)
  super(objective)
  @epsilon = epsilon
end

Instance Method Details

#compare_sub_qualitites(subQualitites1, subQualitites2) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 55

def compare_sub_qualitites(subQualitites1, subQualitites2)
  hat_values = map_hat_operator(subQualitites1, subQualitites2)
  num_1_better = num_2_better = 0
  hat_values.each do |hv|
    if hv == -1
      num_1_better += 1
    elsif hv == 1
      num_2_better += 1
    end
  end
  if num_1_better > 0
    (num_2_better == 0) ? -1 : 0
  else
    (num_2_better > 0) ? 1 : 0
  end
end

#map_hat_operator(sq1, sq2) ⇒ Object

Map hat operator to paired sub-quality values.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/feldtruby/optimize/sub_qualities_comparators.rb', line 43

def map_hat_operator(sq1, sq2)
  # NOTE! Below we assume that all sub-objectives should be minimized. If not we should
  # change the sign of the hat operator return value!
  sq1.zip(sq2).map do |sqv1, sqv2|
    if (sqv1 - sqv2).abs > @epsilon
      (sqv1 < sqv2) ? -1 : 1
    else
      0
    end
  end
end