[15562] | 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 |
|
---|
[16728] | 22 | using HEAL.Attic;
|
---|
[15562] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[15563] | 25 | using HeuristicLab.Data;
|
---|
[15562] | 26 | using HeuristicLab.Parameters;
|
---|
| 27 |
|
---|
[15563] | 28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC {
|
---|
[15616] | 29 | [Item("LAHC Context", "Context for late-acceptance hill climber")]
|
---|
[16728] | 30 | [StorableType("546B6C06-D986-49AA-BDEB-B664D2A9DA8C")]
|
---|
[15572] | 31 | public sealed class LAHCContext : SingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
|
---|
[15562] | 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 | }
|
---|
[15563] | 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 | }
|
---|
[15562] | 59 |
|
---|
| 60 | [StorableConstructor]
|
---|
[16728] | 61 | private LAHCContext(StorableConstructorFlag _) : base(_) { }
|
---|
[15563] | 62 | private LAHCContext(LAHCContext original, Cloner cloner)
|
---|
[15562] | 63 | : base(original, cloner) {
|
---|
| 64 | problem = cloner.Clone(original.problem);
|
---|
| 65 | bestSolution = cloner.Clone(original.bestSolution);
|
---|
[15563] | 66 | memory = cloner.Clone(original.memory);
|
---|
| 67 | lastSuccess = cloner.Clone(original.lastSuccess);
|
---|
[15562] | 68 | }
|
---|
[15563] | 69 | public LAHCContext() {
|
---|
[15562] | 70 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
| 71 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
[15563] | 72 | Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory"));
|
---|
| 73 | Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess"));
|
---|
[15562] | 74 | }
|
---|
| 75 |
|
---|
| 76 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[15563] | 77 | return new LAHCContext(this, cloner);
|
---|
[15562] | 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 | } |
---|