1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.GP.Interfaces;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.GP.StructureIdentification {
|
---|
28 | public class VariableFunctionTree : FunctionTreeBase {
|
---|
29 | private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly();
|
---|
30 | public double Weight { get; set; }
|
---|
31 | public string VariableName { get; set; }
|
---|
32 | public int SampleOffset { get; set; }
|
---|
33 |
|
---|
34 | public VariableFunctionTree(Variable variable) {
|
---|
35 | Function = variable;
|
---|
36 | }
|
---|
37 |
|
---|
38 | protected VariableFunctionTree(VariableFunctionTree original) {
|
---|
39 | Function = original.Function;
|
---|
40 | Weight = original.Weight;
|
---|
41 | VariableName = original.VariableName;
|
---|
42 | SampleOffset = original.SampleOffset;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public override IList<IFunctionTree> SubTrees {
|
---|
46 | get {
|
---|
47 | return subTrees;
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override bool HasLocalParameters {
|
---|
52 | get {
|
---|
53 | return true;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | public override IOperation CreateShakingOperation(IScope scope) {
|
---|
58 | Scope myVariableScope = new Scope();
|
---|
59 | scope.AddSubScope(myVariableScope);
|
---|
60 | myVariableScope.AddVariable(CreateWeightVariable());
|
---|
61 | myVariableScope.AddVariable(CreateVariableNameVariable());
|
---|
62 | myVariableScope.AddVariable(CreateSampleOffsetVariable());
|
---|
63 | return new AtomicOperation(Function.Manipulator, myVariableScope);
|
---|
64 | }
|
---|
65 |
|
---|
66 | public override IOperation CreateInitOperation(IScope scope) {
|
---|
67 | Scope myVariableScope = new Scope();
|
---|
68 | scope.AddSubScope(myVariableScope);
|
---|
69 | myVariableScope.AddVariable(CreateWeightVariable());
|
---|
70 | myVariableScope.AddVariable(CreateVariableNameVariable());
|
---|
71 | myVariableScope.AddVariable(CreateSampleOffsetVariable());
|
---|
72 | return new AtomicOperation(Function.Initializer, myVariableScope);
|
---|
73 | }
|
---|
74 |
|
---|
75 | public override IFunctionTree Clone() {
|
---|
76 | return new VariableFunctionTree(this);
|
---|
77 | }
|
---|
78 |
|
---|
79 | private IVariable CreateSampleOffsetVariable() {
|
---|
80 | IntData data = new IntData(SampleOffset);
|
---|
81 | data.Changed += (sender, args) => SampleOffset = data.Data;
|
---|
82 | var variable = new HeuristicLab.Core.Variable(Variable.OFFSET, data);
|
---|
83 | variable.ValueChanged += (sender, args) => SampleOffset = ((IntData)variable.Value).Data;
|
---|
84 | return variable;
|
---|
85 | }
|
---|
86 |
|
---|
87 | private IVariable CreateVariableNameVariable() {
|
---|
88 | StringData data = new StringData(VariableName);
|
---|
89 | data.Changed += (sender, args) => VariableName = data.Data;
|
---|
90 | var variable = new HeuristicLab.Core.Variable(Variable.VARIABLENAME, data);
|
---|
91 | variable.ValueChanged += (sender, args) => VariableName = ((StringData)variable.Value).Data;
|
---|
92 | return variable;
|
---|
93 | }
|
---|
94 |
|
---|
95 | private IVariable CreateWeightVariable() {
|
---|
96 | DoubleData data = new DoubleData(Weight);
|
---|
97 | data.Changed += (sender, args) => Weight = data.Data;
|
---|
98 | var variable = new HeuristicLab.Core.Variable(Variable.WEIGHT, data);
|
---|
99 | variable.ValueChanged += (sender, args) => Weight = ((DoubleData)variable.Value).Data;
|
---|
100 | return variable;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|