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/Permutation/PermutationMemPR.cs

    r14550 r14551  
    395395    private ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> CrossAbsolute(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p1, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p2, CancellationToken token) {
    396396      var cache = new HashSet<Encodings.PermutationEncoding.Permutation>(new PermutationEqualityComparer());
     397      cache.Add(p1.Solution);
     398      cache.Add(p2.Solution);
     399
    397400      var cacheHits = 0;
    398       var evaluations = 1;
     401      var evaluations = 0;
    399402      ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null;
    400       for (; evaluations <= p1.Solution.Length; evaluations++) {
     403      while (evaluations < p1.Solution.Length) {
    401404        Encodings.PermutationEncoding.Permutation c = null;
    402405        var xochoice = Context.Random.Next(3);
     
    413416        var probe = ToScope(c);
    414417        Evaluate(probe, token);
     418        evaluations++;
    415419        cache.Add(c);
    416420        if (offspring == null || Context.IsBetter(probe, offspring)) {
     
    420424        }
    421425      }
    422       Context.IncrementEvaluatedSolutions(evaluations-1);
     426      Context.IncrementEvaluatedSolutions(evaluations);
    423427      return offspring;
    424428    }
     
    426430    private ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> CrossRelativeDirected(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p1, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p2, CancellationToken token) {
    427431      var cache = new HashSet<Encodings.PermutationEncoding.Permutation>(new PermutationEqualityComparer());
     432      cache.Add(p1.Solution);
     433      cache.Add(p2.Solution);
     434
    428435      var cacheHits = 0;
    429       var evaluations = 1;
     436      var evaluations = 0;
    430437      ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null;
    431       for (; evaluations <= p1.Solution.Length; evaluations++) {
     438      while(evaluations < p1.Solution.Length) {
    432439        Encodings.PermutationEncoding.Permutation c = null;
    433440        var xochoice = Context.Random.Next(3);
     
    444451        var probe = ToScope(c);
    445452        Evaluate(probe, token);
     453        evaluations++;
    446454        cache.Add(c);
    447455        if (offspring == null || Context.IsBetter(probe, offspring)) {
     
    451459        }
    452460      }
    453       Context.IncrementEvaluatedSolutions(evaluations-1);
     461      Context.IncrementEvaluatedSolutions(evaluations);
    454462      return offspring;
    455463    }
     
    457465    private ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> CrossRelativeUndirected(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p1, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p2, CancellationToken token) {
    458466      var cache = new HashSet<Encodings.PermutationEncoding.Permutation>(new PermutationEqualityComparer());
     467      cache.Add(p1.Solution);
     468      cache.Add(p2.Solution);
     469
    459470      var cacheHits = 0;
    460       var evaluations = 1;
     471      var evaluations = 0;
    461472      ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null;
    462       for (; evaluations <= p1.Solution.Length; evaluations++) {
     473      while(evaluations <= p1.Solution.Length) {
    463474        Encodings.PermutationEncoding.Permutation c = null;
    464475        var xochoice = Context.Random.Next(3);
     
    475486        var probe = ToScope(c);
    476487        Evaluate(probe, token);
     488        evaluations++;
    477489        cache.Add(c);
    478490        if (offspring == null || Context.IsBetter(probe, offspring)) {
     
    482494        }
    483495      }
    484       Context.IncrementEvaluatedSolutions(evaluations-1);
     496      Context.IncrementEvaluatedSolutions(evaluations);
    485497      return offspring;
    486498    }
    487499
    488500    protected override ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> Link(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> a, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> b, CancellationToken token, bool delink = false) {
    489       if (double.IsNaN(a.Fitness)) {
    490         Evaluate(a, token);
    491         Context.IncrementEvaluatedSolutions(1);
    492       }
    493       if (double.IsNaN(b.Fitness)) {
    494         Evaluate(b, token);
    495         Context.IncrementEvaluatedSolutions(1);
    496       }
    497 
    498501      var wrapper = new EvaluationWrapper<Encodings.PermutationEncoding.Permutation>(Problem, ToScope(null));
    499502      double quality;
     
    626629      Context.IncrementEvaluatedSolutions(evaluations);
    627630
    628       if (VALIDATE && bestChild != null && !bestChild.Validate()) throw new ArgumentException("Relinking produced invalid child");
    629       if (VALIDATE && Dist(child, p2) > 0) throw new InvalidOperationException("Child is not equal to p2 after relinking");
     631      if (VALIDATE && bestChild != null && !bestChild.Validate()) throw new ArgumentException("Delinking produced invalid child");
    630632
    631633      return bestChild ?? child;
Note: See TracChangeset for help on using the changeset viewer.