#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.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 {
public IValueLookupParameter MaximizationParameter {
get { return (IValueLookupParameter)Parameters["Maximization"]; }
}
public IScopeTreeLookupParameter QualityParameter {
get { return (IScopeTreeLookupParameter)Parameters["Quality"]; }
}
[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() {
Parameters.Add(new ValueLookupParameter("Maximization", "True if the problem is a maximization problem, otherwise false."));
Parameters.Add(new ScopeTreeLookupParameter("Quality", "The value which represents the quality of a solution."));
var selectorProsessor = new UniformSubScopesProcessor();
var eldersSelector = new EldersSelector();
var shiftToRightMigrator = new ShiftToRightMigrator();
var mergingProsessor = new LayerUniformSubScopesProcessor();
var mergingReducer = new MergingReducer();
var subScopesCounter = new SubScopesCounter();
// TODO: if expression calculator supports int, use expression calculator
var countCalculator = new MergingReducerCalculator() { Name = "LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" };
//var countCalculator = new ExpressionCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" };
var bestSelector = new BestSelector();
var rightReducer = new RightReducer();
OperatorGraph.InitialOperator = selectorProsessor;
selectorProsessor.Operator = eldersSelector;
selectorProsessor.Successor = shiftToRightMigrator;
eldersSelector.CopySelected = new BoolValue(false);
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("NumSubScopes"));
//countCalculator.ExpressionParameter.Value = new StringValue("NumSubScopes PopulationSize NumSubScopes PopulationSize < if");
//countCalculator.ExpressionResultParameter.ActualName = "NumSubScopes";
countCalculator.Successor = bestSelector;
bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize";
bestSelector.QualityParameter.ActualName = QualityParameter.Name;
bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
bestSelector.CopySelected = new BoolValue(false);
bestSelector.Successor = rightReducer;
rightReducer.Successor = null;
}
}
}