#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("DoDeletionBeforeCoveringOperator", "Description missing")] [StorableClass] public class DoDeletionBeforeCoveringOperator : SingleSuccessorOperator { #region Parameter Properties public ILookupParameter> ClassifiersParameter { get { return (ILookupParameter>)Parameters["Classifiers"]; } } public ILookupParameter> MatchConditionParameter { get { return (ILookupParameter>)Parameters["MatchCondition"]; } } public ILookupParameter MinimalNumberOfUniqueActionsParameter { get { return (ILookupParameter)Parameters["MinimalNumberOfUniqueActions"]; } } public ILookupParameter CurrentPopulationSizeParameter { get { return (ILookupParameter)Parameters["CurrentPopulationSize"]; } } public ILookupParameter PopulationSizeParameter { get { return (ILookupParameter)Parameters["PopulationSize"]; } } public IValueLookupParameter DoDeletionParameter { get { return (IValueLookupParameter)Parameters["DoDeletion"]; } } public IValueLookupParameter NumberToDeleteParameter { get { return (IValueLookupParameter)Parameters["NumberToDelete"]; } } public ILookupParameter ClassifierComparerParameter { get { return (ILookupParameter)Parameters["ClassifierComparer"]; } } #endregion [StorableConstructor] protected DoDeletionBeforeCoveringOperator(bool deserializing) : base(deserializing) { } protected DoDeletionBeforeCoveringOperator(DoDeletionBeforeCoveringOperator original, Cloner cloner) : base(original, cloner) { } public DoDeletionBeforeCoveringOperator() : base() { Parameters.Add(new ScopeTreeLookupParameter("Classifiers")); Parameters.Add(new ScopeTreeLookupParameter("MatchCondition")); Parameters.Add(new LookupParameter("MinimalNumberOfUniqueActions")); Parameters.Add(new LookupParameter("CurrentPopulationSize")); Parameters.Add(new LookupParameter("PopulationSize")); Parameters.Add(new ValueLookupParameter("DoDeletion")); Parameters.Add(new ValueLookupParameter("NumberToDelete")); Parameters.Add(new LookupParameter("ClassifierComparer")); } public override IDeepCloneable Clone(Cloner cloner) { return new DoDeletionBeforeCoveringOperator(this, cloner); } public override IOperation Apply() { IItemSet uniqueActions = new ItemSet(ClassifierComparerParameter.ActualValue); var classifiers = ClassifiersParameter.ActualValue; var matchcondition = MatchConditionParameter.ActualValue; if (classifiers.Length != matchcondition.Length) { throw new ArgumentException("Number of classifiers is not equal to the number of 'MatchCondition' variables."); } for (int i = 0; i < classifiers.Length; i++) { if (matchcondition[i].Value) { uniqueActions.Add(classifiers[i].Action); } } int populationAfterCovering = MinimalNumberOfUniqueActionsParameter.ActualValue.Value - uniqueActions.Count + CurrentPopulationSizeParameter.ActualValue.Value; BoolValue doDeletion = new BoolValue(populationAfterCovering > PopulationSizeParameter.ActualValue.Value); if (doDeletion.Value) { NumberToDeleteParameter.ActualValue = new IntValue(populationAfterCovering - PopulationSizeParameter.ActualValue.Value); } else { NumberToDeleteParameter.ActualValue = new IntValue(0); } DoDeletionParameter.ActualValue = doDeletion; return base.Apply(); } } }