Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LinearLinkageMemPRContext.cs @ 15049

Last change on this file since 15049 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.3 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 System.Runtime.Remoting.Contexts;
24using HeuristicLab.Algorithms.MemPR.Interfaces;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.LinearLinkageEncoding;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Algorithms.MemPR.Grouping {
33  [Item("MemPR Population Context (linear linkage)", "MemPR population context for linear linkage encoded problems.")]
34  [StorableClass]
35  public sealed class LinearLinkageMemPRPopulationContext : MemPRPopulationContext<ISingleObjectiveHeuristicOptimizationProblem, LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext> {
36
37    [StorableConstructor]
38    private LinearLinkageMemPRPopulationContext(bool deserializing) : base(deserializing) { }
39    private LinearLinkageMemPRPopulationContext(LinearLinkageMemPRPopulationContext original, Cloner cloner)
40      : base(original, cloner) { }
41    public LinearLinkageMemPRPopulationContext() : base("LinearLinkageMemPRPopulationContext") { }
42    public LinearLinkageMemPRPopulationContext(string name) : base(name) { }
43
44    public override IDeepCloneable Clone(Cloner cloner) {
45      return new LinearLinkageMemPRPopulationContext(this, cloner);
46    }
47
48    public override LinearLinkageMemPRSolutionContext CreateSingleSolutionContext(ISingleObjectiveSolutionScope<LinearLinkage> solution) {
49      return new LinearLinkageMemPRSolutionContext(this, solution);
50    }
51
52    public override ISingleObjectiveSolutionScope<LinearLinkage> ToScope(LinearLinkage code, double fitness = double.NaN) {
53      var creator = Problem.SolutionCreator as ILinearLinkageCreator;
54      if (creator == null) throw new InvalidOperationException("Can only solve linear linkage encoded problems with MemPR (linear linkage)");
55      return new SingleObjectiveSolutionScope<LinearLinkage>(code, creator.LLEParameter.ActualName, fitness, Problem.Evaluator.QualityParameter.ActualName) {
56        Parent = Scope
57      };
58    }
59  }
60
61  [Item("MemPR Solution Context (linear linkage)", "MemPR solution context for linear linkage encoded problems.")]
62  [StorableClass]
63  public sealed class LinearLinkageMemPRSolutionContext : MemPRSolutionContext<ISingleObjectiveHeuristicOptimizationProblem, LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext>, ILinearLinkageSubspaceContext {
64
65    [Storable]
66    private IValueParameter<LinearLinkageSolutionSubspace> subspace;
67    public LinearLinkageSolutionSubspace Subspace {
68      get { return subspace.Value; }
69    }
70    ISolutionSubspace<LinearLinkage> ISolutionSubspaceContext<LinearLinkage>.Subspace {
71      get { return Subspace; }
72    }
73
74    [StorableConstructor]
75    private LinearLinkageMemPRSolutionContext(bool deserializing) : base(deserializing) { }
76    private LinearLinkageMemPRSolutionContext(LinearLinkageMemPRSolutionContext original, Cloner cloner)
77      : base(original, cloner) {
78
79    }
80    public LinearLinkageMemPRSolutionContext(LinearLinkageMemPRPopulationContext baseContext, ISingleObjectiveSolutionScope<LinearLinkage> solution)
81      : base(baseContext, solution) {
82
83      Parameters.Add(subspace = new ValueParameter<LinearLinkageSolutionSubspace>("Subspace", new LinearLinkageSolutionSubspace(null)));
84    }
85
86    public override IDeepCloneable Clone(Cloner cloner) {
87      return new LinearLinkageMemPRSolutionContext(this, cloner);
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.