Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.GP.StructureIdentification/3.4/Constant.cs @ 3155

Last change on this file since 3155 was 1618, checked in by gkronber, 16 years ago

Implemented #594 (Manipulators and initialization operators for variables and constants should use more intuitive default values)

File size: 3.7 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 : FunctionBase {
35    public const string VALUE = "Value";
36
37    public override string Description {
38      get { return "Returns the value of local variable 'Value'."; }
39    }
40
41    public Constant()
42      : base() {
43      AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(ConstrainedDoubleData), VariableKind.None));
44      GetVariableInfo(VALUE).Local = true;
45
46      ConstrainedDoubleData valueData = new ConstrainedDoubleData();
47      // initialize a default range for the contant value
48      valueData.AddConstraint(new DoubleBoundedConstraint(-20.0, 20.0));
49      HeuristicLab.Core.Variable value = new HeuristicLab.Core.Variable(VALUE, valueData);
50      AddVariable(value);
51
52      SetupInitialization();
53      SetupManipulation();
54
55      // constant can't have suboperators
56      AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
57    }
58
59    private void SetupInitialization() {
60      // initialization operator
61      AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
62      GetVariableInfo(INITIALIZATION).Local = false;
63      CombinedOperator combinedOp = new CombinedOperator();
64      SequentialProcessor initSeq = new SequentialProcessor();
65      UniformRandomizer randomizer = new UniformRandomizer();
66      randomizer.Min = -20.0;
67      randomizer.Max = 20.0;
68
69      combinedOp.OperatorGraph.AddOperator(initSeq);
70      combinedOp.OperatorGraph.AddOperator(randomizer);
71      combinedOp.OperatorGraph.InitialOperator = initSeq;
72      initSeq.AddSubOperator(randomizer);
73      AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));
74    }
75
76    private void SetupManipulation() {
77      // manipulation operator
78      AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
79      GetVariableInfo(MANIPULATION).Local = false;
80      CombinedOperator combinedOp = new CombinedOperator();
81      SequentialProcessor manipulationSeq = new SequentialProcessor();
82      NormalRandomAdder valueAdder = new NormalRandomAdder();
83      valueAdder.Mu = 0.0;
84      valueAdder.Sigma = 1.0;
85
86      combinedOp.OperatorGraph.AddOperator(manipulationSeq);
87      combinedOp.OperatorGraph.AddOperator(valueAdder);
88      combinedOp.OperatorGraph.InitialOperator = manipulationSeq;
89      manipulationSeq.AddSubOperator(valueAdder);
90      AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.