Changeset 2202 for branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
- Timestamp:
- 07/28/09 19:24:23 (15 years ago)
- Location:
- branches/GP-Refactoring-713
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
r2174 r2202 72 72 AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In)); 73 73 AddVariableInfo(new VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), VariableKind.In)); 74 AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New));74 AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default function library", typeof(FunctionLibrary), VariableKind.New)); 75 75 76 76 AddVariable(DIFFERENTIALS_ALLOWED, false); … … 107 107 108 108 public override IOperation Apply(IScope scope) { 109 StructId.Variable variable; 110 GPOperatorLibrary operatorLibrary; 109 FunctionLibrary functionLibrary = new FunctionLibrary(); 111 110 int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data; 112 111 … … 118 117 int maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data; 119 118 120 variable = new StructId.Variable();121 StructId.Constant constant = new StructId.Constant();122 StructId.Differential differential = new Differential();123 StructId.Addition addition = new StructId.Addition();124 StructId.And and = new StructId.And();125 StructId.Average average = new StructId.Average();126 StructId.Cosinus cosinus = new StructId.Cosinus();127 StructId.Division division = new StructId.Division();128 StructId.Equal equal = new StructId.Equal();129 StructId.Exponential exponential = new StructId.Exponential();130 StructId.GreaterThan greaterThan = new StructId.GreaterThan();131 StructId.IfThenElse ifThenElse = new StructId.IfThenElse();132 StructId.LessThan lessThan = new StructId.LessThan();133 StructId.Logarithm logarithm = new StructId.Logarithm();134 StructId.Multiplication multiplication = new StructId.Multiplication();135 StructId.Not not = new StructId.Not();136 StructId.Or or = new StructId.Or();137 StructId.Power power = new StructId.Power();138 S tructId.Signum signum = new StructId.Signum();139 S tructId.Sinus sinus = new StructId.Sinus();140 S tructId.Sqrt sqrt = new StructId.Sqrt();141 S tructId.Subtraction subtraction = new StructId.Subtraction();142 StructId.Tangens tangens = new StructId.Tangens();143 StructId.Xor xor = new StructId.Xor();144 145 146 List<I Operator> booleanFunctions = new List<IOperator>();147 ConditionalAdd Operator(AND_ALLOWED, and, booleanFunctions);148 ConditionalAdd Operator(EQUAL_ALLOWED, equal, booleanFunctions);149 ConditionalAdd Operator(GREATERTHAN_ALLOWED, greaterThan, booleanFunctions);150 ConditionalAdd Operator(LESSTHAN_ALLOWED, lessThan, booleanFunctions);151 ConditionalAdd Operator(NOT_ALLOWED, not, booleanFunctions);152 ConditionalAdd Operator(OR_ALLOWED, or, booleanFunctions);153 ConditionalAdd Operator(XOR_ALLOWED, xor, booleanFunctions);154 155 List<I Operator> doubleFunctions = new List<IOperator>();156 ConditionalAdd Operator(DIFFERENTIALS_ALLOWED, differential, doubleFunctions);157 ConditionalAdd Operator(VARIABLES_ALLOWED, variable, doubleFunctions);158 ConditionalAdd Operator(CONSTANTS_ALLOWED, constant, doubleFunctions);159 ConditionalAdd Operator(ADDITION_ALLOWED, addition, doubleFunctions);160 ConditionalAdd Operator(AVERAGE_ALLOWED, average, doubleFunctions);161 ConditionalAdd Operator(COSINUS_ALLOWED, cosinus, doubleFunctions);162 ConditionalAdd Operator(DIVISION_ALLOWED, division, doubleFunctions);163 ConditionalAdd Operator(EXPONENTIAL_ALLOWED, exponential, doubleFunctions);164 ConditionalAdd Operator(IFTHENELSE_ALLOWED, ifThenElse, doubleFunctions);165 ConditionalAdd Operator(LOGARTIHM_ALLOWED, logarithm, doubleFunctions);166 ConditionalAdd Operator(MULTIPLICATION_ALLOWED, multiplication, doubleFunctions);167 ConditionalAdd Operator(POWER_ALLOWED, power, doubleFunctions);168 ConditionalAdd Operator(SIGNUM_ALLOWED, signum, doubleFunctions);169 ConditionalAdd Operator(SINUS_ALLOWED, sinus, doubleFunctions);170 ConditionalAdd Operator(SQRT_ALLOWED, sqrt, doubleFunctions);171 ConditionalAdd Operator(SUBTRACTION_ALLOWED, subtraction, doubleFunctions);172 ConditionalAdd Operator(TANGENS_ALLOWED, tangens, doubleFunctions);119 Variable variable = new Variable(); 120 Constant constant = new Constant(); 121 Differential differential = new Differential(); 122 Addition addition = new Addition(); 123 And and = new And(); 124 Average average = new Average(); 125 Cosinus cosinus = new Cosinus(); 126 Division division = new Division(); 127 Equal equal = new Equal(); 128 Exponential exponential = new Exponential(); 129 GreaterThan greaterThan = new GreaterThan(); 130 IfThenElse ifThenElse = new IfThenElse(); 131 LessThan lessThan = new LessThan(); 132 Logarithm logarithm = new Logarithm(); 133 Multiplication multiplication = new Multiplication(); 134 Not not = new Not(); 135 Or or = new Or(); 136 Power power = new Power(); 137 Signum signum = new Signum(); 138 Sinus sinus = new Sinus(); 139 Sqrt sqrt = new Sqrt(); 140 Subtraction subtraction = new Subtraction(); 141 Tangens tangens = new Tangens(); 142 Xor xor = new Xor(); 143 144 145 List<IFunction> booleanFunctions = new List<IFunction>(); 146 ConditionalAddFunction(AND_ALLOWED, and, booleanFunctions); 147 ConditionalAddFunction(EQUAL_ALLOWED, equal, booleanFunctions); 148 ConditionalAddFunction(GREATERTHAN_ALLOWED, greaterThan, booleanFunctions); 149 ConditionalAddFunction(LESSTHAN_ALLOWED, lessThan, booleanFunctions); 150 ConditionalAddFunction(NOT_ALLOWED, not, booleanFunctions); 151 ConditionalAddFunction(OR_ALLOWED, or, booleanFunctions); 152 ConditionalAddFunction(XOR_ALLOWED, xor, booleanFunctions); 153 154 List<IFunction> doubleFunctions = new List<IFunction>(); 155 ConditionalAddFunction(DIFFERENTIALS_ALLOWED, differential, doubleFunctions); 156 ConditionalAddFunction(VARIABLES_ALLOWED, variable, doubleFunctions); 157 ConditionalAddFunction(CONSTANTS_ALLOWED, constant, doubleFunctions); 158 ConditionalAddFunction(ADDITION_ALLOWED, addition, doubleFunctions); 159 ConditionalAddFunction(AVERAGE_ALLOWED, average, doubleFunctions); 160 ConditionalAddFunction(COSINUS_ALLOWED, cosinus, doubleFunctions); 161 ConditionalAddFunction(DIVISION_ALLOWED, division, doubleFunctions); 162 ConditionalAddFunction(EXPONENTIAL_ALLOWED, exponential, doubleFunctions); 163 ConditionalAddFunction(IFTHENELSE_ALLOWED, ifThenElse, doubleFunctions); 164 ConditionalAddFunction(LOGARTIHM_ALLOWED, logarithm, doubleFunctions); 165 ConditionalAddFunction(MULTIPLICATION_ALLOWED, multiplication, doubleFunctions); 166 ConditionalAddFunction(POWER_ALLOWED, power, doubleFunctions); 167 ConditionalAddFunction(SIGNUM_ALLOWED, signum, doubleFunctions); 168 ConditionalAddFunction(SINUS_ALLOWED, sinus, doubleFunctions); 169 ConditionalAddFunction(SQRT_ALLOWED, sqrt, doubleFunctions); 170 ConditionalAddFunction(SUBTRACTION_ALLOWED, subtraction, doubleFunctions); 171 ConditionalAddFunction(TANGENS_ALLOWED, tangens, doubleFunctions); 173 172 174 173 SetAllowedSubOperators(and, booleanFunctions); … … 196 195 SetAllowedSubOperators(tangens, doubleFunctions); 197 196 198 operatorLibrary = new GPOperatorLibrary(); 199 ConditionalAddOperator(DIFFERENTIALS_ALLOWED, operatorLibrary, differential); 200 ConditionalAddOperator(VARIABLES_ALLOWED, operatorLibrary, variable); 201 ConditionalAddOperator(CONSTANTS_ALLOWED, operatorLibrary, constant); 202 ConditionalAddOperator(ADDITION_ALLOWED, operatorLibrary, addition); 203 ConditionalAddOperator(AVERAGE_ALLOWED, operatorLibrary, average); 204 ConditionalAddOperator(AND_ALLOWED, operatorLibrary, and); 205 ConditionalAddOperator(COSINUS_ALLOWED, operatorLibrary, cosinus); 206 ConditionalAddOperator(DIVISION_ALLOWED, operatorLibrary, division); 207 ConditionalAddOperator(EQUAL_ALLOWED, operatorLibrary, equal); 208 ConditionalAddOperator(EXPONENTIAL_ALLOWED, operatorLibrary, exponential); 209 ConditionalAddOperator(GREATERTHAN_ALLOWED, operatorLibrary, greaterThan); 210 ConditionalAddOperator(IFTHENELSE_ALLOWED, operatorLibrary, ifThenElse); 211 ConditionalAddOperator(LESSTHAN_ALLOWED, operatorLibrary, lessThan); 212 ConditionalAddOperator(LOGARTIHM_ALLOWED, operatorLibrary, logarithm); 213 ConditionalAddOperator(MULTIPLICATION_ALLOWED, operatorLibrary, multiplication); 214 ConditionalAddOperator(NOT_ALLOWED, operatorLibrary, not); 215 ConditionalAddOperator(POWER_ALLOWED, operatorLibrary, power); 216 ConditionalAddOperator(OR_ALLOWED, operatorLibrary, or); 217 ConditionalAddOperator(SIGNUM_ALLOWED, operatorLibrary, signum); 218 ConditionalAddOperator(SINUS_ALLOWED, operatorLibrary, sinus); 219 ConditionalAddOperator(SQRT_ALLOWED, operatorLibrary, sqrt); 220 ConditionalAddOperator(SUBTRACTION_ALLOWED, operatorLibrary, subtraction); 221 ConditionalAddOperator(TANGENS_ALLOWED, operatorLibrary, tangens); 222 ConditionalAddOperator(XOR_ALLOWED, operatorLibrary, xor); 197 ConditionalAddOperator(DIFFERENTIALS_ALLOWED, functionLibrary, differential); 198 ConditionalAddOperator(VARIABLES_ALLOWED, functionLibrary, variable); 199 ConditionalAddOperator(CONSTANTS_ALLOWED, functionLibrary, constant); 200 ConditionalAddOperator(ADDITION_ALLOWED, functionLibrary, addition); 201 ConditionalAddOperator(AVERAGE_ALLOWED, functionLibrary, average); 202 ConditionalAddOperator(AND_ALLOWED, functionLibrary, and); 203 ConditionalAddOperator(COSINUS_ALLOWED, functionLibrary, cosinus); 204 ConditionalAddOperator(DIVISION_ALLOWED, functionLibrary, division); 205 ConditionalAddOperator(EQUAL_ALLOWED, functionLibrary, equal); 206 ConditionalAddOperator(EXPONENTIAL_ALLOWED, functionLibrary, exponential); 207 ConditionalAddOperator(GREATERTHAN_ALLOWED, functionLibrary, greaterThan); 208 ConditionalAddOperator(IFTHENELSE_ALLOWED, functionLibrary, ifThenElse); 209 ConditionalAddOperator(LESSTHAN_ALLOWED, functionLibrary, lessThan); 210 ConditionalAddOperator(LOGARTIHM_ALLOWED, functionLibrary, logarithm); 211 ConditionalAddOperator(MULTIPLICATION_ALLOWED, functionLibrary, multiplication); 212 ConditionalAddOperator(NOT_ALLOWED, functionLibrary, not); 213 ConditionalAddOperator(POWER_ALLOWED, functionLibrary, power); 214 ConditionalAddOperator(OR_ALLOWED, functionLibrary, or); 215 ConditionalAddOperator(SIGNUM_ALLOWED, functionLibrary, signum); 216 ConditionalAddOperator(SINUS_ALLOWED, functionLibrary, sinus); 217 ConditionalAddOperator(SQRT_ALLOWED, functionLibrary, sqrt); 218 ConditionalAddOperator(SUBTRACTION_ALLOWED, functionLibrary, subtraction); 219 ConditionalAddOperator(TANGENS_ALLOWED, functionLibrary, tangens); 220 ConditionalAddOperator(XOR_ALLOWED, functionLibrary, xor); 223 221 224 222 variable.SetConstraints(minTimeOffset, maxTimeOffset); 225 223 differential.SetConstraints(minTimeOffset, maxTimeOffset); 226 224 227 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary));225 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), functionLibrary)); 228 226 229 227 return null; 230 228 } 231 229 232 private void ConditionalAddOperator(string condName, IOperator op, List<IOperator> list) { 233 if (GetVariableValue<BoolData>(condName, null, false).Data) list.Add(op); 234 } 235 236 private void ConditionalAddOperator(string condName, GPOperatorLibrary operatorLibrary, IOperator op) { 237 if (GetVariableValue<BoolData>(condName, null, false).Data) operatorLibrary.GPOperatorGroup.AddOperator(op); 238 } 239 240 private void SetAllowedSubOperators(IFunction f, List<IOperator> gs) { 241 foreach (IConstraint c in f.Constraints) { 242 if (c is SubOperatorTypeConstraint) { 243 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 244 typeConstraint.Clear(); 245 foreach (IOperator g in gs) { 246 typeConstraint.AddOperator(g); 247 } 248 } else if (c is AllSubOperatorsTypeConstraint) { 249 AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint; 250 typeConstraint.Clear(); 251 foreach (IOperator g in gs) { 252 typeConstraint.AddOperator(g); 253 } 254 } 230 private void ConditionalAddFunction(string condName, IFunction fun, List<IFunction> list) { 231 if (GetVariableValue<BoolData>(condName, null, false).Data) list.Add(fun); 232 } 233 234 private void ConditionalAddOperator(string condName, FunctionLibrary functionLib, IFunction op) { 235 if (GetVariableValue<BoolData>(condName, null, false).Data) functionLib.AddFunction(op); 236 } 237 238 private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) { 239 for (int i = 0; i < f.MaxArity; i++) { 240 SetAllowedSubOperators(f, i, gs); 255 241 } 256 242 } 257 243 258 private void SetAllowedSubOperators(IFunction f, int p, List<IOperator> gs) { 259 foreach (IConstraint c in f.Constraints) { 260 if (c is SubOperatorTypeConstraint) { 261 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 262 if (typeConstraint.SubOperatorIndex.Data == p) { 263 typeConstraint.Clear(); 264 foreach (IOperator g in gs) { 265 typeConstraint.AddOperator(g); 266 } 267 } 268 } 269 } 244 private void SetAllowedSubOperators(IFunction f, int i, List<IFunction> gs) { 245 gs.ForEach((g) => f.AddAllowedSubFunction(g, i)); 270 246 } 271 247 }
Note: See TracChangeset
for help on using the changeset viewer.