#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 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 System.Collections.Generic;
using System.Text;
using HeuristicLab.Core;
using HeuristicLab.Data;
namespace HeuristicLab.RealVector {
///
/// Mühlenbein, Schlierkamp-Voosen (1993)
/// Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization
/// Changes one position of a real vector by adding/substracting a value of the interval [(2^-15)*range, ..., (2^0)*range], where range is SearchIntervalFactor * (max - min).
///
public class BreederGeneticAlgorithmManipulator : RealVectorManipulatorBase {
///
public override string Description {
get {
return
@"Breeder Genetic Algorithm Manipulator (Mühlenbein, Schlierkamp-Voosen, 1993). Changes one position of a real vector by adding/substracting a value of the interval [(2^-15)*range, ..., (2^0)*range], where range is SearchIntervalFactor * (max - min).
Mühlenbein, Schlierkamp-Voosen (1993). Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization";
}
}
///
/// Initializes a new instance of with three variable
/// infos (Minimum, Maximum and SearchIntervalFactor).
///
public BreederGeneticAlgorithmManipulator()
: base() {
AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In));
AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In));
VariableInfo sifInfo = new VariableInfo("SearchIntervalFactor", "The factor determining the size of the search interval, that will be added/removed to/from the allele selected for manipulation.", typeof(DoubleData), VariableKind.In);
sifInfo.Local = true;
AddVariableInfo(sifInfo);
AddVariable(new Variable("SearchIntervalFactor", new DoubleData(0.1)));
}
///
/// Performs a Breeder Genetic Algorithm Manipulation on the given .
///
/// The current scope.
/// A random number generator.
/// The real vector to manipulate.
/// The minimum number of the sampling range for the vector element (inclusive).
/// The maximum number of the sampling range for the vector element (exclusive).
/// The factor determining the size of the search interval.
/// The manipulated real vector.
public static double[] Apply(IScope scope, IRandom random, double[] vector, double min, double max, double searchIntervalFactor) {
int length = vector.Length;
int pos = random.Next(length);
double range = searchIntervalFactor * (max - min);
double value = range * Sigma(random);
if (random.NextDouble() < 0.5) {
vector[pos] = vector[pos] + value;
} else {
vector[pos] = vector[pos] - value;
}
return vector;
}
private static double Sigma(IRandom random) {
double sigma = 0;
int limit = 16;
for (int i = 0; i < limit; i++) {
if (random.Next(limit) == 15) {
// execute this statement with a probability of 1/16
sigma += Math.Pow(2, -i);
}
}
return sigma;
}
///
/// Performs a Breeder Genetic Algorithm Manipulation on the given .
///
/// Calls .
/// The current scope.
/// The random number generator.
/// The real vector to manipulate.
/// The manipulated real vector
protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
double min = GetVariableValue("Minimum", scope, true).Data;
double max = GetVariableValue("Maximum", scope, true).Data;
double searchIntervalFactor = GetVariableValue("SearchIntervalFactor", scope, true).Data;
return Apply(scope, random, vector, min, max, searchIntervalFactor);
}
}
}