Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/09 19:24:23 (15 years ago)
Author:
gkronber
Message:

Created a branch for #713

Location:
branches/GP-Refactoring-713
Files:
4 added
28 edited
1 copied

Legend:

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

    r1529 r2202  
    4242      : base() {
    4343      // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)
    44       AddConstraint(new NumberOfSubOperatorsConstraint(2, 3));
    45       AddConstraint(new SubOperatorTypeConstraint(0));
    46       AddConstraint(new SubOperatorTypeConstraint(1));
    47       AddConstraint(new SubOperatorTypeConstraint(2));
     44      MinArity = 2;
     45      MaxArity = 3;
    4846    }
    4947  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/And.cs

    r1529 r2202  
    3838    public And()
    3939      : base() {
    40       AddConstraint(new NumberOfSubOperatorsConstraint(2, 3));
    41       AddConstraint(new SubOperatorTypeConstraint(0));
    42       AddConstraint(new SubOperatorTypeConstraint(1));
    43       AddConstraint(new SubOperatorTypeConstraint(2));
     40      MinArity = 2; MaxArity = 3;
    4441    }
    4542  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Average.cs

    r1529 r2202  
    3636    public Average()
    3737      : base() {
    38       AddConstraint(new NumberOfSubOperatorsConstraint(2, 3));
    39       AddConstraint(new SubOperatorTypeConstraint(0));
    40       AddConstraint(new SubOperatorTypeConstraint(1));
    41       AddConstraint(new SubOperatorTypeConstraint(2));
     38      MinArity = 2; MaxArity = 3;
    4239    }
    4340  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/BakedTreeEvaluator.cs

    r1836 r2202  
    183183            return Math.Abs(x - y);
    184184          }
    185         case EvaluatorSymbolTable.UNKNOWN: { // evaluate functions which are not statically defined directly
    186             return currInstr.function.Apply();
    187           }
    188185        default: {
    189186            throw new NotImplementedException();
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Constant.cs

    r2174 r2202  
    3232
    3333namespace HeuristicLab.GP.StructureIdentification {
    34   public sealed class Constant : FunctionBase {
     34  public sealed class Constant : Terminal {
    3535    public const string VALUE = "Value";
     36    private BakedFunctionTree constantNodeTemplate;
    3637
    3738    public override string Description {
     
    3940    }
    4041
     42    public override IEnumerable<string> LocalParameterNames {
     43      get {
     44        return new string[] { VALUE };
     45      }
     46    }
     47
    4148    public Constant()
    4249      : base() {
    43       AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(DoubleData), VariableKind.None));
    44       GetVariableInfo(VALUE).Local = true;
    45 
    4650      DoubleData valueData = new DoubleData();
    47       // initialize a default range for the contant value
    48       HeuristicLab.Core.Variable value = new HeuristicLab.Core.Variable(VALUE, valueData);
    49       AddVariable(value);
     51      constantNodeTemplate = new BakedFunctionTree(this);
     52      constantNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(VALUE, valueData));
    5053
    5154      SetupInitialization();
    5255      SetupManipulation();
     56    }
    5357
    54       // constant can't have suboperators
    55       AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
     58    public override IFunctionTree GetTreeNode() {
     59      return (IFunctionTree)constantNodeTemplate.Clone();
    5660    }
    5761
    5862    private void SetupInitialization() {
    5963      // initialization operator
    60       AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
    61       GetVariableInfo(INITIALIZATION).Local = false;
    6264      CombinedOperator combinedOp = new CombinedOperator();
    6365      SequentialProcessor initSeq = new SequentialProcessor();
     
    7072      combinedOp.OperatorGraph.InitialOperator = initSeq;
    7173      initSeq.AddSubOperator(randomizer);
    72       AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));
     74      Initializer = combinedOp;
    7375    }
    7476
    7577    private void SetupManipulation() {
    7678      // manipulation operator
    77       AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
    78       GetVariableInfo(MANIPULATION).Local = false;
    7979      CombinedOperator combinedOp = new CombinedOperator();
    8080      SequentialProcessor manipulationSeq = new SequentialProcessor();
     
    8787      combinedOp.OperatorGraph.InitialOperator = manipulationSeq;
    8888      manipulationSeq.AddSubOperator(valueAdder);
    89       AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
     89      Manipulator = combinedOp;
    9090    }
    9191  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Cosinus.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Cosinus : FunctionBase {
     31  public sealed class Cosinus : UnaryFunction {
    3232    public override string Description {
    3333      get { return "Returns the cosinus of the first sub-tree."; }
     
    3636    public Cosinus()
    3737      : base() {
    38       // must have exactly one subfunction
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    4138    }
    4239  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Differential.cs

    r1529 r2202  
    4040    }
    4141
    42     public Differential()
    43       : base() {
    44     }
     42    public Differential() : base() { }
    4543  }
    4644}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Division.cs

    r2054 r2202  
    3030
    3131namespace HeuristicLab.GP.StructureIdentification {
    32   public sealed class Division : FunctionBase {
    33     private const double EPSILON = 10.0E-20; // if any divisor is < EPSILON return 0
    34 
     32  public sealed class Division : BinaryFunction {
    3533    public override string Description {
    3634      get {
     
    4644    }
    4745
    48     public Division()
    49       : base() {
    50       // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)
    51       //MK changed to only 2 allowed suboperators to be compliant with HL2
    52       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
    53       AddConstraint(new SubOperatorTypeConstraint(0));
    54       AddConstraint(new SubOperatorTypeConstraint(1));
    55     }
     46    public Division() : base() { }
    5647  }
    5748}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Equal.cs

    r1529 r2202  
    2828
    2929namespace HeuristicLab.GP.StructureIdentification {
    30   public sealed class Equal : FunctionBase {
     30  public sealed class Equal : BinaryFunction {
    3131    public override string Description {
    3232      get {
     
    3535    }
    3636
    37     public Equal()
    38       : base() {
    39       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    41       AddConstraint(new SubOperatorTypeConstraint(1));
    42     }
     37    public Equal() : base() { }
    4338  }
    4439}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Exponential.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Exponential : FunctionBase {
     31  public sealed class Exponential : UnaryFunction {
    3232    public override string Description {
    3333      get { return "Returns returns exponential of the first sub-tree (power(e, x))."; }
    3434    }
    3535
    36     public Exponential()
    37       : base() {
    38       // must have exactly one sub-operator
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    41     }
     36    public Exponential() : base() { }
    4237  }
    4338}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs

    r2174 r2202  
    7272      AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In));
    7373      AddVariableInfo(new VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), VariableKind.In));
    74       AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New));
     74      AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default function library", typeof(FunctionLibrary), VariableKind.New));
    7575
    7676      AddVariable(DIFFERENTIALS_ALLOWED, false);
     
    107107
    108108    public override IOperation Apply(IScope scope) {
    109       StructId.Variable variable;
    110       GPOperatorLibrary operatorLibrary;
     109      FunctionLibrary functionLibrary = new FunctionLibrary();
    111110      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
    112111
     
    118117      int maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data;
    119118
    120       variable = new StructId.Variable();
    121       StructId.Constant constant = new StructId.Constant();
    122       StructId.Differential differential = new Differential();
    123       StructId.Addition addition = new StructId.Addition();
    124       StructId.And and = new StructId.And();
    125       StructId.Average average = new StructId.Average();
    126       StructId.Cosinus cosinus = new StructId.Cosinus();
    127       StructId.Division division = new StructId.Division();
    128       StructId.Equal equal = new StructId.Equal();
    129       StructId.Exponential exponential = new StructId.Exponential();
    130       StructId.GreaterThan greaterThan = new StructId.GreaterThan();
    131       StructId.IfThenElse ifThenElse = new StructId.IfThenElse();
    132       StructId.LessThan lessThan = new StructId.LessThan();
    133       StructId.Logarithm logarithm = new StructId.Logarithm();
    134       StructId.Multiplication multiplication = new StructId.Multiplication();
    135       StructId.Not not = new StructId.Not();
    136       StructId.Or or = new StructId.Or();
    137       StructId.Power power = new StructId.Power();
    138       StructId.Signum signum = new StructId.Signum();
    139       StructId.Sinus sinus = new StructId.Sinus();
    140       StructId.Sqrt sqrt = new StructId.Sqrt();
    141       StructId.Subtraction subtraction = new StructId.Subtraction();
    142       StructId.Tangens tangens = new StructId.Tangens();
    143       StructId.Xor xor = new StructId.Xor();
    144 
    145 
    146       List<IOperator> booleanFunctions = new List<IOperator>();
    147       ConditionalAddOperator(AND_ALLOWED, and, booleanFunctions);
    148       ConditionalAddOperator(EQUAL_ALLOWED, equal, booleanFunctions);
    149       ConditionalAddOperator(GREATERTHAN_ALLOWED, greaterThan, booleanFunctions);
    150       ConditionalAddOperator(LESSTHAN_ALLOWED, lessThan, booleanFunctions);
    151       ConditionalAddOperator(NOT_ALLOWED, not, booleanFunctions);
    152       ConditionalAddOperator(OR_ALLOWED, or, booleanFunctions);
    153       ConditionalAddOperator(XOR_ALLOWED, xor, booleanFunctions);
    154 
    155       List<IOperator> doubleFunctions = new List<IOperator>();
    156       ConditionalAddOperator(DIFFERENTIALS_ALLOWED, differential, doubleFunctions);
    157       ConditionalAddOperator(VARIABLES_ALLOWED, variable, doubleFunctions);
    158       ConditionalAddOperator(CONSTANTS_ALLOWED, constant, doubleFunctions);
    159       ConditionalAddOperator(ADDITION_ALLOWED, addition, doubleFunctions);
    160       ConditionalAddOperator(AVERAGE_ALLOWED, average, doubleFunctions);
    161       ConditionalAddOperator(COSINUS_ALLOWED, cosinus, doubleFunctions);
    162       ConditionalAddOperator(DIVISION_ALLOWED, division, doubleFunctions);
    163       ConditionalAddOperator(EXPONENTIAL_ALLOWED, exponential, doubleFunctions);
    164       ConditionalAddOperator(IFTHENELSE_ALLOWED, ifThenElse, doubleFunctions);
    165       ConditionalAddOperator(LOGARTIHM_ALLOWED, logarithm, doubleFunctions);
    166       ConditionalAddOperator(MULTIPLICATION_ALLOWED, multiplication, doubleFunctions);
    167       ConditionalAddOperator(POWER_ALLOWED, power, doubleFunctions);
    168       ConditionalAddOperator(SIGNUM_ALLOWED, signum, doubleFunctions);
    169       ConditionalAddOperator(SINUS_ALLOWED, sinus, doubleFunctions);
    170       ConditionalAddOperator(SQRT_ALLOWED, sqrt, doubleFunctions);
    171       ConditionalAddOperator(SUBTRACTION_ALLOWED, subtraction, doubleFunctions);
    172       ConditionalAddOperator(TANGENS_ALLOWED, tangens, doubleFunctions);
     119      Variable variable = new Variable();
     120      Constant constant = new Constant();
     121      Differential differential = new Differential();
     122      Addition addition = new Addition();
     123      And and = new And();
     124      Average average = new Average();
     125      Cosinus cosinus = new Cosinus();
     126      Division division = new Division();
     127      Equal equal = new Equal();
     128      Exponential exponential = new Exponential();
     129      GreaterThan greaterThan = new GreaterThan();
     130      IfThenElse ifThenElse = new IfThenElse();
     131      LessThan lessThan = new LessThan();
     132      Logarithm logarithm = new Logarithm();
     133      Multiplication multiplication = new Multiplication();
     134      Not not = new Not();
     135      Or or = new Or();
     136      Power power = new Power();
     137      Signum signum = new Signum();
     138      Sinus sinus = new Sinus();
     139      Sqrt sqrt = new Sqrt();
     140      Subtraction subtraction = new Subtraction();
     141      Tangens tangens = new Tangens();
     142      Xor xor = new Xor();
     143
     144
     145      List<IFunction> booleanFunctions = new List<IFunction>();
     146      ConditionalAddFunction(AND_ALLOWED, and, booleanFunctions);
     147      ConditionalAddFunction(EQUAL_ALLOWED, equal, booleanFunctions);
     148      ConditionalAddFunction(GREATERTHAN_ALLOWED, greaterThan, booleanFunctions);
     149      ConditionalAddFunction(LESSTHAN_ALLOWED, lessThan, booleanFunctions);
     150      ConditionalAddFunction(NOT_ALLOWED, not, booleanFunctions);
     151      ConditionalAddFunction(OR_ALLOWED, or, booleanFunctions);
     152      ConditionalAddFunction(XOR_ALLOWED, xor, booleanFunctions);
     153
     154      List<IFunction> doubleFunctions = new List<IFunction>();
     155      ConditionalAddFunction(DIFFERENTIALS_ALLOWED, differential, doubleFunctions);
     156      ConditionalAddFunction(VARIABLES_ALLOWED, variable, doubleFunctions);
     157      ConditionalAddFunction(CONSTANTS_ALLOWED, constant, doubleFunctions);
     158      ConditionalAddFunction(ADDITION_ALLOWED, addition, doubleFunctions);
     159      ConditionalAddFunction(AVERAGE_ALLOWED, average, doubleFunctions);
     160      ConditionalAddFunction(COSINUS_ALLOWED, cosinus, doubleFunctions);
     161      ConditionalAddFunction(DIVISION_ALLOWED, division, doubleFunctions);
     162      ConditionalAddFunction(EXPONENTIAL_ALLOWED, exponential, doubleFunctions);
     163      ConditionalAddFunction(IFTHENELSE_ALLOWED, ifThenElse, doubleFunctions);
     164      ConditionalAddFunction(LOGARTIHM_ALLOWED, logarithm, doubleFunctions);
     165      ConditionalAddFunction(MULTIPLICATION_ALLOWED, multiplication, doubleFunctions);
     166      ConditionalAddFunction(POWER_ALLOWED, power, doubleFunctions);
     167      ConditionalAddFunction(SIGNUM_ALLOWED, signum, doubleFunctions);
     168      ConditionalAddFunction(SINUS_ALLOWED, sinus, doubleFunctions);
     169      ConditionalAddFunction(SQRT_ALLOWED, sqrt, doubleFunctions);
     170      ConditionalAddFunction(SUBTRACTION_ALLOWED, subtraction, doubleFunctions);
     171      ConditionalAddFunction(TANGENS_ALLOWED, tangens, doubleFunctions);
    173172
    174173      SetAllowedSubOperators(and, booleanFunctions);
     
    196195      SetAllowedSubOperators(tangens, doubleFunctions);
    197196
    198       operatorLibrary = new GPOperatorLibrary();
    199       ConditionalAddOperator(DIFFERENTIALS_ALLOWED, operatorLibrary, differential);
    200       ConditionalAddOperator(VARIABLES_ALLOWED, operatorLibrary, variable);
    201       ConditionalAddOperator(CONSTANTS_ALLOWED, operatorLibrary, constant);
    202       ConditionalAddOperator(ADDITION_ALLOWED, operatorLibrary, addition);
    203       ConditionalAddOperator(AVERAGE_ALLOWED, operatorLibrary, average);
    204       ConditionalAddOperator(AND_ALLOWED, operatorLibrary, and);
    205       ConditionalAddOperator(COSINUS_ALLOWED, operatorLibrary, cosinus);
    206       ConditionalAddOperator(DIVISION_ALLOWED, operatorLibrary, division);
    207       ConditionalAddOperator(EQUAL_ALLOWED, operatorLibrary, equal);
    208       ConditionalAddOperator(EXPONENTIAL_ALLOWED, operatorLibrary, exponential);
    209       ConditionalAddOperator(GREATERTHAN_ALLOWED, operatorLibrary, greaterThan);
    210       ConditionalAddOperator(IFTHENELSE_ALLOWED, operatorLibrary, ifThenElse);
    211       ConditionalAddOperator(LESSTHAN_ALLOWED, operatorLibrary, lessThan);
    212       ConditionalAddOperator(LOGARTIHM_ALLOWED, operatorLibrary, logarithm);
    213       ConditionalAddOperator(MULTIPLICATION_ALLOWED, operatorLibrary, multiplication);
    214       ConditionalAddOperator(NOT_ALLOWED, operatorLibrary, not);
    215       ConditionalAddOperator(POWER_ALLOWED, operatorLibrary, power);
    216       ConditionalAddOperator(OR_ALLOWED, operatorLibrary, or);
    217       ConditionalAddOperator(SIGNUM_ALLOWED, operatorLibrary, signum);
    218       ConditionalAddOperator(SINUS_ALLOWED, operatorLibrary, sinus);
    219       ConditionalAddOperator(SQRT_ALLOWED, operatorLibrary, sqrt);
    220       ConditionalAddOperator(SUBTRACTION_ALLOWED, operatorLibrary, subtraction);
    221       ConditionalAddOperator(TANGENS_ALLOWED, operatorLibrary, tangens);
    222       ConditionalAddOperator(XOR_ALLOWED, operatorLibrary, xor);
     197      ConditionalAddOperator(DIFFERENTIALS_ALLOWED, functionLibrary, differential);
     198      ConditionalAddOperator(VARIABLES_ALLOWED, functionLibrary, variable);
     199      ConditionalAddOperator(CONSTANTS_ALLOWED, functionLibrary, constant);
     200      ConditionalAddOperator(ADDITION_ALLOWED, functionLibrary, addition);
     201      ConditionalAddOperator(AVERAGE_ALLOWED, functionLibrary, average);
     202      ConditionalAddOperator(AND_ALLOWED, functionLibrary, and);
     203      ConditionalAddOperator(COSINUS_ALLOWED, functionLibrary, cosinus);
     204      ConditionalAddOperator(DIVISION_ALLOWED, functionLibrary, division);
     205      ConditionalAddOperator(EQUAL_ALLOWED, functionLibrary, equal);
     206      ConditionalAddOperator(EXPONENTIAL_ALLOWED, functionLibrary, exponential);
     207      ConditionalAddOperator(GREATERTHAN_ALLOWED, functionLibrary, greaterThan);
     208      ConditionalAddOperator(IFTHENELSE_ALLOWED, functionLibrary, ifThenElse);
     209      ConditionalAddOperator(LESSTHAN_ALLOWED, functionLibrary, lessThan);
     210      ConditionalAddOperator(LOGARTIHM_ALLOWED, functionLibrary, logarithm);
     211      ConditionalAddOperator(MULTIPLICATION_ALLOWED, functionLibrary, multiplication);
     212      ConditionalAddOperator(NOT_ALLOWED, functionLibrary, not);
     213      ConditionalAddOperator(POWER_ALLOWED, functionLibrary, power);
     214      ConditionalAddOperator(OR_ALLOWED, functionLibrary, or);
     215      ConditionalAddOperator(SIGNUM_ALLOWED, functionLibrary, signum);
     216      ConditionalAddOperator(SINUS_ALLOWED, functionLibrary, sinus);
     217      ConditionalAddOperator(SQRT_ALLOWED, functionLibrary, sqrt);
     218      ConditionalAddOperator(SUBTRACTION_ALLOWED, functionLibrary, subtraction);
     219      ConditionalAddOperator(TANGENS_ALLOWED, functionLibrary, tangens);
     220      ConditionalAddOperator(XOR_ALLOWED, functionLibrary, xor);
    223221
    224222      variable.SetConstraints(minTimeOffset, maxTimeOffset);
    225223      differential.SetConstraints(minTimeOffset, maxTimeOffset);
    226224
    227       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary));
     225      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), functionLibrary));
    228226
    229227      return null;
    230228    }
    231229
    232     private void ConditionalAddOperator(string condName, IOperator op, List<IOperator> list) {
    233       if (GetVariableValue<BoolData>(condName, null, false).Data) list.Add(op);
    234     }
    235 
    236     private void ConditionalAddOperator(string condName, GPOperatorLibrary operatorLibrary, IOperator op) {
    237       if (GetVariableValue<BoolData>(condName, null, false).Data) operatorLibrary.GPOperatorGroup.AddOperator(op);
    238     }
    239 
    240     private void SetAllowedSubOperators(IFunction f, List<IOperator> gs) {
    241       foreach (IConstraint c in f.Constraints) {
    242         if (c is SubOperatorTypeConstraint) {
    243           SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    244           typeConstraint.Clear();
    245           foreach (IOperator g in gs) {
    246             typeConstraint.AddOperator(g);
    247           }
    248         } else if (c is AllSubOperatorsTypeConstraint) {
    249           AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    250           typeConstraint.Clear();
    251           foreach (IOperator g in gs) {
    252             typeConstraint.AddOperator(g);
    253           }
    254         }
     230    private void ConditionalAddFunction(string condName, IFunction fun, List<IFunction> list) {
     231      if (GetVariableValue<BoolData>(condName, null, false).Data) list.Add(fun);
     232    }
     233
     234    private void ConditionalAddOperator(string condName, FunctionLibrary functionLib, IFunction op) {
     235      if (GetVariableValue<BoolData>(condName, null, false).Data) functionLib.AddFunction(op);
     236    }
     237
     238    private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) {
     239      for (int i = 0; i < f.MaxArity; i++) {
     240        SetAllowedSubOperators(f, i, gs);
    255241      }
    256242    }
    257243
    258     private void SetAllowedSubOperators(IFunction f, int p, List<IOperator> gs) {
    259       foreach (IConstraint c in f.Constraints) {
    260         if (c is SubOperatorTypeConstraint) {
    261           SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    262           if (typeConstraint.SubOperatorIndex.Data == p) {
    263             typeConstraint.Clear();
    264             foreach (IOperator g in gs) {
    265               typeConstraint.AddOperator(g);
    266             }
    267           }
    268         }
    269       }
     244    private void SetAllowedSubOperators(IFunction f, int i, List<IFunction> gs) {
     245      gs.ForEach((g) => f.AddAllowedSubFunction(g, i));
    270246    }
    271247  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/GreaterThan.cs

    r1529 r2202  
    2727
    2828namespace HeuristicLab.GP.StructureIdentification {
    29   public sealed class GreaterThan : FunctionBase {
     29  public sealed class GreaterThan : BinaryFunction {
    3030    public override string Description {
    3131      get {
     
    3434    }
    3535
    36     public GreaterThan()
    37       : base() {
    38       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
    39       AddConstraint(new SubOperatorTypeConstraint(0));
    40       AddConstraint(new SubOperatorTypeConstraint(1));
    41     }
     36    public GreaterThan() : base() { }
    4237  }
    4338}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj

    r2041 r2202  
    8686    <Compile Include="Average.cs" />
    8787    <Compile Include="BakedTreeEvaluator.cs" />
     88    <Compile Include="BaseClasses\BinaryFunction.cs" />
     89    <Compile Include="BaseClasses\Terminal.cs" />
     90    <Compile Include="BaseClasses\UnaryFunction.cs" />
    8891    <Compile Include="Constant.cs" />
    8992    <Compile Include="AlgorithmBase.cs" />
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/IfThenElse.cs

    r1529 r2202  
    3838    public IfThenElse()
    3939      : base() {
    40       AddConstraint(new NumberOfSubOperatorsConstraint(3, 3));
    41       AddConstraint(new SubOperatorTypeConstraint(0));
    42       AddConstraint(new SubOperatorTypeConstraint(1));
    43       AddConstraint(new SubOperatorTypeConstraint(2));
     40      MinArity = 3; MaxArity = 3;
    4441    }
    4542  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/LessThan.cs

    r1529 r2202  
    2828
    2929namespace HeuristicLab.GP.StructureIdentification {
    30   public sealed class LessThan : FunctionBase {
     30  public sealed class LessThan : BinaryFunction {
    3131    public override string Description {
    3232      get {
     
    3737    public LessThan()
    3838      : base() {
    39       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    41       AddConstraint(new SubOperatorTypeConstraint(1));
    4239    }
    4340  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Logarithm.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Logarithm : FunctionBase {
     31  public sealed class Logarithm : UnaryFunction {
    3232    public override string Description {
    3333      get { return "Returns the natural (base e) logarithm of the first sub-tree."; }
     
    3636    public Logarithm()
    3737      : base() {
    38       // must have exactly 1 suboperator
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    4138    }
    4239  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Multiplication.cs

    r1529 r2202  
    4343      : base() {
    4444      // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)
    45       AddConstraint(new NumberOfSubOperatorsConstraint(2, 3));
    46       AddConstraint(new SubOperatorTypeConstraint(0));
    47       AddConstraint(new SubOperatorTypeConstraint(1));
    48       AddConstraint(new SubOperatorTypeConstraint(2));
     45      MinArity = 2; MaxArity = 3;
    4946    }
    5047  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Not.cs

    r1529 r2202  
    2828
    2929namespace HeuristicLab.GP.StructureIdentification {
    30   public sealed class Not : FunctionBase {
     30  public sealed class Not : UnaryFunction {
    3131    public override string Description {
    3232      get {
     
    3737    public Not()
    3838      : base() {
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    4139    }
    4240  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Or.cs

    r1529 r2202  
    3131    public override string Description {
    3232      get {
    33         return @"Logical OR operation. Only defined for sub-tree-results 0.0 and 1.0.
    34 Special form, evaluation stops at first sub-tree that evaluates to 1.0 (true).";
     33        return @"Logical OR operation. Only defined for sub-tree-results 0.0 and 1.0.";
    3534      }
    3635    }
     
    3837    public Or()
    3938      : base() {
    40       AddConstraint(new NumberOfSubOperatorsConstraint(2, 3));
    41       AddConstraint(new SubOperatorTypeConstraint(0));
    42       AddConstraint(new SubOperatorTypeConstraint(1));
    43       AddConstraint(new SubOperatorTypeConstraint(2));
     39      MinArity = 2; MaxArity = 3;
    4440    }
    4541  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Power.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Power : FunctionBase {
     31  public sealed class Power : BinaryFunction {
    3232    public override string Description {
    3333      get { return "Returns the result of the first sub-tree to the power of the second sub-tree (power(x, y))."; }
     
    3636    public Power()
    3737      : base() {
    38       // must have exactly 2 suboperators base ^ exponent
    39       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    41       AddConstraint(new SubOperatorTypeConstraint(1));
    4238    }
    4339  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Signum.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Signum : FunctionBase {
     31  public sealed class Signum : UnaryFunction {
    3232    public override string Description {
    3333      get { return "Returns the signum of the first sub-tree."; }
     
    3636    public Signum()
    3737      : base() {
    38       // must have exactly 1 suboperator
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    4138    }
    4239  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Sinus.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Sinus : FunctionBase {
     31  public sealed class Sinus : UnaryFunction {
    3232    public override string Description {
    3333      get { return "Returns the sinus of the first sub-tree."; }
     
    3636    public Sinus()
    3737      : base() {
    38       // must have exactly 1 suboperator
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    4138    }
    4239  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Sqrt.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Sqrt : FunctionBase {
     31  public sealed class Sqrt : UnaryFunction {
    3232    public override string Description {
    3333      get { return "Returns the square root of the first sub-tree."; }
     
    3636    public Sqrt()
    3737      : base() {
    38       // must have exactly 1 suboperator
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    4138    }
    4239  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Subtraction.cs

    r2054 r2202  
    3030
    3131namespace HeuristicLab.GP.StructureIdentification {
    32   public sealed class Subtraction : FunctionBase {
     32  public sealed class Subtraction : BinaryFunction {
    3333    public override string Description {
    3434      get {
     
    4242    public Subtraction()
    4343      : base() {
    44       // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)
    45       //MK changed to only 2 allowed suboperators to be compliant with HL2
    46       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
    47       AddConstraint(new SubOperatorTypeConstraint(0));
    48       AddConstraint(new SubOperatorTypeConstraint(1));
    4944    }
    5045  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Tangens.cs

    r1529 r2202  
    2929
    3030namespace HeuristicLab.GP.StructureIdentification {
    31   public sealed class Tangens : FunctionBase {
     31  public sealed class Tangens : UnaryFunction {
    3232    public override string Description {
    3333      get { return "Returns the tangens of the first sub-tree."; }
     
    3636    public Tangens()
    3737      : base() {
    38       // must have exactly one suboperator
    39       AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    4138    }
    4239  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs

    r2174 r2202  
    2828using System.Diagnostics;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.Data;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
     
    7879        case EvaluatorSymbolTable.DIFFERENTIAL:
    7980        case EvaluatorSymbolTable.VARIABLE: {
    80             instr.i_arg0 = (short)dataset.GetVariableIndex((string)f.localData[0]); // var
    81             instr.d_arg0 = (double)f.localData[1]; // weight
    82             instr.i_arg1 = (short)(int)f.localData[2]; // sample-offset
     81            instr.i_arg0 = (short)dataset.GetVariableIndex((((StringData)f.localData[1].Value).Data)); // var
     82            instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // weight
     83            instr.i_arg1 = (short)((ConstrainedIntData)f.localData[2].Value).Data; // sample-offset
    8384            break;
    8485          }
    8586        case EvaluatorSymbolTable.CONSTANT: {
    86             instr.d_arg0 = (double)f.localData[0]; // value
     87            instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // value
    8788            break;
    8889          }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Variable.cs

    r2174 r2202  
    3232
    3333namespace HeuristicLab.GP.StructureIdentification {
    34   public class Variable : FunctionBase {
    35 
     34  public class Variable : Terminal {   
    3635    public const string WEIGHT = "Weight";
    3736    public const string OFFSET = "SampleOffset";
    3837    public const string INDEX = "Variable";
     38
     39    private BakedFunctionTree variableNodeTemplate;
    3940
    4041    private int minOffset;
     
    4950    }
    5051
     52    public override IEnumerable<string> LocalParameterNames {
     53      get {
     54        return new string[] { WEIGHT, OFFSET, INDEX };
     55      }
     56    }
     57
     58    public override IFunctionTree GetTreeNode() {
     59      return (IFunctionTree)variableNodeTemplate.Clone();
     60    }
     61
    5162    public Variable()
    5263      : base() {
    53       AddVariableInfo(new VariableInfo(INDEX, "The variable name", typeof(StringData), VariableKind.None));
    54       GetVariableInfo(INDEX).Local = true;
    55       AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(DoubleData), VariableKind.None));
    56       GetVariableInfo(WEIGHT).Local = true;
    57       AddVariableInfo(new VariableInfo(OFFSET, "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None));
    58       GetVariableInfo(OFFSET).Local = true;
    59       AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator for variables", typeof(CombinedOperator), VariableKind.None));
    60       GetVariableInfo(INITIALIZATION).Local = false;
    61       AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator for variables", typeof(CombinedOperator), VariableKind.None));
    62       GetVariableInfo(MANIPULATION).Local = false;
     64      //AddVariableInfo(new VariableInfo(INDEX, "The variable name", typeof(StringData), VariableKind.None));
     65      //GetVariableInfo(INDEX).Local = true;
     66      //AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(DoubleData), VariableKind.None));
     67      //GetVariableInfo(WEIGHT).Local = true;
     68      //AddVariableInfo(new VariableInfo(OFFSET, "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None));
     69      //GetVariableInfo(OFFSET).Local = true;
     70      variableNodeTemplate = new BakedFunctionTree(this);
    6371
    6472      DoubleData weight = new DoubleData();
    65       AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight));
     73      variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight));
    6674
    6775      StringData variable = new StringData();
    68       AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));
     76      variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));
    6977
    7078      ConstrainedIntData sampleOffset = new ConstrainedIntData();
    71       AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));
     79      variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));
    7280
    7381      SetupInitialization();
    7482      SetupManipulation();
    75 
    76       // variable can't have suboperators
    77       AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
    7883    }
    7984
     
    104109      seq.AddSubOperator(weightRandomizer);
    105110      seq.AddSubOperator(offsetRandomizer);
    106       HeuristicLab.Core.IVariable initOp = GetVariable(INITIALIZATION);
    107       if(initOp == null) {
    108         AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));
    109       } else {
    110         initOp.Value = combinedOp;
    111       }
     111      Initializer = combinedOp;
    112112    }
    113113
     
    139139      seq.AddSubOperator(weightRandomAdder);
    140140      seq.AddSubOperator(offsetRandomAdder);
    141       HeuristicLab.Core.IVariable manipulationOp = GetVariable(MANIPULATION);
    142       if(manipulationOp == null) {
    143         AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
    144       } else {
    145         manipulationOp.Value = combinedOp;
    146       }
     141      Manipulator = combinedOp;
    147142    }
    148143
    149144    public void SetConstraints(int minSampleOffset, int maxSampleOffset) {
    150       ConstrainedIntData offset = GetVariableValue<ConstrainedIntData>(OFFSET, null, false);
     145      ConstrainedIntData offset = (ConstrainedIntData)variableNodeTemplate.GetLocalVariable(OFFSET).Value;
    151146      IntBoundedConstraint offsetConstraint = new IntBoundedConstraint();
    152147      this.minOffset = minSampleOffset;
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Xor.cs

    r1529 r2202  
    2828
    2929namespace HeuristicLab.GP.StructureIdentification {
    30   public sealed class Xor : FunctionBase {
     30  public sealed class Xor : BinaryFunction {
    3131    public override string Description {
    3232      get {
     
    3737    public Xor()
    3838      : base() {
    39       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
    40       AddConstraint(new SubOperatorTypeConstraint(0));
    41       AddConstraint(new SubOperatorTypeConstraint(1));
    4239    }
    4340  }
Note: See TracChangeset for help on using the changeset viewer.