Skip to content

Instantly share code, notes, and snippets.

View takahashilabo's full-sized avatar

Keiichi Takahashi takahashilabo

View GitHub Profile
@nikosd
nikosd / pmx_operator.rb
Created January 18, 2009 11:29
Two point partial preservation crossover for PermutationGenotype, also known as Partially Mapped Crossover (PMX).
# Two point partial preservation crossover for PermutationGenotype, also known as Partially Mapped Crossover (PMX).
#
# The PMX proceeds by choosing two cut points at random:
# Parent 1: hkcefd bla igj
# Parent 2: abcdef ghi jkl
#
# The cut-out section defines a series of swapping operations to be performed on the second parent.
# In the example case, we swap b with g, l with h and a with i and end up with the following offspring:
# Offspring: igcdef bla jkh
# Performing similar swapping on the first parent gives the other offspring: