Class: Wallace::Operators::ShuffleMutationOperator

Inherits:
Wallace::Operator show all
Defined in:
lib/operators/shuffle_mutation_operation.rb

Overview

Shuffle mutation selects a random continuous series of genes in the chromosome and shuffles the order of gene values at random.

Instance Method Summary collapse

Methods inherited from Wallace::Operator

#initialize, #produce

Constructor Details

This class inherits a constructor from Wallace::Operator

Instance Method Details

#operate(rng, inputs) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/operators/shuffle_mutation_operation.rb', line 7

def operate(rng, inputs)

  # Shuffle the gene sequence between points i and j, where i < j. 
  i = rng.rand(inputs[0].length - 2)
  j = rng.rand(i...inputs[0].length)
  inputs[0][i..j] = inputs[0][i..j].shuffle(random: rng)
  return inputs

end