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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
26 | using HeuristicLab.Optimization.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace 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 | }
|
---|