#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("CheckGASubsumptionOperator", "Description missing")] [StorableClass] public class CheckGASubsumptionOperator : SingleSuccessorOperator { #region Parameter Properties public ILookupParameter ChildClassifiersParameter { get { return (ILookupParameter)Parameters["ChildClassifiers"]; } } public ILookupParameter> ParentsClassifiersParameter { get { return (ILookupParameter>)Parameters["Classifiers"]; } } public ILookupParameter> NumerositiesParameter { get { return (ILookupParameter>)Parameters["Numerosities"]; } } public ILookupParameter> ExperiencesParameter { get { return (ILookupParameter>)Parameters["Experiences"]; } } public ILookupParameter> ErrorsParameter { get { return (ILookupParameter>)Parameters["Errors"]; } } public ILookupParameter> TempIDParameter { get { return (ILookupParameter>)Parameters["TempID"]; } } public ILookupParameter ErrorZeroParameter { get { return (ILookupParameter)Parameters["ErrorZero"]; } } public ILookupParameter ThetaSubsumptionParameter { get { return (ILookupParameter)Parameters["ThetaSubsumption"]; } } public IValueLookupParameter SubsumedByParameter { get { return (IValueLookupParameter)Parameters["SubsumedBy"]; } } public IValueLookupParameter SubsumedParameter { get { return (IValueLookupParameter)Parameters["Subsumed"]; } } #endregion [StorableConstructor] protected CheckGASubsumptionOperator(bool deserializing) : base(deserializing) { } protected CheckGASubsumptionOperator(CheckGASubsumptionOperator original, Cloner cloner) : base(original, cloner) { } public CheckGASubsumptionOperator() : base() { Parameters.Add(new LookupParameter("ChildClassifiers")); Parameters.Add(new ScopeTreeLookupParameter("Classifiers")); Parameters.Add(new ScopeTreeLookupParameter("Numerosities")); Parameters.Add(new ScopeTreeLookupParameter("Experiences")); Parameters.Add(new ScopeTreeLookupParameter("Errors")); Parameters.Add(new ScopeTreeLookupParameter("TempID")); Parameters.Add(new LookupParameter("ErrorZero")); Parameters.Add(new LookupParameter("ThetaSubsumption")); Parameters.Add(new ValueLookupParameter("SubsumedBy")); Parameters.Add(new ValueLookupParameter("Subsumed")); } public override IDeepCloneable Clone(Cloner cloner) { return new CheckGASubsumptionOperator(this, cloner); } public override IOperation Apply() { var child = ChildClassifiersParameter.ActualValue; var parents = ParentsClassifiersParameter.ActualValue; var numerosities = NumerositiesParameter.ActualValue; var experiences = ExperiencesParameter.ActualValue; var tempIDs = TempIDParameter.ActualValue; var errors = ErrorsParameter.ActualValue; if (errors.Length != parents.Length || errors.Length != numerosities.Length || errors.Length != experiences.Length || errors.Length != tempIDs.Length) { throw new ArgumentException("The number of classifiers, error, numerosity, tempIDs and experience values is not equal."); } SubsumedByParameter.ActualValue = new IntValue(-1); SubsumedParameter.ActualValue = new BoolValue(false); for (int i = 0; i < parents.Length; i++) { IClassifier curParent = parents[i]; if (curParent.MatchAction(child.Action)) { if (CouldSubsume(experiences[i], errors[i])) { if (curParent.IsMoreGeneral(child)) { SubsumedByParameter.ActualValue.Value = i; SubsumedParameter.ActualValue.Value = true; break; } } } } return base.Apply(); } private bool CouldSubsume(IntValue exp, DoubleValue error) { return exp.Value > ThetaSubsumptionParameter.ActualValue.Value && error.Value < ErrorZeroParameter.ActualValue.Value; } } }