Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1910 for trunk


Ignore:
Timestamp:
05/27/09 14:36:09 (15 years ago)
Author:
gkronber
Message:

Fixed a bug in the configurable function library injector (introduced with r1908) #579

File:
1 edited

Legend:

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

    r1908 r1910  
    154154      StructId.Xor xor = new StructId.Xor();
    155155
    156       IFunction[] booleanFunctions = new IFunction[] {
    157         and,
    158         equal,
    159         greaterThan,
    160         lessThan,
    161         not,
    162         or,
    163         xor
    164       };
    165       IFunction[] doubleFunctions = new IFunction[] {
    166         differential,
    167         variable,
    168         constant,
    169         addition,
    170         average,
    171         cosinus,
    172         division,
    173         exponential,
    174         ifThenElse,
    175         logarithm,
    176         multiplication,
    177         power,
    178         signum,
    179         sinus,
    180         sqrt,
    181         subtraction,
    182         tangens
    183       };
     156
     157      List<IOperator> booleanFunctions = new List<IOperator>();
     158      ConditionalAddOperator(AND_ALLOWED, and, booleanFunctions);
     159      ConditionalAddOperator(EQUAL_ALLOWED, equal, booleanFunctions);
     160      ConditionalAddOperator(GREATERTHAN_ALLOWED, greaterThan, booleanFunctions);
     161      ConditionalAddOperator(LESSTHAN_ALLOWED, lessThan, booleanFunctions);
     162      ConditionalAddOperator(NOT_ALLOWED, not, booleanFunctions);
     163      ConditionalAddOperator(OR_ALLOWED, or, booleanFunctions);
     164      ConditionalAddOperator(XOR_ALLOWED, xor, booleanFunctions);
     165
     166      List<IOperator> doubleFunctions = new List<IOperator>();
     167      ConditionalAddOperator(DIFFERENTIALS_ALLOWED, differential, doubleFunctions);
     168      ConditionalAddOperator(VARIABLES_ALLOWED, variable, doubleFunctions);
     169      ConditionalAddOperator(CONSTANTS_ALLOWED, constant, doubleFunctions);
     170      ConditionalAddOperator(ADDITION_ALLOWED, addition, doubleFunctions);
     171      ConditionalAddOperator(AVERAGE_ALLOWED, average, doubleFunctions);
     172      ConditionalAddOperator(COSINUS_ALLOWED, cosinus, doubleFunctions);
     173      ConditionalAddOperator(DIVISION_ALLOWED, division, doubleFunctions);
     174      ConditionalAddOperator(EXPONENTIAL_ALLOWED, exponential, doubleFunctions);
     175      ConditionalAddOperator(IFTHENELSE_ALLOWED, ifThenElse, doubleFunctions);
     176      ConditionalAddOperator(LOGARTIHM_ALLOWED, logarithm, doubleFunctions);
     177      ConditionalAddOperator(MULTIPLICATION_ALLOWED, multiplication, doubleFunctions);
     178      ConditionalAddOperator(POWER_ALLOWED, power, doubleFunctions);
     179      ConditionalAddOperator(SIGNUM_ALLOWED, signum, doubleFunctions);
     180      ConditionalAddOperator(SINUS_ALLOWED, sinus, doubleFunctions);
     181      ConditionalAddOperator(SQRT_ALLOWED, sqrt, doubleFunctions);
     182      ConditionalAddOperator(SUBTRACTION_ALLOWED, subtraction, doubleFunctions);
     183      ConditionalAddOperator(TANGENS_ALLOWED, tangens, doubleFunctions);
    184184
    185185      SetAllowedSubOperators(and, booleanFunctions);
     
    246246    }
    247247
     248    private void ConditionalAddOperator(string condName, IOperator op, List<IOperator> list) {
     249      if (GetVariableValue<BoolData>(condName, null, false).Data) list.Add(op);
     250    }
     251
    248252    private void ConditionalAddOperator(string condName, GPOperatorLibrary operatorLibrary, IOperator op) {
    249253      if (GetVariableValue<BoolData>(condName, null, false).Data) operatorLibrary.GPOperatorGroup.AddOperator(op);
    250254    }
    251255
    252     private void SetAllowedSubOperators(IFunction f, IFunction[] gs) {
     256    private void SetAllowedSubOperators(IFunction f, List<IOperator> gs) {
    253257      foreach (IConstraint c in f.Constraints) {
    254258        if (c is SubOperatorTypeConstraint) {
    255259          SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    256260          typeConstraint.Clear();
    257           foreach (IFunction g in gs) {
     261          foreach (IOperator g in gs) {
    258262            typeConstraint.AddOperator(g);
    259263          }
     
    261265          AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    262266          typeConstraint.Clear();
    263           foreach (IFunction g in gs) {
     267          foreach (IOperator g in gs) {
    264268            typeConstraint.AddOperator(g);
    265269          }
     
    268272    }
    269273
    270     private void SetAllowedSubOperators(IFunction f, int p, IFunction[] gs) {
     274    private void SetAllowedSubOperators(IFunction f, int p, List<IOperator> gs) {
    271275      foreach (IConstraint c in f.Constraints) {
    272276        if (c is SubOperatorTypeConstraint) {
     
    274278          if (typeConstraint.SubOperatorIndex.Data == p) {
    275279            typeConstraint.Clear();
    276             foreach (IFunction g in gs) {
     280            foreach (IOperator g in gs) {
    277281              typeConstraint.AddOperator(g);
    278282            }
Note: See TracChangeset for help on using the changeset viewer.