- Timestamp:
- 03/16/10 10:46:59 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/AverageCrossover.cs
r3053 r3060 45 45 /// <param name="parents">The list of parents.</param> 46 46 /// <returns>The child vector (average) of the parents.</returns> 47 public static DoubleArray Apply(IRandom random, ItemArray<DoubleArray> parents) {47 public static RealVector Apply(IRandom random, ItemArray<RealVector> parents) { 48 48 int length = parents[0].Length, parentsCount = parents.Length; 49 49 if (parents.Length < 2) throw new ArgumentException("AverageCrossover: The number of parents is less than 2.", "parents"); 50 DoubleArray result = new DoubleArray(length);50 RealVector result = new RealVector(length); 51 51 try { 52 52 double avg; … … 65 65 66 66 /// <summary> 67 /// Forwards the call to <see cref="Apply(IRandom, ItemArray< DoubleArray>)"/>.67 /// Forwards the call to <see cref="Apply(IRandom, ItemArray<RealVector>)"/>. 68 68 /// </summary> 69 69 /// <param name="random">The random number generator.</param> 70 70 /// <param name="parents">The list of parents.</param> 71 71 /// <returns>The child vector (average) of the parents.</returns> 72 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {72 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 73 73 return Apply(random, parents); 74 74 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/BlendAlphaBetaCrossover.cs
r3053 r3060 94 94 /// <param name="beta">The parameter beta.</param> 95 95 /// <returns>The real vector that results from the crossover.</returns> 96 public static DoubleArray Apply(IRandom random, DoubleArray betterParent, DoubleArrayworseParent, DoubleValue alpha, DoubleValue beta) {96 public static RealVector Apply(IRandom random, RealVector betterParent, RealVector worseParent, DoubleValue alpha, DoubleValue beta) { 97 97 if (betterParent.Length != worseParent.Length) throw new ArgumentException("BlendAlphaBetaCrossover: The parents' vectors are of different length.", "betterParent"); 98 98 if (alpha.Value < 0) throw new ArgumentException("BlendAlphaBetaCrossover: Parameter alpha must be greater or equal to 0.", "alpha"); … … 100 100 int length = betterParent.Length; 101 101 double min, max, d; 102 DoubleArray result = new DoubleArray(length);102 RealVector result = new RealVector(length); 103 103 104 104 for (int i = 0; i < length; i++) { … … 117 117 118 118 /// <summary> 119 /// Checks if the number of parents is equal to 2, if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, DoubleValue, DoubleValue)"/>.119 /// Checks if the number of parents is equal to 2, if all parameters are available and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector, DoubleValue, DoubleValue)"/>. 120 120 /// </summary> 121 121 /// <exception cref="ArgumentException">Thrown when the number of parents is not equal to 2.</exception> … … 132 132 /// <param name="parents">The collection of parents (must be of size 2).</param> 133 133 /// <returns>The real vector that results from the crossover.</returns> 134 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {134 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 135 135 if (parents.Length != 2) throw new ArgumentException("BlendAlphaBetaCrossover: Number of parents is not equal to 2.", "parents"); 136 136 if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaBetaCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found."); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/BlendAlphaCrossover.cs
r3053 r3060 70 70 /// <param name="alpha">The alpha value for the crossover.</param> 71 71 /// <returns>The newly created real vector resulting from the crossover operation.</returns> 72 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArrayparent2, DoubleValue alpha) {72 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha) { 73 73 if (parent1.Length != parent2.Length) throw new ArgumentException("BlendAlphaCrossover: The parents' vectors are of different length.", "parent1"); 74 74 if (alpha.Value < 0) throw new ArgumentException("BlendAlphaCrossover: Paramter alpha must be greater or equal than 0.", "alpha"); 75 75 int length = parent1.Length; 76 DoubleArray result = new DoubleArray(length);76 RealVector result = new RealVector(length); 77 77 double max = 0, min = 0, d = 0, resMin = 0, resMax = 0; 78 78 … … 90 90 91 91 /// <summary> 92 /// Checks that the number of parents is equal to 2 and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, DoubleValue)"/>.92 /// Checks that the number of parents is equal to 2 and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector, DoubleValue)"/>. 93 93 /// </summary> 94 94 /// <exception cref="ArgumentException">Thrown when the number of parents is not equal to 2.</exception> … … 97 97 /// <param name="parents">The collection of parents (must be of size 2).</param> 98 98 /// <returns>The real vector resulting from the crossover operation.</returns> 99 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {99 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 100 100 if (parents.Length != 2) throw new ArgumentException("BlendAlphaCrossover: The number of parents is not equal to 2", "parents"); 101 101 if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaCrossover: Parameter " + AlphaParameter.ActualName + " could not be found."); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs
r3053 r3060 45 45 /// <param name="parents">An array containing the parents that should be crossed.</param> 46 46 /// <returns>The newly created real vector, resulting from the crossover operation.</returns> 47 public static DoubleArray Apply(IRandom random, ItemArray<DoubleArray> parents) {47 public static RealVector Apply(IRandom random, ItemArray<RealVector> parents) { 48 48 int length = parents[0].Length; 49 49 … … 53 53 } 54 54 55 DoubleArray result = new DoubleArray(length);55 RealVector result = new RealVector(length); 56 56 for (int i = 0; i < length; i++) { 57 57 result[i] = parents[random.Next(parents.Length)][i]; … … 62 62 63 63 /// <summary> 64 /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, ItemArray< DoubleArray>)"/>.64 /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, ItemArray<RealVector>)"/>. 65 65 /// </summary> 66 66 /// <exception cref="ArgumentException">Thrown when <paramref name="parents"/> contains less than 2 elements.</exception> … … 68 68 /// <param name="parents">The collection of parents (must be of size 2 or greater).</param> 69 69 /// <returns>The real vector resulting from the crossover.</returns> 70 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {70 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 71 71 if (parents.Length < 2) throw new ArgumentException("DiscreteCrossover: The number of parents is less than 2.", "parents"); 72 72 return Apply(random, parents); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/HeuristicCrossover.cs
r3053 r3060 68 68 /// <param name="worseParent">The second parent for the crossover operation.</param> 69 69 /// <returns>The newly created real vector, resulting from the heuristic crossover.</returns> 70 public static DoubleArray Apply(IRandom random, DoubleArray betterParent, DoubleArrayworseParent) {70 public static RealVector Apply(IRandom random, RealVector betterParent, RealVector worseParent) { 71 71 if (betterParent.Length != worseParent.Length) 72 72 throw new ArgumentException("HeuristicCrossover: the two parents are not of the same length"); … … 79 79 result[i] = betterParent[i] + factor * (betterParent[i] - worseParent[i]); 80 80 } 81 return new DoubleArray(result);81 return new RealVector(result); 82 82 } 83 83 … … 96 96 /// <param name="parents">An array containing the two real vectors that should be crossed.</param> 97 97 /// <returns>The newly created real vector, resulting from the crossover operation.</returns> 98 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {98 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 99 99 if (parents.Length != 2) throw new ArgumentException("HeuristicCrossover: The number of parents is not equal to 2"); 100 100 -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/LocalCrossover.cs
r3053 r3060 43 43 /// <param name="parent2">The second parent for the crossover operation.</param> 44 44 /// <returns>The newly created real vector, resulting from the local crossover.</returns> 45 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArrayparent2) {45 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2) { 46 46 if (parent1.Length != parent2.Length) 47 47 throw new ArgumentException("LocalCrossover: the two parents are not of the same length"); … … 55 55 result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]); 56 56 } 57 return new DoubleArray(result);57 return new RealVector(result); 58 58 } 59 59 … … 65 65 /// <param name="parents">An array containing the two real vectors that should be crossed.</param> 66 66 /// <returns>The newly created real vector, resulting from the crossover operation.</returns> 67 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {67 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 68 68 if (parents.Length != 2) throw new ArgumentException("LocalCrossover: The number of parents is not equal to 2"); 69 69 return Apply(random, parents[0], parents[1]); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/RandomConvexCrossover.cs
r3053 r3060 43 43 /// <param name="parent2">The second parent vector for the crossover.</param> 44 44 /// <returns>The newly created real vector, resulting from the random convex crossover.</returns> 45 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArrayparent2) {45 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2) { 46 46 if (parent1.Length != parent2.Length) 47 47 throw new ArgumentException("ERROR in RandomConvexCrossover: the two parents are not of the same length"); … … 53 53 for (int i = 0; i < length; i++) 54 54 result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]); 55 return new DoubleArray(result);55 return new RealVector(result); 56 56 } 57 57 … … 63 63 /// <param name="parents">An array containing the two real vectors that should be crossed.</param> 64 64 /// <returns>The newly created real vector, resulting from the crossover operation.</returns> 65 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {65 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 66 66 if (parents.Length != 2) throw new ArgumentException("ERROR in RandomConvexCrossover: The number of parents is not equal to 2"); 67 67 return Apply(random, parents[0], parents[1]); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/SimulatedBinaryCrossover.cs
r3053 r3060 66 66 /// <param name="contiguity">The contiguity value that specifies how close a child should be to its parents (larger value means closer). The value must be greater or equal than 0. Typical values are in the range [2;5].</param> 67 67 /// <returns>The vector resulting from the crossover.</returns> 68 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArrayparent2, DoubleValue contiguity) {68 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue contiguity) { 69 69 if (parent1.Length != parent2.Length) throw new ArgumentException("SimulatedBinaryCrossover: Parents are of unequal length"); 70 70 if (contiguity.Value < 0) throw new ArgumentException("SimulatedBinaryCrossover: Contiguity value is smaller than 0", "contiguity"); 71 71 int length = parent1.Length; 72 DoubleArray result = new DoubleArray(length);72 RealVector result = new RealVector(length); 73 73 for (int i = 0; i < length; i++) { 74 74 if (length == 1 || random.NextDouble() < 0.5) { // cross this variable … … 92 92 93 93 /// <summary> 94 /// Checks number of parents, availability of the parameters and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, DoubleValue)"/>.94 /// Checks number of parents, availability of the parameters and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector, DoubleValue)"/>. 95 95 /// </summary> 96 96 /// <exception cref="ArgumentException">Thrown when there are not exactly 2 parents or when the contiguity parameter could not be found.</exception> … … 98 98 /// <param name="parents">The collection of parents (must be of size 2).</param> 99 99 /// <returns>The real vector resulting from the crossover.</returns> 100 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {100 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 101 101 if (parents.Length != 2) throw new ArgumentException("SimulatedBinaryCrossover: The number of parents is not equal to 2"); 102 102 if (ContiguityParameter.ActualValue == null) throw new InvalidOperationException("SimulatedBinaryCrossover: Parameter " + ContiguityParameter.ActualName + " could not be found."); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r3053 r3060 46 46 /// <param name="parent2">The second parent for crossover.</param> 47 47 /// <returns>The newly created real vector, resulting from the single point crossover.</returns> 48 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArrayparent2) {48 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2) { 49 49 if (parent1.Length != parent2.Length) throw new ArgumentException("SinglePointCrossover: Parents are of unequal length"); 50 50 int length = parent1.Length; 51 DoubleArray result = new DoubleArray(length);51 RealVector result = new RealVector(length); 52 52 int breakPoint = random.Next(1, length - 1); 53 53 … … 61 61 62 62 /// <summary> 63 /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray)"/>.63 /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector)"/>. 64 64 /// </summary> 65 65 /// <exception cref="ArgumentException">Thrown when the parents' vectors are of unequal length or when <paramref name="contiguity"/> is smaller than 0.</exception> … … 67 67 /// <param name="parents">The list of parents.</param> 68 68 /// <returns>A new real vector.</returns> 69 protected override HeuristicLab.Data.DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {69 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 70 70 if (parents.Length != 2) throw new ArgumentException("SinglePointCrossover: The number of parents is not equal to 2"); 71 71 return Apply(random, parents[0], parents[1]); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/UniformAllPositionsArithmeticCrossover.cs
r3053 r3060 61 61 /// <param name="alpha">The alpha parameter (<see cref="AlphaParameter"/>).</param> 62 62 /// <returns>The vector resulting from the crossover.</returns> 63 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArrayparent2, DoubleValue alpha) {63 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha) { 64 64 int length = parent1.Length; 65 65 if (length != parent2.Length) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: The parent vectors are of different length.", "parent1"); 66 66 if (alpha.Value < 0 || alpha.Value > 1) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: Parameter alpha must be in the range [0;1]", "alpha"); 67 DoubleArray result = new DoubleArray(length);67 RealVector result = new RealVector(length); 68 68 for (int i = 0; i < length; i++) { 69 69 result[i] = alpha.Value * parent1[i] + (1 - alpha.Value) * parent2[i]; … … 73 73 74 74 /// <summary> 75 /// Checks that there are exactly 2 parents, that the alpha parameter is not null and fowards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArrrayData, DoubleValue)"/>.75 /// Checks that there are exactly 2 parents, that the alpha parameter is not null and fowards the call to <see cref="Apply(IRandom, RealVector, DoubleArrrayData, DoubleValue)"/>. 76 76 /// </summary> 77 77 /// <exception cref="ArgumentException">Thrown when there are not exactly two parents.</exception> … … 80 80 /// <param name="parents">The collection of parents (must be of size 2).</param> 81 81 /// <returns>The vector resulting from the crossover.</returns> 82 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {82 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 83 83 if (parents.Length != 2) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: There must be exactly two parents.", "parents"); 84 84 if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("UniformAllPositionsArithmeticCrossover: Parameter " + AlphaParameter.ActualName + " could not be found."); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/UniformSomePositionsArithmeticCrossover.cs
r3053 r3060 68 68 /// <param name="probability">The probability parameter (<see cref="ProbabilityParameter"/>).</param> 69 69 /// <returns>The vector resulting from the crossover.</returns> 70 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArrayparent2, DoubleValue alpha, DoubleValue probability) {70 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha, DoubleValue probability) { 71 71 int length = parent1.Length; 72 72 if (length != parent2.Length) throw new ArgumentException("UniformSomePositionsArithmeticCrossover: The parent vectors are of different length.", "parent1"); … … 74 74 if (probability.Value < 0 || probability.Value > 1) throw new ArgumentException("UniformSomePositionsArithmeticCrossover: Parameter probability must be in the range [0;1]", "probability"); 75 75 76 DoubleArray result = new DoubleArray(length);76 RealVector result = new RealVector(length); 77 77 for (int i = 0; i < length; i++) { 78 78 if (random.NextDouble() < probability.Value) … … 84 84 85 85 /// <summary> 86 /// Checks that there are exactly 2 parents, that the alpha and the probability parameter are not null and fowards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArrrayData, DoubleValue)"/>.86 /// Checks that there are exactly 2 parents, that the alpha and the probability parameter are not null and fowards the call to <see cref="Apply(IRandom, RealVector, DoubleArrrayData, DoubleValue)"/>. 87 87 /// </summary> 88 88 /// <exception cref="ArgumentException">Thrown when there are not exactly two parents.</exception> … … 91 91 /// <param name="parents">The collection of parents (must be of size 2).</param> 92 92 /// <returns>The vector resulting from the crossover.</returns> 93 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {93 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) { 94 94 if (parents.Length != 2) throw new ArgumentException("UniformSomePositionsArithmeticCrossover: There must be exactly two parents.", "parents"); 95 95 if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("UniformSomePositionsArithmeticCrossover: Parameter " + AlphaParameter.ActualName + " could not be found.");
Note: See TracChangeset
for help on using the changeset viewer.