Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/LAHCContext.cs @ 17915

Last change on this file since 17915 was 16728, checked in by abeham, 6 years ago

#1614: updated to new persistence and .NET 4.6.1

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 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 HEAL.Attic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC {
29  [Item("LAHC Context", "Context for late-acceptance hill climber")]
30  [StorableType("546B6C06-D986-49AA-BDEB-B664D2A9DA8C")]
31  public sealed class LAHCContext : SingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
32    [Storable]
33    private IValueParameter<GQAP> problem;
34    public GQAP Problem {
35      get { return problem.Value; }
36      set { problem.Value = value; }
37    }
38
39    [Storable]
40    private IValueParameter<GQAPSolution> bestSolution;
41    public GQAPSolution BestSolution {
42      get { return bestSolution.Value; }
43      set { bestSolution.Value = value; }
44    }
45
46    [Storable]
47    private IValueParameter<DoubleArray> memory;
48    public DoubleArray Memory {
49      get { return memory.Value; }
50      set { memory.Value = value; }
51    }
52
53    [Storable]
54    private IValueParameter<IntValue> lastSuccess;
55    public int LastSuccess {
56      get { return lastSuccess.Value.Value; }
57      set { lastSuccess.Value.Value = value; }
58    }
59   
60    [StorableConstructor]
61    private LAHCContext(StorableConstructorFlag _) : base(_) { }
62    private LAHCContext(LAHCContext original, Cloner cloner)
63    : base(original, cloner) {
64      problem = cloner.Clone(original.problem);
65      bestSolution = cloner.Clone(original.bestSolution);
66      memory = cloner.Clone(original.memory);
67      lastSuccess = cloner.Clone(original.lastSuccess);
68    }
69    public LAHCContext() {
70      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
71      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
72      Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory"));
73      Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess"));
74    }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
77      return new LAHCContext(this, cloner);
78    }
79
80    public ISingleObjectiveSolutionScope<GQAPSolution> ToScope(GQAPSolution code, double fitness = double.NaN) {
81      var name = Problem.Encoding.Name;
82      var scope = new SingleObjectiveSolutionScope<GQAPSolution>(code,
83        name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
84        Parent = Scope
85      };
86      scope.Variables.Add(new Variable(name, code.Assignment));
87      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
88      return scope;
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.