#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 System.Collections.Generic; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Optimization.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { [Item("ReplaceBranchMoveTabuMaker", "")] [StorableClass] public class ReplaceBranchMoveTabuMaker : TabuMaker, ISymbolicExpressionTreeMoveOperator { public ILookupParameter SymbolicExpressionTreeParameter { get { return (ILookupParameter)Parameters["SymbolicExpressionTree"]; } } public ILookupParameter ReplaceBranchMoveParameter { get { return (LookupParameter)Parameters["ReplaceBranchMove"]; } } [StorableConstructor] protected ReplaceBranchMoveTabuMaker(bool deserializing) : base(deserializing) { } protected ReplaceBranchMoveTabuMaker(ReplaceBranchMoveTabuMaker original, Cloner cloner) : base(original, cloner) { } public ReplaceBranchMoveTabuMaker() : base() { Parameters.Add(new LookupParameter("ReplaceBranchMove", "The move that was made.")); Parameters.Add(new LookupParameter("SymbolicExpressionTree", "The solution as symbolic expression tree.")); } public override IDeepCloneable Clone(Cloner cloner) { return new ReplaceBranchMoveTabuMaker(this, cloner); } protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) { var move = ReplaceBranchMoveParameter.ActualValue; var tree = SymbolicExpressionTreeParameter.ActualValue; double aspirationThreshold = moveQuality; if (maximization && quality > moveQuality || !maximization && quality < moveQuality) aspirationThreshold = quality; // if we make a bad move, the aspriation threshold is the solution quality List path = new List(); path.Add(move.SubtreeIndex); var parent = move.Parent.Parent; var child = move.Parent; while (parent != null) { path.Add(parent.IndexOfSubtree(child)); child = parent; parent = parent.Parent; } path.Reverse(); return new ChangeNodeTypeMoveAbsoluteAttribute(path.ToArray(), aspirationThreshold, move.OriginalOutput, move.NewOutput); } } }