#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 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("TempSubScopeIDAssigner", "Description missing")] [StorableClass] public class TempSubScopeIDAssigner : SingleSuccessorOperator { #region Parameter Properties public IValueLookupParameter LeftSideParameter { get { return (IValueLookupParameter)Parameters["LeftSide"]; } } private ScopeParameter CurrentScopeParameter { get { return (ScopeParameter)Parameters["CurrentScope"]; } } public IScope CurrentScope { get { return CurrentScopeParameter.ActualValue; } } #endregion [StorableConstructor] protected TempSubScopeIDAssigner(bool deserializing) : base(deserializing) { } protected TempSubScopeIDAssigner(TempSubScopeIDAssigner original, Cloner cloner) : base(original, cloner) { } public TempSubScopeIDAssigner() : base() { Parameters.Add(new ValueLookupParameter("LeftSide")); Parameters.Add(new ScopeParameter("CurrentScope")); } public override IDeepCloneable Clone(Cloner cloner) { return new TempSubScopeIDAssigner(this, cloner); } public override IOperation Apply() { var subscopes = CurrentScope.SubScopes; string name = LeftSideParameter.ActualName; for (int i = 0; i < subscopes.Count; i++) { if (subscopes[i].Variables.ContainsKey(name)) { ((IntValue)subscopes[i].Variables[name].Value).Value = i; } else { subscopes[i].Variables.Add(new Variable(name, new IntValue(i))); } } return base.Apply(); } } }