#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.ProgramSynthesis {
[Item("EvolutionTrackingAnalyzer", "Base class for analyzers that use the genealogy graph")]
[StorableClass]
public abstract class EvolutionTrackingAnalyzer : SingleSuccessorOperator, IAnalyzer {
#region parameter names
private const string GenerationsParameterName = "Generations";
private const string ResultsParameterName = "Results";
private const string PopulationSizeParameterName = "PopulationSize";
protected const string PopulationGraphResultName = "PopulationGraph";
#endregion
#region parameters
public ILookupParameter GenerationsParameter {
get { return (ILookupParameter)Parameters[GenerationsParameterName]; }
}
public ILookupParameter ResultsParameter {
get { return (ILookupParameter)Parameters[ResultsParameterName]; }
}
public IValueParameter UpdateIntervalParameter {
get { return (IValueParameter)Parameters["UpdateInterval"]; }
}
public ILookupParameter UpdateCounterParameter {
get { return (ILookupParameter)Parameters["UpdateCounter"]; }
}
public ILookupParameter PopulationSizeParameter {
get { return (ILookupParameter)Parameters[PopulationSizeParameterName]; }
}
#endregion
#region properties
public IntValue Generations { get { return GenerationsParameter.ActualValue; } }
public ResultCollection Results { get { return ResultsParameter.ActualValue; } }
public IntValue UpdateCounter { get { return UpdateCounterParameter.ActualValue; } }
public IntValue UpdateInterval { get { return UpdateIntervalParameter.Value; } }
public IntValue Generation { get { return GenerationsParameter.ActualValue; } }
public IntValue PopulationSize { get { return PopulationSizeParameter.ActualValue; } }
public IGenealogyGraph PopulationGraph {
get {
if (Results.ContainsKey(PopulationGraphResultName))
return (IGenealogyGraph)Results[PopulationGraphResultName].Value;
return null;
}
}
#endregion
public bool EnabledByDefault {
get { return false; }
}
protected EvolutionTrackingAnalyzer() {
Parameters.Add(new LookupParameter(PopulationGraphResultName, "The genealogy graph."));
Parameters.Add(new LookupParameter(GenerationsParameterName, "The number of generations."));
Parameters.Add(new LookupParameter(ResultsParameterName, "The results collection."));
Parameters.Add(new ValueParameter("UpdateInterval", new IntValue(1)));
Parameters.Add(new LookupParameter("UpdateCounter"));
Parameters.Add(new LookupParameter(PopulationSizeParameterName, "The population size"));
}
protected EvolutionTrackingAnalyzer(EvolutionTrackingAnalyzer original, Cloner cloner)
: base(original, cloner) {
}
[StorableConstructor]
protected EvolutionTrackingAnalyzer(bool deserializing) : base(deserializing) { }
}
[Item("EvolutionTrackingAnalyzer", "Base class for analyzers that use the genealogy graph")]
[StorableClass]
public class EvolutionTrackingAnalyzer : EvolutionTrackingAnalyzer where T : class, IItem {
public EvolutionTrackingAnalyzer() { }
protected EvolutionTrackingAnalyzer(EvolutionTrackingAnalyzer original, Cloner cloner) : base(original, cloner) { }
public override IDeepCloneable Clone(Cloner cloner) {
return new EvolutionTrackingAnalyzer(this, cloner);
}
[StorableConstructor]
protected EvolutionTrackingAnalyzer(bool deserializing) : base(deserializing) { }
public new IGenealogyGraph PopulationGraph {
get {
if (Results.ContainsKey(PopulationGraphResultName))
return (IGenealogyGraph)Results[PopulationGraphResultName].Value;
return null;
}
}
}
}