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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Xml;
|
---|
28 | using HeuristicLab.Constraints;
|
---|
29 | using HeuristicLab.DataAnalysis;
|
---|
30 | using HeuristicLab.Operators;
|
---|
31 | using HeuristicLab.Random;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.GP.StructureIdentification {
|
---|
34 | public sealed class Constant : Terminal {
|
---|
35 | public const string VALUE = "Value";
|
---|
36 | private BakedFunctionTree constantNodeTemplate;
|
---|
37 |
|
---|
38 | public override string Description {
|
---|
39 | get { return "Returns the value of local variable 'Value'."; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override IEnumerable<string> LocalParameterNames {
|
---|
43 | get {
|
---|
44 | return new string[] { VALUE };
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public Constant()
|
---|
49 | : base() {
|
---|
50 | DoubleData valueData = new DoubleData();
|
---|
51 | constantNodeTemplate = new BakedFunctionTree(this);
|
---|
52 | constantNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(VALUE, valueData));
|
---|
53 |
|
---|
54 | SetupInitialization();
|
---|
55 | SetupManipulation();
|
---|
56 | }
|
---|
57 |
|
---|
58 | public override IFunctionTree GetTreeNode() {
|
---|
59 | return (IFunctionTree)constantNodeTemplate.Clone();
|
---|
60 | }
|
---|
61 |
|
---|
62 | private void SetupInitialization() {
|
---|
63 | // initialization operator
|
---|
64 | CombinedOperator combinedOp = new CombinedOperator();
|
---|
65 | SequentialProcessor initSeq = new SequentialProcessor();
|
---|
66 | UniformRandomizer randomizer = new UniformRandomizer();
|
---|
67 | randomizer.Min = -20.0;
|
---|
68 | randomizer.Max = 20.0;
|
---|
69 |
|
---|
70 | combinedOp.OperatorGraph.AddOperator(initSeq);
|
---|
71 | combinedOp.OperatorGraph.AddOperator(randomizer);
|
---|
72 | combinedOp.OperatorGraph.InitialOperator = initSeq;
|
---|
73 | initSeq.AddSubOperator(randomizer);
|
---|
74 | Initializer = combinedOp;
|
---|
75 | }
|
---|
76 |
|
---|
77 | private void SetupManipulation() {
|
---|
78 | // manipulation operator
|
---|
79 | CombinedOperator combinedOp = new CombinedOperator();
|
---|
80 | SequentialProcessor manipulationSeq = new SequentialProcessor();
|
---|
81 | NormalRandomAdder valueAdder = new NormalRandomAdder();
|
---|
82 | valueAdder.Mu = 0.0;
|
---|
83 | valueAdder.Sigma = 1.0;
|
---|
84 |
|
---|
85 | combinedOp.OperatorGraph.AddOperator(manipulationSeq);
|
---|
86 | combinedOp.OperatorGraph.AddOperator(valueAdder);
|
---|
87 | combinedOp.OperatorGraph.InitialOperator = manipulationSeq;
|
---|
88 | manipulationSeq.AddSubOperator(valueAdder);
|
---|
89 | Manipulator = combinedOp;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|