Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/LAHCContext.cs @ 16375

Last change on this file since 16375 was 15616, checked in by abeham, 7 years ago

#1614:

  • Added missing Item and StorableClass attributes
  • Removed running analyzer on empty solutions in GRASP
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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC {
29  [Item("LAHC Context", "Context for late-acceptance hill climber")]
30  [StorableClass]
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(bool deserializing) : base(deserializing) { }
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.