using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Optimization; namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms { [Item("ScopeDuplicator", "Places clones of the first sub-scope as sub-scopes into n newly created scopes.")] [StorableClass] public class ScopeDuplicator : SingleSuccessorOperator { #region Parameter Properties public LookupParameter NrOfDuplicatesParameter { get { return (LookupParameter)Parameters["NrOfDuplicates"]; } } #endregion #region Parameter Values private int NrOfDuplicates { get { return NrOfDuplicatesParameter.ActualValue.Value; } } #endregion #region Construction & Cloning [StorableConstructor] protected ScopeDuplicator(bool deserializing) : base(deserializing) { } protected ScopeDuplicator(ScopeDuplicator original, Cloner cloner) : base(original, cloner) { } public ScopeDuplicator() : base() { Parameters.Add(new LookupParameter("NrOfDuplicates", "Nr of copies to be created from the first sub-scope.")); } public override IDeepCloneable Clone(Cloner cloner) { return new ScopeDuplicator(this, cloner); } #endregion public override IOperation Apply() { IScope parentScope = ExecutionContext.Scope; if (parentScope.SubScopes.Count > 0) { IScope scope = parentScope.SubScopes[0]; parentScope.SubScopes.Remove(scope); for (int i = 0; i