- Timestamp:
- 03/15/10 23:49:54 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/AverageCrossover.cs
r3017 r3048 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 Data Apply(IRandom random, ItemArray<DoubleArrayData> parents) {47 public static DoubleArray Apply(IRandom random, ItemArray<DoubleArray> 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 Data result = new DoubleArrayData(length);50 DoubleArray result = new DoubleArray(length); 51 51 try { 52 52 double avg; … … 65 65 66 66 /// <summary> 67 /// Forwards the call to <see cref="Apply(IRandom, ItemArray<DoubleArray Data>)"/>.67 /// Forwards the call to <see cref="Apply(IRandom, ItemArray<DoubleArray>)"/>. 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {72 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) { 73 73 return Apply(random, parents); 74 74 } -
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/BlendAlphaBetaCrossover.cs
r3017 r3048 43 43 /// Whether the problem is a maximization or minimization problem. 44 44 /// </summary> 45 public ValueLookupParameter<Bool Data> MaximizationParameter {46 get { return (ValueLookupParameter<Bool Data>)Parameters["Maximization"]; }45 public ValueLookupParameter<BoolValue> MaximizationParameter { 46 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 47 47 } 48 48 /// <summary> 49 49 /// The quality of the parents. 50 50 /// </summary> 51 public SubScopesLookupParameter<Double Data> QualityParameter {52 get { return (SubScopesLookupParameter<Double Data>)Parameters["Quality"]; }51 public SubScopesLookupParameter<DoubleValue> QualityParameter { 52 get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; } 53 53 } 54 54 /// <summary> 55 55 /// The alpha parameter specifies how much the interval between the parents should be extended in direction of the better parent. 56 56 /// </summary> 57 public ValueLookupParameter<Double Data> AlphaParameter {58 get { return (ValueLookupParameter<Double Data>)Parameters["Alpha"]; }57 public ValueLookupParameter<DoubleValue> AlphaParameter { 58 get { return (ValueLookupParameter<DoubleValue>)Parameters["Alpha"]; } 59 59 } 60 60 /// <summary> 61 61 /// The beta parameter specifies how much the interval between the parents should be extended in direction of the worse parent. 62 62 /// </summary> 63 public ValueLookupParameter<Double Data> BetaParameter {64 get { return (ValueLookupParameter<Double Data>)Parameters["Beta"]; }63 public ValueLookupParameter<DoubleValue> BetaParameter { 64 get { return (ValueLookupParameter<DoubleValue>)Parameters["Beta"]; } 65 65 } 66 66 … … 71 71 public BlendAlphaBetaCrossover() 72 72 : base() { 73 Parameters.Add(new ValueLookupParameter<Bool Data>("Maximization", "Whether the problem is a maximization problem or not."));74 Parameters.Add(new SubScopesLookupParameter<Double Data>("Quality", "The quality values of the parents."));75 Parameters.Add(new ValueLookupParameter<Double Data>("Alpha", "The value for alpha.", new DoubleData(0.75)));76 Parameters.Add(new ValueLookupParameter<Double Data>("Beta", "The value for beta.", new DoubleData(0.25)));73 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem or not.")); 74 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The quality values of the parents.")); 75 Parameters.Add(new ValueLookupParameter<DoubleValue>("Alpha", "The value for alpha.", new DoubleValue(0.75))); 76 Parameters.Add(new ValueLookupParameter<DoubleValue>("Beta", "The value for beta.", new DoubleValue(0.25))); 77 77 } 78 78 … … 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 Data Apply(IRandom random, DoubleArrayData betterParent, DoubleArrayData worseParent, DoubleData alpha, DoubleDatabeta) {96 public static DoubleArray Apply(IRandom random, DoubleArray betterParent, DoubleArray 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 Data result = new DoubleArrayData(length);102 DoubleArray result = new DoubleArray(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 Data, DoubleArrayData, DoubleData, DoubleData)"/>.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)"/>. 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {134 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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."); … … 138 138 if (AlphaParameter.ActualValue == null || BetaParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaBetaCrossover: Parameter " + AlphaParameter.ActualName + " or paramter " + BetaParameter.ActualName + " could not be found."); 139 139 140 ItemArray<Double Data> qualities = QualityParameter.ActualValue;140 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 141 141 bool maximization = MaximizationParameter.ActualValue.Value; 142 142 // the better parent -
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/BlendAlphaCrossover.cs
r3017 r3048 45 45 /// values left and right of the min and max value for each gene. 46 46 /// </summary> 47 public ValueLookupParameter<Double Data> AlphaParameter {48 get { return (ValueLookupParameter<Double Data>)Parameters["Alpha"]; }47 public ValueLookupParameter<DoubleValue> AlphaParameter { 48 get { return (ValueLookupParameter<DoubleValue>)Parameters["Alpha"]; } 49 49 } 50 50 /// <summary> … … 53 53 public BlendAlphaCrossover() 54 54 : base() { 55 Parameters.Add(new ValueLookupParameter<Double Data>("Alpha", "Value for alpha", new DoubleData(0.5)));55 Parameters.Add(new ValueLookupParameter<DoubleValue>("Alpha", "Value for alpha", new DoubleValue(0.5))); 56 56 } 57 57 … … 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 Data Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2, DoubleDataalpha) {72 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray 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 Data result = new DoubleArrayData(length);76 DoubleArray result = new DoubleArray(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 Data, DoubleArrayData, DoubleData)"/>.92 /// Checks that the number of parents is equal to 2 and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {99 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.RealVector/3.3/Crossovers/DiscreteCrossover.cs
r3017 r3048 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 Data Apply(IRandom random, ItemArray<DoubleArrayData> parents) {47 public static DoubleArray Apply(IRandom random, ItemArray<DoubleArray> parents) { 48 48 int length = parents[0].Length; 49 49 … … 53 53 } 54 54 55 DoubleArray Data result = new DoubleArrayData(length);55 DoubleArray result = new DoubleArray(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 Data>)"/>.64 /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, ItemArray<DoubleArray>)"/>. 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {70 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.RealVector/3.3/Crossovers/HeuristicCrossover.cs
r3017 r3048 40 40 /// Whether the problem is a maximization or minimization problem. 41 41 /// </summary> 42 public ValueLookupParameter<Bool Data> MaximizationParameter {43 get { return (ValueLookupParameter<Bool Data>)Parameters["Maximization"]; }42 public ValueLookupParameter<BoolValue> MaximizationParameter { 43 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 44 44 } 45 45 /// <summary> 46 46 /// The quality of the parents. 47 47 /// </summary> 48 public SubScopesLookupParameter<Double Data> QualityParameter {49 get { return (SubScopesLookupParameter<Double Data>)Parameters["Quality"]; }48 public SubScopesLookupParameter<DoubleValue> QualityParameter { 49 get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; } 50 50 } 51 51 … … 56 56 public HeuristicCrossover() 57 57 : base() { 58 Parameters.Add(new ValueLookupParameter<Bool Data>("Maximization", "Whether the problem is a maximization problem or not."));59 Parameters.Add(new SubScopesLookupParameter<Double Data>("Quality", "The quality values of the parents."));58 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem or not.")); 59 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The quality values of the parents.")); 60 60 } 61 61 … … 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 Data Apply(IRandom random, DoubleArrayData betterParent, DoubleArrayDataworseParent) {70 public static DoubleArray Apply(IRandom random, DoubleArray betterParent, DoubleArray 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 Data(result);81 return new DoubleArray(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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {98 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) { 99 99 if (parents.Length != 2) throw new ArgumentException("HeuristicCrossover: The number of parents is not equal to 2"); 100 100 … … 102 102 if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != parents.Length) throw new InvalidOperationException("HeuristicCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents."); 103 103 104 ItemArray<Double Data> qualities = QualityParameter.ActualValue;104 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 105 105 bool maximization = MaximizationParameter.ActualValue.Value; 106 106 -
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/LocalCrossover.cs
r3017 r3048 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 Data Apply(IRandom random, DoubleArrayData parent1, DoubleArrayDataparent2) {45 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray 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 Data(result);57 return new DoubleArray(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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {67 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.RealVector/3.3/Crossovers/RandomConvexCrossover.cs
r3017 r3048 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 Data Apply(IRandom random, DoubleArrayData parent1, DoubleArrayDataparent2) {45 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray 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 Data(result);55 return new DoubleArray(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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {65 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.RealVector/3.3/Crossovers/SimulatedBinaryCrossover.cs
r3017 r3048 40 40 /// The parameter must be greater or equal than 0. Common values are in the range [0;5] and more often just [2;5]. 41 41 /// </summary> 42 public ValueLookupParameter<Double Data> ContiguityParameter {43 get { return (ValueLookupParameter<Double Data>)Parameters["Contiguity"]; }42 public ValueLookupParameter<DoubleValue> ContiguityParameter { 43 get { return (ValueLookupParameter<DoubleValue>)Parameters["Contiguity"]; } 44 44 } 45 45 … … 50 50 public SimulatedBinaryCrossover() 51 51 : base() { 52 Parameters.Add(new ValueLookupParameter<Double Data>("Contiguity", "Specifies whether the crossover should produce very different (small value) or very similar (large value) children. Valid values must be greater or equal to 0.", new DoubleData(2)));52 Parameters.Add(new ValueLookupParameter<DoubleValue>("Contiguity", "Specifies whether the crossover should produce very different (small value) or very similar (large value) children. Valid values must be greater or equal to 0.", new DoubleValue(2))); 53 53 } 54 54 … … 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 Data Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2, DoubleDatacontiguity) {68 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray 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 Data result = new DoubleArrayData(length);72 DoubleArray result = new DoubleArray(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 Data, DoubleArrayData, DoubleData)"/>.94 /// Checks number of parents, availability of the parameters and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {100 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.RealVector/3.3/Crossovers/SinglePointCrossover.cs
r3017 r3048 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 Data Apply(IRandom random, DoubleArrayData parent1, DoubleArrayDataparent2) {48 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray 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 Data result = new DoubleArrayData(length);51 DoubleArray result = new DoubleArray(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 Data, DoubleArrayData)"/>.63 /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray)"/>. 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {69 protected override HeuristicLab.Data.DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.RealVector/3.3/Crossovers/UniformAllPositionsArithmeticCrossover.cs
r3017 r3048 40 40 /// The alpha parameter needs to be in the interval [0;1] and specifies how close the resulting offspring should be either to parent1 (alpha -> 0) or parent2 (alpha -> 1). 41 41 /// </summary> 42 public ValueLookupParameter<Double Data> AlphaParameter {43 get { return (ValueLookupParameter<Double Data>)Parameters["Alpha"]; }42 public ValueLookupParameter<DoubleValue> AlphaParameter { 43 get { return (ValueLookupParameter<DoubleValue>)Parameters["Alpha"]; } 44 44 } 45 45 … … 49 49 public UniformAllPositionsArithmeticCrossover() 50 50 : base() { 51 Parameters.Add(new ValueLookupParameter<Double Data>("Alpha", "The alpha value in the range [0;1]", new DoubleData(0.33)));51 Parameters.Add(new ValueLookupParameter<DoubleValue>("Alpha", "The alpha value in the range [0;1]", new DoubleValue(0.33))); 52 52 } 53 53 … … 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 Data Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2, DoubleDataalpha) {63 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray 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 Data result = new DoubleArrayData(length);67 DoubleArray result = new DoubleArray(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 Data, DoubleArrrayData, DoubleData)"/>.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)"/>. 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {82 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.RealVector/3.3/Crossovers/UniformSomePositionsArithmeticCrossover.cs
r3017 r3048 40 40 /// The alpha parameter needs to be in the interval [0;1] and specifies how close the resulting offspring should be either to parent1 (alpha -> 0) or parent2 (alpha -> 1). 41 41 /// </summary> 42 public ValueLookupParameter<Double Data> AlphaParameter {43 get { return (ValueLookupParameter<Double Data>)Parameters["Alpha"]; }42 public ValueLookupParameter<DoubleValue> AlphaParameter { 43 get { return (ValueLookupParameter<DoubleValue>)Parameters["Alpha"]; } 44 44 } 45 45 /// <summary> 46 46 /// The probability in the range [0;1] for each position in the vector to be crossed. 47 47 /// </summary> 48 public ValueLookupParameter<Double Data> ProbabilityParameter {49 get { return (ValueLookupParameter<Double Data>)Parameters["Probability"]; }48 public ValueLookupParameter<DoubleValue> ProbabilityParameter { 49 get { return (ValueLookupParameter<DoubleValue>)Parameters["Probability"]; } 50 50 } 51 51 … … 55 55 public UniformSomePositionsArithmeticCrossover() 56 56 : base() { 57 Parameters.Add(new ValueLookupParameter<Double Data>("Alpha", "The alpha value in the range [0;1]", new DoubleData(0.5)));58 Parameters.Add(new ValueLookupParameter<Double Data>("Probability", "The probability for crossing a position in the range [0;1]", new DoubleData(0.5)));57 Parameters.Add(new ValueLookupParameter<DoubleValue>("Alpha", "The alpha value in the range [0;1]", new DoubleValue(0.5))); 58 Parameters.Add(new ValueLookupParameter<DoubleValue>("Probability", "The probability for crossing a position in the range [0;1]", new DoubleValue(0.5))); 59 59 } 60 60 … … 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 Data Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2, DoubleData alpha, DoubleDataprobability) {70 public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray 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 Data result = new DoubleArrayData(length);76 DoubleArray result = new DoubleArray(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 Data, DoubleArrrayData, DoubleData)"/>.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)"/>. 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 Data Cross(IRandom random, ItemArray<DoubleArrayData> parents) {93 protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> 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.