Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/07/16 23:46:29 (8 years ago)
Author:
abeham
Message:

#2701:

  • Added MemPR for linear linkage (tabu walk still missing)
  • Added graph coloring problem
Location:
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage
Files:
2 added
1 copied

Legend:

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

    r14450 r14466  
    2222using System.Threading;
    2323using HeuristicLab.Algorithms.MemPR.Interfaces;
     24using HeuristicLab.Algorithms.MemPR.Util;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HeuristicLab.Encodings.Binary.LocalSearch;
    27 using HeuristicLab.Encodings.BinaryVectorEncoding;
     27using HeuristicLab.Encodings.LinearLinkageEncoding;
    2828using HeuristicLab.Optimization;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    31 namespace HeuristicLab.Algorithms.MemPR.Binary.LocalSearch {
    32   [Item("Exhaustive Bitflip Local (Subspace) Search (binary)", "", ExcludeGenericTypeInfo = true)]
     31namespace HeuristicLab.Algorithms.MemPR.LinearLinkage.LocalSearch {
     32  [Item("Exhaustive Local (Subspace) Search (linear linkage)", "", ExcludeGenericTypeInfo = true)]
    3333  [StorableClass]
    34   public class ExhaustiveBitflipSubspace<TContext> : NamedItem, ILocalSearch<TContext>
    35       where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<BinaryVectorEncoding>, BinaryVector>, IBinaryVectorSubspaceContext {
     34  public class ExhaustiveSubspace<TContext> : NamedItem, ILocalSearch<TContext>
     35      where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, Encodings.LinearLinkageEncoding.LinearLinkage>, ILinearLinkageSubspaceContext {
    3636
    3737    [StorableConstructor]
    38     protected ExhaustiveBitflipSubspace(bool deserializing) : base(deserializing) { }
    39     protected ExhaustiveBitflipSubspace(ExhaustiveBitflipSubspace<TContext> original, Cloner cloner) : base(original, cloner) { }
    40     public ExhaustiveBitflipSubspace() {
     38    protected ExhaustiveSubspace(bool deserializing) : base(deserializing) { }
     39    protected ExhaustiveSubspace(ExhaustiveSubspace<TContext> original, Cloner cloner) : base(original, cloner) { }
     40    public ExhaustiveSubspace() {
    4141      Name = ItemName;
    4242      Description = ItemDescription;
     
    4444
    4545    public override IDeepCloneable Clone(Cloner cloner) {
    46       return new ExhaustiveBitflipSubspace<TContext>(this, cloner);
     46      return new ExhaustiveSubspace<TContext>(this, cloner);
    4747    }
    4848
    4949    public void Optimize(TContext context) {
    50       var evalWrapper = new EvaluationWrapper(context);
     50      var evalWrapper = new EvaluationWrapper<Encodings.LinearLinkageEncoding.LinearLinkage>(context.Problem, context.Solution);
    5151      var quality = context.Solution.Fitness;
    5252      try {
    53         var result = ExhaustiveBitflip.Optimize(context.Random, context.Solution.Solution, ref quality,
     53        var result = ExhaustiveLocalSearch.Optimize(context.Random, context.Solution.Solution, ref quality,
    5454          context.Problem.Maximization, evalWrapper.Evaluate, CancellationToken.None, context.Subspace.Subspace);
    5555        context.IncrementEvaluatedSolutions(result.Item1);
     
    5959      }
    6060    }
    61 
    62     public sealed class EvaluationWrapper {
    63       private readonly TContext context;
    64       private readonly ISingleObjectiveSolutionScope<BinaryVector> scope;
    65       private readonly SingleEncodingIndividual individual;
    66 
    67       public EvaluationWrapper(TContext context) {
    68         this.context = context;
    69         // don't clone the solution, which is thrown away again
    70         var cloner = new Cloner();
    71         cloner.RegisterClonedObject(context.Solution.Solution, null);
    72         this.scope = (ISingleObjectiveSolutionScope<BinaryVector>)context.Solution.Clone(cloner);
    73         this.individual = new SingleEncodingIndividual(context.Problem.Encoding, this.scope);
    74       }
    75 
    76       public double Evaluate(BinaryVector b) {
    77         scope.Solution = b;
    78         return context.Problem.Evaluate(individual, null);
    79       }
    80     }
    8161  }
    8262}
Note: See TracChangeset for help on using the changeset viewer.