Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Binary/BinaryMemPRContext.cs @ 15728

Last change on this file since 15728 was 14552, checked in by abeham, 8 years ago

#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
File size: 4.1 KB
RevLine 
[14420]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[14552]22using System;
[14450]23using HeuristicLab.Algorithms.MemPR.Interfaces;
[14420]24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.BinaryVectorEncoding;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.MemPR.Binary {
[14450]32  [Item("MemPR Population Context (binary)", "MemPR population context for binary encoded problems.")]
[14420]33  [StorableClass]
[14552]34  public sealed class BinaryMemPRPopulationContext : MemPRPopulationContext<ISingleObjectiveHeuristicOptimizationProblem, BinaryVector, BinaryMemPRPopulationContext, BinaryMemPRSolutionContext> {
[14420]35
36    [StorableConstructor]
[14450]37    private BinaryMemPRPopulationContext(bool deserializing) : base(deserializing) { }
38    private BinaryMemPRPopulationContext(BinaryMemPRPopulationContext original, Cloner cloner)
[14420]39      : base(original, cloner) { }
[14450]40    public BinaryMemPRPopulationContext() : base("BinaryMemPRPopulationContext") { }
41    public BinaryMemPRPopulationContext(string name) : base(name) { }
[14420]42
43    public override IDeepCloneable Clone(Cloner cloner) {
[14450]44      return new BinaryMemPRPopulationContext(this, cloner);
[14420]45    }
46
[14450]47    public override BinaryMemPRSolutionContext CreateSingleSolutionContext(ISingleObjectiveSolutionScope<BinaryVector> solution) {
48      return new BinaryMemPRSolutionContext(this, solution);
[14420]49    }
[14552]50
51    public override ISingleObjectiveSolutionScope<BinaryVector> ToScope(BinaryVector code, double fitness = double.NaN) {
52      var creator = Problem.SolutionCreator as IBinaryVectorCreator;
53      if (creator == null) throw new InvalidOperationException("MemPR (binary) context expects a problem with an IBinaryVectorCreator as solution creator.");
54      return new SingleObjectiveSolutionScope<BinaryVector>(code, creator.BinaryVectorParameter.ActualName, fitness, Problem.Evaluator.QualityParameter.ActualName) {
55        Parent = Scope
56      };
57    }
[14420]58  }
59
[14450]60  [Item("MemPR Solution Context (binary)", "MemPR solution context for binary encoded problems.")]
[14420]61  [StorableClass]
[14552]62  public sealed class BinaryMemPRSolutionContext : MemPRSolutionContext<ISingleObjectiveHeuristicOptimizationProblem, BinaryVector, BinaryMemPRPopulationContext, BinaryMemPRSolutionContext>, IBinaryVectorSubspaceContext {
[14420]63
64    [Storable]
65    private IValueParameter<BinarySolutionSubspace> subspace;
66    public BinarySolutionSubspace Subspace {
67      get { return subspace.Value; }
68    }
[14450]69    ISolutionSubspace<BinaryVector> ISolutionSubspaceContext<BinaryVector>.Subspace {
[14420]70      get { return Subspace; }
71    }
72
73    [StorableConstructor]
[14450]74    private BinaryMemPRSolutionContext(bool deserializing) : base(deserializing) { }
75    private BinaryMemPRSolutionContext(BinaryMemPRSolutionContext original, Cloner cloner)
[14420]76      : base(original, cloner) {
77
78    }
[14450]79    public BinaryMemPRSolutionContext(BinaryMemPRPopulationContext baseContext, ISingleObjectiveSolutionScope<BinaryVector> solution)
[14420]80      : base(baseContext, solution) {
81
82      Parameters.Add(subspace = new ValueParameter<BinarySolutionSubspace>("Subspace", new BinarySolutionSubspace(null)));
83    }
84
85    public override IDeepCloneable Clone(Cloner cloner) {
[14450]86      return new BinaryMemPRSolutionContext(this, cloner);
[14420]87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.