Changeset 2216


Ignore:
Timestamp:
07/30/09 19:41:58 (12 years ago)
Author:
gkronber
Message:

GP Refactoring #713

  • cleaned code
  • reintegrated GP.Boolean and GP.SantaFe
  • worked on serialization of function trees
Location:
branches/GP-Refactoring-713/sources
Files:
6 added
41 edited
16 moved

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/BooleanTreeInterpreter.cs

    r2174 r2216  
    2424using System.Linq;
    2525using System.Text;
    26 using HeuristicLab.DataAnalysis;
    2726using HeuristicLab.Core;
    2827using System.Xml;
    2928using System.Diagnostics;
    3029using HeuristicLab.Data;
     30using HeuristicLab.GP.Interfaces;
     31using HeuristicLab.DataAnalysis;
    3132
    3233namespace HeuristicLab.GP.Boolean {
     
    3435    private const double EPSILON = 0.00001;
    3536    private Dataset dataset;
    36     private List<LightWeightFunction> expression;
     37    private IFunctionTree tree;
    3738    private int targetVariable;
    3839    private int currentRow;
    39     private int pc;
    4040
    41     public void Reset(Dataset dataset, BakedFunctionTree tree, int targetVariable) {
     41    public void Reset(Dataset dataset, IFunctionTree tree, int targetVariable) {
    4242      this.dataset = dataset;
    43       this.expression = tree.LinearRepresentation;
     43      this.tree = tree;
    4444      this.targetVariable = targetVariable;
    4545    }
     
    4848      int errors = 0;
    4949      for (int i = start; i < end; i++) {
    50         pc = 0;
    5150        currentRow = i;
    52         int result = Step() ? 1 : 0;
     51        int result = Step(tree) ? 1 : 0;
    5352        if (Math.Abs(result - dataset.GetValue(i, targetVariable)) > EPSILON) errors++;
    5453      }
     
    5655    }
    5756
    58     internal bool Step() {
    59       LightWeightFunction curFun = expression[pc++];
    60       int symbol = SymbolTable.MapFunction(curFun.functionType);
     57    internal bool Step(IFunctionTree t) {
     58      int symbol = SymbolTable.MapFunction(t.Function);
    6159      switch (symbol) {
    62         case SymbolTable.AND: return Step() & Step();
    63         case SymbolTable.OR: return Step() | Step();
    64         case SymbolTable.NOT: return !Step();
    65         case SymbolTable.XOR: return Step() ^ Step();
    66         case SymbolTable.NAND: return !(Step() & Step());
    67         case SymbolTable.NOR: return !(Step() | Step());
    68         case SymbolTable.VARIABLE:
    69           return dataset.GetValue(currentRow, (int)curFun.localData[0]) != 0.0;
     60        case SymbolTable.AND: return Step(t.SubTrees[0]) && Step(t.SubTrees[1]);
     61        case SymbolTable.OR: return Step(t.SubTrees[0]) || Step(t.SubTrees[1]);
     62        case SymbolTable.NOT: return !Step(t.SubTrees[0]);
     63        case SymbolTable.XOR: return Step(t.SubTrees[0]) ^ Step(t.SubTrees[1]);
     64        case SymbolTable.NAND: return !(Step(t.SubTrees[0]) && Step(t.SubTrees[1]));
     65        case SymbolTable.NOR: return !(Step(t.SubTrees[0]) || Step(t.SubTrees[1]));
     66        case SymbolTable.VARIABLE: {
     67            var varNode = (VariableFunctionTree)t;
     68            int index = dataset.GetVariableIndex(varNode.VariableName);
     69            return !IsAlmost(dataset.GetValue(currentRow, index), 0.0);
     70          }
    7071        case SymbolTable.UNKNOWN:
    7172        default:
    72           throw new InvalidOperationException(curFun.functionType.ToString());
     73          throw new UnknownFunctionException(t.Function.Name);
     74      }
     75    }
    7376
    74       }
     77    private bool IsAlmost(double x, double y) {
     78      return Math.Abs(x - y) < EPSILON;
    7579    }
    7680  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Evaluator.cs

    r1529 r2216  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.GP.Interfaces;
    2829using HeuristicLab.DataAnalysis;
    2930
     
    3233    public Evaluator()
    3334      : base() {
    34       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the ant", typeof(BakedFunctionTree), VariableKind.In));
     35      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the boolean expression to evaluate", typeof(IGeneticProgrammingModel), VariableKind.In));
    3536      AddVariableInfo(new VariableInfo("Dataset", "The boolean dataset (values 0.0 = false, 1.0=true)", typeof(Dataset), VariableKind.In));
    3637      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
     
    4142
    4243    public override IOperation Apply(IScope scope) {
    43       BakedFunctionTree tree = GetVariableValue<BakedFunctionTree>("FunctionTree", scope, true);
     44      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true);
    4445      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    4546      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     
    4849
    4950      BooleanTreeInterpreter interpreter = new BooleanTreeInterpreter();
    50       interpreter.Reset(dataset, tree, targetVariable);
     51      interpreter.Reset(dataset, gpModel.FunctionTree, targetVariable);
    5152      int errors = interpreter.GetNumberOfErrors(start, end);
    5253
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/FunctionLibraryInjector.cs

    r2202 r2216  
    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 FunctionLibrary 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(FunctionLibrary), 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 FunctionLibrary();
    85       operatorLibrary.FunctionGroup.AddFunction(and);
    86       operatorLibrary.FunctionGroup.AddFunction(or);
    87       //operatorLibrary.GPOperatorGroup.AddOperator(not);
    88       operatorLibrary.FunctionGroup.AddFunction(nand);
    89       operatorLibrary.FunctionGroup.AddFunction(nor);
    90       //operatorLibrary.GPOperatorGroup.AddOperator(xor);
    91       operatorLibrary.FunctionGroup.AddFunction(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  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/HeuristicLab.GP.Boolean-3.3.csproj

    r1534 r2216  
    8181  <ItemGroup>
    8282    <Compile Include="BooleanTreeInterpreter.cs" />
    83     <Compile Include="Not.cs" />
    84     <Compile Include="Xor.cs" />
    85     <Compile Include="Or.cs" />
    86     <Compile Include="Nand.cs" />
    87     <Compile Include="Nor.cs" />
     83    <Compile Include="Symbols\And.cs" />
     84    <Compile Include="Symbols\Nand.cs" />
     85    <Compile Include="Symbols\Nor.cs" />
     86    <Compile Include="Symbols\Not.cs" />
     87    <Compile Include="Symbols\Or.cs" />
     88    <Compile Include="Symbols\SymbolTable.cs" />
     89    <Compile Include="Symbols\Variable.cs" />
     90    <Compile Include="Symbols\VariableFunctionTree.cs" />
     91    <Compile Include="Symbols\Xor.cs" />
    8892    <Compile Include="Evaluator.cs" />
    8993    <Compile Include="FunctionLibraryInjector.cs" />
    9094    <Compile Include="HeuristicLabGPBooleanPlugin.cs" />
    91     <Compile Include="And.cs" />
    92     <Compile Include="Variable.cs" />
    9395    <Compile Include="Properties\AssemblyInfo.cs" />
    94     <Compile Include="SymbolTable.cs" />
    9596  </ItemGroup>
    9697  <ItemGroup>
     
    99100  </ItemGroup>
    100101  <ItemGroup>
    101     <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">
    102       <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>
    103       <Name>HeuristicLab.Constraints-3.2</Name>
    104     </ProjectReference>
    105102    <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    106103      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
     
    114111      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
    115112      <Name>HeuristicLab.Data-3.2</Name>
     113    </ProjectReference>
     114    <ProjectReference Include="..\..\HeuristicLab.GP.Interfaces\3.3\HeuristicLab.GP.Interfaces-3.3.csproj">
     115      <Project>{924B6BEA-9A99-40FE-9334-5C01E8D540EC}</Project>
     116      <Name>HeuristicLab.GP.Interfaces-3.3</Name>
    116117    </ProjectReference>
    117118    <ProjectReference Include="..\..\HeuristicLab.GP\3.3\HeuristicLab.GP-3.3.csproj">
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/HeuristicLabGPBooleanPlugin.cs

    r1529 r2216  
    2828  [ClassInfo(Name = "HeuristicLab.GP.Boolean-3.3")]
    2929  [PluginFile(Filename = "HeuristicLab.GP.Boolean-3.3.dll", Filetype = PluginFileType.Assembly)]
    30   [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]
    31   [Dependency(Dependency = "HeuristicLab.GP-3.3")]
    3230  [Dependency(Dependency = "HeuristicLab.Core-3.2")]
    3331  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
    3432  [Dependency(Dependency = "HeuristicLab.DataAnalysis-3.2")]
     33  [Dependency(Dependency = "HeuristicLab.GP-3.3")]
     34  [Dependency(Dependency = "HeuristicLab.GP.Interfaces-3.3")]
    3535  [Dependency(Dependency = "HeuristicLab.Operators-3.2")]
    3636  [Dependency(Dependency = "HeuristicLab.Random-3.2")]
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/And.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    3022
    3123namespace HeuristicLab.GP.Boolean{
    32   public sealed class And : FunctionBase {
    33 
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public And()
    39       : base() {
    40       MinArity = 2; MaxArity = 2;
    41     }
     24  public sealed class And : BinaryFunction {
    4225  }
    4326}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Nand.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    3022
    3123namespace HeuristicLab.GP.Boolean{
    32   public sealed class Nand : FunctionBase {
    33 
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public Nand()
    39       : base() {
    40       MinArity = 2; MaxArity = 2;
    41     }
     24  public sealed class Nand : BinaryFunction {
    4225  }
    4326}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Nor.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 
    3122namespace HeuristicLab.GP.Boolean{
    32   public sealed class Nor : FunctionBase {
    33 
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public Nor()
    39       : base() {
    40       MinArity = 2; MaxArity = 2;
    41     }
     23  public sealed class Nor : BinaryFunction {
    4224  }
    4325}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Not.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 
    3122namespace HeuristicLab.GP.Boolean{
    32   public sealed class Not : FunctionBase {
    33 
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public Not()
    39       : base() {
    40       MinArity = 1; MaxArity = 1;
    41     }
     23  public sealed class Not : UnaryFunction {
    4224  }
    4325}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Or.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 
    3122namespace HeuristicLab.GP.Boolean{
    32   public sealed class Or : FunctionBase {
    33 
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public Or()
    39       : base() {
    40       MinArity = 2; MaxArity = 2;
    41     }
     23  public sealed class Or : BinaryFunction {
    4224  }
    4325}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/SymbolTable.cs

    r2211 r2216  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Core;
    27 using System.Xml;
     25using HeuristicLab.GP.Interfaces;
    2826
    2927namespace HeuristicLab.GP.Boolean {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Variable.cs

    r2211 r2216  
    2626using HeuristicLab.Core;
    2727using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    3028using HeuristicLab.Operators;
    3129using HeuristicLab.Random;
    3230
    3331namespace HeuristicLab.GP.Boolean {
    34   public sealed class Variable : FunctionBase {
    35     public const string INDEX = "Variable";
    36 
    37     private int minIndex;
    38     private int maxIndex;
    39 
    40     public override string Description {
    41       get { return ""; }
    42     }
     32  public sealed class Variable : Terminal {
     33    public const string VARIABLENAME = "Variable";
    4334
    4435    public Variable()
    4536      : base() {
    46       AddVariableInfo(new VariableInfo(INDEX, "Index of the variable in the dataset representing this feature", typeof(ConstrainedIntData), VariableKind.None));
    47       GetVariableInfo(INDEX).Local = true;
    48       AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator for variables", typeof(CombinedOperator), VariableKind.None));
    49       GetVariableInfo(INITIALIZATION).Local = false;
    50       AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator for variables", typeof(CombinedOperator), VariableKind.None));
    51       GetVariableInfo(MANIPULATION).Local = false;
    52 
    53       MinArity = 0; MaxArity = 0;
    54 
    55       ConstrainedIntData variable = new ConstrainedIntData();
    56       AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));
    57       minIndex = 0; maxIndex = 100;
    58 
    5937      SetupInitialization();
    6038      SetupManipulation();
     39    }
    6140
     41    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     42      return new VariableFunctionTree(this);
    6243    }
    6344
     
    6546      CombinedOperator combinedOp = new CombinedOperator();
    6647      SequentialProcessor seq = new SequentialProcessor();
    67       UniformRandomizer indexRandomizer = new UniformRandomizer();
    68       indexRandomizer.Min = minIndex;
    69       indexRandomizer.Max = maxIndex + 1; // uniform randomizer generates numbers in the range [min, max[
    70       indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
    71       indexRandomizer.Name = "Index Randomizer";
     48      UniformItemChooser variableRandomizer = new UniformItemChooser();
     49      variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
     50      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
     51      variableRandomizer.Name = "Variable randomizer";
    7252
    7353      combinedOp.OperatorGraph.AddOperator(seq);
    74       combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     54      combinedOp.OperatorGraph.AddOperator(variableRandomizer);
    7555      combinedOp.OperatorGraph.InitialOperator = seq;
    76       seq.AddSubOperator(indexRandomizer);
     56      seq.AddSubOperator(variableRandomizer);
    7757      Initializer = combinedOp;
    7858    }
     
    8262      CombinedOperator combinedOp = new CombinedOperator();
    8363      SequentialProcessor seq = new SequentialProcessor();
    84       UniformRandomizer indexRandomizer = new UniformRandomizer();
    85       indexRandomizer.Min = minIndex;
    86       indexRandomizer.Max = maxIndex + 1;
    87       indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
    88       indexRandomizer.Name = "Index Randomizer";
     64      UniformItemChooser variableRandomizer = new UniformItemChooser();
     65      variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
     66      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
     67      variableRandomizer.Name = "Variable randomizer";
    8968
    9069      combinedOp.OperatorGraph.AddOperator(seq);
    91       combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     70      combinedOp.OperatorGraph.AddOperator(variableRandomizer);
    9271      combinedOp.OperatorGraph.InitialOperator = seq;
    93       seq.AddSubOperator(indexRandomizer);
     72      seq.AddSubOperator(variableRandomizer);
    9473      Manipulator = combinedOp;
    95     }
    96 
    97     public void SetConstraints(int[] allowedIndexes) {
    98       //ConstrainedIntData index = GetVariableValue<ConstrainedIntData>(INDEX, null, false);
    99       Array.Sort(allowedIndexes);
    100       minIndex = allowedIndexes[0]; maxIndex = allowedIndexes[allowedIndexes.Length - 1];
    101       List<IConstraint> constraints = new List<IConstraint>();
    102       int start = allowedIndexes[0];
    103       int prev = start;
    104       for(int i = 1; i < allowedIndexes.Length; i++) {
    105         if(allowedIndexes[i] != prev + 1) {
    106           IntBoundedConstraint lastRange = new IntBoundedConstraint();
    107           lastRange.LowerBound = start;
    108           lastRange.LowerBoundEnabled = true;
    109           lastRange.LowerBoundIncluded = true;
    110           lastRange.UpperBound = prev;
    111           lastRange.UpperBoundEnabled = true;
    112           lastRange.UpperBoundIncluded = true;
    113           constraints.Add(lastRange);
    114           start = allowedIndexes[i];
    115           prev = start;
    116         }
    117         prev = allowedIndexes[i];
    118       }
    119       IntBoundedConstraint range = new IntBoundedConstraint();
    120       range.LowerBound = start;
    121       range.LowerBoundEnabled = true;
    122       range.LowerBoundIncluded = true;
    123       range.UpperBound = prev;
    124       range.UpperBoundEnabled = true;
    125       range.UpperBoundIncluded = true;
    126       constraints.Add(range);
    127       if(constraints.Count > 1) {
    128         OrConstraint or = new OrConstraint();
    129         foreach(IConstraint c in constraints) or.Clauses.Add(c);
    130         index.AddConstraint(or);
    131       } else {
    132         index.AddConstraint(constraints[0]);
    133       }
    134 
    135       SetupInitialization();
    136       SetupManipulation();
    13774    }
    13875  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Xor.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 
    3122namespace HeuristicLab.GP.Boolean{
    32   public sealed class Xor : FunctionBase {
    33 
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public Xor()
    39       : base() {
    40       MinArity = 2; MaxArity = 2;
    41     }
     23  public sealed class Xor : BinaryFunction {
    4224  }
    4325}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Interfaces/3.3/HeuristicLab.GP.Interfaces-3.3.csproj

    r2210 r2216  
    8383      <SubType>Code</SubType>
    8484    </Compile>
     85    <Compile Include="IFunctionTreeSerializer.cs" />
    8586    <Compile Include="IGeneticProgrammingModel.cs" />
    8687    <Compile Include="HeuristicLabGPInterfacesPlugin.cs" />
    8788    <Compile Include="IFunction.cs" />
    8889    <Compile Include="IFunctionTree.cs" />
    89     <Compile Include="IFunctionTreeExporter.cs" />
    9090    <Compile Include="Properties\AssemblyInfo.cs" />
    9191  </ItemGroup>
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Interfaces/3.3/IFunctionTreeSerializer.cs

    r2211 r2216  
    2626
    2727namespace HeuristicLab.GP.Interfaces {
    28   public interface IFunctionTreeExporter {
     28  public interface IFunctionTreeSerializer {
    2929    string Name { get; }
    3030    string Export(IFunctionTree tree);
    3131    bool TryExport(IFunctionTree tree, out string exported);
     32    IFunctionTree Import(string tree);
     33    bool TryImport(string tree, out IFunctionTree importedTree);
    3234  }
    3335}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/AntInterpreter.cs

    r1529 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using HeuristicLab.DataAnalysis;
    27 using HeuristicLab.Core;
    28 using System.Xml;
    29 using System.Diagnostics;
     23using HeuristicLab.GP.Interfaces;
    3024
    3125namespace HeuristicLab.GP.SantaFe {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Evaluator.cs

    r1529 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Data;
    28 using HeuristicLab.DataAnalysis;
     24using HeuristicLab.GP.Interfaces;
    2925
    3026namespace HeuristicLab.GP.SantaFe {
     
    3228    public Evaluator()
    3329      : base() {
    34       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the ant", typeof(IFunctionTree), VariableKind.In));
     30      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the ant", typeof(IGeneticProgrammingModel), VariableKind.In));
    3531      AddVariableInfo(new VariableInfo("FoodEaten", "Number of food items that the ant found", typeof(DoubleData), VariableKind.New | VariableKind.Out));
    3632    }
    3733
    3834    public override IOperation Apply(IScope scope) {
    39       IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, false);
     35      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, false);
    4036      AntInterpreter interpreter = new AntInterpreter();
    4137      interpreter.MaxTimeSteps = 600;
    42       interpreter.Run(tree);
     38      interpreter.Run(gpModel.FunctionTree);
    4339
    4440      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FoodEaten"), new DoubleData(interpreter.FoodEaten)));
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/FunctionLibraryInjector.cs

    r2202 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    26 using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    28 using HeuristicLab.DataAnalysis;
    29 using HeuristicLab.Constraints;
     22using HeuristicLab.GP.Interfaces;
    3023
    3124namespace HeuristicLab.GP.SantaFe {
    32   public class FunctionLibraryInjector : OperatorBase {
    33     private const string OPERATORLIBRARY = "FunctionLibrary";
    34 
    35     private FunctionLibrary operatorLibrary;
     25  public class FunctionLibraryInjector : FunctionLibraryInjectorBase {
    3626
    3727    public override string Description {
     
    4131    public FunctionLibraryInjector()
    4232      : base() {
    43       AddVariableInfo(new VariableInfo(OPERATORLIBRARY, "Preconfigured default operator library", typeof(FunctionLibrary), VariableKind.New));
    4433    }
    4534
    46     public override IOperation Apply(IScope scope) {
    47       InitDefaultOperatorLibrary();
    48       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OPERATORLIBRARY), operatorLibrary));
    49       return null;
    50     }
    51 
    52     private void InitDefaultOperatorLibrary() {
     35    protected override FunctionLibrary CreateFunctionLibrary() {
     36      FunctionLibrary funLib = new FunctionLibrary();
    5337      IfFoodAhead ifFoodAhead = new IfFoodAhead();
    5438      Prog2 prog2 = new Prog2();
     
    7155      SetAllowedSubOperators(prog3, allFunctions);
    7256
    73       operatorLibrary = new FunctionLibrary();
    74       operatorLibrary.FunctionGroup.AddFunction(ifFoodAhead);
    75       operatorLibrary.FunctionGroup.AddFunction(prog2);
    76       operatorLibrary.FunctionGroup.AddFunction(prog3);
    77       operatorLibrary.FunctionGroup.AddFunction(move);
    78       operatorLibrary.FunctionGroup.AddFunction(left);
    79       operatorLibrary.FunctionGroup.AddFunction(right);
    80     }
    81 
    82     private void SetAllowedSubOperators(IFunction f, IFunction[] gs) {
    83       foreach(IConstraint c in f.Constraints) {
    84         if(c is SubOperatorTypeConstraint) {
    85           SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    86           typeConstraint.Clear();
    87           foreach(IFunction g in gs) {
    88             typeConstraint.AddOperator(g);
    89           }
    90         } else if(c is AllSubOperatorsTypeConstraint) {
    91           AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    92           typeConstraint.Clear();
    93           foreach(IFunction g in gs) {
    94             typeConstraint.AddOperator(g);
    95           }
    96         }
    97       }
     57      funLib.AddFunction(ifFoodAhead);
     58      funLib.AddFunction(prog2);
     59      funLib.AddFunction(prog3);
     60      funLib.AddFunction(move);
     61      funLib.AddFunction(left);
     62      funLib.AddFunction(right);
     63      return funLib;
    9864    }
    9965  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/HeuristicLab.GP.SantaFe-3.3.csproj

    r1534 r2216  
    8383    <Compile Include="AntInterpreter.cs" />
    8484    <Compile Include="FunctionLibraryInjector.cs" />
    85     <Compile Include="Prog3.cs" />
    86     <Compile Include="Prog2.cs" />
    87     <Compile Include="IfFoodAhead.cs" />
    88     <Compile Include="Right.cs" />
    89     <Compile Include="Left.cs" />
    90     <Compile Include="Move.cs" />
    9185    <Compile Include="HeuristicLabGPSantaFePlugin.cs" />
    9286    <Compile Include="Properties\AssemblyInfo.cs" />
    9387    <Compile Include="Evaluator.cs" />
    94     <Compile Include="SymbolTable.cs" />
     88    <Compile Include="Symbols\IfFoodAhead.cs" />
     89    <Compile Include="Symbols\Left.cs" />
     90    <Compile Include="Symbols\Move.cs" />
     91    <Compile Include="Symbols\Prog2.cs" />
     92    <Compile Include="Symbols\Prog3.cs" />
     93    <Compile Include="Symbols\Right.cs" />
     94    <Compile Include="Symbols\SymbolTable.cs" />
    9595  </ItemGroup>
    9696  <ItemGroup>
    97     <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">
    98       <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>
    99       <Name>HeuristicLab.Constraints-3.2</Name>
    100     </ProjectReference>
    10197    <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    10298      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    10399      <Name>HeuristicLab.Core-3.2</Name>
    104100    </ProjectReference>
    105     <ProjectReference Include="..\..\HeuristicLab.DataAnalysis\3.2\HeuristicLab.DataAnalysis-3.2.csproj">
    106       <Project>{7DD3A97A-56E9-462F-90E2-A351FE7AF5C2}</Project>
    107       <Name>HeuristicLab.DataAnalysis-3.2</Name>
    108     </ProjectReference>
    109101    <ProjectReference Include="..\..\HeuristicLab.Data\3.2\HeuristicLab.Data-3.2.csproj">
    110102      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
    111103      <Name>HeuristicLab.Data-3.2</Name>
     104    </ProjectReference>
     105    <ProjectReference Include="..\..\HeuristicLab.GP.Interfaces\3.3\HeuristicLab.GP.Interfaces-3.3.csproj">
     106      <Project>{924B6BEA-9A99-40FE-9334-5C01E8D540EC}</Project>
     107      <Name>HeuristicLab.GP.Interfaces-3.3</Name>
    112108    </ProjectReference>
    113109    <ProjectReference Include="..\..\HeuristicLab.GP\3.3\HeuristicLab.GP-3.3.csproj">
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/HeuristicLabGPSantaFePlugin.cs

    r1529 r2216  
    2828  [ClassInfo(Name = "HeuristicLab.GP.SantaFe-3.3")]
    2929  [PluginFile(Filename = "HeuristicLab.GP.SantaFe-3.3.dll", Filetype = PluginFileType.Assembly)]
    30   [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]
    31   [Dependency(Dependency = "HeuristicLab.GP-3.3")]
    3230  [Dependency(Dependency = "HeuristicLab.Core-3.2")]
    3331  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
     32  [Dependency(Dependency = "HeuristicLab.GP-3.3")]
     33  [Dependency(Dependency = "HeuristicLab.GP.Interfaces-3.3")]
    3434  [Dependency(Dependency = "HeuristicLab.DataAnalysis-3.2")]
    3535  [Dependency(Dependency = "HeuristicLab.Random-3.2")]
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/IfFoodAhead.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class IfFoodAhead : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public IfFoodAhead()
    40       : base() {
    41       MinArity = 2; MaxArity = 2;
    42     }
     23  public sealed class IfFoodAhead : BinaryFunction {
    4324  }
    4425}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Left.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Left : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public Left()
    40       : base() {
    41       MinArity = 0; MaxArity = 0;
    42     }
     23  public sealed class Left : Terminal {
    4324  }
    4425}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Move.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Move : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public Move()
    40       : base() {
    41       MinArity = 0; MaxArity = 0;
    42     }
     23  public sealed class Move : Terminal {
    4324  }
    4425}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Prog2.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    3122
    3223namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Prog2 : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public Prog2()
    40       : base() {
    41       MinArity = 2; MaxArity = 2;
    42     }
     24  public sealed class Prog2 : BinaryFunction {
    4325  }
    4426}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Prog3.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    3323  public sealed class Prog3 : FunctionBase {
    3424
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    3925    public Prog3()
    4026      : base() {
    41       MinArity = 3; MaxArity = 3;
     27      MinSubTrees = 3; MaxSubTrees = 3;
    4228    }
    4329  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Right.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Right : FunctionBase {
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public Right()
    39       : base() {
    40       MinArity = 0; MaxArity = 0;
    41     }
     23  public sealed class Right : Terminal {
    4224  }
    4325}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/SymbolTable.cs

    r2211 r2216  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Core;
    27 using System.Xml;
     25using HeuristicLab.GP.Interfaces;
    2826
    2927namespace HeuristicLab.GP.SantaFe {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/AccuracyEvaluator.cs

    r1891 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    28 using HeuristicLab.GP.StructureIdentification;
    2925using HeuristicLab.DataAnalysis;
    3026
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/ClassificationMeanSquaredErrorEvaluator.cs

    r1891 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    28 using HeuristicLab.GP.StructureIdentification;
    2925
    3026namespace HeuristicLab.GP.StructureIdentification.Classification {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/ConfusionMatrixEvaluator.cs

    r1891 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Data;
    28 using HeuristicLab.GP.StructureIdentification;
    2924
    3025namespace HeuristicLab.GP.StructureIdentification.Classification {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/CrossValidation.cs

    r1529 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    2825using HeuristicLab.DataAnalysis;
    2926
    30 namespace HeuristicLab.GP.StructureIdentification.Classification
    31 {
    32     public class CrossValidation : OperatorBase
    33     {
     27namespace HeuristicLab.GP.StructureIdentification.Classification {
     28  public class CrossValidation : OperatorBase {
    3429
    35         private const string DATASET = "Dataset";
    36         private const string NFOLD = "n-Fold";
    37         private const string TRAININGSAMPLESSTART = "TrainingSamplesStart";
    38         private const string TRAININGSAMPLESEND = "TrainingSamplesEnd";
    39         private const string VALIDATIONSAMPLESSTART = "ValidationSamplesStart";
    40         private const string VALIDATIONSAMPLESEND = "ValidationSamplesEnd";
    41         private const string TESTSAMPLESSTART = "TestSamplesStart";
    42         private const string TESTSAMPLESEND = "TestSamplesEnd";
     30    private const string DATASET = "Dataset";
     31    private const string NFOLD = "n-Fold";
     32    private const string TRAININGSAMPLESSTART = "TrainingSamplesStart";
     33    private const string TRAININGSAMPLESEND = "TrainingSamplesEnd";
     34    private const string VALIDATIONSAMPLESSTART = "ValidationSamplesStart";
     35    private const string VALIDATIONSAMPLESEND = "ValidationSamplesEnd";
     36    private const string TESTSAMPLESSTART = "TestSamplesStart";
     37    private const string TESTSAMPLESEND = "TestSamplesEnd";
    4338
    44         public override string Description
    45         {
    46             get { return @"TASK"; }
    47         }
     39    public override string Description {
     40      get { return @"TASK"; }
     41    }
    4842
    49         public CrossValidation()
    50             : base()
    51         {
    52             AddVariableInfo(new VariableInfo(DATASET, "The original dataset and the new datasets in the newly created subscopes", typeof(Dataset), VariableKind.In));
    53             AddVariableInfo(new VariableInfo(NFOLD, "Number of folds for the cross-validation", typeof(IntData), VariableKind.In));
    54             AddVariableInfo(new VariableInfo(TRAININGSAMPLESSTART, "The start of training samples in the original dataset and starts of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
    55             AddVariableInfo(new VariableInfo(TRAININGSAMPLESEND, "The end of training samples in the original dataset and ends of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
    56             AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESSTART, "The start of validation samples in the original dataset and starts of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
    57             AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESEND, "The end of validation samples in the original dataset and ends of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
    58             AddVariableInfo(new VariableInfo(TESTSAMPLESSTART, "The start of the test samples in the new datasets", typeof(IntData), VariableKind.New));
    59             AddVariableInfo(new VariableInfo(TESTSAMPLESEND, "The end of the test samples in the new datasets", typeof(IntData), VariableKind.New));
    60         }
     43    public CrossValidation()
     44      : base() {
     45      AddVariableInfo(new VariableInfo(DATASET, "The original dataset and the new datasets in the newly created subscopes", typeof(Dataset), VariableKind.In));
     46      AddVariableInfo(new VariableInfo(NFOLD, "Number of folds for the cross-validation", typeof(IntData), VariableKind.In));
     47      AddVariableInfo(new VariableInfo(TRAININGSAMPLESSTART, "The start of training samples in the original dataset and starts of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
     48      AddVariableInfo(new VariableInfo(TRAININGSAMPLESEND, "The end of training samples in the original dataset and ends of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
     49      AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESSTART, "The start of validation samples in the original dataset and starts of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
     50      AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESEND, "The end of validation samples in the original dataset and ends of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
     51      AddVariableInfo(new VariableInfo(TESTSAMPLESSTART, "The start of the test samples in the new datasets", typeof(IntData), VariableKind.New));
     52      AddVariableInfo(new VariableInfo(TESTSAMPLESEND, "The end of the test samples in the new datasets", typeof(IntData), VariableKind.New));
     53    }
    6154
    62         public override IOperation Apply(IScope scope) {
     55    public override IOperation Apply(IScope scope) {
    6356      Dataset origDataset = GetVariableValue<Dataset>(DATASET, scope, true);
    6457      int nFolds = GetVariableValue<IntData>(NFOLD, scope, true).Data;
    65       if (nFolds < 2) throw new ArgumentException("The number of folds (nFolds) has to be >=2 for cross validation"); 
     58      if (nFolds < 2) throw new ArgumentException("The number of folds (nFolds) has to be >=2 for cross validation");
    6659      int origTrainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data;
    6760      int origTrainingSamplesEnd = GetVariableValue<IntData>(TRAININGSAMPLESEND, scope, true).Data;
    6861      int origValidationSamplesStart = GetVariableValue<IntData>(VALIDATIONSAMPLESSTART, scope, true).Data;
    6962      int origValidationSamplesEnd = GetVariableValue<IntData>(VALIDATIONSAMPLESEND, scope, true).Data;
    70       int n=origDataset.Rows;
    71       int origTrainingSamples = (origTrainingSamplesEnd-origTrainingSamplesStart);
    72       int origValidationSamples = (origValidationSamplesEnd-origValidationSamplesStart);
     63      int n = origDataset.Rows;
     64      int origTrainingSamples = (origTrainingSamplesEnd - origTrainingSamplesStart);
     65      int origValidationSamples = (origValidationSamplesEnd - origValidationSamplesStart);
    7366
    7467      double percentTrainingSamples = origTrainingSamples / (double)(origValidationSamples + origTrainingSamples);
     
    8275      int newTestSamplesEnd = n;
    8376
    84       for(int i = 0; i < nFolds; i++) {
     77      for (int i = 0; i < nFolds; i++) {
    8578        Scope childScope = new Scope(i.ToString());
    8679        Dataset rotatedSet = new Dataset();
     
    10699    }
    107100
    108         private void RotateArray(double[] samples, int p)
    109         {
    110             Array.Reverse(samples, 0, p);
    111             Array.Reverse(samples, p, samples.Length - p);
    112             Array.Reverse(samples);
    113         }
     101    private void RotateArray(double[] samples, int p) {
     102      Array.Reverse(samples, 0, p);
     103      Array.Reverse(samples, p, samples.Length - p);
     104      Array.Reverse(samples);
    114105    }
     106  }
    115107}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/GPClassificationEvaluatorBase.cs

    r1891 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    28 using HeuristicLab.GP.StructureIdentification;
    2925using HeuristicLab.DataAnalysis;
    3026
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/HeuristicLabGPClassificationPlugin.cs

    r2210 r2216  
    2828  [ClassInfo(Name = "HeuristicLab.GP.StructureIdentification.Classification-3.3")]
    2929  [PluginFile(Filename = "HeuristicLab.GP.StructureIdentification.Classification-3.3.dll", Filetype = PluginFileType.Assembly)]
    30   [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]
    3130  [Dependency(Dependency = "HeuristicLab.Core-3.2")]
    3231  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassModeller.cs

    r1529 r2216  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2624using HeuristicLab.Core;
    2725using HeuristicLab.Data;
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassOneVsOneAnalyzer.cs

    r2211 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    2825using HeuristicLab.DataAnalysis;
    29 using HeuristicLab.GP.StructureIdentification;
    3026using HeuristicLab.GP.Interfaces;
    3127
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/OffspringSelectionGP.cs

    r2161 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    27 using System.Xml;
    28 using System.Diagnostics;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 using HeuristicLab.Data;
    3223using HeuristicLab.Modeling;
    3324
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/ROCAnalyzer.cs

    r1529 r2216  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Core;
    2725using HeuristicLab.Data;
    28 using HeuristicLab.DataAnalysis;
    2926
    3027
     
    8986      foreach (double key in classes.Keys)
    9087        classes[key].Sort();
    91  
     88
    9289      //calculate ROC Curve
    9390      foreach (double key in classes.Keys) {
     
    133130          }
    134131        }
    135           myAucValues.Add(new DoubleData(bestAUC));
    136           myRocValues.Add(Convert(bestROC));
    137        
     132        myAucValues.Add(new DoubleData(bestAUC));
     133        myRocValues.Add(Convert(bestROC));
     134
    138135      } else { //last class
    139136        actNegatives = negatives.Where<double>(value => value > classes[positiveClassKey].Min<double>()).ToList<double>();
     
    158155
    159156      actTP = positives.Count<double>(value => minThreshold <= value && value <= negatives.Max<double>());
    160       actFP = negatives.Count<double>(value => minThreshold <= value );
     157      actFP = negatives.Count<double>(value => minThreshold <= value);
    161158      //add point (1,TPR) for AUC 'correct' calculation
    162159      roc.Add(new KeyValuePair<double, double>(1, actTP / positives.Count));
     
    222219
    223220        //stop calculation if truePositiveRate == 0 => straight line with y=0 & save runtime
    224         if (actTP == 0 || actFP==0)
     221        if (actTP == 0 || actFP == 0)
    225222          break;
    226223      }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/StandardGP.cs

    r2161 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    27 using System.Xml;
    28 using System.Diagnostics;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 using HeuristicLab.Data;
     23using HeuristicLab.Modeling;
    3224using HeuristicLab.Operators;
    33 using HeuristicLab.Modeling;
    3425
    3526namespace HeuristicLab.GP.StructureIdentification.Classification {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/AveragePercentageChangeEvaluator.cs

    r1891 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    28 using HeuristicLab.GP.StructureIdentification;
    2925
    3026namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/HeuristicLab.GP.StructureIdentification.TimeSeries-3.3.csproj

    r2210 r2216  
    9191  </ItemGroup>
    9292  <ItemGroup>
    93     <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">
    94       <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>
    95       <Name>HeuristicLab.Constraints-3.2</Name>
    96     </ProjectReference>
    9793    <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    9894      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/HeuristicLabGPTimeSeriesPlugin.cs

    r2210 r2216  
    3535  [Dependency(Dependency = "HeuristicLab.GP.Interfaces-3.3")]
    3636  [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification-3.3")]
     37  [Dependency(Dependency = "HeuristicLab.Logging-3.2")]
    3738  [Dependency(Dependency = "HeuristicLab.Modeling-3.2")]
    38   [Dependency(Dependency = "HeuristicLab.Logging-3.2")]
    3939  [Dependency(Dependency = "HeuristicLab.Operators-3.2")]
    4040  public class HeuristicLabGPTimeSeriesPlugin : PluginBase {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/OffspringSelectionGP.cs

    r2161 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    27 using System.Xml;
    28 using System.Diagnostics;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Data;
     23using HeuristicLab.Modeling;
    3124using HeuristicLab.Operators;
    32 using HeuristicLab.Logging;
    33 using HeuristicLab.Modeling;
    3425
    3526namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/ProfitEvaluator.cs

    r1891 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Data;
    28 using HeuristicLab.GP.StructureIdentification;
    2924
    3025namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/StandardGP.cs

    r2161 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    27 using System.Xml;
    28 using System.Diagnostics;
    29 using HeuristicLab.DataAnalysis;
    3023using HeuristicLab.Data;
    31 using HeuristicLab.Operators;
    3224using HeuristicLab.Logging;
    3325using HeuristicLab.Modeling;
     26using HeuristicLab.Operators;
    3427
    3528namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/TheilInequalityCoefficientEvaluator.cs

    r1891 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    28 using HeuristicLab.GP.StructureIdentification;
    2925using HeuristicLab.DataAnalysis;
    3026
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs

    r2212 r2216  
    2424using HeuristicLab.Data;
    2525using HeuristicLab.GP.Interfaces;
     26using HeuristicLab.GP.SantaFe;
    2627
    2728namespace HeuristicLab.GP.StructureIdentification {
    28   public class FunctionLibraryInjector : OperatorBase {
    29     private const string FUNCTIONLIBRARY = "FunctionLibrary";
    30     private const string TARGETVARIABLE = "TargetVariable";
     29  public class FunctionLibraryInjector : FunctionLibraryInjectorBase {
    3130    private const string MINTIMEOFFSET = "MinTimeOffset";
    3231    private const string MAXTIMEOFFSET = "MaxTimeOffset";
     
    5756    private const string XOR_ALLOWED = "Xor";
    5857
     58    private int minTimeOffset;
     59    private int maxTimeOffset;
    5960
    6061    public override string Description {
     
    6465    public FunctionLibraryInjector()
    6566      : base() {
    66       AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));
    6767      AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In));
    6868      AddVariableInfo(new VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), VariableKind.In));
    69       AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default function library", typeof(FunctionLibrary), VariableKind.New));
    7069
    7170      AddVariable(DIFFERENTIALS_ALLOWED, false);
     
    102101
    103102    public override IOperation Apply(IScope scope) {
    104       FunctionLibrary functionLibrary = new FunctionLibrary();
    105       int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
    106 
    107103      // try to get minTimeOffset (use 0 as default if not available)
    108104      IItem minTimeOffsetItem = GetVariableValue(MINTIMEOFFSET, scope, true, false);
    109       int minTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data;
     105      minTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data;
    110106      // try to get maxTimeOffset (use 0 as default if not available)
    111107      IItem maxTimeOffsetItem = GetVariableValue(MAXTIMEOFFSET, scope, true, false);
    112       int maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data;
     108      maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data;
     109
     110      return base.Apply(scope);
     111    }
     112
     113    protected override FunctionLibrary CreateFunctionLibrary() {
     114      FunctionLibrary functionLibrary = new FunctionLibrary();
    113115
    114116      Variable variable = new Variable();
     
    218220      differential.SetConstraints(minTimeOffset, maxTimeOffset);
    219221
    220       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), functionLibrary));
    221 
    222       return null;
     222      return functionLibrary;
    223223    }
    224224
     
    230230      if (GetVariableValue<BoolData>(condName, null, false).Data) functionLib.AddFunction(op);
    231231    }
    232 
    233     private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) {
    234       for (int i = 0; i < f.MaxSubTrees; i++) {
    235         SetAllowedSubOperators(f, i, gs);
    236       }
    237     }
    238 
    239     private void SetAllowedSubOperators(IFunction f, int i, List<IFunction> gs) {
    240       gs.ForEach((g) => f.AddAllowedSubFunction(g, i));
    241     }
    242232  }
    243233}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/ModelAnalyzerExporter.cs

    r2212 r2216  
    2121
    2222using HeuristicLab.GP.Interfaces;
     23using System;
    2324
    2425namespace HeuristicLab.GP.StructureIdentification {
    25   public class ModelAnalyzerExporter : IFunctionTreeExporter, IFunctionTreeNameGenerator {
     26  public class ModelAnalyzerExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator {
    2627    #region IFunctionTreeExporter Members
    2728
     
    5354      if(tree.SubTrees.Count > 0) result += ")";
    5455      return result;
     56    }
     57
     58    public IFunctionTree Import(string tree) {
     59      throw new UnknownFunctionException(tree);
     60    }
     61
     62    public bool TryImport(string tree, out IFunctionTree importedTree) {
     63      try {
     64        importedTree = Import(tree);
     65        return true;
     66      }
     67      catch (UnknownFunctionException) {
     68        importedTree = null;
     69        return false;
     70      }
    5571    }
    5672
     
    104120
    105121    #endregion
     122
     123
    106124  }
    107125
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs

    r2212 r2216  
    2222using System.Text;
    2323using HeuristicLab.GP.Interfaces;
     24using System;
     25using System.Collections.Generic;
    2426
    2527namespace HeuristicLab.GP.StructureIdentification {
    26   public class SymbolicExpressionExporter : IFunctionTreeExporter, IFunctionTreeNameGenerator {
     28  public class SymbolicExpressionExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator {
    2729    private StringBuilder builder;
    2830    private string currentIndent;
     
    4850      } catch(UnknownFunctionException) {
    4951        exported = "";
     52        return false;
     53      }
     54    }
     55
     56    public IFunctionTree Import(string tree) {
     57      Queue<string> tokens = new Queue<string>(tree.Split(' ', '\n', '\t'));
     58      return ParseTree(tokens);
     59    }
     60
     61    private IFunctionTree ParseTree(Queue<string> tokens) {
     62      Expect("(", tokens);
     63      string funSymb = tokens.Peek();
     64      double constValue;
     65      if (double.TryParse(funSymb, out constValue)) {
     66        throw new UnknownFunctionException(funSymb);
     67      }
     68      switch (funSymb) {
     69        case "variable": return ParseVariable(tokens);
     70        case "differential": return ParseDifferential(tokens);
     71        default:
     72          IFunctionTree fNode = ParseFunction(tokens);
     73          Expect(")", tokens);
     74          return fNode;
     75      }
     76
     77    }
     78
     79    private IFunctionTree ParseFunction(Queue<string> tokens) {
     80      throw new UnknownFunctionException(tokens.Dequeue());
     81    }
     82
     83    private IFunctionTree ParseDifferential(Queue<string> tokens) {
     84      throw new UnknownFunctionException(tokens.Dequeue());
     85    }
     86
     87    private IFunctionTree ParseVariable(Queue<string> tokens) {
     88      throw new UnknownFunctionException(tokens.Dequeue());
     89    }
     90
     91    private void Expect(string p, Queue<string> tokens) {
     92      throw new NotImplementedException();
     93    }
     94
     95    public bool TryImport(string tree, out IFunctionTree importedTree) {
     96      try {
     97        importedTree = Import(tree);
     98        return true;
     99      }
     100      catch (UnknownFunctionException) {
     101        importedTree = null;
    50102        return false;
    51103      }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Constant.cs

    r2212 r2216  
    3131    public override string Description {
    3232      get { return "Returns the value of local variable 'Value'."; }
    33     }
    34 
    35     public override IEnumerable<string> LocalParameterNames {
    36       get {
    37         return new string[] { VALUE };
    38       }
    3933    }
    4034
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/ConstantFunctionTree.cs

    r2212 r2216  
    2626
    2727namespace HeuristicLab.GP.StructureIdentification {
    28   public class ConstantFunctionTree : FunctionTreeBase {
    29     private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly();
     28  public class ConstantFunctionTree : TerminalTreeNode {
    3029    public double Value { get; set; }
    3130
    32     public ConstantFunctionTree(Constant constant) {
    33       Function = constant;
     31    public ConstantFunctionTree(Constant constant) : base(constant){
    3432    }
    3533
    36     protected ConstantFunctionTree(ConstantFunctionTree original) {
    37       Function = original.Function;
     34    protected ConstantFunctionTree(ConstantFunctionTree original) : base(original){
    3835      Value = original.Value;
    39     }
    40 
    41     public override IList<IFunctionTree> SubTrees {
    42       get {
    43         return subTrees;
    44       }
    4536    }
    4637
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/VariableFunctionTree.cs

    r2212 r2216  
    2626
    2727namespace HeuristicLab.GP.StructureIdentification {
    28   public class VariableFunctionTree : FunctionTreeBase {
    29     private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly();
     28  public class VariableFunctionTree : TerminalTreeNode {
    3029    public double Weight { get; set; }
    3130    public string VariableName { get; set; }
    3231    public int SampleOffset { get; set; }
    3332
    34     public VariableFunctionTree(Variable variable) {
    35       Function = variable;
     33    public VariableFunctionTree(Variable variable)
     34      : base(variable) {
    3635    }
    3736
    38     protected VariableFunctionTree(VariableFunctionTree original) {
    39       Function = original.Function;
     37    protected VariableFunctionTree(VariableFunctionTree original)
     38      : base(original) {
    4039      Weight = original.Weight;
    4140      VariableName = original.VariableName;
    4241      SampleOffset = original.SampleOffset;
    43     }
    44 
    45     public override IList<IFunctionTree> SubTrees {
    46       get {
    47         return subTrees;
    48       }
    4942    }
    5043
     
    6659    public override IOperation CreateInitOperation(IScope scope) {
    6760      Scope myVariableScope = new Scope();
    68       scope.AddSubScope(myVariableScope); 
     61      scope.AddSubScope(myVariableScope);
    6962      myVariableScope.AddVariable(CreateWeightVariable());
    7063      myVariableScope.AddVariable(CreateVariableNameVariable());
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs

    r2212 r2216  
    101101    }
    102102
    103     public virtual IEnumerable<string> LocalParameterNames {
    104       get { return new string[0]; }
    105     }
    106 
    107103    public virtual IFunctionTree GetTreeNode() {
    108104      return new FunctionTreeBase(this);
     
    158154      minTreeHeight = height + 1;
    159155    }
     156
     157    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     158      throw new NotSupportedException();
     159    }
     160
     161    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     162      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     163      XmlAttribute minSubTreesAttr = document.CreateAttribute("MinSubTrees");
     164      minSubTreesAttr.Value = XmlConvert.ToString(MinSubTrees);
     165      XmlAttribute maxSubTreesAttr = document.CreateAttribute("MaxSubTrees");
     166      maxSubTreesAttr.Value = XmlConvert.ToString(MaxSubTrees);
     167      node.Attributes.Append(minSubTreesAttr);
     168      node.Attributes.Append(maxSubTreesAttr);
     169      for (int i = 0; i < MaxSubTrees; i++) {
     170        XmlNode slotNode = document.CreateElement("AllowedSubFunctions");
     171        XmlAttribute slotAttr = document.CreateAttribute("Slot");
     172        slotAttr.Value = XmlConvert.ToString(i);
     173        slotNode.Attributes.Append(slotAttr);
     174        node.AppendChild(slotNode);
     175        foreach (IFunction f in GetAllowedSubFunctions(i)) {
     176          slotNode.AppendChild(PersistenceManager.Persist(f, document, persistedObjects));
     177        }
     178      }
     179      return node;
     180    }
     181
     182    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     183      base.Populate(node, restoredObjects);
     184      MinSubTrees = XmlConvert.ToInt32(node.Attributes["MinSubTrees"].Value);
     185      MaxSubTrees = XmlConvert.ToInt32(node.Attributes["MaxSubTrees"].Value);
     186      foreach (XmlNode allowedSubFunctionsNode in node.SelectNodes("AllowedSubFunctions")) {
     187        int slot = XmlConvert.ToInt32(allowedSubFunctionsNode.Attributes["Slot"].Value);
     188        foreach (XmlNode fNode in allowedSubFunctionsNode.ChildNodes) {
     189          AddAllowedSubFunction((IFunction)PersistenceManager.Restore(fNode, restoredObjects), slot);
     190        }
     191      }
     192    }
    160193  }
    161194}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs

    r2211 r2216  
    5858    public IFunction Function {
    5959      get { return function; }
    60       protected set {
    61         function = value;
    62       }
     60      protected set { function = value; }
    6361    }
    6462
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionLibrary.cs

    r2212 r2216  
    5858    }
    5959
     60    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     61      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     62      foreach (IFunction f in functions) {
     63        node.AppendChild(PersistenceManager.Persist("Function", f, document, persistedObjects));
     64      }
     65      return node;
     66    }
     67
     68    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     69      base.Populate(node, restoredObjects);
     70      foreach (XmlNode fNode in node.SelectNodes("Function")) {
     71        AddFunction((IFunction)PersistenceManager.Restore(fNode, restoredObjects));
     72      }
     73    }
     74
    6075    public override IView CreateView() {
    6176      return new FunctionLibraryEditor(this);
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionTreeView.cs

    r2212 r2216  
    6767      treeNodeContextMenu.MenuItems.Add(representationsMenu);
    6868      DiscoveryService discoveryService = new DiscoveryService();
    69       IFunctionTreeExporter[] exporters = discoveryService.GetInstances<IFunctionTreeExporter>();
    70       foreach (IFunctionTreeExporter exporter in exporters) {
     69      IFunctionTreeSerializer[] exporters = discoveryService.GetInstances<IFunctionTreeSerializer>();
     70      foreach (IFunctionTreeSerializer exporter in exporters) {
    7171        string result;
    7272        // register a menu item for the exporter
     
    101101    }
    102102
    103     private EventHandler MakeExporterDelegate(IFunctionTreeExporter exporter) {
     103    private EventHandler MakeExporterDelegate(IFunctionTreeSerializer exporter) {
    104104      return delegate(object source, EventArgs args) {
    105105        TreeNode node = funTreeView.SelectedNode;
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/GeneticProgrammingModel.cs

    r2210 r2216  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.GP.Interfaces;
     27using System.Xml;
    2728
    2829namespace HeuristicLab.GP {
     
    5657    }
    5758
    58     public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    59       throw new NotImplementedException();
     59    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     60      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     61      node.Value = GeneralTreeSerializer.Export(FunctionTree);
     62      return node;
    6063    }
    6164
    62     public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    63       throw new NotImplementedException();
     65    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     66      base.Populate(node, restoredObjects);
     67      FunctionTree = GeneralTreeSerializer.Import(node.Value);
    6468    }
    6569
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/HeuristicLab.GP-3.3.csproj

    r2212 r2216  
    8383  <ItemGroup>
    8484    <Compile Include="BaseClasses\BinaryFunction.cs" />
     85    <Compile Include="BaseClasses\FunctionLibraryInjectorBase.cs" />
     86    <Compile Include="BaseClasses\TerminalTreeNode.cs" />
    8587    <Compile Include="BaseClasses\FunctionBase.cs" />
    8688    <Compile Include="BaseClasses\FunctionTreeBase.cs" />
    8789    <Compile Include="BaseClasses\Terminal.cs" />
    8890    <Compile Include="BaseClasses\UnaryFunction.cs" />
     91    <Compile Include="FunctionTreeSerializer.cs" />
    8992    <Compile Include="FunctionLibrary.cs" />
    9093    <Compile Include="FunctionLibraryEditor.cs">
Note: See TracChangeset for help on using the changeset viewer.