#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 System.Collections.Generic; 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("ExecuteGASubsumptionOperator", "Description missing")] [StorableClass] public class ExecuteGASubsumptionOperator : SingleSuccessorOperator { #region Parameter Properties public ILookupParameter> TempIDParameter { get { return (ILookupParameter>)Parameters["TempID"]; } } public ILookupParameter> NumerositiesParameter { get { return (ILookupParameter>)Parameters["Numerosities"]; } } public ILookupParameter> SubsumedByParameter { get { return (ILookupParameter>)Parameters["SubsumedBy"]; } } #endregion [StorableConstructor] protected ExecuteGASubsumptionOperator(bool deserializing) : base(deserializing) { } protected ExecuteGASubsumptionOperator(ExecuteGASubsumptionOperator original, Cloner cloner) : base(original, cloner) { } public ExecuteGASubsumptionOperator() : base() { Parameters.Add(new ScopeTreeLookupParameter("TempID")); Parameters.Add(new ScopeTreeLookupParameter("Numerosities")); Parameters.Add(new ScopeTreeLookupParameter("SubsumedBy")); } public override IDeepCloneable Clone(Cloner cloner) { return new ExecuteGASubsumptionOperator(this, cloner); } public override IOperation Apply() { var tempId = TempIDParameter.ActualValue; var numerosities = NumerositiesParameter.ActualValue; var subsumedBy = SubsumedByParameter.ActualValue; if (tempId.Length != numerosities.Length || tempId.Length != subsumedBy.Length) { throw new ArgumentException("The number of tempId, numerosity and subsumedBy values is not equal."); } IList ids = new List(); for (int i = 0; i < tempId.Length; i++) { if (subsumedBy[i].Value >= 0) { ids.Add(subsumedBy[i].Value); numerosities[i].Value = 0; } } foreach (var id in ids) { var subsumedId = tempId.FindIndex(x => x.Value == id); numerosities[subsumedId].Value++; } return base.Apply(); } } }