Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Algorithms.MemPR/3.3/Binary/BinaryMemPRContext.cs @ 16310

Last change on this file since 16310 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
Line 
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
22using System;
23using HeuristicLab.Algorithms.MemPR.Interfaces;
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 {
32  [Item("MemPR Population Context (binary)", "MemPR population context for binary encoded problems.")]
33  [StorableClass]
34  public sealed class BinaryMemPRPopulationContext : MemPRPopulationContext<ISingleObjectiveHeuristicOptimizationProblem, BinaryVector, BinaryMemPRPopulationContext, BinaryMemPRSolutionContext> {
35
36    [StorableConstructor]
37    private BinaryMemPRPopulationContext(bool deserializing) : base(deserializing) { }
38    private BinaryMemPRPopulationContext(BinaryMemPRPopulationContext original, Cloner cloner)
39      : base(original, cloner) { }
40    public BinaryMemPRPopulationContext() : base("BinaryMemPRPopulationContext") { }
41    public BinaryMemPRPopulationContext(string name) : base(name) { }
42
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new BinaryMemPRPopulationContext(this, cloner);
45    }
46
47    public override BinaryMemPRSolutionContext CreateSingleSolutionContext(ISingleObjectiveSolutionScope<BinaryVector> solution) {
48      return new BinaryMemPRSolutionContext(this, solution);
49    }
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    }
58  }
59
60  [Item("MemPR Solution Context (binary)", "MemPR solution context for binary encoded problems.")]
61  [StorableClass]
62  public sealed class BinaryMemPRSolutionContext : MemPRSolutionContext<ISingleObjectiveHeuristicOptimizationProblem, BinaryVector, BinaryMemPRPopulationContext, BinaryMemPRSolutionContext>, IBinaryVectorSubspaceContext {
63
64    [Storable]
65    private IValueParameter<BinarySolutionSubspace> subspace;
66    public BinarySolutionSubspace Subspace {
67      get { return subspace.Value; }
68    }
69    ISolutionSubspace<BinaryVector> ISolutionSubspaceContext<BinaryVector>.Subspace {
70      get { return Subspace; }
71    }
72
73    [StorableConstructor]
74    private BinaryMemPRSolutionContext(bool deserializing) : base(deserializing) { }
75    private BinaryMemPRSolutionContext(BinaryMemPRSolutionContext original, Cloner cloner)
76      : base(original, cloner) {
77
78    }
79    public BinaryMemPRSolutionContext(BinaryMemPRPopulationContext baseContext, ISingleObjectiveSolutionScope<BinaryVector> solution)
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) {
86      return new BinaryMemPRSolutionContext(this, cloner);
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.