Changeset 155 for trunk/sources/HeuristicLab.Functions/Constant.cs
- Timestamp:
- 04/22/08 18:05:14 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/Constant.cs
r2 r155 31 31 namespace HeuristicLab.Functions { 32 32 public class Constant : FunctionBase { 33 34 private IVariable value; 33 public static readonly string VALUE = "Value"; 35 34 36 35 public override string Description { … … 38 37 } 39 38 40 public ConstrainedDoubleData Value {41 get {42 return (ConstrainedDoubleData)value.Value;43 }44 }45 46 39 public Constant() 47 40 : 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; 50 43 51 44 ConstrainedDoubleData valueData = new ConstrainedDoubleData(); 52 45 // initialize a default range for the contant value 53 46 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); 58 49 59 50 // constant can't have suboperators … … 61 52 } 62 53 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; 66 57 } 67 58 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(); 83 62 } 84 63
Note: See TracChangeset
for help on using the changeset viewer.