- Timestamp:
- 01/08/17 22:16:19 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LinearLinkageMemPR.cs
r14550 r14551 248 248 } 249 249 250 protected override ISingleObjectiveSolutionScope<LinearLinkage> Breed(ISingleObjectiveSolutionScope<LinearLinkage> p1 Scope, ISingleObjectiveSolutionScope<LinearLinkage> p2Scope, CancellationToken token) {250 protected override ISingleObjectiveSolutionScope<LinearLinkage> Breed(ISingleObjectiveSolutionScope<LinearLinkage> p1, ISingleObjectiveSolutionScope<LinearLinkage> p2, CancellationToken token) { 251 251 var cache = new HashSet<LinearLinkage>(new LinearLinkageEqualityComparer()); 252 cache.Add(p1.Solution); 253 cache.Add(p2.Solution); 254 252 255 var cachehits = 0; 253 var evaluations = 1; 256 var evaluations = 0; 257 var probe = ToScope((LinearLinkage)p1.Solution.Clone()); 254 258 ISingleObjectiveSolutionScope<LinearLinkage> offspring = null; 255 for (; evaluations < p1Scope.Solution.Length; evaluations++) { 256 var code = GroupCrossover.Apply(Context.Random, p1Scope.Solution, p2Scope.Solution); 257 if (cache.Contains(code)) { 259 while (evaluations < p1.Solution.Length) { 260 LinearLinkage c = null; 261 if (Context.Random.NextDouble() < 0.8) 262 c = GroupCrossover.Apply(Context.Random, p1.Solution, p2.Solution); 263 else c = SinglePointCrossover.Apply(Context.Random, p1.Solution, p2.Solution); 264 265 if (cache.Contains(c)) { 258 266 cachehits++; 259 267 if (cachehits > 10) break; 260 268 continue; 261 269 } 262 var probe = ToScope(code);263 270 Evaluate(probe, token); 264 cache.Add(code); 271 evaluations++; 272 cache.Add(c); 265 273 if (offspring == null || Context.IsBetter(probe, offspring)) { 266 274 offspring = probe; 267 if (Context.IsBetter(offspring, p1 Scope) && Context.IsBetter(offspring, p2Scope))275 if (Context.IsBetter(offspring, p1) && Context.IsBetter(offspring, p2)) 268 276 break; 269 277 } 270 278 } 271 Context.IncrementEvaluatedSolutions(evaluations -1);272 return offspring ;279 Context.IncrementEvaluatedSolutions(evaluations); 280 return offspring ?? probe; 273 281 } 274 282
Note: See TracChangeset
for help on using the changeset viewer.