Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/08/17 22:16:19 (8 years ago)
Author:
abeham
Message:

#2701: refactored breeding, removed hillclimbing after breeding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LinearLinkageMemPR.cs

    r14550 r14551  
    248248    }
    249249
    250     protected override ISingleObjectiveSolutionScope<LinearLinkage> Breed(ISingleObjectiveSolutionScope<LinearLinkage> p1Scope, ISingleObjectiveSolutionScope<LinearLinkage> p2Scope, CancellationToken token) {
     250    protected override ISingleObjectiveSolutionScope<LinearLinkage> Breed(ISingleObjectiveSolutionScope<LinearLinkage> p1, ISingleObjectiveSolutionScope<LinearLinkage> p2, CancellationToken token) {
    251251      var cache = new HashSet<LinearLinkage>(new LinearLinkageEqualityComparer());
     252      cache.Add(p1.Solution);
     253      cache.Add(p2.Solution);
     254
    252255      var cachehits = 0;
    253       var evaluations = 1;
     256      var evaluations = 0;
     257      var probe = ToScope((LinearLinkage)p1.Solution.Clone());
    254258      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)) {
    258266          cachehits++;
    259267          if (cachehits > 10) break;
    260268          continue;
    261269        }
    262         var probe = ToScope(code);
    263270        Evaluate(probe, token);
    264         cache.Add(code);
     271        evaluations++;
     272        cache.Add(c);
    265273        if (offspring == null || Context.IsBetter(probe, offspring)) {
    266274          offspring = probe;
    267           if (Context.IsBetter(offspring, p1Scope) && Context.IsBetter(offspring, p2Scope))
     275          if (Context.IsBetter(offspring, p1) && Context.IsBetter(offspring, p2))
    268276            break;
    269277        }
    270278      }
    271       Context.IncrementEvaluatedSolutions(evaluations-1);
    272       return offspring;
     279      Context.IncrementEvaluatedSolutions(evaluations);
     280      return offspring ?? probe;
    273281    }
    274282
Note: See TracChangeset for help on using the changeset viewer.