Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

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