#region License Information /* HeuristicLab * Copyright (C) 2002-2015 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.Algorithms.ALPS.SteadyState { [Item("ScopeIndexAssigner", "Description missing")] [StorableClass] public class ScopeIndexAssigner : SingleSuccessorOperator { #region Parameter Properties public ILookupParameter ValueParameter { get { return (ILookupParameter)Parameters["Value"]; } } #endregion [StorableConstructor] protected ScopeIndexAssigner(bool deserializing) : base(deserializing) { } public ScopeIndexAssigner() : base() { Parameters.Add(new LookupParameter("Value")); } protected ScopeIndexAssigner(ScopeIndexAssigner original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new ScopeIndexAssigner(this, cloner); } public override IOperation Apply() { var scope = ExecutionContext.Scope; int index = scope.Parent.SubScopes.IndexOf(scope); if (index == -1) throw new InvalidOperationException("Current Scope is not included in parents sub-scopes."); ValueParameter.ActualValue = new IntValue(index); return base.Apply(); } } }