Changeset 15506 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/CordeauCrossover.cs
- Timestamp:
- 12/11/17 11:57:56 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/CordeauCrossover.cs
r15504 r15506 35 35 public class CordeauCrossover : GQAPCrossover, 36 36 IQualitiesAwareGQAPOperator, IProblemInstanceAwareGQAPOperator { 37 38 public ILookupParameter<BoolValue> MaximizationParameter { 39 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 40 } 37 41 38 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 42 39 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } … … 56 53 public CordeauCrossover() 57 54 : base() { 58 Parameters.Add(new LookupParameter<BoolValue>("Maximization", ""));59 55 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parents", 1)); 60 56 Parameters.Add(new ScopeTreeLookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription, 1)); … … 66 62 } 67 63 68 public static IntegerVector Apply(IRandom random, bool maximization,64 public static IntegerVector Apply(IRandom random, 69 65 IntegerVector parent1, DoubleValue quality1, 70 66 IntegerVector parent2, DoubleValue quality2, … … 80 76 81 77 bool onefound = false; 82 double fbest, fbestAttempt = maximization ? double.MinValue :double.MaxValue;78 double fbest, fbestAttempt = double.MaxValue; 83 79 IntegerVector bestAttempt = null; 84 80 IntegerVector result = null; 85 81 86 82 fbest = quality1.Value; 87 if (maximization && quality1.Value < quality2.Value 88 || !maximization && quality1.Value > quality2.Value) { 83 if (quality1.Value > quality2.Value) { 89 84 var temp = parent1; 90 85 parent1 = parent2; … … 102 97 var childFit = problemInstance.ToSingleObjective(problemInstance.Evaluate(child)); 103 98 evaluatedSolutions.Value++; 104 if (maximization && childFit >= fbest 105 || !maximization && childFit <= fbest) { 99 if (childFit <= fbest) { 106 100 fbest = childFit; 107 101 result = child; 108 102 onefound = true; 109 103 } 110 if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {104 if (!onefound && fbestAttempt > childFit) { 111 105 bestAttempt = child; 112 106 fbestAttempt = childFit; … … 130 124 } 131 125 132 if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {126 if (!onefound && fbestAttempt > childFit) { 133 127 bestAttempt = child; 134 128 fbestAttempt = childFit; … … 203 197 204 198 var qualities = QualityParameter.ActualValue; 205 return Apply(random, MaximizationParameter.ActualValue.Value,199 return Apply(random, 206 200 parents[0], qualities[0], 207 201 parents[1], qualities[1],
Note: See TracChangeset
for help on using the changeset viewer.