Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/09 12:26:42 (15 years ago)
Author:
gkronber
Message:

Merged changes from GP-refactoring branch back into the trunk #713.

File:
1 edited

Legend:

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

    r2165 r2222  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.DataAnalysis;
    29 using HeuristicLab.Constraints;
     29using HeuristicLab.GP.Interfaces;
     30using HeuristicLab.GP.SantaFe;
    3031
    3132namespace HeuristicLab.GP.Boolean {
    32   public class FunctionLibraryInjector : OperatorBase {
    33     private const string TARGETVARIABLE = "TargetVariable";
    34     private const string OPERATORLIBRARY = "FunctionLibrary";
    35 
    36     private GPOperatorLibrary operatorLibrary;
    37     private Variable variable;
    38 
     33  public class FunctionLibraryInjector : FunctionLibraryInjectorBase {
    3934    public override string Description {
    4035      get { return @"Injects a function library for boolean logic."; }
     
    4338    public FunctionLibraryInjector()
    4439      : base() {
    45       AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));
    46       AddVariableInfo(new VariableInfo(OPERATORLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New));
    4740    }
    4841
    49     public override IOperation Apply(IScope scope) {
    50       int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
    51 
    52       InitDefaultOperatorLibrary();
    53 
    54       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OPERATORLIBRARY), operatorLibrary));
    55       return null;
    56     }
    57 
    58     private void InitDefaultOperatorLibrary() {
     42    protected override FunctionLibrary CreateFunctionLibrary() {
    5943      And and = new And();
    6044      Or or = new Or();
    61       //Not not = new Not();
     45      Not not = new Not();
    6246      Nand nand = new Nand();
    6347      Nor nor = new Nor();
    64       //Xor xor = new Xor();
    65       variable = new HeuristicLab.GP.Boolean.Variable();
     48      Xor xor = new Xor();
     49      Variable variable = new Variable();
    6650
    6751      IFunction[] allFunctions = new IFunction[] {
    6852        and,
    6953        or,
    70         //not,
     54        not,
    7155        nand,
    7256        nor,
    73         //xor,
     57        xor,
    7458        variable
    7559      };
     
    7761      SetAllowedSubOperators(and, allFunctions);
    7862      SetAllowedSubOperators(or, allFunctions);
    79       //SetAllowedSubOperators(not, allFunctions);
     63      SetAllowedSubOperators(not, allFunctions);
    8064      SetAllowedSubOperators(nand, allFunctions);
    8165      SetAllowedSubOperators(nor, allFunctions);
    82       //SetAllowedSubOperators(xor, allFunctions);
     66      SetAllowedSubOperators(xor, allFunctions);
    8367
    84       operatorLibrary = new GPOperatorLibrary();
    85       operatorLibrary.GPOperatorGroup.AddOperator(and);
    86       operatorLibrary.GPOperatorGroup.AddOperator(or);
    87       //operatorLibrary.GPOperatorGroup.AddOperator(not);
    88       operatorLibrary.GPOperatorGroup.AddOperator(nand);
    89       operatorLibrary.GPOperatorGroup.AddOperator(nor);
    90       //operatorLibrary.GPOperatorGroup.AddOperator(xor);
    91       operatorLibrary.GPOperatorGroup.AddOperator(variable);
    92     }
    93 
    94     private void SetAllowedSubOperators(IFunction f, IFunction[] gs) {
    95       foreach (IConstraint c in f.Constraints) {
    96         if (c is SubOperatorTypeConstraint) {
    97           SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    98           typeConstraint.Clear();
    99           foreach (IFunction g in gs) {
    100             typeConstraint.AddOperator(g);
    101           }
    102         } else if (c is AllSubOperatorsTypeConstraint) {
    103           AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    104           typeConstraint.Clear();
    105           foreach (IFunction g in gs) {
    106             typeConstraint.AddOperator(g);
    107           }
    108         }
    109       }
     68      var functionLibrary = new FunctionLibrary();
     69      functionLibrary.AddFunction(and);
     70      functionLibrary.AddFunction(or);
     71      functionLibrary.AddFunction(not);
     72      functionLibrary.AddFunction(nand);
     73      functionLibrary.AddFunction(nor);
     74      functionLibrary.AddFunction(xor);
     75      functionLibrary.AddFunction(variable);
     76      return functionLibrary;
    11077    }
    11178  }
Note: See TracChangeset for help on using the changeset viewer.