Changeset 14466 for branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LocalSearch/ExhaustiveSubspace.cs
- Timestamp:
- 12/07/16 23:46:29 (8 years ago)
- 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 22 22 using System.Threading; 23 23 using HeuristicLab.Algorithms.MemPR.Interfaces; 24 using HeuristicLab.Algorithms.MemPR.Util; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.Binary.LocalSearch; 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 27 using HeuristicLab.Encodings.LinearLinkageEncoding; 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.Algorithms.MemPR. Binary.LocalSearch {32 [Item("Exhaustive Bitflip Local (Subspace) Search (binary)", "", ExcludeGenericTypeInfo = true)]31 namespace HeuristicLab.Algorithms.MemPR.LinearLinkage.LocalSearch { 32 [Item("Exhaustive Local (Subspace) Search (linear linkage)", "", ExcludeGenericTypeInfo = true)] 33 33 [StorableClass] 34 public class Exhaustive BitflipSubspace<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 { 36 36 37 37 [StorableConstructor] 38 protected Exhaustive BitflipSubspace(bool deserializing) : base(deserializing) { }39 protected Exhaustive BitflipSubspace(ExhaustiveBitflipSubspace<TContext> original, Cloner cloner) : base(original, cloner) { }40 public Exhaustive BitflipSubspace() {38 protected ExhaustiveSubspace(bool deserializing) : base(deserializing) { } 39 protected ExhaustiveSubspace(ExhaustiveSubspace<TContext> original, Cloner cloner) : base(original, cloner) { } 40 public ExhaustiveSubspace() { 41 41 Name = ItemName; 42 42 Description = ItemDescription; … … 44 44 45 45 public override IDeepCloneable Clone(Cloner cloner) { 46 return new Exhaustive BitflipSubspace<TContext>(this, cloner);46 return new ExhaustiveSubspace<TContext>(this, cloner); 47 47 } 48 48 49 49 public void Optimize(TContext context) { 50 var evalWrapper = new EvaluationWrapper (context);50 var evalWrapper = new EvaluationWrapper<Encodings.LinearLinkageEncoding.LinearLinkage>(context.Problem, context.Solution); 51 51 var quality = context.Solution.Fitness; 52 52 try { 53 var result = Exhaustive Bitflip.Optimize(context.Random, context.Solution.Solution, ref quality,53 var result = ExhaustiveLocalSearch.Optimize(context.Random, context.Solution.Solution, ref quality, 54 54 context.Problem.Maximization, evalWrapper.Evaluate, CancellationToken.None, context.Subspace.Subspace); 55 55 context.IncrementEvaluatedSolutions(result.Item1); … … 59 59 } 60 60 } 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 again70 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 }81 61 } 82 62 }
Note: See TracChangeset
for help on using the changeset viewer.