Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/09/17 00:36:20 (8 years ago)
Author:
abeham
Message:

#2701:

  • Added alternating bits binary test Problem
  • Refactored MemPR to work with programmable problem in current trunk
  • fixed a bug in permutation MemPR when crossover doesn't assign an offspring
Location:
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimb.cs

    r14450 r14552  
    3333  [StorableClass]
    3434  public class ExhaustiveHillClimb<TContext> : NamedItem, ILocalSearch<TContext>
    35       where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<PermutationEncoding>, Encodings.PermutationEncoding.Permutation> {
     35      where TContext : ISingleSolutionHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation>,
     36                       IEvaluationServiceContext<Encodings.PermutationEncoding.Permutation> {
    3637
    3738    [StorableConstructor]
     
    4849
    4950    public void Optimize(TContext context) {
    50       var evalWrapper = new EvaluationWrapper<Encodings.PermutationEncoding.Permutation>(context.Problem, context.Solution);
    5151      var quality = context.Solution.Fitness;
    5252      try {
    5353        var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, ref quality,
    54           context.Problem.Maximization, evalWrapper.Evaluate, CancellationToken.None);
     54          context.Maximization, context.Evaluate, CancellationToken.None);
    5555        context.IncrementEvaluatedSolutions(result.Item1);
    5656        context.Iterations = result.Item2;
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimbSubspace.cs

    r14450 r14552  
    3434  public class ExhaustiveHillClimbSubspace<TContext> : NamedItem, ILocalSearch<TContext>
    3535      where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<PermutationEncoding>, Encodings.PermutationEncoding.Permutation>,
    36                        IPermutationSubspaceContext {
     36                       IPermutationSubspaceContext, IEvaluationServiceContext<Encodings.PermutationEncoding.Permutation> {
    3737
    3838    [StorableConstructor]
     
    4949
    5050    public void Optimize(TContext context) {
    51       var evalWrapper = new EvaluationWrapper<Encodings.PermutationEncoding.Permutation>(context.Problem, context.Solution);
    5251      var quality = context.Solution.Fitness;
    5352      try {
    5453        var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, ref quality,
    55           context.Problem.Maximization, evalWrapper.Evaluate, CancellationToken.None, context.Subspace.Subspace);
     54          context.Problem.Maximization, context.Evaluate, CancellationToken.None, context.Subspace.Subspace);
    5655        context.IncrementEvaluatedSolutions(result.Item1);
    5756        context.Iterations = result.Item2;
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive.cs

    r14456 r14552  
    3434
    3535    public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,
    36       ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,
     36      ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval,
    3737      CancellationToken token, bool[,] subspace = null) {
    38       if (double.IsNaN(quality)) quality = eval(perm);
     38      if (double.IsNaN(quality)) quality = eval(perm, token);
    3939      Tuple<int, int> changes;
    4040      switch (perm.PermutationType) {
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive1Shift.cs

    r14456 r14552  
    3131  public static class Exhaustive1Shift {
    3232    public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,
    33       ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,
     33      ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval,
    3434      CancellationToken token, bool[,] subspace = null) {
    3535      var evaluations = 0;
    3636      var current = perm;
    3737      if (double.IsNaN(quality)) {
    38         quality = eval(current);
     38        quality = eval(current, token);
    3939        evaluations++;
    4040      }
     
    5959            continue;
    6060          TranslocationManipulator.Apply(current, shift.Index1, shift.Index2, shift.Index3);
    61           var q = eval(current);
     61          var q = eval(current, token);
    6262          evaluations++;
    6363          if (FitnessComparer.IsBetter(maximization, q, quality)) {
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive2Opt.cs

    r14456 r14552  
    3131  public static class Exhaustive2Opt {
    3232    public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,
    33       ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,
     33      ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval,
    3434      CancellationToken token, bool[,] subspace = null) {
    3535      var evaluations = 0;
    3636      var current = perm;
    3737      if (double.IsNaN(quality)) {
    38         quality = eval(current);
     38        quality = eval(current, token);
    3939        evaluations++;
    4040      }
     
    5656
    5757          InversionManipulator.Apply(current, opt.Index1, opt.Index2);
    58           var q = eval(current);
     58          var q = eval(current, token);
    5959          evaluations++;
    6060          if (FitnessComparer.IsBetter(maximization, q, quality)) {
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/ExhaustiveSwap2.cs

    r14456 r14552  
    3131  public static class ExhaustiveSwap2 {
    3232    public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,
    33       ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,
     33      ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval,
    3434      CancellationToken token, bool[,] subspace = null) {
    3535      var evaluations = 0;
    3636      var current = perm;
    3737      if (double.IsNaN(quality)) {
    38         quality = eval(current);
     38        quality = eval(current, token);
    3939        evaluations++;
    4040      }
     
    5555          current[swap.Index1] = current[swap.Index2];
    5656          current[swap.Index2] = h;
    57           var q = eval(current);
     57          var q = eval(current, token);
    5858          evaluations++;
    5959          if (FitnessComparer.IsBetter(maximization, q, quality)) {
Note: See TracChangeset for help on using the changeset viewer.