Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Constant.cs @ 2202

Last change on this file since 2202 was 2202, checked in by gkronber, 15 years ago

Created a branch for #713

File size: 3.1 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Data;
26using HeuristicLab.Core;
27using System.Xml;
28using HeuristicLab.Constraints;
29using HeuristicLab.DataAnalysis;
30using HeuristicLab.Operators;
31using HeuristicLab.Random;
32
33namespace 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}
Note: See TracBrowser for help on using the repository browser.