Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary/ESContext.cs @ 15616

Last change on this file since 15616 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
RevLine 
[15553]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
[15562]27namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.Evolutionary {
28  [Item("Evolution Strategy (GQAP) Context", "Context for Evolution Strategies (GQAP).")]
[15553]29  [StorableClass]
[15572]30  public sealed class ESContext : PopulationContext<ISingleObjectiveSolutionScope<ESGQAPSolution>> {
[15553]31   
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]
[15562]40    private IValueParameter<ESGQAPSolution> bestSolution;
41    public ESGQAPSolution BestSolution {
[15553]42      get { return bestSolution.Value; }
43      set { bestSolution.Value = value; }
44    }
45
[15563]46    [Storable]
47    private IValueParameter<IRandom> normalRand;
48    public IRandom NormalRand {
49      get { return normalRand.Value; }
50      set { normalRand.Value = value; }
51    }
[15553]52   
53    [StorableConstructor]
[15562]54    private ESContext(bool deserializing) : base(deserializing) { }
55    private ESContext(ESContext original, Cloner cloner)
[15553]56      : base(original, cloner) {
57      problem = cloner.Clone(original.problem);
58      bestSolution = cloner.Clone(original.bestSolution);
[15563]59      normalRand = cloner.Clone(original.normalRand);
[15553]60    }
[15562]61    public ESContext() : this("Evolution Strategy (GQAP) Context") { }
62    public ESContext(string name) : base(name) {
[15553]63      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
[15562]64      Parameters.Add(bestSolution = new ValueParameter<ESGQAPSolution>("BestFoundSolution"));
[15563]65      Parameters.Add(normalRand = new ValueParameter<IRandom>("NormalRand"));
[15553]66    }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
[15562]69      return new ESContext(this, cloner);
[15553]70    }
71
[15562]72    public ISingleObjectiveSolutionScope<ESGQAPSolution> ToScope(ESGQAPSolution code, double fitness = double.NaN) {
[15553]73      var name = Problem.Encoding.Name;
[15562]74      var scope = new SingleObjectiveSolutionScope<ESGQAPSolution>(code,
[15553]75        name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
76        Parent = Scope
77      };
78      scope.Variables.Add(new Variable(name, code.Assignment));
79      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
[15563]80      scope.Variables.Add(new Variable("StrategyParameter", code.sParam));
[15553]81      return scope;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.