Changeset 2216 for branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
- Timestamp:
- 07/30/09 19:41:58 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
r2212 r2216 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.GP.Interfaces; 26 using HeuristicLab.GP.SantaFe; 26 27 27 28 namespace HeuristicLab.GP.StructureIdentification { 28 public class FunctionLibraryInjector : OperatorBase { 29 private const string FUNCTIONLIBRARY = "FunctionLibrary"; 30 private const string TARGETVARIABLE = "TargetVariable"; 29 public class FunctionLibraryInjector : FunctionLibraryInjectorBase { 31 30 private const string MINTIMEOFFSET = "MinTimeOffset"; 32 31 private const string MAXTIMEOFFSET = "MaxTimeOffset"; … … 57 56 private const string XOR_ALLOWED = "Xor"; 58 57 58 private int minTimeOffset; 59 private int maxTimeOffset; 59 60 60 61 public override string Description { … … 64 65 public FunctionLibraryInjector() 65 66 : base() { 66 AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));67 67 AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In)); 68 68 AddVariableInfo(new VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), VariableKind.In)); 69 AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default function library", typeof(FunctionLibrary), VariableKind.New));70 69 71 70 AddVariable(DIFFERENTIALS_ALLOWED, false); … … 102 101 103 102 public override IOperation Apply(IScope scope) { 104 FunctionLibrary functionLibrary = new FunctionLibrary();105 int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;106 107 103 // try to get minTimeOffset (use 0 as default if not available) 108 104 IItem minTimeOffsetItem = GetVariableValue(MINTIMEOFFSET, scope, true, false); 109 intminTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data;105 minTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data; 110 106 // try to get maxTimeOffset (use 0 as default if not available) 111 107 IItem maxTimeOffsetItem = GetVariableValue(MAXTIMEOFFSET, scope, true, false); 112 int maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data; 108 maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data; 109 110 return base.Apply(scope); 111 } 112 113 protected override FunctionLibrary CreateFunctionLibrary() { 114 FunctionLibrary functionLibrary = new FunctionLibrary(); 113 115 114 116 Variable variable = new Variable(); … … 218 220 differential.SetConstraints(minTimeOffset, maxTimeOffset); 219 221 220 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), functionLibrary)); 221 222 return null; 222 return functionLibrary; 223 223 } 224 224 … … 230 230 if (GetVariableValue<BoolData>(condName, null, false).Data) functionLib.AddFunction(op); 231 231 } 232 233 private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) {234 for (int i = 0; i < f.MaxSubTrees; i++) {235 SetAllowedSubOperators(f, i, gs);236 }237 }238 239 private void SetAllowedSubOperators(IFunction f, int i, List<IFunction> gs) {240 gs.ForEach((g) => f.AddAllowedSubFunction(g, i));241 }242 232 } 243 233 }
Note: See TracChangeset
for help on using the changeset viewer.