Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/ReplaceBranchMoveTabuMaker.cs @ 12147

Last change on this file since 12147 was 8214, checked in by gkronber, 12 years ago

#1847: bug fixes and improvements discussed with andreas

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Optimization.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
31  [Item("ReplaceBranchMoveTabuMaker", "")]
32  [StorableClass]
33  public class ReplaceBranchMoveTabuMaker : TabuMaker, ISymbolicExpressionTreeMoveOperator {
34    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
35      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
36    }
37    public ILookupParameter<ReplaceBranchMove> ReplaceBranchMoveParameter {
38      get { return (LookupParameter<ReplaceBranchMove>)Parameters["ReplaceBranchMove"]; }
39    }
40
41    [StorableConstructor]
42    protected ReplaceBranchMoveTabuMaker(bool deserializing) : base(deserializing) { }
43    protected ReplaceBranchMoveTabuMaker(ReplaceBranchMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
44    public ReplaceBranchMoveTabuMaker()
45      : base() {
46      Parameters.Add(new LookupParameter<ReplaceBranchMove>("ReplaceBranchMove", "The move that was made."));
47      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The solution as symbolic expression tree."));
48    }
49
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new ReplaceBranchMoveTabuMaker(this, cloner);
52    }
53
54    protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) {
55      var move = ReplaceBranchMoveParameter.ActualValue;
56      var tree = SymbolicExpressionTreeParameter.ActualValue;
57      double aspirationThreshold = moveQuality;
58      if (maximization && quality > moveQuality || !maximization && quality < moveQuality) aspirationThreshold = quality; // if we make a bad move, the aspriation threshold is the solution quality
59
60      List<int> path = new List<int>();
61      path.Add(move.SubtreeIndex);
62      var parent = move.Parent.Parent;
63      var child = move.Parent;
64      while (parent != null) {
65        path.Add(parent.IndexOfSubtree(child));
66        child = parent;
67        parent = parent.Parent;
68      }
69      path.Reverse();
70      return new ChangeNodeTypeMoveAbsoluteAttribute(path.ToArray(), aspirationThreshold, move.OriginalOutput, move.NewOutput);
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.