Changeset 525 for trunk/sources/HeuristicLab.Functions
- Timestamp:
- 08/20/08 10:48:40 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Functions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/FunctionBase.cs
r429 r525 27 27 using System.Xml; 28 28 using HeuristicLab.DataAnalysis; 29 using HeuristicLab.Constraints; 29 30 30 31 namespace HeuristicLab.Functions { … … 36 37 public const string INITIALIZATION = "Initialization"; 37 38 public const string MANIPULATION = "Manipulation"; 38 39 private List<IFunction>[] allowedSubFunctions; 40 private int minArity = -1; 41 private int maxArity = -1; 39 42 40 43 public virtual double Apply(Dataset dataset, int sampleIndex, double[] args) { … … 48 51 public virtual IFunctionTree GetTreeNode() { 49 52 return new BakedFunctionTree(this); 53 } 54 55 public int MinArity { 56 get { 57 if(minArity < 0) RefreshArity(); 58 return minArity; 59 } 60 } 61 62 public int MaxArity { 63 get { 64 if(maxArity < 0) RefreshArity(); 65 return maxArity; 66 } 67 } 68 69 private void RefreshArity() { 70 minArity = 2; maxArity = 2; // default arity is 2 71 foreach(IConstraint constraint in Constraints) { 72 NumberOfSubOperatorsConstraint theConstraint = constraint as NumberOfSubOperatorsConstraint; 73 if(theConstraint != null) { 74 minArity = theConstraint.MinOperators.Data; 75 maxArity = theConstraint.MaxOperators.Data; 76 } 77 } 78 } 79 80 public IList<IFunction> AllowedSubFunctions(int index) { 81 if(allowedSubFunctions == null) { 82 allowedSubFunctions = new List<IFunction>[MaxArity]; 83 for(int i = 0; i < MaxArity; i++) { 84 foreach(IConstraint constraint in Constraints) { 85 if(constraint is SubOperatorTypeConstraint) { 86 SubOperatorTypeConstraint subOpConstraint = constraint as SubOperatorTypeConstraint; 87 if(subOpConstraint.SubOperatorIndex.Data == index) { 88 allowedSubFunctions[i] = new List<IFunction>(); 89 foreach(IFunction f in subOpConstraint.AllowedSubOperators) allowedSubFunctions[i].Add(f); 90 break; 91 } 92 } else if(constraint is AllSubOperatorsTypeConstraint) { 93 AllSubOperatorsTypeConstraint subOpConstraint = constraint as AllSubOperatorsTypeConstraint; 94 allowedSubFunctions[i] = new List<IFunction>(); 95 foreach(IFunction f in subOpConstraint.AllowedSubOperators) allowedSubFunctions[i].Add(f); 96 break; 97 } 98 } 99 } 100 } 101 return allowedSubFunctions[index]; 50 102 } 51 103 -
trunk/sources/HeuristicLab.Functions/IFunction.cs
r189 r525 31 31 double Apply(Dataset dataset, int sampleIndex, double[] args); 32 32 void Accept(IFunctionVisitor visitor); 33 IList<IFunction> AllowedSubFunctions(int index); 34 int MinArity { get; } 35 int MaxArity { get; } 33 36 } 34 37 }
Note: See TracChangeset
for help on using the changeset viewer.