Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1208


Ignore:
Timestamp:
02/05/09 12:54:52 (16 years ago)
Author:
gkronber
Message:

fixed #487 (GPOperatorLibrary/GPOperatorGroup doesn't work in ThreadParallelEngines) in CEDMA refactoring branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/FunctionLibraryInjector.cs

    r1050 r1208  
    3636    private const string FUNCTIONLIBRARY = "FunctionLibrary";
    3737
    38     private StructId.Variable variable;
    39     private GPOperatorLibrary operatorLibrary;
    40 
    4138    public override string Description {
    4239      get { return @"Injects a default function library for regression and classification problems."; }
     
    5148
    5249    public override IOperation Apply(IScope scope) {
     50      StructId.Variable variable;
     51      GPOperatorLibrary operatorLibrary;
     52
    5353      ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true);
    5454      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
     
    5656      // remove the target-variable in case it occures in allowed features
    5757      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
    7460      variable = new StructId.Variable();
    7561      StructId.Constant constant = new StructId.Constant();
     
    173159      operatorLibrary.GPOperatorGroup.AddOperator(tangens);
    174160      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;
    175171    }
    176172
    177173    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) {
    180176          SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    181177          typeConstraint.Clear();
    182           foreach(IFunction g in gs) {
     178          foreach (IFunction g in gs) {
    183179            typeConstraint.AddOperator(g);
    184180          }
    185         } else if(c is AllSubOperatorsTypeConstraint) {
     181        } else if (c is AllSubOperatorsTypeConstraint) {
    186182          AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    187183          typeConstraint.Clear();
    188           foreach(IFunction g in gs) {
     184          foreach (IFunction g in gs) {
    189185            typeConstraint.AddOperator(g);
    190186          }
     
    194190
    195191    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) {
    198194          SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    199           if(typeConstraint.SubOperatorIndex.Data == p) {
     195          if (typeConstraint.SubOperatorIndex.Data == p) {
    200196            typeConstraint.Clear();
    201             foreach(IFunction g in gs) {
     197            foreach (IFunction g in gs) {
    202198              typeConstraint.AddOperator(g);
    203199            }
Note: See TracChangeset for help on using the changeset viewer.