Changeset 2936 for trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/RandomConvexCrossover.cs
- Timestamp:
- 03/05/10 13:14:26 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/RandomConvexCrossover.cs
r2900 r2936 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Encodings.RealVector { … … 32 33 /// (1 - the randomly chosen factor). 33 34 /// </summary> 34 public class RandomConvexCrossover : RealVectorCrossoverBase { 35 /// <inheritdoc select="summary"/> 36 public override string Description { 37 get { return "Random convex crossover for real vectors."; } 38 } 39 35 /// <remarks> 36 /// It is implemented as described in Dumitrescu, D. et al. (2000), Evolutionary computation, CRC Press, Boca Raton, FL, pp. 193 - 194. 37 /// </remarks> 38 [Item("RandomConvexCrossover", "Random convex crossover for real vectors: Takes for each element the allele of the first parent times a once created randomly chosen factor and adds the allele of the second parent times (1 - the randomly chosen factor). " + 39 "It is implementes as described in Dumitrescu, D. et al. (2000), Evolutionary computation, CRC Press, Boca Raton, FL, pp. 193 - 194.")] 40 [EmptyStorableClass] 41 public class RandomConvexCrossover : RealVectorCrossover { 40 42 /// <summary> 41 43 /// Performs a random convex crossover on the two given parents. 42 44 /// </summary> 45 /// <exception cref="ArgumentException">Thrown when two parents are not of the same length.</exception> 43 46 /// <param name="random">The random number generator.</param> 44 47 /// <param name="parent1">The first parent vector for the crossover.</param> 45 48 /// <param name="parent2">The second parent vector for the crossover.</param> 46 49 /// <returns>The newly created real vector, resulting from the random convex crossover.</returns> 47 public static double[] Apply(IRandom random, double[] parent1, double[] parent2) { 50 public static DoubleArrayData Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2) { 51 if (parent1.Length != parent2.Length) 52 throw new ArgumentException("ERROR in RandomConvexCrossover: the two parents are not of the same length"); 53 48 54 int length = parent1.Length; 49 55 double[] result = new double[length]; … … 52 58 for (int i = 0; i < length; i++) 53 59 result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]); 54 return result;60 return new DoubleArrayData(result); 55 61 } 56 62 … … 58 64 /// Performs a random convex crossover operation for two given parent real vectors. 59 65 /// </summary> 60 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 61 /// <param name="scope">The current scope.</param> 66 /// <exception cref="ArgumentException">Thrown if there are not exactly two parents.</exception> 62 67 /// <param name="random">A random number generator.</param> 63 68 /// <param name="parents">An array containing the two real vectors that should be crossed.</param> 64 69 /// <returns>The newly created real vector, resulting from the crossover operation.</returns> 65 protected override double[] Cross(IScope scope, IRandom random, double[][]parents) {66 if (parents.Length != 2) throw new InvalidOperationException("ERROR in RandomConvexCrossover: The number of parents is not equal to 2");70 protected override DoubleArrayData Cross(IRandom random, ItemArray<DoubleArrayData> parents) { 71 if (parents.Length != 2) throw new ArgumentException("ERROR in RandomConvexCrossover: The number of parents is not equal to 2"); 67 72 return Apply(random, parents[0], parents[1]); 68 73 }
Note: See TracChangeset
for help on using the changeset viewer.