Changeset 15553 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs
- Timestamp:
- 12/20/17 15:41:27 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs
r15512 r15553 94 94 } 95 95 96 /// <summary> 97 /// The implementation differs slightly from Mateus et al. in that the maximumIterations parameter defines a cap 98 /// on the number of steps that the local search can perform. While the maxSampleSize parameter corresponds to 99 /// the maxItr parameter defined by Mateus et al. 100 /// </summary> 101 /// <param name="random">The random number generator to use.</param> 102 /// <param name="assignment">The equipment-location assignment vector.</param> 103 /// <param name="quality">The solution quality.</param> 104 /// <param name="evaluation">The evaluation result of the solution.</param> 105 /// <param name="maxCLS">The maximum number of candidates that should be found in each step.</param> 106 /// <param name="maximumIterations">The maximum number of iterations that should be performed each time the candidate list is generated.</param> 107 /// <param name="problemInstance">The problem instance that contains the data.</param> 108 /// <param name="evaluatedSolutions">The number of evaluated solutions.</param> 109 /// <param name="oneMoveProbability">The probability for performing a 1-move, which is the opposite of performing a 2-move.</param> 110 public static void Apply(IRandom random, IntegerVector assignment, 111 DoubleValue quality, ref Evaluation evaluation, IntValue maxCLS, IntValue maximumIterations, 112 GQAPInstance problemInstance, IntValue evaluatedSolutions, PercentValue oneMoveProbability) { 96 public static void Apply(IRandom random, GQAPSolution sol, int maxCLS, 97 double oneMoveProbability, int maximumIterations, 98 GQAPInstance problemInstance, out int evaluatedSolutions) { 99 var fit = problemInstance.ToSingleObjective(sol.Evaluation); 100 var eval = sol.Evaluation; 101 Apply(random, sol.Assignment, ref fit, ref eval, maxCLS, oneMoveProbability, maximumIterations, problemInstance, 102 out evaluatedSolutions); 103 sol.Evaluation = eval; 104 } 105 106 /// <summary> 107 /// The implementation differs slightly from Mateus et al. in that the maximumIterations parameter defines a cap 108 /// on the number of steps that the local search can perform. While the maxSampleSize parameter corresponds to 109 /// the maxItr parameter defined by Mateus et al. 110 /// </summary> 111 /// <param name="random">The random number generator to use.</param> 112 /// <param name="assignment">The equipment-location assignment vector.</param> 113 /// <param name="quality">The solution quality.</param> 114 /// <param name="evaluation">The evaluation result of the solution.</param> 115 /// <param name="maxCLS">The maximum number of candidates that should be found in each step.</param> 116 /// <param name="oneMoveProbability">The probability for performing a 1-move, which is the opposite of performing a 2-move.</param> 117 /// <param name="maximumIterations">The maximum number of iterations that should be performed each time the candidate list is generated.</param> 118 /// <param name="problemInstance">The problem instance that contains the data.</param> 119 /// <param name="evaluatedSolutions">The number of evaluated solutions.</param> 120 public static void Apply(IRandom random, IntegerVector assignment, 121 ref double quality, ref Evaluation evaluation, int maxCLS, 122 double oneMoveProbability, int maximumIterations, 123 GQAPInstance problemInstance, out int evaluatedSolutions) { 124 evaluatedSolutions = 0; 113 125 var capacities = problemInstance.Capacities; 114 126 var demands = problemInstance.Demands; … … 121 133 do { 122 134 NMove move; 123 if (random.NextDouble() < oneMoveProbability .Value)124 move = StochasticNMoveSingleMoveGenerator.Generate ExactlyN(random, assignment, 1, capacities);125 else move = StochasticNMoveSingleMoveGenerator.Generate ExactlyN(random, assignment, 2, capacities);135 if (random.NextDouble() < oneMoveProbability) 136 move = StochasticNMoveSingleMoveGenerator.GenerateOneMove(random, assignment, capacities); 137 else move = StochasticNMoveSingleMoveGenerator.GenerateTwoMove(random, assignment, capacities); 126 138 127 139 var moveEval = GQAPNMoveEvaluator.Evaluate(move, assignment, evaluation, problemInstance); … … 129 141 double moveQuality = problemInstance.ToSingleObjective(moveEval); 130 142 131 if (moveEval.ExcessDemand <= 0.0 && moveQuality < quality .Value) {143 if (moveEval.ExcessDemand <= 0.0 && moveQuality < quality) { 132 144 CLS.Add(Tuple.Create(move, moveQuality, moveEval)); 133 145 sum += 1.0 / moveQuality; 134 146 } 135 147 count++; 136 } while (CLS.Count < maxCLS .Value && count < maximumIterations.Value);148 } while (CLS.Count < maxCLS && count < maximumIterations); 137 149 138 150 if (CLS.Count == 0) { 139 evaluatedSolutions .Value+= (int)Math.Ceiling(evaluations);151 evaluatedSolutions += (int)Math.Ceiling(evaluations); 140 152 return; // END 141 153 } else { … … 150 162 } 151 163 NMoveMaker.Apply(assignment, selected.Item1); 152 quality .Value= selected.Item2;164 quality = selected.Item2; 153 165 evaluation = selected.Item3; 154 166 } … … 158 170 public override IOperation Apply() { 159 171 var evaluation = EvaluationParameter.ActualValue; 172 var quality = QualityParameter.ActualValue; 173 var fit = quality.Value; 174 var evaluatedSolutions = 0; 175 160 176 Apply(RandomParameter.ActualValue, 161 177 AssignmentParameter.ActualValue, 162 QualityParameter.ActualValue,178 ref fit, 163 179 ref evaluation, 164 MaximumCandidateListSizeParameter.ActualValue, 165 MaximumIterationsParameter.ActualValue, 180 MaximumCandidateListSizeParameter.ActualValue.Value, 181 OneMoveProbabilityParameter.ActualValue.Value, 182 MaximumIterationsParameter.ActualValue.Value, 166 183 ProblemInstanceParameter.ActualValue, 167 EvaluatedSolutionsParameter.ActualValue,168 OneMoveProbabilityParameter.ActualValue); 184 out evaluatedSolutions); 185 169 186 EvaluationParameter.ActualValue = evaluation; 187 quality.Value = fit; 188 EvaluatedSolutionsParameter.ActualValue.Value += evaluatedSolutions; 170 189 return base.Apply(); 171 190 }
Note: See TracChangeset
for help on using the changeset viewer.