#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 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.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Algorithms.ScatterSearch {
///
/// An operator that creates a subscope with subscopes for every variable in the current scope.
///
[Item("OffspringProcessor", "An operator that creates a subscope with subscopes for every variable in the current scope.")]
[StorableClass]
public sealed class OffspringProcessor : SingleSuccessorOperator, IScatterSearchTargetProcessor {
#region Parameter properties
public ScopeParameter CurrentScopeParameter {
get { return (ScopeParameter)Parameters["CurrentScope"]; }
}
public IValueLookupParameter TargetParameter {
get { return (IValueLookupParameter)Parameters["Target"]; }
}
#endregion
#region Properties
private IScope CurrentScope {
get { return CurrentScopeParameter.ActualValue; }
}
private IItem Target {
get { return TargetParameter.ActualValue; }
}
#endregion
[StorableConstructor]
private OffspringProcessor(bool deserializing) : base(deserializing) { }
private OffspringProcessor(OffspringProcessor original, Cloner cloner) : base(original, cloner) { }
public OffspringProcessor() : base() { Initialize(); }
public override IDeepCloneable Clone(Cloner cloner) {
return new OffspringProcessor(this, cloner);
}
private void Initialize() {
#region Create parameters
Parameters.Add(new ScopeParameter("CurrentScope"));
Parameters.Add(new ValueLookupParameter("Target"));
#endregion
TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
}
public override IOperation Apply() {
var offspringSolutions = CurrentScope.Variables;
var offspringScope = new Scope("Offspring");
foreach (var solution in offspringSolutions) {
var scope = new Scope();
scope.Variables.Add(new Variable(TargetParameter.ActualName, solution.Value));
offspringScope.SubScopes.Add(scope);
}
CurrentScope.SubScopes.Add(offspringScope);
CurrentScope.Variables.Clear();
return base.Apply();
}
}
}