#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 HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Selection; namespace HeuristicLab.Algorithms.ALPS { [Item("EldersEmigrator", "Moves Individuals which are too old for its current layer up to the next layer.")] [StorableClass] public sealed class EldersEmigrator : AlgorithmOperator { [StorableConstructor] private EldersEmigrator(bool deserializing) : base(deserializing) { } private EldersEmigrator(EldersEmigrator original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new EldersEmigrator(this, cloner); } public EldersEmigrator() : base() { var selectorProsessor = new UniformSubScopesProcessor(); var eldersSelector = new EldersSelector(); var shiftToRightMigrator = new ShiftToRightMigrator(); var mergingProsessor = new UniformSubScopesProcessor(); var mergingReducer = new MergingReducer(); var subScopesCounter = new SubScopesCounter(); var countCalculator = new ExpressionCalculator() { Name = "LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" }; var bestSelector = new BestSelector(); var rightReducer = new RightReducer(); OperatorGraph.InitialOperator = selectorProsessor; selectorProsessor.Operator = eldersSelector; selectorProsessor.Successor = shiftToRightMigrator; eldersSelector.Successor = null; shiftToRightMigrator.Successor = mergingProsessor; mergingProsessor.Operator = mergingReducer; mergingProsessor.Successor = null; mergingReducer.Successor = subScopesCounter; subScopesCounter.ValueParameter.ActualName = "LayerPopulationSize"; subScopesCounter.AccumulateParameter.Value = new BoolValue(false); subScopesCounter.Successor = countCalculator; countCalculator.CollectedValues.Add(new LookupParameter("PopulationSize")); countCalculator.CollectedValues.Add(new LookupParameter("LayerPopulationSize")); countCalculator.ExpressionParameter.Value = new StringValue("LayerPopulationSize PopulationSize LayerPopulationSize PopulationSize < if toint"); countCalculator.ExpressionResultParameter.ActualName = "LayerPopulationSize"; countCalculator.Successor = bestSelector; bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize"; bestSelector.CopySelected = new BoolValue(false); bestSelector.Successor = rightReducer; rightReducer.Successor = null; } } }