Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/22/08 18:05:14 (16 years ago)
Author:
gkronber
Message:

merged FunctionsAndStructIdRefactoring-branch (r142, r143, r144, r145, r146, r147, r148, r149, r152, r153) back into the trunk (ticket #112)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Functions/Constant.cs

    r2 r155  
    3131namespace HeuristicLab.Functions {
    3232  public class Constant : FunctionBase {
    33 
    34     private IVariable value;
     33    public static readonly string VALUE = "Value";
    3534
    3635    public override string Description {
     
    3837    }
    3938
    40     public ConstrainedDoubleData Value {
    41       get {
    42         return (ConstrainedDoubleData)value.Value;
    43       }
    44     }
    45 
    4639    public Constant()
    4740      : base() {
    48       AddVariableInfo(new VariableInfo("Value", "The constant value", typeof(ConstrainedDoubleData), VariableKind.None));
    49       GetVariableInfo("Value").Local = true;
     41      AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(ConstrainedDoubleData), VariableKind.None));
     42      GetVariableInfo(VALUE).Local = true;
    5043
    5144      ConstrainedDoubleData valueData = new ConstrainedDoubleData();
    5245      // initialize a default range for the contant value
    5346      valueData.AddConstraint(new DoubleBoundedConstraint(-20.0, 20.0));
    54 
    55       // create the local variable
    56       value = new HeuristicLab.Core.Variable("Value", valueData);
    57       AddLocalVariable(value);
     47      HeuristicLab.Core.Variable value = new HeuristicLab.Core.Variable(VALUE, valueData);
     48      AddVariable(value);
    5849
    5950      // constant can't have suboperators
     
    6152    }
    6253
    63     public Constant(Constant source, IDictionary<Guid, object> clonedObjects)
    64       : base(source, clonedObjects) {
    65       value = GetVariable("Value");
     54    // constant is evaluated directly. Evaluation reads the local variable value from the tree and returns
     55    public override double Evaluate(Dataset dataset, int sampleIndex, IFunctionTree tree) {
     56      return ((ConstrainedDoubleData)tree.GetLocalVariable(VALUE).Value).Data;
    6657    }
    6758
    68     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    69       Constant clone = new Constant(this, clonedObjects);
    70       clonedObjects.Add(clone.Guid, clone);
    71       return clone;
    72     }
    73 
    74 
    75     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    76       base.Populate(node, restoredObjects);
    77 
    78       value = GetVariable("Value");
    79     }
    80 
    81     public override double Evaluate(Dataset dataset, int sampleIndex) {
    82       return ((ConstrainedDoubleData)value.Value).Data;
     59    // can't apply a constant
     60    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
     61      throw new NotSupportedException();
    8362    }
    8463
Note: See TracChangeset for help on using the changeset viewer.