- Timestamp:
- 02/16/09 01:21:53 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.RealVector/BlendAlphaBetaCrossover.cs
r1184 r1218 34 34 /// solution by the factor alpha, into the direction of the 'worse' solution by the factor beta. 35 35 /// </summary> 36 public class BlendAlphaBetaCrossover : CrossoverBase {36 public class BlendAlphaBetaCrossover : RealVectorCrossoverBase { 37 37 /// <inheritdoc select="summary"/> 38 38 public override string Description { … … 45 45 /// <summary> 46 46 /// Initializes a new instance of <see cref="BlendAlphaBetaCrossover"/> with five variable infos 47 /// (<c>Maximization</c>, <c>Quality</c>, <c> RealVector</c>, <c>Alpha</c> and <c>Beta</c>).47 /// (<c>Maximization</c>, <c>Quality</c>, <c>Alpha</c> and <c>Beta</c>). 48 48 /// </summary> 49 49 public BlendAlphaBetaCrossover() … … 51 51 AddVariableInfo(new VariableInfo("Maximization", "Maximization problem", typeof(BoolData), VariableKind.In)); 52 52 AddVariableInfo(new VariableInfo("Quality", "Quality value", typeof(DoubleData), VariableKind.In)); 53 AddVariableInfo(new VariableInfo("RealVector", "Parent and child real vector", typeof(DoubleArrayData), VariableKind.In | VariableKind.New));54 53 VariableInfo alphaVarInfo = new VariableInfo("Alpha", "Value for alpha", typeof(DoubleData), VariableKind.In); 55 54 alphaVarInfo.Local = true; … … 110 109 111 110 /// <summary> 112 /// Performs a blend alpha beta crossover o f tworeal vectors.111 /// Performs a blend alpha beta crossover operation for two given parent real vectors. 113 112 /// </summary> 113 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 114 114 /// <param name="scope">The current scope.</param> 115 /// <param name="random"> Therandom number generator.</param>116 /// <param name="parent 1">The first parent for the crossover.</param>117 /// < param name="parent2">The second parent for the crossover.</param>118 /// <param name="child">The created child generated through the blend alpha beta crossover.</param>119 protected sealed override void Cross(IScope scope, IRandom random, IScope parent1, IScope parent2, IScope child) {115 /// <param name="random">A random number generator.</param> 116 /// <param name="parents">An array containing the two real vectors that should be crossed.</param> 117 /// <returns>The newly created real vector, resulting from the crossover operation.</returns> 118 protected override double[] Cross(IScope scope, IRandom random, double[][] parents) { 119 if (parents.Length != 2) throw new InvalidOperationException("ERROR in BlendAlphaBetaCrossover: The number of parents is not equal to 2"); 120 120 bool maximization = GetVariableValue<BoolData>("Maximization", scope, true).Data; 121 DoubleArrayData vector1 = parent1.GetVariableValue<DoubleArrayData>("RealVector", false); 122 DoubleData quality1 = parent1.GetVariableValue<DoubleData>("Quality", false); 123 DoubleArrayData vector2 = parent2.GetVariableValue<DoubleArrayData>("RealVector", false); 124 DoubleData quality2 = parent2.GetVariableValue<DoubleData>("Quality", false); 121 double quality1 = scope.SubScopes[0].GetVariableValue<DoubleData>("Quality", false).Data; 122 double quality2 = scope.SubScopes[1].GetVariableValue<DoubleData>("Quality", false).Data; 125 123 double alpha = GetVariableValue<DoubleData>("Alpha", scope, true).Data; 126 124 double beta = GetVariableValue<DoubleData>("Beta", scope, true).Data; 127 125 128 if (vector1.Data.Length != vector2.Data.Length) throw new InvalidOperationException("Cannot apply crossover to real vectors of different length."); 129 130 double[] result = Apply(random, maximization, vector1.Data, quality1.Data, vector2.Data, quality2.Data, alpha, beta); 131 child.AddVariable(new Variable(child.TranslateName("RealVector"), new DoubleArrayData(result))); 126 return Apply(random, maximization, parents[0], quality1, parents[1], quality2, alpha, beta); 132 127 } 133 128 }
Note: See TracChangeset
for help on using the changeset viewer.