#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 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.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Parameters;
namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
[StorableClass]
[Item("FullTreeShaker", "Manipulates all nodes that have local parameters.")]
public sealed class FullTreeShaker : SymbolicExpressionTreeManipulator {
private const string ShakingFactorParameterName = "ShakingFactor";
#region parameter properties
public IValueParameter ShakingFactorParameter {
get { return (IValueParameter)Parameters[ShakingFactorParameterName]; }
}
#endregion
#region properties
public double ShakingFactor {
get { return ShakingFactorParameter.Value.Value; }
set { ShakingFactorParameter.Value.Value = value; }
}
#endregion
[StorableConstructor]
private FullTreeShaker(bool deserializing) : base(deserializing) { }
private FullTreeShaker(FullTreeShaker original, Cloner cloner) : base(original, cloner) { }
public FullTreeShaker()
: base() {
Parameters.Add(new FixedValueParameter(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0)));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new FullTreeShaker(this, cloner);
}
protected override void Manipulate(IRandom random, ISymbolicExpressionTree tree) {
tree.Root.ForEachNodePostfix(node => {
if (node.HasLocalParameters) {
node.ShakeLocalParameters(random, ShakingFactor);
}
});
}
}
}