#region License Information
/* HeuristicLab
* Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HEAL.Attic;
namespace HeuristicLab.Encodings.BinaryVectorEncoding {
///
/// Single point crossover for binary vectors.
///
///
/// It is implemented based on the NPointCrossover
///
[Item("SinglePointCrossover", "Single point crossover for binary vectors. It is implemented based on the NPointCrossover.")]
[StorableType("40B6A5D5-8937-495E-8B98-2E4F8FD06D93")]
public sealed class SinglePointCrossover : BinaryVectorCrossover {
[StorableConstructor]
private SinglePointCrossover(StorableConstructorFlag _) : base(_) { }
private SinglePointCrossover(SinglePointCrossover original, Cloner cloner) : base(original, cloner) { }
public SinglePointCrossover() : base() { }
public override IDeepCloneable Clone(Cloner cloner) {
return new SinglePointCrossover(this, cloner);
}
///
/// Performs a single point crossover at a randomly chosen position of two
/// given parent binary vectors.
///
/// Thrown if there are not exactly two parents.
/// A random number generator.
/// An array containing the two binary vectors that should be crossed.
/// The newly created binary vector, resulting from the single point crossover.
protected override BinaryVector Cross(IRandom random, ItemArray parents) {
if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2");
return NPointCrossover.Apply(random, parents[0], parents[1], new IntValue(1));
}
}
}