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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC {
|
---|
29 | public sealed class LAHCContext : SingleSolutionContext<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<DoubleArray> memory;
|
---|
46 | public DoubleArray Memory {
|
---|
47 | get { return memory.Value; }
|
---|
48 | set { memory.Value = value; }
|
---|
49 | }
|
---|
50 |
|
---|
51 | [Storable]
|
---|
52 | private IValueParameter<IntValue> lastSuccess;
|
---|
53 | public int LastSuccess {
|
---|
54 | get { return lastSuccess.Value.Value; }
|
---|
55 | set { lastSuccess.Value.Value = value; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | [StorableConstructor]
|
---|
59 | private LAHCContext(bool deserializing) : base(deserializing) { }
|
---|
60 | private LAHCContext(LAHCContext original, Cloner cloner)
|
---|
61 | : base(original, cloner) {
|
---|
62 | problem = cloner.Clone(original.problem);
|
---|
63 | bestSolution = cloner.Clone(original.bestSolution);
|
---|
64 | memory = cloner.Clone(original.memory);
|
---|
65 | lastSuccess = cloner.Clone(original.lastSuccess);
|
---|
66 | }
|
---|
67 | public LAHCContext() {
|
---|
68 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
69 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
70 | Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory"));
|
---|
71 | Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess"));
|
---|
72 | }
|
---|
73 |
|
---|
74 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
75 | return new LAHCContext(this, cloner);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public ISingleObjectiveSolutionScope<GQAPSolution> ToScope(GQAPSolution code, double fitness = double.NaN) {
|
---|
79 | var name = Problem.Encoding.Name;
|
---|
80 | var scope = new SingleObjectiveSolutionScope<GQAPSolution>(code,
|
---|
81 | name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
|
---|
82 | Parent = Scope
|
---|
83 | };
|
---|
84 | scope.Variables.Add(new Variable(name, code.Assignment));
|
---|
85 | scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
|
---|
86 | return scope;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | } |
---|