Class: Operator::Tweak::RandomSwap

Inherits:
Object
  • Object
show all
Defined in:
lib/opt_alg_framework/operator/tweak/random_swap.rb

Instance Method Summary collapse

Instance Method Details

#tweak(solution) ⇒ Object

Main method.



6
7
8
9
10
11
12
13
14
# File 'lib/opt_alg_framework/operator/tweak/random_swap.rb', line 6

def tweak(solution)
  copy = solution.dup
  piece1 = Random.rand(0...copy.size)
  piece2 = Random.rand(0...copy.size)
  x = copy[piece1]
  copy[piece1] = copy[piece2]
  copy[piece2] = x
  copy
end