Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/09 19:24:23 (15 years ago)
Author:
gkronber
Message:

Created a branch for #713

Location:
branches/GP-Refactoring-713
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Constant.cs

    r2174 r2202  
    3232
    3333namespace HeuristicLab.GP.StructureIdentification {
    34   public sealed class Constant : FunctionBase {
     34  public sealed class Constant : Terminal {
    3535    public const string VALUE = "Value";
     36    private BakedFunctionTree constantNodeTemplate;
    3637
    3738    public override string Description {
     
    3940    }
    4041
     42    public override IEnumerable<string> LocalParameterNames {
     43      get {
     44        return new string[] { VALUE };
     45      }
     46    }
     47
    4148    public Constant()
    4249      : base() {
    43       AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(DoubleData), VariableKind.None));
    44       GetVariableInfo(VALUE).Local = true;
    45 
    4650      DoubleData valueData = new DoubleData();
    47       // initialize a default range for the contant value
    48       HeuristicLab.Core.Variable value = new HeuristicLab.Core.Variable(VALUE, valueData);
    49       AddVariable(value);
     51      constantNodeTemplate = new BakedFunctionTree(this);
     52      constantNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(VALUE, valueData));
    5053
    5154      SetupInitialization();
    5255      SetupManipulation();
     56    }
    5357
    54       // constant can't have suboperators
    55       AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
     58    public override IFunctionTree GetTreeNode() {
     59      return (IFunctionTree)constantNodeTemplate.Clone();
    5660    }
    5761
    5862    private void SetupInitialization() {
    5963      // initialization operator
    60       AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
    61       GetVariableInfo(INITIALIZATION).Local = false;
    6264      CombinedOperator combinedOp = new CombinedOperator();
    6365      SequentialProcessor initSeq = new SequentialProcessor();
     
    7072      combinedOp.OperatorGraph.InitialOperator = initSeq;
    7173      initSeq.AddSubOperator(randomizer);
    72       AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));
     74      Initializer = combinedOp;
    7375    }
    7476
    7577    private void SetupManipulation() {
    7678      // manipulation operator
    77       AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
    78       GetVariableInfo(MANIPULATION).Local = false;
    7979      CombinedOperator combinedOp = new CombinedOperator();
    8080      SequentialProcessor manipulationSeq = new SequentialProcessor();
     
    8787      combinedOp.OperatorGraph.InitialOperator = manipulationSeq;
    8888      manipulationSeq.AddSubOperator(valueAdder);
    89       AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
     89      Manipulator = combinedOp;
    9090    }
    9191  }
Note: See TracChangeset for help on using the changeset viewer.