Changeset 1208
- Timestamp:
- 02/05/09 12:54:52 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/FunctionLibraryInjector.cs
r1050 r1208 36 36 private const string FUNCTIONLIBRARY = "FunctionLibrary"; 37 37 38 private StructId.Variable variable;39 private GPOperatorLibrary operatorLibrary;40 41 38 public override string Description { 42 39 get { return @"Injects a default function library for regression and classification problems."; } … … 51 48 52 49 public override IOperation Apply(IScope scope) { 50 StructId.Variable variable; 51 GPOperatorLibrary operatorLibrary; 52 53 53 ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true); 54 54 int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data; … … 56 56 // remove the target-variable in case it occures in allowed features 57 57 List<IntData> ts = allowedFeatures.FindAll(d => d.Data == targetVariable); 58 foreach(IntData t in ts) allowedFeatures.Remove(t); 59 60 InitDefaultOperatorLibrary(); 61 62 int[] allowedIndexes = new int[allowedFeatures.Count]; 63 for(int i = 0; i < allowedIndexes.Length; i++) { 64 allowedIndexes[i] = allowedFeatures[i].Data; 65 } 66 67 variable.SetConstraints(allowedIndexes, 0, 0); 68 69 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary)); 70 return null; 71 } 72 73 private void InitDefaultOperatorLibrary() { 58 foreach (IntData t in ts) allowedFeatures.Remove(t); 59 74 60 variable = new StructId.Variable(); 75 61 StructId.Constant constant = new StructId.Constant(); … … 173 159 operatorLibrary.GPOperatorGroup.AddOperator(tangens); 174 160 operatorLibrary.GPOperatorGroup.AddOperator(xor); 161 162 int[] allowedIndexes = new int[allowedFeatures.Count]; 163 for (int i = 0; i < allowedIndexes.Length; i++) { 164 allowedIndexes[i] = allowedFeatures[i].Data; 165 } 166 167 variable.SetConstraints(allowedIndexes, 0, 0); 168 169 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary)); 170 return null; 175 171 } 176 172 177 173 private void SetAllowedSubOperators(IFunction f, IFunction[] gs) { 178 foreach (IConstraint c in f.Constraints) {179 if (c is SubOperatorTypeConstraint) {174 foreach (IConstraint c in f.Constraints) { 175 if (c is SubOperatorTypeConstraint) { 180 176 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 181 177 typeConstraint.Clear(); 182 foreach (IFunction g in gs) {178 foreach (IFunction g in gs) { 183 179 typeConstraint.AddOperator(g); 184 180 } 185 } else if (c is AllSubOperatorsTypeConstraint) {181 } else if (c is AllSubOperatorsTypeConstraint) { 186 182 AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint; 187 183 typeConstraint.Clear(); 188 foreach (IFunction g in gs) {184 foreach (IFunction g in gs) { 189 185 typeConstraint.AddOperator(g); 190 186 } … … 194 190 195 191 private void SetAllowedSubOperators(IFunction f, int p, IFunction[] gs) { 196 foreach (IConstraint c in f.Constraints) {197 if (c is SubOperatorTypeConstraint) {192 foreach (IConstraint c in f.Constraints) { 193 if (c is SubOperatorTypeConstraint) { 198 194 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 199 if (typeConstraint.SubOperatorIndex.Data == p) {195 if (typeConstraint.SubOperatorIndex.Data == p) { 200 196 typeConstraint.Clear(); 201 foreach (IFunction g in gs) {197 foreach (IFunction g in gs) { 202 198 typeConstraint.AddOperator(g); 203 199 }
Note: See TracChangeset
for help on using the changeset viewer.