Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1614: added additional algorithms

File size: 3.1 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 System.Collections.Generic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.Evolutionary {
29  [Item("Evolution Strategy (GQAP) Context", "Context for Evolution Strategies (GQAP).")]
30  [StorableClass]
31  public sealed class ESContext : SingleObjectivePopulationContext<ISingleObjectiveSolutionScope<ESGQAPSolution>> {
32   
33    [Storable]
34    private IValueParameter<GQAP> problem;
35    public GQAP Problem {
36      get { return problem.Value; }
37      set { problem.Value = value; }
38    }
39
40    [Storable]
41    private IValueParameter<ESGQAPSolution> bestSolution;
42    public ESGQAPSolution BestSolution {
43      get { return bestSolution.Value; }
44      set { bestSolution.Value = value; }
45    }
46
47    public void ReplacePopulation(IEnumerable<ISingleObjectiveSolutionScope<ESGQAPSolution>> replacement) {
48      Scope.SubScopes.Replace(replacement);
49    }
50   
51    [StorableConstructor]
52    private ESContext(bool deserializing) : base(deserializing) { }
53    private ESContext(ESContext original, Cloner cloner)
54      : base(original, cloner) {
55      problem = cloner.Clone(original.problem);
56      bestSolution = cloner.Clone(original.bestSolution);
57    }
58    public ESContext() : this("Evolution Strategy (GQAP) Context") { }
59    public ESContext(string name) : base(name) {
60      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
61      Parameters.Add(bestSolution = new ValueParameter<ESGQAPSolution>("BestFoundSolution"));
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new ESContext(this, cloner);
66    }
67
68    public ISingleObjectiveSolutionScope<ESGQAPSolution> ToScope(ESGQAPSolution code, double fitness = double.NaN) {
69      var name = Problem.Encoding.Name;
70      var scope = new SingleObjectiveSolutionScope<ESGQAPSolution>(code,
71        name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
72        Parent = Scope
73      };
74      scope.Variables.Add(new Variable(name, code.Assignment));
75      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
76      return scope;
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.