#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;
namespace HeuristicLab.Optimization.Operators {
///
/// A base class for operators that perform path relinking between single objective solutions.
///
[Item("SingleObjectivePathRelinker", "A base class for operators that perform path relinking between single objective solutions.")]
[StorableClass("75BA9220-1A58-4BEF-B061-D3368F284940")]
public abstract class SingleObjectivePathRelinker : SingleSuccessorOperator, ISingleObjectivePathRelinker {
#region Parameter properties
public ScopeParameter CurrentScopeParameter {
get { return (ScopeParameter)Parameters["CurrentScope"]; }
}
public ILookupParameter> ParentsParameter {
get { return (IScopeTreeLookupParameter)Parameters["Parents"]; }
}
public IValueParameter RelinkingAccuracyParameter {
get { return (IValueParameter)Parameters["RelinkingAccuracy"]; }
}
#endregion
#region Properties
private IScope CurrentScope {
get { return CurrentScopeParameter.ActualValue; }
}
private ItemArray Parents {
get { return ParentsParameter.ActualValue; }
}
private PercentValue RelinkingAccuracy {
get { return RelinkingAccuracyParameter.Value; }
}
#endregion
[StorableConstructor]
protected SingleObjectivePathRelinker(bool deserializing) : base(deserializing) { }
protected SingleObjectivePathRelinker(SingleObjectivePathRelinker original, Cloner cloner) : base(original, cloner) { }
protected SingleObjectivePathRelinker()
: base() {
#region Create parameters
Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the parents."));
Parameters.Add(new ScopeTreeLookupParameter("Parents", "The parents used for path relinking."));
Parameters.Add(new ValueParameter("RelinkingAccuracy", "The percentage of relinked offspring that should be yielded.", new PercentValue(0.25)));
#endregion
}
public sealed override IOperation Apply() {
ItemArray relinkedSolutions = Relink(Parents, RelinkingAccuracy);
var offspringScope = new Scope("Offspring");
foreach (var solution in relinkedSolutions) {
var scope = new Scope();
scope.Variables.Add(new Variable(ParentsParameter.ActualName, solution));
offspringScope.SubScopes.Add(scope);
}
CurrentScope.SubScopes.Add(offspringScope);
return base.Apply();
}
protected abstract ItemArray Relink(ItemArray parents, PercentValue n);
}
}