- Timestamp:
- 04/21/08 00:17:54 (17 years ago)
- Location:
- branches/FunctionsAndStructIdRefactoring
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/Division.cs
r2 r142 36 36 get { 37 37 return @"Protected division 38 Divides the result of the first sub- operator by the results of the following sub-operators.38 Divides the result of the first sub-tree by the results of the following sub-tree. 39 39 In case one of the divisors is 0 returns 0. 40 40 (/ 3) => 1/3 … … 48 48 public Division() 49 49 : base() { 50 51 50 // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze) 52 51 AddConstraint(new NumberOfSubOperatorsConstraint(2, 3)); 53 52 } 54 53 55 public Division(Division source, IDictionary<Guid, object> clonedObjects) 56 : base(source, clonedObjects) { 57 } 58 59 public override double Evaluate(Dataset dataset, int sampleIndex) { 54 public override double Apply(Dataset dataset, int sampleIndex, double[] args) { 60 55 // (/ 3) => 1/3 61 56 // (/ 2 3) => 2/3 62 57 // (/ 3 4 5) => 3/20 63 58 64 if( SubFunctions.Count== 1) {65 double divisor = SubFunctions[0].Evaluate(dataset, sampleIndex);59 if(args.Length == 1) { 60 double divisor = args[0]; 66 61 if(Math.Abs(divisor) < EPSILON) return 0; 67 62 else return 1.0 / divisor; 68 63 } else { 69 double result = SubFunctions[0].Evaluate(dataset, sampleIndex);70 for(int i = 1; i < SubFunctions.Count; i++) {71 double divisor = SubFunctions[i].Evaluate(dataset, sampleIndex);64 double result = args[0]; 65 for(int i = 1; i < args.Length; i++) { 66 double divisor = args[i]; 72 67 if(Math.Abs(divisor) < EPSILON) return 0.0; 73 68 result /= divisor; … … 77 72 } 78 73 79 public override object Clone(IDictionary<Guid, object> clonedObjects) {80 Division clone = new Division(this, clonedObjects);81 clonedObjects.Add(clone.Guid, clone);82 return clone;83 }84 85 74 public override void Accept(IFunctionVisitor visitor) { 86 75 visitor.Visit(this);
Note: See TracChangeset
for help on using the changeset viewer.