#region License Information /* HeuristicLab * Copyright (C) 2002-2013 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 HEAL.Attic; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [Item("SymbolicDataAnalysisSolutionPruningOptimizer", "An operator which automatically removes nodes that have a negative impact from the tree model, optimizing the remaining constants.")] [StorableType("8F0C09F6-7138-4D95-9EB0-F65D8E8C3811")] public abstract class SymbolicDataAnalysisSolutionPruningOptimizer { public abstract ISymbolicDataAnalysisSolution PruneAndOptimizeSolution(ISymbolicDataAnalysisSolution solution); protected ConstantTreeNode MakeConstantTreeNode(double value) { var constant = new Constant { MinValue = value - 1, MaxValue = value + 1 }; var constantTreeNode = (ConstantTreeNode)constant.CreateTreeNode(); constantTreeNode.Value = value; return constantTreeNode; } protected void ReplaceWithConstantNode(ISymbolicExpressionTreeNode originalNode, ISymbolicExpressionTreeNode constantNode) { var parent = originalNode.Parent; var index = parent.IndexOfSubtree(originalNode); parent.RemoveSubtree(index); parent.InsertSubtree(index, constantNode); } } }