- Timestamp:
- 03/05/10 13:14:26 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/LocalCrossover.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 { … … 31 32 /// always newly created randomly chosen factor and adds the allele of the second parent times (1 - the randomly chosen factor). 32 33 /// </summary> 33 public class LocalCrossover : RealVectorCrossoverBase { 34 /// <inheritdoc select="summary"/> 35 public override string Description { 36 get { return "Local crossover for real vectors."; } 37 } 38 34 /// <remarks> 35 /// It is implemented as described in Dumitrescu, D. et al. (2000), Evolutionary computation, CRC Press, Boca Raton, FL, p. 194. 36 /// </remarks> 37 [Item("LocalCrossover", "Local crossover for real vectors: Takes for each element the allele of the first parent times a always newly created randomly chosen factor and adds the allele of the second parent times (1 - the randomly chosen factor. " + 38 "It is implemented as described in Dumitrescu, D. et al. (2000), Evolutionary computation, CRC Press, Boca Raton, FL., p. 194.")] 39 [EmptyStorableClass] 40 public class LocalCrossover : RealVectorCrossover { 39 41 /// <summary> 40 42 /// Performs a local crossover on the two given parent vectors. 41 43 /// </summary> 44 /// <exception cref="ArgumentException">Thrown when two parents are not of the same length.</exception> 42 45 /// <param name="random">The random number generator.</param> 43 46 /// <param name="parent1">The first parent for the crossover operation.</param> 44 47 /// <param name="parent2">The second parent for the crossover operation.</param> 45 48 /// <returns>The newly created real vector, resulting from the local crossover.</returns> 46 public static double[] Apply(IRandom random, double[] parent1, double[] parent2) { 49 public static DoubleArrayData Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2) { 50 if (parent1.Length != parent2.Length) 51 throw new ArgumentException("ERROR in LocalCrossover: the two parents are not of the same length"); 52 47 53 double factor; 48 54 int length = parent1.Length; … … 53 59 result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]); 54 60 } 55 return result;61 return new DoubleArrayData(result); 56 62 } 57 63 … … 59 65 /// Performs a local crossover operation for two given parent real vectors. 60 66 /// </summary> 61 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 62 /// <param name="scope">The current scope.</param> 67 /// <exception cref="ArgumentException">Thrown if there are not exactly two parents.</exception> 63 68 /// <param name="random">A random number generator.</param> 64 69 /// <param name="parents">An array containing the two real vectors that should be crossed.</param> 65 70 /// <returns>The newly created real vector, resulting from the crossover operation.</returns> 66 protected override double[] Cross(IScope scope, IRandom random, double[][]parents) {67 if (parents.Length != 2) throw new InvalidOperationException("ERROR in LocalCrossover: The number of parents is not equal to 2");71 protected override DoubleArrayData Cross(IRandom random, ItemArray<DoubleArrayData> parents) { 72 if (parents.Length != 2) throw new ArgumentException("ERROR in LocalCrossover: The number of parents is not equal to 2"); 68 73 return Apply(random, parents[0], parents[1]); 69 74 }
Note: See TracChangeset
for help on using the changeset viewer.