Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/09 19:41:58 (15 years ago)
Author:
gkronber
Message:

GP Refactoring #713

  • cleaned code
  • reintegrated GP.Boolean and GP.SantaFe
  • worked on serialization of function trees
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs

    r2212 r2216  
    2424using HeuristicLab.Data;
    2525using HeuristicLab.GP.Interfaces;
     26using HeuristicLab.GP.SantaFe;
    2627
    2728namespace 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 {
    3130    private const string MINTIMEOFFSET = "MinTimeOffset";
    3231    private const string MAXTIMEOFFSET = "MaxTimeOffset";
     
    5756    private const string XOR_ALLOWED = "Xor";
    5857
     58    private int minTimeOffset;
     59    private int maxTimeOffset;
    5960
    6061    public override string Description {
     
    6465    public FunctionLibraryInjector()
    6566      : base() {
    66       AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));
    6767      AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In));
    6868      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));
    7069
    7170      AddVariable(DIFFERENTIALS_ALLOWED, false);
     
    102101
    103102    public override IOperation Apply(IScope scope) {
    104       FunctionLibrary functionLibrary = new FunctionLibrary();
    105       int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
    106 
    107103      // try to get minTimeOffset (use 0 as default if not available)
    108104      IItem minTimeOffsetItem = GetVariableValue(MINTIMEOFFSET, scope, true, false);
    109       int minTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data;
     105      minTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data;
    110106      // try to get maxTimeOffset (use 0 as default if not available)
    111107      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();
    113115
    114116      Variable variable = new Variable();
     
    218220      differential.SetConstraints(minTimeOffset, maxTimeOffset);
    219221
    220       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), functionLibrary));
    221 
    222       return null;
     222      return functionLibrary;
    223223    }
    224224
     
    230230      if (GetVariableValue<BoolData>(condName, null, false).Data) functionLib.AddFunction(op);
    231231    }
    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     }
    242232  }
    243233}
Note: See TracChangeset for help on using the changeset viewer.