#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.Drawing;
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;
namespace HeuristicLab.Algorithms.ALPS {
[Item("LayerReseeder", "An operator that encapsulates the reseeding of the lowest layer in ALPS.")]
[StorableClass]
public sealed class LayerReseeder : SingleSuccessorOperator, IOperatorGraphOperator {
public static new Image StaticItemImage {
get { return HeuristicLab.Common.Resources.VSImageLibrary.Module; }
}
public override Image ItemImage {
get {
if (Breakpoint) return HeuristicLab.Common.Resources.VSImageLibrary.BreakpointActive;
else return base.ItemImage;
}
}
private ILookupParameter GenerationsParameter {
get { return (ILookupParameter)Parameters["Generations"]; }
}
private ILookupParameter AgeGapParameter {
get { return (ILookupParameter)Parameters["AgeGap"]; }
}
[Storable]
private OperatorGraph operatorGraph;
public OperatorGraph OperatorGraph {
get { return operatorGraph; }
}
[StorableConstructor]
private LayerReseeder(bool deserializing)
: base(deserializing) { }
private LayerReseeder(LayerReseeder original, Cloner cloner)
: base(original, cloner) {
operatorGraph = cloner.Clone(original.operatorGraph);
}
public override IDeepCloneable Clone(Cloner cloner) {
return new LayerReseeder(this, cloner);
}
public LayerReseeder()
: base() {
Parameters.Add(new LookupParameter("Generations"));
Parameters.Add(new LookupParameter("AgeGap"));
operatorGraph = new OperatorGraph();
var removeIndividuals = new SubScopesRemover();
var createIndividuals = new SolutionsCreator();
var initializeAgeProsessor = new UniformSubScopesProcessor();
var initializeAge = new VariableCreator() { Name = "Initialize Age" };
var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
OperatorGraph.InitialOperator = removeIndividuals;
removeIndividuals.Successor = createIndividuals;
createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize";
createIndividuals.Successor = initializeAgeProsessor;
initializeAgeProsessor.Operator = initializeAge;
initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
initializeAge.CollectedValues.Add(new ValueParameter("Age", new DoubleValue(0)));
initializeAge.Successor = null;
incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
incrEvaluatedSolutionsAfterReseeding.Successor = null;
}
public override IOperation Apply() {
int generations = GenerationsParameter.ActualValue.Value;
int ageGap = AgeGapParameter.ActualValue.Value;
var next = new OperationCollection(base.Apply());
if (generations % ageGap == 0) {
var layerZeroScope = ExecutionContext.Scope.SubScopes[0];
if (operatorGraph.InitialOperator != null)
next.Insert(0, ExecutionContext.CreateChildOperation(operatorGraph.InitialOperator, layerZeroScope));
}
return next;
}
}
}