#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 System; using HeuristicLab.Analysis; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Optimization.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Algorithms.ALPS { [Item("OldestAverageYoungestAgeAnalyzer", "An operator which calculates the current oldest, average and youngest age in the scope tree.")] [StorableClass] public sealed class OldestAverageYoungestAgeAnalyzer : AlgorithmOperator, IAnalyzer { #region Parameter properties public IScopeTreeLookupParameter AgeParameter { get { return (IScopeTreeLookupParameter)Parameters["Age"]; } } public IValueLookupParameter CurrentOldestAgeParameter { get { return (IValueLookupParameter)Parameters["CurrentOldestAge"]; } } public IValueLookupParameter CurrentAverageAgeParameter { get { return (IValueLookupParameter)Parameters["CurrentAverageAge"]; } } public IValueLookupParameter CurrentYoungestAgeParameter { get { return (IValueLookupParameter)Parameters["CurrentYoungestAge"]; } } public IValueLookupParameter AgesParameter { get { return (IValueLookupParameter)Parameters["Ages"]; } } public ValueLookupParameter ResultsParameter { get { return (ValueLookupParameter)Parameters["Results"]; } } #endregion #region Properties public bool EnabledByDefault { get { return false; } } private OldestAverageYoungestAgeCalculator OldestAverageYoungestAgeCalculator { get { return (OldestAverageYoungestAgeCalculator)OperatorGraph.InitialOperator; } } #endregion #region Storing & Cloning [StorableConstructor] private OldestAverageYoungestAgeAnalyzer(bool deserializing) : base(deserializing) { } private OldestAverageYoungestAgeAnalyzer(OldestAverageYoungestAgeAnalyzer original, Cloner cloner) : base(original, cloner) { Initialize(); } public override IDeepCloneable Clone(Cloner cloner) { return new OldestAverageYoungestAgeAnalyzer(this, cloner); } #endregion public OldestAverageYoungestAgeAnalyzer() : base() { #region Create parameters Parameters.Add(new ScopeTreeLookupParameter("Age", "The value which represents the age of a solution.")); Parameters.Add(new ValueLookupParameter("CurrentOldestAge", "The oldest age value found in the current population.")); Parameters.Add(new ValueLookupParameter("CurrentAverageAge", "The average age value of all solutions in the current population.")); Parameters.Add(new ValueLookupParameter("CurrentYoungestAge", "The youngest age value found in the current population.")); Parameters.Add(new ValueLookupParameter("Ages", "The data table to store the current oldest, current average, current youngest age value.")); Parameters.Add(new ValueLookupParameter("Results", "The results collection where the analysis values should be stored.")); CurrentOldestAgeParameter.Hidden = true; CurrentAverageAgeParameter.Hidden = true; CurrentYoungestAgeParameter.Hidden = true; AgesParameter.Hidden = true; #endregion #region Create operators var oldestAverageYoungestAgeCalculator = new OldestAverageYoungestAgeCalculator(); var dataTableValuesCollector = new DataTableValuesCollector(); var resultsCollector = new ResultsCollector(); oldestAverageYoungestAgeCalculator.AverageAgeParameter.ActualName = CurrentAverageAgeParameter.Name; oldestAverageYoungestAgeCalculator.OldestAgeParameter.ActualName = CurrentOldestAgeParameter.Name; oldestAverageYoungestAgeCalculator.AgeParameter.ActualName = AgeParameter.Name; oldestAverageYoungestAgeCalculator.AgeParameter.Depth = AgeParameter.Depth; oldestAverageYoungestAgeCalculator.YoungestAgeParameter.ActualName = CurrentYoungestAgeParameter.Name; dataTableValuesCollector.CollectedValues.Add(new LookupParameter("CurrentOldestAge", null, CurrentOldestAgeParameter.Name)); dataTableValuesCollector.CollectedValues.Add(new LookupParameter("CurrentAverageAge", null, CurrentAverageAgeParameter.Name)); dataTableValuesCollector.CollectedValues.Add(new LookupParameter("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name)); dataTableValuesCollector.DataTableParameter.ActualName = AgesParameter.Name; //resultsCollector.CollectedValues.Add(new LookupParameter("CurrentOldestAge", null, CurrentOldestAgeParameter.Name)); //resultsCollector.CollectedValues.Add(new LookupParameter("CurrentAverageAge", null, CurrentAverageAgeParameter.Name)); //resultsCollector.CollectedValues.Add(new LookupParameter("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(AgesParameter.Name)); resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name; #endregion #region Create operator graph OperatorGraph.InitialOperator = oldestAverageYoungestAgeCalculator; oldestAverageYoungestAgeCalculator.Successor = dataTableValuesCollector; dataTableValuesCollector.Successor = resultsCollector; resultsCollector.Successor = null; #endregion Initialize(); } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { Initialize(); } private void Initialize() { AgeParameter.DepthChanged += new EventHandler(AgeParameter_DepthChanged); } private void AgeParameter_DepthChanged(object sender, EventArgs e) { OldestAverageYoungestAgeCalculator.AgeParameter.Depth = AgeParameter.Depth; } } }