- Timestamp:
- 08/20/08 21:44:59 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/FunctionBase.cs
r528 r529 28 28 using HeuristicLab.DataAnalysis; 29 29 using HeuristicLab.Constraints; 30 using System.Diagnostics; 30 31 31 32 namespace HeuristicLab.Functions { … … 80 81 public IList<IFunction> AllowedSubFunctions(int index) { 81 82 if(allowedSubFunctions == null) { 83 // first time: analyze the constraint and create a cached copy of the allowed sub-functions 82 84 allowedSubFunctions = new List<IFunction>[MaxArity]; 83 85 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 == i) { 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 } 86 allowedSubFunctions[i] = GetAllowedSubFunctions(i); 99 87 } 100 88 } 101 89 return allowedSubFunctions[index]; 90 } 91 92 private List<IFunction> GetAllowedSubFunctions(int index) { 93 List<IFunction> allowedSubFunctions = new List<IFunction>(); 94 foreach(IConstraint constraint in Constraints) { 95 if(constraint is SubOperatorTypeConstraint) { 96 SubOperatorTypeConstraint subOpConstraint = constraint as SubOperatorTypeConstraint; 97 if(subOpConstraint.SubOperatorIndex.Data == index) { 98 foreach(IFunction f in subOpConstraint.AllowedSubOperators) allowedSubFunctions.Add(f); 99 subOpConstraint.Changed += new EventHandler(subOpConstraint_Changed); // register an event-handler to invalidate the cache on constraing changes 100 return allowedSubFunctions; 101 } 102 } else if(constraint is AllSubOperatorsTypeConstraint) { 103 AllSubOperatorsTypeConstraint subOpConstraint = constraint as AllSubOperatorsTypeConstraint; 104 foreach(IFunction f in subOpConstraint.AllowedSubOperators) allowedSubFunctions.Add(f); 105 subOpConstraint.Changed += new EventHandler(subOpConstraint_Changed); // register an event-handler to invalidate the cache on constraint changes 106 return allowedSubFunctions; 107 } 108 } 109 return allowedSubFunctions; 110 } 111 112 private void subOpConstraint_Changed(object sender, EventArgs e) { 113 allowedSubFunctions = null; 102 114 } 103 115 -
trunk/sources/HeuristicLab.StructureIdentification/GPOperatorGroup.cs
r468 r529 184 184 if(c is SubOperatorTypeConstraint || c is AllSubOperatorsTypeConstraint) c.Changed -= new EventHandler(UpdateTreeBounds); 185 185 } 186 187 // remove the operator from the allowed sub-functions of the remaining operators 188 foreach(IOperator o in Operators) { 189 if(o != op) { 190 foreach(IConstraint c in o.Constraints) { 191 if(c is SubOperatorTypeConstraint) { 192 ((SubOperatorTypeConstraint)c).RemoveOperator(op); 193 } else if(c is AllSubOperatorsTypeConstraint) { 194 ((AllSubOperatorsTypeConstraint)c).RemoveOperator(op); 195 } 196 } 197 } 198 } 186 199 OnOperatorRemoved(op); 187 200 }
Note: See TracChangeset
for help on using the changeset viewer.