Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/08/08 13:55:59 (16 years ago)
Author:
gkronber
Message:

fixed bugs in GP.boolean plugin #340 (Plugin for genetic programming for boolean logic)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.Boolean/FunctionLibraryInjector.cs

    r720 r722  
    3131namespace HeuristicLab.GP.Boolean {
    3232  public class FunctionLibraryInjector : OperatorBase {
     33    private const string TARGETVARIABLE = "TargetVariable";
     34    private const string ALLOWEDFEATURES = "AllowedFeatures";
    3335    private const string OPERATORLIBRARY = "FunctionLibrary";
    3436
    3537    private GPOperatorLibrary operatorLibrary;
     38    private Variable variable;
    3639
    3740    public override string Description {
     
    4144    public FunctionLibraryInjector()
    4245      : base() {
     46      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));
     47      AddVariableInfo(new VariableInfo(ALLOWEDFEATURES, "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    4348      AddVariableInfo(new VariableInfo(OPERATORLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New));
    4449    }
    4550
    4651    public override IOperation Apply(IScope scope) {
     52      ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true);
     53      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
     54
     55      // remove the target-variable in case it occures in allowed features
     56      List<IntData> ts = allowedFeatures.FindAll(d => d.Data == targetVariable);
     57      foreach (IntData t in ts) allowedFeatures.Remove(t);
     58
    4759      InitDefaultOperatorLibrary();
     60
     61      int[] allowedIndexes = new int[allowedFeatures.Count];
     62      for (int i = 0; i < allowedIndexes.Length; i++) {
     63        allowedIndexes[i] = allowedFeatures[i].Data;
     64      }
     65
     66      variable.SetConstraints(allowedIndexes);
     67
    4868      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OPERATORLIBRARY), operatorLibrary));
    4969      return null;
     
    5777      Nor nor = new Nor();
    5878      Xor xor = new Xor();
    59       HeuristicLab.GP.Boolean.Variable variable = new HeuristicLab.GP.Boolean.Variable();
     79      variable = new HeuristicLab.GP.Boolean.Variable();
    6080
    6181      IFunction[] allFunctions = new IFunction[] {
     
    7494      SetAllowedSubOperators(nand, allFunctions);
    7595      SetAllowedSubOperators(nor, allFunctions);
    76       SetAllowedSubOperators(not, allFunctions);
     96      SetAllowedSubOperators(xor, allFunctions);
    7797
    7898      operatorLibrary = new GPOperatorLibrary();
     
    87107
    88108    private void SetAllowedSubOperators(IFunction f, IFunction[] gs) {
    89       foreach(IConstraint c in f.Constraints) {
    90         if(c is SubOperatorTypeConstraint) {
     109      foreach (IConstraint c in f.Constraints) {
     110        if (c is SubOperatorTypeConstraint) {
    91111          SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    92112          typeConstraint.Clear();
    93           foreach(IFunction g in gs) {
     113          foreach (IFunction g in gs) {
    94114            typeConstraint.AddOperator(g);
    95115          }
    96         } else if(c is AllSubOperatorsTypeConstraint) {
     116        } else if (c is AllSubOperatorsTypeConstraint) {
    97117          AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    98118          typeConstraint.Clear();
    99           foreach(IFunction g in gs) {
     119          foreach (IFunction g in gs) {
    100120            typeConstraint.AddOperator(g);
    101121          }
Note: See TracChangeset for help on using the changeset viewer.