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;
|
---|
24 | using HeuristicLab.Parameters;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.Evolutionary {
|
---|
28 | [Item("Evolution Strategy (GQAP) Context", "Context for Evolution Strategies (GQAP).")]
|
---|
29 | [StorableClass]
|
---|
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(bool deserializing) : base(deserializing) { }
|
---|
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 | }
|
---|