#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.Data;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Algorithms.ScatterSearch {
///
/// A base class for operators that perform path relinking.
///
[Item("PathRelinker", "A base class for operators that perform a crossover of bool-valued vectors.")]
[StorableClass]
public abstract class PathRelinker : SingleSuccessorOperator, IPathRelinker {
#region Parameter properties
public ScopeParameter CurrentScopeParameter {
get { return (ScopeParameter)Parameters["CurrentScope"]; }
}
public IValueLookupParameter RelinkingAccuracyParameter {
get { return (IValueLookupParameter)Parameters["RelinkingAccuracy"]; }
}
public ILookupParameter> ParentsParameter {
get { return (IScopeTreeLookupParameter)Parameters["Parents"]; }
}
#endregion
#region Properties
private IScope CurrentScope {
get { return CurrentScopeParameter.ActualValue; }
}
#endregion
[StorableConstructor]
protected PathRelinker(bool deserializing) : base(deserializing) { }
protected PathRelinker(PathRelinker original, Cloner cloner) : base(original, cloner) { }
protected PathRelinker()
: base() {
#region Create parameters
Parameters.Add(new ScopeParameter("CurrentScope"));
Parameters.Add(new ValueLookupParameter("RelinkingAccuracy", new PercentValue(0.25)));
Parameters.Add(new ScopeTreeLookupParameter("Parents"));
#endregion
}
public sealed override IOperation Apply() {
var relinkedSolutions = Relink(ParentsParameter.ActualValue, RelinkingAccuracyParameter.ActualValue);
for (int i = 0; i < relinkedSolutions.Length; i++) {
CurrentScope.Variables.Add(new Variable(string.Format("Child {0}", i), relinkedSolutions[i]));
}
return base.Apply();
}
protected abstract ItemArray Relink(ItemArray parents, PercentValue n);
}
}