Changeset 9090 for branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Crossovers
- Timestamp:
- 12/29/12 20:15:48 (12 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3
- Property svn:ignore
-
old new 1 1 *.user 2 2 Plugin.cs 3 obj
-
- Property svn:ignore
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r9089 r9090 38 38 } 39 39 40 public static CombinedIntegerVector Apply(IRandom random, CombinedIntegerVector parent1, CombinedIntegerVector parent2) { 41 if (parent1.Length != parent2.Length && parent1.ActionLength != parent2.ActionLength && parent1.Bounds.Equals(parent2.Bounds)) 42 throw new ArgumentException("SinglePointCrossover: The parents are of different length."); 43 44 int length = parent1.Length; 45 int actionLength = parent1.ActionLength; 46 int conditionLength = length - actionLength; 47 int[] result = new int[length]; 48 int breakPoint = random.Next(1, conditionLength); 49 50 for (int i = 0; i < breakPoint; i++) { 51 result[i] = parent1[i]; 52 } 53 for (int i = breakPoint; i < conditionLength; i++) { 54 result[i] = parent2[i]; 55 } 56 57 CombinedIntegerVector actionParent = random.Next(2) == 1 ? parent1 : parent2; 58 for (int i = conditionLength; i < length; i++) { 59 result[i] = actionParent[i]; 60 } 61 62 return new CombinedIntegerVector(result, actionLength, parent1.Bounds); 63 } 64 40 65 protected override CombinedIntegerVector Cross(IRandom random, ItemArray<CombinedIntegerVector> parents) { 41 66 if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2"); 42 return new CombinedIntegerVector(HeuristicLab.Encodings.IntegerVectorEncoding.SinglePointCrossover.Apply(random, parents[0], parents[1]), parents[0].ActionLength, parents[0].Bounds);67 return Apply(random, parents[0], parents[1]); 43 68 } 44 69 }
Note: See TracChangeset
for help on using the changeset viewer.