Changeset 220 for branches/ExperimentalFunctionsBaking/Constant.cs
- Timestamp:
- 05/07/08 00:02:43 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ExperimentalFunctionsBaking/Constant.cs
r201 r220 30 30 31 31 namespace HeuristicLab.Functions { 32 public class Constant : FunctionBase {32 public sealed class Constant : FunctionBase { 33 33 public const string VALUE = "Value"; 34 34 … … 51 51 AddConstraint(new NumberOfSubOperatorsConstraint(0, 0)); 52 52 } 53 54 //public override IFunctionTree GetTreeNode() {55 // return new ConstantFunctionTree(this);56 //}57 58 // can't apply a constant59 public override double Apply(Dataset dataset, int sampleIndex, double[] args) {60 throw new NotSupportedException();61 }62 63 53 public override void Accept(IFunctionVisitor visitor) { 64 54 visitor.Visit(this); 65 55 } 66 56 } 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 }96 57 }
Note: See TracChangeset
for help on using the changeset viewer.