Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/05/16 12:27:19 (7 years ago)
Author:
abeham
Message:

#2701:

  • Worked on MemPR algorithm for permutations
    • Made Evaluate() method mostly thread-safe and moved evaluated solutions counting to caller
  • Removed TSP specific similarity calculator (it is actually not specific to the TSP) and added it to the permutation encoding as HammingSimilarityCalculator
  • Fixed bug in qap basicproblem
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Binary/BinaryMemPR.cs

    r14450 r14453  
    9898
    9999    protected override void TabuWalk(ISingleObjectiveSolutionScope<BinaryVector> scope, int steps, CancellationToken token, ISolutionSubspace<BinaryVector> subspace = null) {
     100      var evaluations = 0;
    100101      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      }
    102106      SingleObjectiveSolutionScope<BinaryVector> bestOfTheWalk = null;
    103107      var currentScope = (SingleObjectiveSolutionScope<BinaryVector>)scope.Clone();
     
    121125          current[idx] = !current[idx];
    122126          Evaluate(currentScope, token);
     127          evaluations++;
    123128          var after = currentScope.Fitness;
    124129
     
    151156      }
    152157
     158      Context.IncrementEvaluatedSolutions(evaluations);
    153159      scope.Adopt(bestOfTheWalk ?? currentScope);
    154160    }
     
    187193
    188194    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      }
    191203      if (Context.Random.NextDouble() < 0.5)
    192204        return IsBetter(a, b) ? Relink(a, b, token, false) : Relink(b, a, token, true);
     
    195207
    196208    protected virtual ISingleObjectiveSolutionScope<BinaryVector> Relink(ISingleObjectiveSolutionScope<BinaryVector> betterScope, ISingleObjectiveSolutionScope<BinaryVector> worseScope, CancellationToken token, bool fromWorseToBetter) {
     209      var evaluations = 0;
    197210      var childScope = (ISingleObjectiveSolutionScope<BinaryVector>)(fromWorseToBetter ? worseScope : betterScope).Clone();
    198211      var child = childScope.Solution;
     
    213226          child[idx] = !child[idx]; // move
    214227          Evaluate(childScope, token);
     228          evaluations++;
    215229          var s = childScope.Fitness;
    216230          childScope.Fitness = cF;
     
    236250        }
    237251      }
     252      Context.IncrementEvaluatedSolutions(evaluations);
    238253      return best ?? childScope;
    239254    }
Note: See TracChangeset for help on using the changeset viewer.