Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/21/08 00:17:54 (17 years ago)
Author:
gkronber
Message:

Created a branch for refactoring functions and structId. Largest change: splitting IFunction/FunctionBase into two classes, one for the function and one for the treenode+local variables. _work in progress_

Location:
branches/FunctionsAndStructIdRefactoring
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/Division.cs

    r2 r142  
    3636      get {
    3737        return @"Protected division
    38 Divides the result of the first sub-operator by the results of the following sub-operators.
     38Divides the result of the first sub-tree by the results of the following sub-tree.
    3939In case one of the divisors is 0 returns 0.
    4040    (/ 3) => 1/3
     
    4848    public Division()
    4949      : base() {
    50 
    5150      // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)
    5251      AddConstraint(new NumberOfSubOperatorsConstraint(2, 3));
    5352    }
    5453
    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) {
    6055      // (/ 3) => 1/3
    6156      // (/ 2 3) => 2/3
    6257      // (/ 3 4 5) => 3/20
    6358
    64       if(SubFunctions.Count == 1) {
    65         double divisor = SubFunctions[0].Evaluate(dataset, sampleIndex);
     59      if(args.Length == 1) {
     60        double divisor = args[0];
    6661        if(Math.Abs(divisor) < EPSILON) return 0;
    6762        else return 1.0 / divisor;
    6863      } 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];
    7267          if(Math.Abs(divisor) < EPSILON) return 0.0;
    7368          result /= divisor;
     
    7772    }
    7873
    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 
    8574    public override void Accept(IFunctionVisitor visitor) {
    8675      visitor.Visit(this);
Note: See TracChangeset for help on using the changeset viewer.