Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary/ESContext.cs

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

#1614: updated to new persistence and .NET 4.6.1

File size: 3.2 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 HEAL.Attic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Parameters;
26
27namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.Evolutionary {
28  [Item("Evolution Strategy (GQAP) Context", "Context for Evolution Strategies (GQAP).")]
29  [StorableType("8A811131-337D-4CF6-A938-FFA08BF50B40")]
30  public sealed class ESContext : PopulationContext<ISingleObjectiveSolutionScope<ESGQAPSolution>> {
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]
40    private IValueParameter<ESGQAPSolution> bestSolution;
41    public ESGQAPSolution BestSolution {
42      get { return bestSolution.Value; }
43      set { bestSolution.Value = value; }
44    }
45
46    [Storable]
47    private IValueParameter<IRandom> normalRand;
48    public IRandom NormalRand {
49      get { return normalRand.Value; }
50      set { normalRand.Value = value; }
51    }
52   
53    [StorableConstructor]
54    private ESContext(StorableConstructorFlag _) : base(_) { }
55    private ESContext(ESContext original, Cloner cloner)
56      : base(original, cloner) {
57      problem = cloner.Clone(original.problem);
58      bestSolution = cloner.Clone(original.bestSolution);
59      normalRand = cloner.Clone(original.normalRand);
60    }
61    public ESContext() : this("Evolution Strategy (GQAP) Context") { }
62    public ESContext(string name) : base(name) {
63      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
64      Parameters.Add(bestSolution = new ValueParameter<ESGQAPSolution>("BestFoundSolution"));
65      Parameters.Add(normalRand = new ValueParameter<IRandom>("NormalRand"));
66    }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new ESContext(this, cloner);
70    }
71
72    public ISingleObjectiveSolutionScope<ESGQAPSolution> ToScope(ESGQAPSolution code, double fitness = double.NaN) {
73      var name = Problem.Encoding.Name;
74      var scope = new SingleObjectiveSolutionScope<ESGQAPSolution>(code,
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));
80      scope.Variables.Add(new Variable("StrategyParameter", code.sParam));
81      return scope;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.