#region License Information /* HeuristicLab * Copyright (C) 2002-2012 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.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Encodings.ConditionActionEncoding { [Item("XCSAfterCrossoverOperator", "Description missing")] [StorableClass] public class XCSAfterCrossoverOperator : XCSAfterCopyingParentOperator { #region Parameter Properties public IValueLookupParameter TimestampParameter { get { return (IValueLookupParameter)Parameters["Timestamp"]; } } public IValueLookupParameter PredictionParameter { get { return (IValueLookupParameter)Parameters["Prediction"]; } } public IValueLookupParameter AverageActionSetSizeParameter { get { return (IValueLookupParameter)Parameters["AverageActionSetSize"]; } } public IValueLookupParameter ErrorParameter { get { return (IValueLookupParameter)Parameters["Error"]; } } public IValueLookupParameter FitnessParameter { get { return (IValueLookupParameter)Parameters["Fitness"]; } } public ILookupParameter CurrentIterationParameter { get { return (ILookupParameter)Parameters["CurrentIteration"]; } } public ILookupParameter> ParentAverageActionSetSizeParameter { get { return (ILookupParameter>)Parameters["ParentAverageActionSetSize"]; } } public ILookupParameter> ParentPredictionParameter { get { return (ILookupParameter>)Parameters["ParentPrediction"]; } } public ILookupParameter> ParentErrorParameter { get { return (ILookupParameter>)Parameters["ParentError"]; } } public ILookupParameter> ParentFitnessParameter { get { return (ILookupParameter>)Parameters["ParentFitness"]; } } #endregion [StorableConstructor] protected XCSAfterCrossoverOperator(bool deserializing) : base(deserializing) { } protected XCSAfterCrossoverOperator(XCSAfterCrossoverOperator original, Cloner cloner) : base(original, cloner) { } public XCSAfterCrossoverOperator() : base() { Parameters.Add(new ValueLookupParameter("Timestamp")); Parameters.Add(new ValueLookupParameter("AverageActionSetSize")); Parameters.Add(new ValueLookupParameter("Prediction")); Parameters.Add(new ValueLookupParameter("Error")); Parameters.Add(new ValueLookupParameter("Fitness")); Parameters.Add(new LookupParameter("CurrentIteration")); Parameters.Add(new ScopeTreeLookupParameter("ParentAverageActionSetSize")); Parameters.Add(new ScopeTreeLookupParameter("ParentPrediction")); Parameters.Add(new ScopeTreeLookupParameter("ParentError")); Parameters.Add(new ScopeTreeLookupParameter("ParentFitness")); } public override IDeepCloneable Clone(Cloner cloner) { return new XCSAfterCrossoverOperator(this, cloner); } public override IOperation Apply() { TimestampParameter.ActualValue = new IntValue(CurrentIterationParameter.ActualValue.Value); var parentAverageActionSetSize = ParentAverageActionSetSizeParameter.ActualValue; var parentPrecision = ParentPredictionParameter.ActualValue; var parentPrecisionError = ParentErrorParameter.ActualValue; var parentFitness = ParentFitnessParameter.ActualValue; AverageActionSetSizeParameter.ActualValue = new DoubleValue(parentAverageActionSetSize.Select(x => x.Value).Average()); PredictionParameter.ActualValue = new DoubleValue(parentPrecision.Select(x => x.Value).Average()); ErrorParameter.ActualValue = new DoubleValue(0.25 * parentPrecisionError.Select(x => x.Value).Average()); FitnessParameter.ActualValue = new DoubleValue(0.1 * parentFitness.Select(x => x.Value).Average()); return base.Apply(); } } }