Free cookie consent management tool by TermsFeed Policy Generator

Changeset 192


Ignore:
Timestamp:
04/25/08 14:46:58 (16 years ago)
Author:
gkronber
Message:

performance tuning of functions framework by removing the need for calling Activator in StorableBase

Location:
trunk/sources/HeuristicLab.Functions
Files:
6 edited

Legend:

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

    r189 r192  
    6767      }
    6868      // all sub-trees evaluated to 1.0 (true) => return 1.0 (true)
    69       return 1.0;     
     69      return 1.0;
     70    }
     71
     72    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     73      AndFunctionTree clone = new AndFunctionTree();
     74      clonedObjects.Add(clone.Guid, clone);
     75      FillClone(clone, clonedObjects);
     76      return clone;
    7077    }
    7178  }
  • trunk/sources/HeuristicLab.Functions/Constant.cs

    r189 r192  
    8282
    8383    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    84       ConstantFunctionTree clone = (ConstantFunctionTree)base.Clone(clonedObjects);
     84      ConstantFunctionTree clone = new ConstantFunctionTree();
     85      clonedObjects.Add(clone.Guid, clone);
     86      FillClone(clone, clonedObjects);
    8587      clone.UpdateCachedValues();
    8688      return clone;
  • trunk/sources/HeuristicLab.Functions/FunctionTree.cs

    r189 r192  
    9393    }
    9494
     95    double[] evaluationResults;
    9596    public virtual double Evaluate(Dataset dataset, int sampleIndex) {
    96       double[] evaluationResults = new double[SubTrees.Count];
     97      // lazy creation of evaluationResults to unburden the GC
     98      if(evaluationResults == null) {
     99        evaluationResults = new double[SubTrees.Count];
     100      }
    97101      for(int i = 0; i < evaluationResults.Length; i++) {
    98102        evaluationResults[i] = SubTrees[i].Evaluate(dataset, sampleIndex);
     
    128132
    129133    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    130       FunctionTree clone = (FunctionTree)base.Clone(clonedObjects);
     134      FunctionTree clone = new FunctionTree();
     135      clonedObjects.Add(clone.Guid, clone);
     136      FillClone(clone, clonedObjects);
     137      return clone;
     138    }
     139
     140    public void FillClone(FunctionTree clone, IDictionary<Guid, object> clonedObjects) {
     141      clone.function = function;
     142      foreach(IVariable variable in localVariables) {
     143        clone.AddVariable((IVariable)variable.Clone(clonedObjects));
     144      }
    131145      foreach(IFunctionTree tree in subTrees) {
    132146        clone.AddSubTree((IFunctionTree)tree.Clone(clonedObjects));
    133147      }
    134       foreach(IVariable variable in localVariables) {
    135         clone.AddVariable((IVariable)variable.Clone(clonedObjects));
    136       }
    137       clone.function = function;
    138       return clone;
    139148    }
    140149
  • trunk/sources/HeuristicLab.Functions/IfThenElse.cs

    r189 r192  
    6565      else return double.NaN;
    6666    }
     67
     68    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     69      IfThenElseFunctionTree clone = new IfThenElseFunctionTree();
     70      clonedObjects.Add(clone.Guid, clone);
     71      FillClone(clone, clonedObjects);
     72      return clone;
     73    }
    6774  }
    6875}
  • trunk/sources/HeuristicLab.Functions/Or.cs

    r189 r192  
    6666      return 0.0;
    6767    }
     68
     69    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     70      OrFunctionTree clone = new OrFunctionTree();
     71      clonedObjects.Add(clone.Guid, clone);
     72      FillClone(clone, clonedObjects);
     73      return clone;
     74    }
    6875  }
    6976}
  • trunk/sources/HeuristicLab.Functions/Variable.cs

    r189 r192  
    102102
    103103    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    104       VariableFunctionTree clone = (VariableFunctionTree)base.Clone(clonedObjects);
     104      VariableFunctionTree clone = new VariableFunctionTree();
     105      clonedObjects.Add(clone.Guid, clone);
     106      FillClone(clone, clonedObjects);
    105107      clone.UpdateCachedValues();
    106108      return clone;
Note: See TracChangeset for help on using the changeset viewer.