[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("pLAHC-s Context", "Context for parameterless late-acceptance hill climber with seeding.")]
|
---|
[16728] | 30 | [StorableType("3C550AB5-8FEC-42DA-9200-ABC98A1C20EA")]
|
---|
[15572] | 31 | public sealed class PLAHCContext : 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<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 | }
|
---|
[15562] | 73 |
|
---|
| 74 | [StorableConstructor]
|
---|
[16728] | 75 | private PLAHCContext(StorableConstructorFlag _) : base(_) { }
|
---|
[15563] | 76 | private PLAHCContext(PLAHCContext original, Cloner cloner)
|
---|
[15562] | 77 | : base(original, cloner) {
|
---|
| 78 | problem = cloner.Clone(original.problem);
|
---|
| 79 | bestSolution = cloner.Clone(original.bestSolution);
|
---|
[15563] | 80 | sprintIterations = cloner.Clone(original.sprintIterations);
|
---|
| 81 | memory = cloner.Clone(original.memory);
|
---|
| 82 | lastSuccess = cloner.Clone(original.lastSuccess);
|
---|
| 83 | bestList = cloner.Clone(original.bestList);
|
---|
[15562] | 84 | }
|
---|
[15563] | 85 | public PLAHCContext() {
|
---|
[15562] | 86 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
| 87 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
[15563] | 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"));
|
---|
[15562] | 92 | }
|
---|
| 93 |
|
---|
| 94 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[15563] | 95 | return new PLAHCContext(this, cloner);
|
---|
[15562] | 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 | } |
---|