Changeset 7775 for branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/NChildCrossover.cs
- Timestamp:
- 05/02/12 19:09:48 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/NChildCrossover.cs
r7756 r7775 58 58 if (parent1.Length != parent2.Length) 59 59 throw new ArgumentException("NChildCrossover: The parents are of different length."); 60 61 60 if (n.Value > Math.Pow(2, parent1.Length) - 2) 62 61 throw new ArgumentException("NChildCrossover: There cannot be more children than 2^size of parents - 2."); 63 64 62 if (n.Value < 1) 65 63 throw new ArgumentException("NChildCrossover: N cannot be < 1."); … … 68 66 for (int i = 0; i < n.Value; i++) { 69 67 var solution = new BinaryVector(parent1.Length); 70 for (int j = 0; j < solution.Length; j++) {68 for (int j = 0; j < solution.Length; j++) 71 69 solution[j] = random.Next(2) % 2 == 0 ? parent1[j] : parent2[j]; 72 }73 70 solutions[i] = solution; 74 71 } … … 78 75 79 76 protected override ItemArray<BinaryVector> Cross(IRandom random, ItemArray<BinaryVector> parents) { 80 if (parents.Length != 2) throw new ArgumentException("NChildCrossover: The number of parents is not equal to 2.");81 82 if (NParameter.ActualValue == null) throw new InvalidOperationException("NChildCrossover: Parameter " + NParameter.ActualName + " could not be found.");83 77 if (parents.Length != 2) 78 throw new ArgumentException("NChildCrossover: The number of parents is not equal to 2."); 79 if (NParameter.ActualValue == null) 80 throw new InvalidOperationException("NChildCrossover: Parameter " + NParameter.ActualName + " could not be found."); 84 81 return Apply(random, parents[0], parents[1], NParameter.Value); 85 82 }
Note: See TracChangeset
for help on using the changeset viewer.