/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
 */
package io.jenetics.ext;

import java.util.Random;

import io.jenetics.AbstractAlterer;
import io.jenetics.Chromosome;
import io.jenetics.Gene;
import io.jenetics.Mutator;
import io.jenetics.MutatorResult;
import io.jenetics.internal.math.comb;
import io.jenetics.internal.math.probability;
import io.jenetics.util.MSeq;

/**
 * The Hybridizing
 *  ing PSM and RSM Operator (HPRM)
 * constructs an offspring from a pair of parents by hybridizing
 * two mutation
 *  tion operators, PSM and RSM.
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 * @version !__version__!
 * @since !__version__!
 */
public class HPRMutator<
	G extends Gene<?, G>,
	C extends Comparable<? super C>
>
	extends Mutator<G, C>
{

	/**
	 * Constructs an alterer with a given recombination probability.
	 *
	 * @param probability the crossover probability.
	 * @throws IllegalArgumentException if the {@code probability} is not in the
	 *          valid range of {@code [0, 1]}.
	 */
	public HPRMutator(final double probability) {
		super(probability);
	}

	/**
	 * Default constructor, with default mutation probability
	 * ({@link AbstractAlterer#DEFAULT_ALTER_PROBABILITY}).
	 */
	public HPRMutator() {
		this(DEFAULT_ALTER_PROBABILITY);
	}

	@Override
	protected MutatorResult<Chromosome<G>> mutate(
		final Chromosome<G> chromosome,
		final double p,
		final Random random
	) {
		final MutatorResult<Chromosome<G>> result;
		if (chromosome.length() > 1) {
			final int P = probability.toInt(p);
			final int[] points = comb.subset(chromosome.length() + 1, 2);
			final MSeq<G> genes = chromosome.toSeq().copy();

			int mutations = 0;
			for (int i = points[0], j = points[1]; i < j; ++i, --j) {
				genes.swap(i, j);
				++mutations;

				if (random.nextInt() < P) {
					genes.swap(i, random.nextInt(chromosome.length()));
					++mutations;
				}
			}

			result = MutatorResult.of(
				chromosome.newInstance(genes.toISeq()),
				mutations
			);
		} else {
			result = MutatorResult.of(chromosome);
		}

		return result;
	}

}

@@ -1085,16 +1085,8 @@
 zing
-%0A *  ing
  PSM
@@ -1109,19 +1109,16 @@
 r (HPRM)
-%0A *
  constru
@@ -1140,16 +1140,19 @@
 g from a
+%0A *
  pair of
@@ -1174,19 +1174,16 @@
 ridizing
-%0A *
  two mut
@@ -1191,17 +1191,8 @@
 tion
-%0A *  tion
  ope
@@ -1211,16 +1211,337 @@
 and RSM.
+%0A * %3Cp%3E%0A * This mutator is described in %3Ca href=%22https://arxiv.org/abs/1203.5028%22%3EA New%0A * Mutation Operator for Solving an NP-Complete Problem: Travelling Salesman%0A * Problem%3C/a%3E, by %3Cem%3EOtman Abdoun, Chakir Tajani%3C/em%3E and%0A * %3Cem%3EJaafar Abouchabka%3C/em%3E.%0A *%0A * @see ReverseSequenceMutator%0A * @see io.jenetics.SwapMutator
 %0A *%0A * @
@@ -2611,18 +2611,14 @@
 th()
- + 1
 , 2);%0A
+
 %09%09%09f
@@ -2685,17 +2685,45 @@
 tions = 
-0
+(points%5B1%5D - points%5B0%5D + 1)/2
 ;%0A%09%09%09for
@@ -2773,24 +2773,24 @@
 ++i, --j) %7B%0A
+
 %09%09%09%09genes.sw
@@ -2803,26 +2803,8 @@
 j);%0A
-%09%09%09%09++mutations;%0A%0A
 %09%09%09%09

Fix mutator + Javadoc.