Module: EvoSynth::Problems::BinaryBenchmarkFuntions
- Defined in:
- lib/evosynth/problems/binary_benchmark_functions.rb
Overview
This module contains some multi-dimensional Benchmarkfunctions. You simply set the number of dimensions by the length of the given (boolean) array.
Class Method Summary collapse
-
.count_ones(bs) ⇒ Object
count-ones function.
-
.n_peaks(peaks, xs) ⇒ Object
N-Peak problem presented in “Using Problem Generators to Explore the Effects of Epistasis”, De Jong et al 1997.
-
.royal_road(k, bs) ⇒ Object
Royal-Road function (Mitchell et al 1992).
Class Method Details
.count_ones(bs) ⇒ Object
count-ones function
global maximum at f(x) = x at x(i) = 1 (or true), i = 1..n
37 38 39 |
# File 'lib/evosynth/problems/binary_benchmark_functions.rb', line 37 def BinaryBenchmarkFuntions.count_ones(bs) bs.inject(0) { |sum, b| sum += (b == true || b == 1 ? 1 : 0) } end |
.n_peaks(peaks, xs) ⇒ Object
N-Peak problem presented in “Using Problem Generators to Explore the Effects of Epistasis”, De Jong et al 1997
global maximum: f(x) = 1.0 when peak == xs (hamming distance is 0)
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/evosynth/problems/binary_benchmark_functions.rb', line 60 def BinaryBenchmarkFuntions.n_peaks(peaks, xs) max_hamming_dist = xs.size peaks.each do |peak| new_dist = 0.0 xs.each_with_index { |x, index| new_dist += 1 if x != peak[index] } max_hamming_dist = new_dist if new_dist < max_hamming_dist end 1.0 / xs.size * (xs.size - max_hamming_dist) end |
.royal_road(k, bs) ⇒ Object
Royal-Road function (Mitchell et al 1992)
global minimum: f(x) = 0 at x(i) = 1, i = 1..n (bs.size % k == 0)
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/evosynth/problems/binary_benchmark_functions.rb', line 45 def BinaryBenchmarkFuntions.royal_road(k, bs) m = bs.size / k sum = 0 m.times do |i| sum += bs[(i*k)..(i+1)*k-1].inject(1) { |res, b| res = (b != 1 ? 0 : res) } end sum end |