Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/LAHCContext.cs @ 15572

Last change on this file since 15572 was 15572, checked in by abeham, 7 years ago

#1614:

  • fixed a bug in GRASP where solutions in the elite set would be mutated
  • introduced termination criteria when reaching best-known quality
  • tweaked generating random numbers in StochasticNMoveSingleMoveGenerator
  • changed DiscreteLocationCrossover to use an allele from one of the parents instead of introducing a mutation in case no feasible insert location is found
  • changed OSGA maxselpress to 500
  • slight change to contexts, introduced single-objectiveness much earlier in the class hierachy
    • limited ContextAlgorithm to SingleObjectiveBasicProblems (doesn't matter here)
File size: 3.3 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.Data;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace 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}
Note: See TracBrowser for help on using the repository browser.