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 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Algorithms.MemPR.Interfaces;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 |
|
---|
31 | namespace 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 | }
|
---|