Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/EvolutionTrackingOperator.cs

Last change on this file was 17434, checked in by bburlacu, 5 years ago

#1772: Merge trunk changes and fix all errors and compilation warnings.

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.EvolutionTracking {
32  [Item("EvolutionTrackingOperator", "A base operator which facilitates access to the genealogy graph.")]
33  [StorableType("27D4603D-0EDC-4C77-9AB9-ED10CA6D4613")]
34  public class EvolutionTrackingOperator<T> : SingleSuccessorOperator where T : class, IItem {
35    // evolution tracking-related parameters
36    private const string ResultsParameterName = "Results";
37    private const string PopulationGraphParameterName = "PopulationGraph";
38    private const string GenerationsParameterName = "Generations";
39
40    public ILookupParameter<ResultCollection> ResultsParameter {
41      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
42    }
43    public ILookupParameter<IntValue> GenerationsParameter {
44      get { return (ILookupParameter<IntValue>)Parameters[GenerationsParameterName]; }
45    }
46    public ResultCollection Results {
47      get { return ResultsParameter.ActualValue; }
48    }
49    public IntValue Generations {
50      get { return GenerationsParameter.ActualValue; }
51    }
52    public IGenealogyGraph<T> GenealogyGraph {
53      get {
54        IResult result;
55        if (!Results.ContainsKey(PopulationGraphParameterName)) {
56          result = new Result(PopulationGraphParameterName, new GenealogyGraph<T>());
57          Results.Add(result);
58        } else {
59          result = Results[PopulationGraphParameterName];
60        }
61        var graph = (GenealogyGraph<T>)result.Value;
62        return graph;
63      }
64    }
65    public EvolutionTrackingOperator() {
66      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName));
67      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName));
68    }
69    protected EvolutionTrackingOperator(EvolutionTrackingOperator<T> original, Cloner cloner)
70      : base(original, cloner) {
71    }
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new EvolutionTrackingOperator<T>(this, cloner);
74    }
75    [StorableConstructor]
76    protected EvolutionTrackingOperator(StorableConstructorFlag _) : base(_) { }
77  }
78}
Note: See TracBrowser for help on using the repository browser.