[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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[15563] | 24 | using HeuristicLab.Data;
|
---|
[15562] | 25 | using HeuristicLab.Parameters;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
[15563] | 28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC {
|
---|
| 29 | public sealed class LAHCContext : SingleObjectiveSingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
|
---|
[15562] | 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 | }
|
---|
[15563] | 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 | }
|
---|
[15562] | 57 |
|
---|
| 58 | [StorableConstructor]
|
---|
[15563] | 59 | private LAHCContext(bool deserializing) : base(deserializing) { }
|
---|
| 60 | private LAHCContext(LAHCContext original, Cloner cloner)
|
---|
[15562] | 61 | : base(original, cloner) {
|
---|
| 62 | problem = cloner.Clone(original.problem);
|
---|
| 63 | bestSolution = cloner.Clone(original.bestSolution);
|
---|
[15563] | 64 | memory = cloner.Clone(original.memory);
|
---|
| 65 | lastSuccess = cloner.Clone(original.lastSuccess);
|
---|
[15562] | 66 | }
|
---|
[15563] | 67 | public LAHCContext() {
|
---|
[15562] | 68 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
| 69 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
[15563] | 70 | Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory"));
|
---|
| 71 | Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess"));
|
---|
[15562] | 72 | }
|
---|
| 73 |
|
---|
| 74 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[15563] | 75 | return new LAHCContext(this, cloner);
|
---|
[15562] | 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 | } |
---|