source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/pLAHCContext.cs @ 15563

Last change on this file since 15563 was 15563, checked in by abeham, 4 years ago

#1614:

  • Added LAHC and pLAHC-s
  • Changed all algorithms to update high frequency results only every second
File size: 4.0 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  public sealed class PLAHCContext : SingleObjectiveSingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
30    [Storable]
31    private IValueParameter<GQAP> problem;
32    public GQAP Problem {
33      get { return problem.Value; }
34      set { problem.Value = value; }
35    }
36
37    [Storable]
38    private IValueParameter<GQAPSolution> bestSolution;
39    public GQAPSolution BestSolution {
40      get { return bestSolution.Value; }
41      set { bestSolution.Value = value; }
42    }
43
44    [Storable]
45    private IValueParameter<IntValue> sprintIterations;
46    public int SprintIterations {
47      get { return sprintIterations.Value.Value; }
48      set { sprintIterations.Value.Value = value; }
49    }
50
51    [Storable]
52    private IValueParameter<DoubleArray> memory;
53    public DoubleArray Memory {
54      get { return memory.Value; }
55      set { memory.Value = value; }
56    }
57
58    [Storable]
59    private IValueParameter<IntValue> lastSuccess;
60    public int LastSuccess {
61      get { return lastSuccess.Value.Value; }
62      set { lastSuccess.Value.Value = value; }
63    }
64
65    [Storable]
66    private IValueParameter<ItemList<DoubleValue>> bestList;
67    public ItemList<DoubleValue> BestList {
68      get { return bestList.Value; }
69      set { bestList.Value = value; }
70    }
71   
72    [StorableConstructor]
73    private PLAHCContext(bool deserializing) : base(deserializing) { }
74    private PLAHCContext(PLAHCContext original, Cloner cloner)
75    : base(original, cloner) {
76      problem = cloner.Clone(original.problem);
77      bestSolution = cloner.Clone(original.bestSolution);
78      sprintIterations = cloner.Clone(original.sprintIterations);
79      memory = cloner.Clone(original.memory);
80      lastSuccess = cloner.Clone(original.lastSuccess);
81      bestList = cloner.Clone(original.bestList);
82    }
83    public PLAHCContext() {
84      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
85      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
86      Parameters.Add(sprintIterations = new ValueParameter<IntValue>("SprintIterations"));
87      Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory"));
88      Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess"));
89      Parameters.Add(bestList = new ValueParameter<ItemList<DoubleValue>>("BestList"));
90    }
91
92    public override IDeepCloneable Clone(Cloner cloner) {
93      return new PLAHCContext(this, cloner);
94    }
95
96    public ISingleObjectiveSolutionScope<GQAPSolution> ToScope(GQAPSolution code, double fitness = double.NaN) {
97      var name = Problem.Encoding.Name;
98      var scope = new SingleObjectiveSolutionScope<GQAPSolution>(code,
99        name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
100        Parent = Scope
101      };
102      scope.Variables.Add(new Variable(name, code.Assignment));
103      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
104      return scope;
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.