Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/pLAHCContext.cs @ 17717

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

#1614: updated to new persistence and .NET 4.6.1

File size: 4.1 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("pLAHC-s Context", "Context for parameterless late-acceptance hill climber with seeding.")]
30  [StorableType("3C550AB5-8FEC-42DA-9200-ABC98A1C20EA")]
31  public sealed class PLAHCContext : 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<IntValue> sprintIterations;
48    public int SprintIterations {
49      get { return sprintIterations.Value.Value; }
50      set { sprintIterations.Value.Value = value; }
51    }
52
53    [Storable]
54    private IValueParameter<DoubleArray> memory;
55    public DoubleArray Memory {
56      get { return memory.Value; }
57      set { memory.Value = value; }
58    }
59
60    [Storable]
61    private IValueParameter<IntValue> lastSuccess;
62    public int LastSuccess {
63      get { return lastSuccess.Value.Value; }
64      set { lastSuccess.Value.Value = value; }
65    }
66
67    [Storable]
68    private IValueParameter<ItemList<DoubleValue>> bestList;
69    public ItemList<DoubleValue> BestList {
70      get { return bestList.Value; }
71      set { bestList.Value = value; }
72    }
73   
74    [StorableConstructor]
75    private PLAHCContext(StorableConstructorFlag _) : base(_) { }
76    private PLAHCContext(PLAHCContext original, Cloner cloner)
77    : base(original, cloner) {
78      problem = cloner.Clone(original.problem);
79      bestSolution = cloner.Clone(original.bestSolution);
80      sprintIterations = cloner.Clone(original.sprintIterations);
81      memory = cloner.Clone(original.memory);
82      lastSuccess = cloner.Clone(original.lastSuccess);
83      bestList = cloner.Clone(original.bestList);
84    }
85    public PLAHCContext() {
86      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
87      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
88      Parameters.Add(sprintIterations = new ValueParameter<IntValue>("SprintIterations"));
89      Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory"));
90      Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess"));
91      Parameters.Add(bestList = new ValueParameter<ItemList<DoubleValue>>("BestList"));
92    }
93
94    public override IDeepCloneable Clone(Cloner cloner) {
95      return new PLAHCContext(this, cloner);
96    }
97
98    public ISingleObjectiveSolutionScope<GQAPSolution> ToScope(GQAPSolution code, double fitness = double.NaN) {
99      var name = Problem.Encoding.Name;
100      var scope = new SingleObjectiveSolutionScope<GQAPSolution>(code,
101        name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
102        Parent = Scope
103      };
104      scope.Variables.Add(new Variable(name, code.Assignment));
105      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
106      return scope;
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.