#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("ActionSetSubsumptionoperator", "Description missing")] [StorableClass] public class ActionSetSubsumptionOperator : SingleSuccessorOperator, IActionSetSubsumption { #region Parameter Properties public ILookupParameter> ClassifiersParameter { 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> HasBeenSubsumedParameter { get { return (ILookupParameter>)Parameters["HasBeenSubsumed"]; } } public ILookupParameter ErrorZeroParameter { get { return (ILookupParameter)Parameters["ErrorZero"]; } } public ILookupParameter ThetaSubsumptionParameter { get { return (ILookupParameter)Parameters["ThetaSubsumption"]; } } #endregion [StorableConstructor] protected ActionSetSubsumptionOperator(bool deserializing) : base(deserializing) { } protected ActionSetSubsumptionOperator(ActionSetSubsumptionOperator original, Cloner cloner) : base(original, cloner) { } public ActionSetSubsumptionOperator() : base() { Parameters.Add(new ScopeTreeLookupParameter("Classifiers")); Parameters.Add(new ScopeTreeLookupParameter("Numerosities")); Parameters.Add(new ScopeTreeLookupParameter("Experiences")); Parameters.Add(new ScopeTreeLookupParameter("Errors")); Parameters.Add(new ScopeTreeLookupParameter("HasBeenSubsumed")); Parameters.Add(new LookupParameter("ErrorZero")); Parameters.Add(new LookupParameter("ThetaSubsumption")); } public override IDeepCloneable Clone(Cloner cloner) { return new ActionSetSubsumptionOperator(this, cloner); } public override IOperation Apply() { var classifiers = ClassifiersParameter.ActualValue; var numerosities = NumerositiesParameter.ActualValue; var experiences = ExperiencesParameter.ActualValue; var hasBeenSubsumed = HasBeenSubsumedParameter.ActualValue; var errors = ErrorsParameter.ActualValue; if (errors.Length != classifiers.Length || errors.Length != numerosities.Length || errors.Length != experiences.Length || errors.Length != hasBeenSubsumed.Length) { throw new ArgumentException("The number of classifiers, error, numerosity, hasBeenSubsumed and experience values is not equal."); } int subsumptionClassifier = -1; for (int i = 0; i < classifiers.Length; i++) { if (CouldSubsume(experiences[i], errors[i])) { if (subsumptionClassifier == -1 || classifiers[i].IsMoreGeneral(classifiers[subsumptionClassifier])) { subsumptionClassifier = i; } } } if (subsumptionClassifier != -1) { for (int i = 0; i < classifiers.Length; i++) { if (classifiers[subsumptionClassifier].IsMoreGeneral(classifiers[i])) { numerosities[subsumptionClassifier].Value += numerosities[i].Value; hasBeenSubsumed[i].Value = true; } } } return base.Apply(); } private bool CouldSubsume(IntValue exp, DoubleValue error) { return exp.Value > ThetaSubsumptionParameter.ActualValue.Value && error.Value < ErrorZeroParameter.ActualValue.Value; } } }