Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/EvolutionTrackingAnalyzer.cs @ 16189

Last change on this file since 16189 was 13482, checked in by bburlacu, 9 years ago

#1772: Merged trunk changes

File size: 5.1 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.EvolutionTracking {
31  [Item("EvolutionTrackingAnalyzer", "Base class for analyzers that use the genealogy graph")]
32  [StorableClass]
33  public abstract class EvolutionTrackingAnalyzer : SingleSuccessorOperator, IAnalyzer {
34    #region parameter names
35    private const string GenerationsParameterName = "Generations";
36    private const string ResultsParameterName = "Results";
37    private const string PopulationSizeParameterName = "PopulationSize";
38    protected const string PopulationGraphResultName = "PopulationGraph";
39    #endregion
40
41    #region parameters
42    public ILookupParameter<IntValue> GenerationsParameter {
43      get { return (ILookupParameter<IntValue>)Parameters[GenerationsParameterName]; }
44    }
45    public ILookupParameter<ResultCollection> ResultsParameter {
46      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
47    }
48    public IValueParameter<IntValue> UpdateIntervalParameter {
49      get { return (IValueParameter<IntValue>)Parameters["UpdateInterval"]; }
50    }
51    public ILookupParameter<IntValue> UpdateCounterParameter {
52      get { return (ILookupParameter<IntValue>)Parameters["UpdateCounter"]; }
53    }
54    public ILookupParameter<IntValue> PopulationSizeParameter {
55      get { return (ILookupParameter<IntValue>)Parameters[PopulationSizeParameterName]; }
56    }
57    #endregion
58
59    #region properties
60    public IntValue Generations { get { return GenerationsParameter.ActualValue; } }
61    public ResultCollection Results { get { return ResultsParameter.ActualValue; } }
62    public IntValue UpdateCounter { get { return UpdateCounterParameter.ActualValue; } }
63    public IntValue UpdateInterval { get { return UpdateIntervalParameter.Value; } }
64    public IntValue Generation { get { return GenerationsParameter.ActualValue; } }
65    public IntValue PopulationSize { get { return PopulationSizeParameter.ActualValue; } }
66    public IGenealogyGraph PopulationGraph {
67      get {
68        if (Results.ContainsKey(PopulationGraphResultName))
69          return (IGenealogyGraph)Results[PopulationGraphResultName].Value;
70        return null;
71      }
72    }
73
74    #endregion
75
76    public bool EnabledByDefault {
77      get { return false; }
78    }
79
80    protected EvolutionTrackingAnalyzer() {
81      Parameters.Add(new LookupParameter<IGenealogyGraph>(PopulationGraphResultName, "The genealogy graph."));
82      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations."));
83      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection."));
84      Parameters.Add(new ValueParameter<IntValue>("UpdateInterval", new IntValue(1)));
85      Parameters.Add(new LookupParameter<IntValue>("UpdateCounter"));
86      Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population size"));
87    }
88
89    protected EvolutionTrackingAnalyzer(EvolutionTrackingAnalyzer original, Cloner cloner)
90      : base(original, cloner) {
91    }
92
93    [StorableConstructor]
94    protected EvolutionTrackingAnalyzer(bool deserializing) : base(deserializing) { }
95  }
96
97  [Item("EvolutionTrackingAnalyzer", "Base class for analyzers that use the genealogy graph")]
98  [StorableClass]
99  public class EvolutionTrackingAnalyzer<T> : EvolutionTrackingAnalyzer where T : class, IItem {
100    public EvolutionTrackingAnalyzer() { }
101
102    protected EvolutionTrackingAnalyzer(EvolutionTrackingAnalyzer original, Cloner cloner) : base(original, cloner) { }
103
104    public override IDeepCloneable Clone(Cloner cloner) {
105      return new EvolutionTrackingAnalyzer<T>(this, cloner);
106    }
107
108    [StorableConstructor]
109    protected EvolutionTrackingAnalyzer(bool deserializing) : base(deserializing) { }
110
111    public new IGenealogyGraph<T> PopulationGraph {
112      get {
113        if (Results.ContainsKey(PopulationGraphResultName))
114          return (IGenealogyGraph<T>)Results[PopulationGraphResultName].Value;
115        return null;
116      }
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.