#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; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Encodings.ConditionActionEncoding { [Item("CheckIfGAShouldBeApplied", "Description missing")] [StorableClass] public class XCSCheckIfGAShouldBeApplied : SingleSuccessorOperator { #region Parameter Properties public ILookupParameter ThetaGAParameter { get { return (ILookupParameter)Parameters["ThetaGA"]; } } public ILookupParameter IterationParameter { get { return (ILookupParameter)Parameters["Iteration"]; } } public ILookupParameter> TimeStampsParameter { get { return (ILookupParameter>)Parameters["TimeStamps"]; } } public ILookupParameter> NumerositiesParameter { get { return (ILookupParameter>)Parameters["Numerosities"]; } } public IValueLookupParameter RunGAParameter { get { return (IValueLookupParameter)Parameters["RunGA"]; } } #endregion [StorableConstructor] protected XCSCheckIfGAShouldBeApplied(bool deserializing) : base(deserializing) { } protected XCSCheckIfGAShouldBeApplied(XCSCheckIfGAShouldBeApplied original, Cloner cloner) : base(original, cloner) { } public XCSCheckIfGAShouldBeApplied() : base() { Parameters.Add(new LookupParameter("ThetaGA")); Parameters.Add(new LookupParameter("Iteration")); Parameters.Add(new ScopeTreeLookupParameter("TimeStamps")); Parameters.Add(new ScopeTreeLookupParameter("Numerosities")); Parameters.Add(new ValueLookupParameter("RunGA")); } public override IDeepCloneable Clone(Cloner cloner) { return new XCSCheckIfGAShouldBeApplied(this, cloner); } public override IOperation Apply() { int numerositySum = 0; int timestamNumerositySum = 0; var timestamps = TimeStampsParameter.ActualValue; var numerosities = NumerositiesParameter.ActualValue; int actualtime = IterationParameter.ActualValue.Value; int thetaGA = ThetaGAParameter.ActualValue.Value; if (timestamps.Length != numerosities.Length) { throw new ArgumentException("The number of timestamps and numerosities is not the same."); } for (int i = 0; i < numerosities.Length; i++) { numerositySum += numerosities[i].Value; timestamNumerositySum += timestamps[i].Value * numerosities[i].Value; } RunGAParameter.ActualValue = new BoolValue(actualtime - (timestamNumerositySum / numerositySum) > thetaGA); return base.Apply(); } } }