Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSearch/LocalSearchContext.cs @ 15562

Last change on this file since 15562 was 15562, checked in by abeham, 6 years ago

#1614: added additional algorithms

File size: 2.7 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.Parameters;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSearch {
28  public sealed class LocalSearchContext : SingleObjectiveSingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
29    [Storable]
30    private IValueParameter<GQAP> problem;
31    public GQAP Problem {
32      get { return problem.Value; }
33      set { problem.Value = value; }
34    }
35
36    [Storable]
37    private IValueParameter<GQAPSolution> bestSolution;
38    public GQAPSolution BestSolution {
39      get { return bestSolution.Value; }
40      set { bestSolution.Value = value; }
41    }
42   
43    [StorableConstructor]
44    private LocalSearchContext(bool deserializing) : base(deserializing) { }
45    private LocalSearchContext(LocalSearchContext original, Cloner cloner)
46    : base(original, cloner) {
47      problem = cloner.Clone(original.problem);
48      bestSolution = cloner.Clone(original.bestSolution);
49    }
50    public LocalSearchContext() {
51      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
52      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
53    }
54
55    public override IDeepCloneable Clone(Cloner cloner) {
56      return new LocalSearchContext(this, cloner);
57    }
58
59    public ISingleObjectiveSolutionScope<GQAPSolution> ToScope(GQAPSolution code, double fitness = double.NaN) {
60      var name = Problem.Encoding.Name;
61      var scope = new SingleObjectiveSolutionScope<GQAPSolution>(code,
62        name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
63        Parent = Scope
64      };
65      scope.Variables.Add(new Variable(name, code.Assignment));
66      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
67      return scope;
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.