Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/08 08:55:19 (16 years ago)
Author:
gkronber
Message:

merged changes (r201 r203 r206 r208 r220 r223 r224 r225 r226 r227) from branch ExperimentalFunctionsBaking into the trunk. (ticket #139)

File:
1 edited

Legend:

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

    r192 r229  
    3030
    3131namespace HeuristicLab.Functions {
    32   public class Constant : FunctionBase {
     32  public sealed class Constant : FunctionBase {
    3333    public const string VALUE = "Value";
    3434
     
    5151      AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
    5252    }
    53 
    54     public override IFunctionTree GetTreeNode() {
    55       return new ConstantFunctionTree(this);
    56     }
    57 
    58     // can't apply a constant
    59     public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
    60       throw new NotSupportedException();
    61     }
    62 
    6353    public override void Accept(IFunctionVisitor visitor) {
    6454      visitor.Visit(this);
    6555    }
    6656  }
    67 
    68   class ConstantFunctionTree : FunctionTree {
    69     private ConstrainedDoubleData value;
    70     public ConstantFunctionTree() : base() { }
    71     public ConstantFunctionTree(Constant constant) : base(constant) {
    72       UpdateCachedValues();
    73     }
    74 
    75     private void UpdateCachedValues() {
    76       value = (ConstrainedDoubleData)GetLocalVariable(Constant.VALUE).Value;
    77     }
    78 
    79     public override double Evaluate(Dataset dataset, int sampleIndex) {
    80       return value.Data;
    81     }
    82 
    83     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    84       ConstantFunctionTree clone = new ConstantFunctionTree();
    85       clonedObjects.Add(clone.Guid, clone);
    86       FillClone(clone, clonedObjects);
    87       clone.UpdateCachedValues();
    88       return clone;
    89     }
    90 
    91     public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    92       base.Populate(node, restoredObjects);
    93       UpdateCachedValues();
    94     }
    95   }
    9657}
Note: See TracChangeset for help on using the changeset viewer.