- Timestamp:
- 12/05/16 12:27:19 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Binary/BinaryMemPR.cs ¶
r14450 r14453 98 98 99 99 protected override void TabuWalk(ISingleObjectiveSolutionScope<BinaryVector> scope, int steps, CancellationToken token, ISolutionSubspace<BinaryVector> subspace = null) { 100 var evaluations = 0; 100 101 var subset = subspace != null ? ((BinarySolutionSubspace)subspace).Subspace : null; 101 if (double.IsNaN(scope.Fitness)) Evaluate(scope, token); 102 if (double.IsNaN(scope.Fitness)) { 103 Evaluate(scope, token); 104 evaluations++; 105 } 102 106 SingleObjectiveSolutionScope<BinaryVector> bestOfTheWalk = null; 103 107 var currentScope = (SingleObjectiveSolutionScope<BinaryVector>)scope.Clone(); … … 121 125 current[idx] = !current[idx]; 122 126 Evaluate(currentScope, token); 127 evaluations++; 123 128 var after = currentScope.Fitness; 124 129 … … 151 156 } 152 157 158 Context.IncrementEvaluatedSolutions(evaluations); 153 159 scope.Adopt(bestOfTheWalk ?? currentScope); 154 160 } … … 187 193 188 194 protected override ISingleObjectiveSolutionScope<BinaryVector> Relink(ISingleObjectiveSolutionScope<BinaryVector> a, ISingleObjectiveSolutionScope<BinaryVector> b, CancellationToken token) { 189 if (double.IsNaN(a.Fitness)) Evaluate(a, token); 190 if (double.IsNaN(b.Fitness)) Evaluate(b, token); 195 if (double.IsNaN(a.Fitness)) { 196 Evaluate(a, token); 197 Context.IncrementEvaluatedSolutions(1); 198 } 199 if (double.IsNaN(b.Fitness)) { 200 Evaluate(b, token); 201 Context.IncrementEvaluatedSolutions(1); 202 } 191 203 if (Context.Random.NextDouble() < 0.5) 192 204 return IsBetter(a, b) ? Relink(a, b, token, false) : Relink(b, a, token, true); … … 195 207 196 208 protected virtual ISingleObjectiveSolutionScope<BinaryVector> Relink(ISingleObjectiveSolutionScope<BinaryVector> betterScope, ISingleObjectiveSolutionScope<BinaryVector> worseScope, CancellationToken token, bool fromWorseToBetter) { 209 var evaluations = 0; 197 210 var childScope = (ISingleObjectiveSolutionScope<BinaryVector>)(fromWorseToBetter ? worseScope : betterScope).Clone(); 198 211 var child = childScope.Solution; … … 213 226 child[idx] = !child[idx]; // move 214 227 Evaluate(childScope, token); 228 evaluations++; 215 229 var s = childScope.Fitness; 216 230 childScope.Fitness = cF; … … 236 250 } 237 251 } 252 Context.IncrementEvaluatedSolutions(evaluations); 238 253 return best ?? childScope; 239 254 }
Note: See TracChangeset
for help on using the changeset viewer.