Changeset 3675
- Timestamp:
- 05/06/10 16:41:51 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r3376 r3675 49 49 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2) { 50 50 if (parent1.Length != parent2.Length) throw new ArgumentException("SinglePointCrossover: Parents are of unequal length"); 51 if (parent1.Length < 2) throw new ArgumentException("SinglePointCrossover: Cannot be applied to vectors with just one dimension."); 51 52 int length = parent1.Length; 52 53 RealVector result = new RealVector(length); 53 int breakPoint = random.Next(1, length - 1); 54 int breakPoint; 55 if (length == 2) breakPoint = 1; 56 else breakPoint = random.Next(1, length - 1); 54 57 55 58 for (int i = 0; i < breakPoint; i++) -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/SinglePointCrossoverTest.cs
r3376 r3675 95 95 } 96 96 Assert.IsTrue(exceptionFired); 97 // The following test checks if there is an exception when the vector has just one dimension 98 random.Reset(); 99 parents = new ItemArray<RealVector>(new RealVector[] { new RealVector(1) }); 100 exceptionFired = false; 101 try { 102 RealVector actual; 103 actual = target.Cross(random, parents); 104 } catch (System.ArgumentException) { 105 exceptionFired = true; 106 } 107 Assert.IsTrue(exceptionFired); 97 108 } 98 109 … … 125 136 } 126 137 Assert.IsTrue(exceptionFired); 138 // The following test is not based on published examples 139 random.Reset(); 140 random.IntNumbers = new int[] { 5 }; // should not have an effect 141 parent1 = new RealVector(new double[] { 0.2, 0.4 }); 142 parent2 = new RealVector(new double[] { 0.6, 0.1 }); 143 expected = new RealVector(new double[] { 0.2, 0.1 }); 144 actual = SinglePointCrossover.Apply(random, parent1, parent2); 145 Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected)); 146 // The following test is not based on published examples 127 147 } 128 148
Note: See TracChangeset
for help on using the changeset viewer.