Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/11 14:07:47 (14 years ago)
Author:
mkommend
Message:

#1418: Corrected problem interfaces & unified naming of subtrees.

Location:
branches/DataAnalysis Refactoring
Files:
3 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs

    r5681 r5733  
    9090      ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
    9191      ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
    92       tree.Root.AddSubTree(startNode);
     92      tree.Root.AddSubtree(startNode);
    9393      ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode();
    94       startNode.AddSubTree(addition);
     94      startNode.AddSubtree(addition);
    9595
    9696      int col = 0;
     
    9999        vNode.VariableName = column;
    100100        vNode.Weight = w[col];
    101         addition.AddSubTree(vNode);
     101        addition.AddSubtree(vNode);
    102102        col++;
    103103      }
     
    105105      ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
    106106      cNode.Value = w[w.Length - 1];
    107       addition.AddSubTree(cNode);
     107      addition.AddSubtree(cNode);
    108108
    109109
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r5658 r5733  
    9494      ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
    9595      ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
    96       tree.Root.AddSubTree(startNode);
     96      tree.Root.AddSubtree(startNode);
    9797      ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode();
    98       startNode.AddSubTree(addition);
     98      startNode.AddSubtree(addition);
    9999
    100100      int col = 0;
     
    103103        vNode.VariableName = column;
    104104        vNode.Weight = coefficients[col];
    105         addition.AddSubTree(vNode);
     105        addition.AddSubtree(vNode);
    106106        col++;
    107107      }
     
    109109      ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
    110110      cNode.Value = coefficients[coefficients.Length - 1];
    111       addition.AddSubTree(cNode);
     111      addition.AddSubtree(cNode);
    112112
    113113      SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), problemData);
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r5549 r5733  
    263263
    264264      //draw terminal node
    265       if (node.SubTrees.Count() == 0) {
     265      if (node.Subtrees.Count() == 0) {
    266266        graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    267267        graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
     
    281281      //calculate areas for the subtrees according to their tree size and call drawFunctionTree
    282282      Point connectFrom = new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y + visualTreeNode.Height);
    283       int[] xBoundaries = new int[node.SubTrees.Count() + 1];
     283      int[] xBoundaries = new int[node.Subtrees.Count() + 1];
    284284      xBoundaries[0] = x;
    285       for (int i = 0; i < node.SubTrees.Count(); i++) {
    286         xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.SubTrees.ElementAt(i).GetLength()) / (node.GetLength() - 1));
    287         DrawFunctionTree(node.SubTrees.ElementAt(i), graphics, xBoundaries[i], y + height,
     285      for (int i = 0; i < node.Subtrees.Count(); i++) {
     286        xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.Subtrees.ElementAt(i).GetLength()) / (node.GetLength() - 1));
     287        DrawFunctionTree(node.Subtrees.ElementAt(i), graphics, xBoundaries[i], y + height,
    288288          xBoundaries[i + 1] - xBoundaries[i], height, connectFrom);
    289289      }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs

    r5686 r5733  
    124124      // the branch at the cut point is to be replaced by a new argument node
    125125      var cutPoints = (from node in defunBranch.IterateNodesPrefix()
    126                        where node.SubTrees.Count() > 0
    127                        from subtree in node.SubTrees
     126                       where node.Subtrees.Count() > 0
     127                       from subtree in node.Subtrees
    128128                       select new CutPoint(node, subtree)).ToList();
    129129
     
    134134      // replace the branch at the cut point with an argument node
    135135      var replacedBranch = selectedCutPoint.Child;
    136       selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint.ChildIndex);
    137       selectedCutPoint.Parent.InsertSubTree(selectedCutPoint.ChildIndex, newArgumentNode);
     136      selectedCutPoint.Parent.RemoveSubtree(selectedCutPoint.ChildIndex);
     137      selectedCutPoint.Parent.InsertSubtree(selectedCutPoint.ChildIndex, newArgumentNode);
    138138
    139139      // find all old invocations of the selected ADF and attach a cloned version of the replaced branch (with all argument-nodes expanded)
     
    141141      var invocationNodes = (from node in tree.IterateNodesPostfix().OfType<InvokeFunctionTreeNode>()
    142142                             where node.Symbol.FunctionName == defunBranch.FunctionName
    143                              where node.SubTrees.Count() == defunBranch.NumberOfArguments
     143                             where node.Subtrees.Count() == defunBranch.NumberOfArguments
    144144                             select node).ToList();
    145145      // do this repeatedly until no matching invocations are found     
     
    148148        foreach (var invocationNode in invocationNodes) {
    149149          // check that the invocation node really has the correct number of arguments
    150           if (invocationNode.SubTrees.Count() != defunBranch.NumberOfArguments) throw new InvalidOperationException();
     150          if (invocationNode.Subtrees.Count() != defunBranch.NumberOfArguments) throw new InvalidOperationException();
    151151          // append a new argument branch after expanding all argument nodes
    152152          var clonedBranch = (ISymbolicExpressionTreeNode)replacedBranch.Clone();
    153           clonedBranch = ReplaceArgumentsInBranch(clonedBranch, invocationNode.SubTrees);
    154           invocationNode.InsertSubTree(newArgumentNode.Symbol.ArgumentIndex, clonedBranch);
     153          clonedBranch = ReplaceArgumentsInBranch(clonedBranch, invocationNode.Subtrees);
     154          invocationNode.InsertSubtree(newArgumentNode.Symbol.ArgumentIndex, clonedBranch);
    155155          newlyAddedBranches.Add(clonedBranch);
    156156        }
     
    159159                           from node in newlyAddedBranch.IterateNodesPostfix().OfType<InvokeFunctionTreeNode>()
    160160                           where node.Symbol.FunctionName == defunBranch.FunctionName
    161                            where node.SubTrees.Count() == defunBranch.NumberOfArguments
     161                           where node.Subtrees.Count() == defunBranch.NumberOfArguments
    162162                           select node).ToList();
    163163      }
     
    173173          defunBranch.Grammar.AddAllowedChildSymbol(symb, newArgumentNode.Symbol, i);
    174174        }
    175       foreach (var subtree in tree.Root.SubTrees) {
     175      foreach (var subtree in tree.Root.Subtrees) {
    176176        // when the changed function is known in the branch then update the number of arguments
    177177        var matchingSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == defunBranch.FunctionName).SingleOrDefault();
     
    196196      } else {
    197197        // call recursively for all subtree
    198         List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(branch.SubTrees);
    199         while (branch.SubTrees.Count() > 0) branch.RemoveSubTree(0);
     198        List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(branch.Subtrees);
     199        while (branch.Subtrees.Count() > 0) branch.RemoveSubtree(0);
    200200        foreach (var subtree in subtrees) {
    201           branch.AddSubTree(ReplaceArgumentsInBranch(subtree, argumentTrees));
     201          branch.AddSubtree(ReplaceArgumentsInBranch(subtree, argumentTrees));
    202202        }
    203203        return branch;
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs

    r5686 r5733  
    7171                             select node).ToList();
    7272      foreach (var invokeNode in invocationNodes) {
    73         invokeNode.RemoveSubTree(removedArgument);
     73        invokeNode.RemoveSubtree(removedArgument);
    7474      }
    7575
     
    8181      selectedDefunBranch.NumberOfArguments--;
    8282      // reduce arity in known functions of all root branches
    83       foreach (var subtree in symbolicExpressionTree.Root.SubTrees) {
     83      foreach (var subtree in symbolicExpressionTree.Root.Subtrees) {
    8484        var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == selectedDefunBranch.FunctionName).SingleOrDefault();
    8585        if (matchingInvokeSymbol != null) {
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs

    r5686 r5733  
    8686      var invocationNodes = (from node in symbolicExpressionTree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
    8787                             where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
    88                              where node.SubTrees.Count() == selectedDefunBranch.NumberOfArguments
     88                             where node.Subtrees.Count() == selectedDefunBranch.NumberOfArguments
    8989                             select node).ToList();
    9090      // do this repeatedly until no matching invocations are found     
     
    9393        foreach (var invokeNode in invocationNodes) {
    9494          // check that the invocation node really has the correct number of arguments
    95           if (invokeNode.SubTrees.Count() != selectedDefunBranch.NumberOfArguments) throw new InvalidOperationException();
    96           var argumentBranch = invokeNode.GetSubTree(selectedArgumentSymbol.ArgumentIndex);
     95          if (invokeNode.Subtrees.Count() != selectedDefunBranch.NumberOfArguments) throw new InvalidOperationException();
     96          var argumentBranch = invokeNode.GetSubtree(selectedArgumentSymbol.ArgumentIndex);
    9797          var clonedArgumentBranch = (ISymbolicExpressionTreeNode)argumentBranch.Clone();
    98           invokeNode.InsertSubTree(newArgumentIndex, clonedArgumentBranch);
     98          invokeNode.InsertSubtree(newArgumentIndex, clonedArgumentBranch);
    9999          newlyAddedBranches.Add(clonedArgumentBranch);
    100100        }
     
    102102                           from node in newlyAddedBranch.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
    103103                           where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
    104                            where node.SubTrees.Count() == selectedDefunBranch.NumberOfArguments
     104                           where node.Subtrees.Count() == selectedDefunBranch.NumberOfArguments
    105105                           select node).ToList();
    106106      }
     
    116116
    117117      // increase the arity of the changed ADF in all branches that can use this ADF
    118       foreach (var subtree in symbolicExpressionTree.Root.SubTrees) {
     118      foreach (var subtree in symbolicExpressionTree.Root.Subtrees) {
    119119        var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>()
    120120                                    where symb.FunctionName == selectedDefunBranch.FunctionName
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs

    r5686 r5733  
    9595
    9696      // select a random body (either the result producing branch or an ADF branch)
    97       var bodies = from node in symbolicExpressionTree.Root.SubTrees
     97      var bodies = from node in symbolicExpressionTree.Root.Subtrees
    9898                   select new { Tree = node, Length = node.GetLength() };
    9999      var totalNumberOfBodyNodes = bodies.Select(x => x.Length).Sum();
     
    111111      // select a random cut point in the selected branch
    112112      var allCutPoints = (from parent in selectedBody.IterateNodesPrefix()
    113                           from subtree in parent.SubTrees
     113                          from subtree in parent.Subtrees
    114114                          select new CutPoint(parent, subtree)).ToList();
    115115      if (allCutPoints.Count() == 0)
     
    122122      ISymbolicExpressionTreeNode functionBody = selectedCutPoint.Child;
    123123      // disconnect the function body from the tree
    124       selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint.ChildIndex);
     124      selectedCutPoint.Parent.RemoveSubtree(selectedCutPoint.ChildIndex);
    125125      // disconnect the argument branches from the function
    126126      functionBody = DisconnectBranches(functionBody, argumentCutPoints);
    127127      // insert a function invocation symbol instead
    128128      var invokeNode = (InvokeFunctionTreeNode)(new InvokeFunction(newFunctionName)).CreateTreeNode();
    129       selectedCutPoint.Parent.InsertSubTree(selectedCutPoint.ChildIndex, invokeNode);
     129      selectedCutPoint.Parent.InsertSubtree(selectedCutPoint.ChildIndex, invokeNode);
    130130      // add the branches selected as argument as subtrees of the function invocation node
    131131      foreach (var argumentCutPoint in argumentCutPoints)
    132         invokeNode.AddSubTree(argumentCutPoint.Child);
     132        invokeNode.AddSubtree(argumentCutPoint.Child);
    133133
    134134      // insert a new function defining branch
    135135      var defunNode = (DefunTreeNode)(new Defun()).CreateTreeNode();
    136136      defunNode.FunctionName = newFunctionName;
    137       defunNode.AddSubTree(functionBody);
    138       symbolicExpressionTree.Root.AddSubTree(defunNode);
     137      defunNode.AddSubtree(functionBody);
     138      symbolicExpressionTree.Root.AddSubtree(defunNode);
    139139      // the grammar in the newly defined function is a clone of the grammar of the originating branch
    140140      defunNode.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBody.Grammar.Clone());
     
    157157      if (selectedBody.Symbol is Defun) {
    158158        var originalFunctionDefinition = selectedBody as DefunTreeNode;
    159         foreach (var subtree in symbolicExpressionTree.Root.SubTrees) {
     159        foreach (var subtree in symbolicExpressionTree.Root.Subtrees) {
    160160          var originalBranchInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>()
    161161                                            where symb.FunctionName == originalFunctionDefinition.FunctionName
     
    177177      }
    178178      // remove the subtrees so that we can clone only the root node
    179       List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.SubTrees);
    180       while (node.SubTrees.Count() > 0) node.RemoveSubTree(0);
     179      List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);
     180      while (node.Subtrees.Count() > 0) node.RemoveSubtree(0);
    181181      // recursively apply function for subtrees or append a argument terminal node
    182182      foreach (var subtree in subtrees) {
    183         node.AddSubTree(DisconnectBranches(subtree, argumentCutPoints));
     183        node.AddSubtree(DisconnectBranches(subtree, argumentCutPoints));
    184184      }
    185185      return node;
     
    198198      } else {
    199199        // get the number of argument nodes (which must be cut-off) in the sub-trees
    200         var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.SubTrees
     200        var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.Subtrees
    201201                                           let nArgumentsInTree = subtree.IterateNodesPrefix().OfType<ArgumentTreeNode>().Count()
    202202                                           select nArgumentsInTree).ToList();
     
    209209        }
    210210        // cut-off in the sub-trees in random order
    211         var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.SubTrees.Count())
     211        var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.Subtrees.Count())
    212212                             select new { Index = index, OrderValue = random.NextDouble() })
    213213                             .OrderBy(x => x.OrderValue)
    214214                             .Select(x => x.Index);
    215215        foreach (var subtreeIndex in randomIndexes) {
    216           var subtree = selectedRoot.GetSubTree(subtreeIndex);
     216          var subtree = selectedRoot.GetSubtree(subtreeIndex);
    217217          minNewArgumentsForSubtrees[subtreeIndex] = 0;
    218218          // => cut-off at 0..n points somewhere in the current sub-tree
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs

    r5686 r5733  
    6262      var selectedDefunBranch = functionDefiningBranches.SelectRandom(random);
    6363      // remove the selected defun
    64       int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubTree(selectedDefunBranch);
    65       symbolicExpressionTree.Root.RemoveSubTree(defunSubtreeIndex);
     64      int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubtree(selectedDefunBranch);
     65      symbolicExpressionTree.Root.RemoveSubtree(defunSubtreeIndex);
    6666
    6767      // remove references to deleted function
    68       foreach (var subtree in symbolicExpressionTree.Root.SubTrees.OfType<SymbolicExpressionTreeTopLevelNode>()) {
     68      foreach (var subtree in symbolicExpressionTree.Root.Subtrees.OfType<SymbolicExpressionTreeTopLevelNode>()) {
    6969        var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>()
    7070                                    where symb.FunctionName == selectedDefunBranch.FunctionName
     
    8484      // the invocations below it are removed already
    8585      var invocationCutPoint = (from node in symbolicExpressionTree.IterateNodesPrefix()
    86                                 from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>()
     86                                from subtree in node.Subtrees.OfType<InvokeFunctionTreeNode>()
    8787                                where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName
    8888                                select new CutPoint(node, subtree)).FirstOrDefault();
     
    101101        if (replacementTree.HasLocalParameters)
    102102          replacementTree.ResetLocalParameters(random);
    103         invocationCutPoint.Parent.RemoveSubTree(invocationCutPoint.ChildIndex);
    104         invocationCutPoint.Parent.InsertSubTree(invocationCutPoint.ChildIndex, replacementTree);
     103        invocationCutPoint.Parent.RemoveSubtree(invocationCutPoint.ChildIndex);
     104        invocationCutPoint.Parent.InsertSubtree(invocationCutPoint.ChildIndex, replacementTree);
    105105
    106106        ProbabilisticTreeCreator.PTC2(random, replacementTree, maxLength, maxDepth);
    107107
    108108        invocationCutPoint = (from node in symbolicExpressionTree.IterateNodesPrefix()
    109                               from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>()
     109                              from subtree in node.Subtrees.OfType<InvokeFunctionTreeNode>()
    110110                              where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName
    111111                              select new CutPoint(node, subtree)).FirstOrDefault();
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs

    r5686 r5733  
    7171      string newFunctionName = allowedFunctionNames.Except(UsedFunctionNames(symbolicExpressionTree)).First();
    7272      duplicatedDefunBranch.FunctionName = newFunctionName;
    73       symbolicExpressionTree.Root.AddSubTree(duplicatedDefunBranch);
     73      symbolicExpressionTree.Root.AddSubtree(duplicatedDefunBranch);
    7474      duplicatedDefunBranch.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBranch.Grammar.Clone());
    7575      // add an invoke symbol for each branch that is allowed to invoke the original function
    76       foreach (var subtree in symbolicExpressionTree.Root.SubTrees.OfType<SymbolicExpressionTreeTopLevelNode>()) {
     76      foreach (var subtree in symbolicExpressionTree.Root.Subtrees.OfType<SymbolicExpressionTreeTopLevelNode>()) {
    7777        var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>()
    7878                                    where symb.FunctionName == selectedBranch.FunctionName
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs

    r5571 r5733  
    3333      entryPoint.Clear();
    3434      // compile main body branches
    35       foreach (var branch in tree.Root.GetSubTree(0).SubTrees) {
     35      foreach (var branch in tree.Root.GetSubtree(0).Subtrees) {
    3636        code.AddRange(Compile(branch, opCodeMapper));
    3737      }
     
    4343        if (code.Count > ushort.MaxValue) throw new ArgumentException("Code for the tree is too long (> ushort.MaxValue).");
    4444        entryPoint[branch.FunctionName] = (ushort)code.Count;
    45         code.AddRange(Compile(branch.GetSubTree(0), opCodeMapper));
     45        code.AddRange(Compile(branch.GetSubtree(0), opCodeMapper));
    4646      }
    4747      // address of all functions is fixed now
     
    6262      foreach (var node in branch.IterateNodesPrefix()) {
    6363        Instruction instr = new Instruction();
    64         int subTreesCount = node.SubTrees.Count();
    65         if (subTreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)");
    66         instr.nArguments = (byte)subTreesCount;
     64        int subtreesCount = node.SubtreesCount;
     65        if (subtreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)");
     66        instr.nArguments = (byte)subtreesCount;
    6767        instr.opCode = opCodeMapper(node);
    6868        if (node.Symbol is Argument) {
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r5727 r5733  
    8989      startNode.SetGrammar(new SymbolicExpressionTreeGrammar(grammar));
    9090      if (startNode.HasLocalParameters) startNode.ResetLocalParameters(random);
    91       rootNode.AddSubTree(startNode);
     91      rootNode.AddSubtree(startNode);
    9292      PTC2(random, startNode, maxTreeLength, maxTreeDepth);
    9393      tree.Root = rootNode;
     
    120120        } else {
    121121          // clean seedNode
    122           while (seedNode.SubTrees.Count() > 0) seedNode.RemoveSubTree(0);
     122          while (seedNode.Subtrees.Count() > 0) seedNode.RemoveSubtree(0);
    123123        }
    124124        // try a different length MAX_TRIES times
     
    138138        // insert a dummy sub-tree and add the pending extension to the list
    139139        var dummy = new SymbolicExpressionTreeNode();
    140         root.AddSubTree(dummy);
     140        root.AddSubtree(dummy);
    141141        extensionPoints.Add(new TreeExtensionPoint { Parent = root, ChildIndex = i, ExtensionPointDepth = 0 });
    142142      }
     
    162162          ISymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode();
    163163          if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random);
    164           parent.RemoveSubTree(argumentIndex);
    165           parent.InsertSubTree(argumentIndex, newTree);
     164          parent.RemoveSubtree(argumentIndex);
     165          parent.InsertSubtree(argumentIndex, newTree);
    166166
    167167          var topLevelNode = newTree as SymbolicExpressionTreeTopLevelNode;
     
    177177            // insert a dummy sub-tree and add the pending extension to the list
    178178            var dummy = new SymbolicExpressionTreeNode();
    179             newTree.AddSubTree(dummy);
     179            newTree.AddSubtree(dummy);
    180180            extensionPoints.Add(new TreeExtensionPoint { Parent = newTree, ChildIndex = i, ExtensionPointDepth = extensionDepth + 1 });
    181181          }
     
    207207      var tree = selectedSymbol.CreateTreeNode();
    208208      if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
    209       parent.RemoveSubTree(childIndex);
    210       parent.InsertSubTree(childIndex, tree);
     209      parent.RemoveSubtree(childIndex);
     210      parent.InsertSubtree(childIndex, tree);
    211211
    212212      var topLevelNode = tree as SymbolicExpressionTreeTopLevelNode;
     
    217217        // insert a dummy sub-tree and add the pending extension to the list
    218218        var dummy = new SymbolicExpressionTreeNode();
    219         tree.AddSubTree(dummy);
     219        tree.AddSubtree(dummy);
    220220        // replace the just inserted dummy by recursive application
    221221        ReplaceWithMinimalTree(random, root, tree, i);
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r5686 r5733  
    9393
    9494      // calculate the max length and depth that the inserted branch can have
    95       int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubTree(replacedSubtreeIndex).GetLength());
     95      int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubtree(replacedSubtreeIndex).GetLength());
    9696      int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0);
    9797
     
    111111        // manipulate the tree of parent0 in place
    112112        // replace the branch in tree0 with the selected branch from tree1
    113         crossoverPoint0.RemoveSubTree(replacedSubtreeIndex);
    114         crossoverPoint0.InsertSubTree(replacedSubtreeIndex, selectedBranch);
     113        crossoverPoint0.RemoveSubtree(replacedSubtreeIndex);
     114        crossoverPoint0.InsertSubtree(replacedSubtreeIndex, selectedBranch);
    115115        return parent0;
    116116      }
     
    139139      List<CutPoint> leafCrossoverPoints = new List<CutPoint>();
    140140      parent0.Root.ForEachNodePostfix((n) => {
    141         if (n.SubTrees.Any() && n != parent0.Root) {
    142           foreach (var child in n.SubTrees) {
     141        if (n.Subtrees.Any() && n != parent0.Root) {
     142          foreach (var child in n.Subtrees) {
    143143            if (child.GetLength() <= maxBranchLength &&
    144144                child.GetDepth() <= maxBranchDepth) {
    145               if (child.SubTrees.Any())
     145              if (child.Subtrees.Any())
    146146                internalCrossoverPoints.Add(new CutPoint(n, child));
    147147              else
     
    185185        // select internal node if possible
    186186        allowedInternalBranches = (from branch in branches
    187                                    where branch.SubTrees.Any()
     187                                   where branch.Subtrees.Any()
    188188                                   select branch).ToList();
    189189        if (allowedInternalBranches.Count > 0) {
     
    192192          // no internal nodes allowed => select leaf nodes
    193193          allowedLeafBranches = (from branch in branches
    194                                  where !branch.SubTrees.Any()
     194                                 where !branch.Subtrees.Any()
    195195                                 select branch).ToList();
    196196          return allowedLeafBranches.SelectRandom(random);
     
    199199        // select leaf node if possible
    200200        allowedLeafBranches = (from branch in branches
    201                                where !branch.SubTrees.Any()
     201                               where !branch.Subtrees.Any()
    202202                               select branch).ToList();
    203203        if (allowedLeafBranches.Count > 0) {
     
    205205        } else {
    206206          allowedInternalBranches = (from branch in branches
    207                                      where branch.SubTrees.Any()
     207                                     where branch.Subtrees.Any()
    208208                                     select branch).ToList();
    209209          return allowedInternalBranches.SelectRandom(random);
     
    214214    private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) {
    215215      if (root == point) return 0;
    216       foreach (var subtree in root.SubTrees) {
     216      foreach (var subtree in root.Subtrees) {
    217217        int branchLevel = GetBranchLevel(subtree, point);
    218218        if (branchLevel < int.MaxValue) return 1 + branchLevel;
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/CutPoint.cs

    r5686 r5733  
    3232      this.Parent = parent;
    3333      this.Child = child;
    34       this.childIndex = parent.IndexOfSubTree(child);
     34      this.childIndex = parent.IndexOfSubtree(child);
    3535    }
    3636  }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs

    r5510 r5733  
    5555      strBuilder.Append("(");
    5656      // internal nodes or leaf nodes?
    57       if (node.SubTrees.Count() > 0) {
     57      if (node.Subtrees.Count() > 0) {
    5858        // symbol on same line as '('
    5959        strBuilder.AppendLine(node.ToString());
    6060        // each subtree expression on a new line
    6161        // and closing ')' also on new line
    62         foreach (var subtree in node.SubTrees) {
     62        foreach (var subtree in node.Subtrees) {
    6363          strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2));
    6464        }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs

    r5686 r5733  
    3838    void ForEachNodePrefix(Action<ISymbolicExpressionTreeNode> a);
    3939
    40     IEnumerable<ISymbolicExpressionTreeNode> SubTrees { get; }
     40    IEnumerable<ISymbolicExpressionTreeNode> Subtrees { get; }
    4141    int SubtreesCount { get; }
    42     ISymbolicExpressionTreeNode GetSubTree(int index);
    43     int IndexOfSubTree(ISymbolicExpressionTreeNode tree);
    44     void AddSubTree(ISymbolicExpressionTreeNode tree);
    45     void InsertSubTree(int index, ISymbolicExpressionTreeNode tree);
    46     void RemoveSubTree(int index);
     42    ISymbolicExpressionTreeNode GetSubtree(int index);
     43    int IndexOfSubtree(ISymbolicExpressionTreeNode tree);
     44    void AddSubtree(ISymbolicExpressionTreeNode tree);
     45    void InsertSubtree(int index, ISymbolicExpressionTreeNode tree);
     46    void RemoveSubtree(int index);
    4747
    4848    void ResetLocalParameters(IRandom random);
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs

    r5686 r5733  
    4545      // select any node as parent (except the root node)
    4646      var manipulationPoints = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1)
    47                                 let subtreeCount = parent.SubTrees.Count()
     47                                let subtreeCount = parent.Subtrees.Count()
    4848                                from subtreeIndex in Enumerable.Range(0, subtreeCount)
    49                                 let subtree = parent.GetSubTree(subtreeIndex)
    50                                 let existingSubtreeCount = subtree.SubTrees.Count()
     49                                let subtree = parent.GetSubtree(subtreeIndex)
     50                                let existingSubtreeCount = subtree.Subtrees.Count()
    5151                                // find possible symbols for the node (also considering the existing branches below it)
    5252                                let allowedSymbols = (from symbol in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, subtreeIndex)
     
    5757                                                      // keep only symbols that are still possible considering the existing sub-trees
    5858                                                      where (from existingSubtreeIndex in Enumerable.Range(0, existingSubtreeCount)
    59                                                              let existingSubtree = subtree.GetSubTree(existingSubtreeIndex)
     59                                                             let existingSubtree = subtree.GetSubtree(existingSubtreeIndex)
    6060                                                             select parent.Grammar.IsAllowedChildSymbol(symbol, existingSubtree.Symbol, existingSubtreeIndex))
    6161                                                             .All(x => x == true)
     
    7575      if (newNode.HasLocalParameters)
    7676        newNode.ResetLocalParameters(random);
    77       foreach (var subtree in selectedManipulationPoint.Child.SubTrees)
    78         newNode.AddSubTree(subtree);
    79       selectedManipulationPoint.Parent.RemoveSubTree(selectedManipulationPoint.Index);
    80       selectedManipulationPoint.Parent.InsertSubTree(selectedManipulationPoint.Index, newNode);
     77      foreach (var subtree in selectedManipulationPoint.Child.Subtrees)
     78        newNode.AddSubtree(subtree);
     79      selectedManipulationPoint.Parent.RemoveSubtree(selectedManipulationPoint.Index);
     80      selectedManipulationPoint.Parent.InsertSubtree(selectedManipulationPoint.Index, newNode);
    8181    }
    8282  }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs

    r5686 r5733  
    7070      // select any node as parent (except the root node)
    7171      var manipulationPoints = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1)
    72                                 from subtree in parent.SubTrees
    73                                 let subtreeIndex = parent.IndexOfSubTree(subtree)
     72                                from subtree in parent.Subtrees
     73                                let subtreeIndex = parent.IndexOfSubtree(subtree)
    7474                                let maxLength = maxTreeLength - symbolicExpressionTree.Length + subtree.GetLength()
    7575                                let maxDepth = maxTreeDepth - symbolicExpressionTree.Depth + subtree.GetDepth()
     
    103103        seedNode.ResetLocalParameters(random);
    104104
    105       selectedManipulationPoint.Parent.RemoveSubTree(selectedManipulationPoint.Index);
    106       selectedManipulationPoint.Parent.InsertSubTree(selectedManipulationPoint.Index, seedNode);
     105      selectedManipulationPoint.Parent.RemoveSubtree(selectedManipulationPoint.Index);
     106      selectedManipulationPoint.Parent.InsertSubtree(selectedManipulationPoint.Index, seedNode);
    107107      ProbabilisticTreeCreator.PTC2(random, seedNode, selectedManipulationPoint.MaxLength, selectedManipulationPoint.MaxDepth);
    108108    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs

    r5728 r5733  
    3030  public class SymbolicExpressionTreeNode : DeepCloneable, ISymbolicExpressionTreeNode {
    3131    [Storable]
    32     private IList<ISymbolicExpressionTreeNode> subTrees;
     32    private IList<ISymbolicExpressionTreeNode> subtrees;
    3333    [Storable]
    3434    private ISymbol symbol;
     
    5555      : base() {
    5656      symbol = original.symbol; // symbols are reused
    57       subTrees = new List<ISymbolicExpressionTreeNode>(original.subTrees.Count);
    58       foreach (var subtree in original.subTrees) {
    59         var clonedSubTree = cloner.Clone(subtree);
    60         subTrees.Add(clonedSubTree);
    61         clonedSubTree.Parent = this;
     57      subtrees = new List<ISymbolicExpressionTreeNode>(original.subtrees.Count);
     58      foreach (var subtree in original.subtrees) {
     59        var clonedSubtree = cloner.Clone(subtree);
     60        subtrees.Add(clonedSubtree);
     61        clonedSubtree.Parent = this;
    6262      }
    6363    }
     
    7474    public SymbolicExpressionTreeNode(ISymbol symbol)
    7575      : base() {
    76       subTrees = new List<ISymbolicExpressionTreeNode>(3);
     76      subtrees = new List<ISymbolicExpressionTreeNode>(3);
    7777      this.symbol = symbol;
    7878    }
     
    8181    [StorableHook(HookType.AfterDeserialization)]
    8282    private void AfterDeserialization() {
    83       if (subTrees != null) {
    84         foreach (var subtree in subTrees)
     83      if (subtrees != null) {
     84        foreach (var subtree in subtrees)
    8585          subtree.Parent = this;
    8686      }
     
    9191    }
    9292
    93     public virtual IEnumerable<ISymbolicExpressionTreeNode> SubTrees {
    94       get { return subTrees; }
     93    public virtual IEnumerable<ISymbolicExpressionTreeNode> Subtrees {
     94      get { return subtrees; }
    9595    }
    9696
     
    103103      else {
    104104        length = 1;
    105         if (subTrees != null) {
    106           for (int i = 0; i < subTrees.Count; i++) {
    107             checked { length += (ushort)subTrees[i].GetLength(); }
     105        if (subtrees != null) {
     106          for (int i = 0; i < subtrees.Count; i++) {
     107            checked { length += (ushort)subtrees[i].GetLength(); }
    108108          }
    109109        }
     
    115115      if (depth > 0) return depth;
    116116      else {
    117         if (subTrees != null) {
    118           for (int i = 0; i < subTrees.Count; i++) depth = Math.Max(depth, (ushort)subTrees[i].GetDepth());
     117        if (subtrees != null) {
     118          for (int i = 0; i < subtrees.Count; i++) depth = Math.Max(depth, (ushort)subtrees[i].GetDepth());
    119119        }
    120120        depth++;
     
    128128    public int SubtreesCount {
    129129      get {
    130         if (subTrees == null) return 0;
    131         return subTrees.Count;
     130        if (subtrees == null) return 0;
     131        return subtrees.Count;
    132132      }
    133133    }
    134134
    135     public virtual ISymbolicExpressionTreeNode GetSubTree(int index) {
    136       return subTrees[index];
     135    public virtual ISymbolicExpressionTreeNode GetSubtree(int index) {
     136      return subtrees[index];
    137137    }
    138     public virtual int IndexOfSubTree(ISymbolicExpressionTreeNode tree) {
    139       return subTrees.IndexOf(tree);
     138    public virtual int IndexOfSubtree(ISymbolicExpressionTreeNode tree) {
     139      return subtrees.IndexOf(tree);
    140140    }
    141     public virtual void AddSubTree(ISymbolicExpressionTreeNode tree) {
    142       subTrees.Add(tree);
     141    public virtual void AddSubtree(ISymbolicExpressionTreeNode tree) {
     142      subtrees.Add(tree);
    143143      tree.Parent = this;
    144144      ResetCachedValues();
    145145    }
    146     public virtual void InsertSubTree(int index, ISymbolicExpressionTreeNode tree) {
    147       subTrees.Insert(index, tree);
     146    public virtual void InsertSubtree(int index, ISymbolicExpressionTreeNode tree) {
     147      subtrees.Insert(index, tree);
    148148      tree.Parent = this;
    149149      ResetCachedValues();
    150150    }
    151     public virtual void RemoveSubTree(int index) {
    152       subTrees[index].Parent = null;
    153       subTrees.RemoveAt(index);
     151    public virtual void RemoveSubtree(int index) {
     152      subtrees[index].Parent = null;
     153      subtrees.RemoveAt(index);
    154154      ResetCachedValues();
    155155    }
     
    163163    public void ForEachNodePrefix(Action<ISymbolicExpressionTreeNode> a) {
    164164      a(this);
    165       if (SubTrees != null) {
    166         foreach (var subtree in SubTrees) {
     165      if (Subtrees != null) {
     166        foreach (var subtree in Subtrees) {
    167167          subtree.ForEachNodePrefix(a);
    168168        }
     
    177177
    178178    public void ForEachNodePostfix(Action<ISymbolicExpressionTreeNode> a) {
    179       if (SubTrees != null) {
    180         foreach (var subtree in SubTrees) {
     179      if (Subtrees != null) {
     180        foreach (var subtree in Subtrees) {
    181181          subtree.ForEachNodePostfix(a);
    182182        }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeTerminalNode.cs

    r5686 r5733  
    2929  [StorableClass]
    3030  public abstract class SymbolicExpressionTreeTerminalNode : SymbolicExpressionTreeNode {
    31     public override IEnumerable<ISymbolicExpressionTreeNode> SubTrees {
     31    public override IEnumerable<ISymbolicExpressionTreeNode> Subtrees {
    3232      get {
    3333        return Enumerable.Empty<ISymbolicExpressionTreeNode>();
     
    5151    }
    5252
    53     public override int IndexOfSubTree(ISymbolicExpressionTreeNode tree) {
     53    public override int IndexOfSubtree(ISymbolicExpressionTreeNode tree) {
    5454      return -1;
    5555    }
    56     public override ISymbolicExpressionTreeNode GetSubTree(int index) {
     56    public override ISymbolicExpressionTreeNode GetSubtree(int index) {
    5757      throw new NotSupportedException();
    5858    }
    59     public override void AddSubTree(ISymbolicExpressionTreeNode tree) {
     59    public override void AddSubtree(ISymbolicExpressionTreeNode tree) {
    6060      throw new NotSupportedException();
    6161    }
    62     public override void InsertSubTree(int index, ISymbolicExpressionTreeNode tree) {
     62    public override void InsertSubtree(int index, ISymbolicExpressionTreeNode tree) {
    6363      throw new NotSupportedException();
    6464    }
    65     public override void RemoveSubTree(int index) {
     65    public override void RemoveSubtree(int index) {
    6666      throw new NotSupportedException();
    6767    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/AllArchitectureAlteringOperatorsTest.cs

    r5686 r5733  
    110110        Util.GetSizeDistributionString(trees, 200, 5) + Environment.NewLine +
    111111        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    112         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     112        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    113113        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    114114        );
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentCreaterTest.cs

    r5686 r5733  
    7272        Util.GetSizeDistributionString(trees, 200, 20) + Environment.NewLine +
    7373        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    74         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     74        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    7575        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    7676        );
     
    7878
    7979    private bool TreeHasAdfWithParameter(ISymbolicExpressionTree tree, int maxParameters) {
    80       if (tree.Root.SubTrees.Count() != 2) return false;
    81       var firstAdf = tree.Root.GetSubTree(1);
     80      if (tree.Root.Subtrees.Count() != 2) return false;
     81      var firstAdf = tree.Root.GetSubtree(1);
    8282      return firstAdf.Grammar.GetAllowedChildSymbols(firstAdf.Symbol, 0).Where(x => x is Argument).Count() < maxParameters;
    8383    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentDeleterTest.cs

    r5686 r5733  
    6767        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
    6868        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    69         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     69        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    7070        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    7171        );
    7272    }
    7373    private bool TreeHasAdfWithArguments(ISymbolicExpressionTree tree) {
    74       if (tree.Root.SubTrees.Count() != 2) return false;
    75       var firstAdf = tree.Root.GetSubTree(1);
     74      if (tree.Root.Subtrees.Count() != 2) return false;
     75      var firstAdf = tree.Root.GetSubtree(1);
    7676      return firstAdf.Grammar.GetAllowedChildSymbols(firstAdf.Symbol, 0).Where(x => x is Argument).Count() >= 2;
    7777    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentDuplicaterTest.cs

    r5686 r5733  
    6767        Util.GetSizeDistributionString(trees, 200, 5) + Environment.NewLine +
    6868        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    69         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     69        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    7070        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    7171        );
     
    7373
    7474    private bool HasAdfWithArguments(ISymbolicExpressionTree tree) {
    75       if (tree.Root.SubTrees.Count() != 2) return false;
    76       var firstAdf = tree.Root.GetSubTree(1);
     75      if (tree.Root.Subtrees.Count() != 2) return false;
     76      var firstAdf = tree.Root.GetSubtree(1);
    7777      return firstAdf.Grammar.GetAllowedChildSymbols(firstAdf.Symbol, 0).Where(x => x is Argument).Count() == 1;
    7878    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ChangeNodeTypeManipulationTest.cs

    r5686 r5733  
    6767        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
    6868        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    69         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     69        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    7070        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    7171        );
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ProbabilisticTreeCreaterTest.cs

    r5686 r5733  
    6969        Util.GetSizeDistributionString(randomTrees, 105, 5) + Environment.NewLine +
    7070        Util.GetFunctionDistributionString(randomTrees) + Environment.NewLine +
    71         Util.GetNumberOfSubTreesDistributionString(randomTrees) + Environment.NewLine +
     71        Util.GetNumberOfSubtreesDistributionString(randomTrees) + Environment.NewLine +
    7272        Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine
    7373        );
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ReplaceBranchManipulationTest.cs

    r5686 r5733  
    6666        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
    6767        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    68         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     68        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    6969        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    7070        );
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubroutineCreaterTest.cs

    r5686 r5733  
    6363        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
    6464        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    65         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     65        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    6666        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    6767        );
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubroutineDeleterTest.cs

    r5686 r5733  
    6868        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
    6969        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    70         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     70        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    7171        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    7272        );
     
    7474
    7575    private bool HasAtLeastOneAdf(ISymbolicExpressionTree tree) {
    76       return tree.Root.SubTrees.Count() > 1;
     76      return tree.Root.Subtrees.Count() > 1;
    7777    }
    7878  }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubroutineDuplicaterTest.cs

    r5686 r5733  
    6868        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
    6969        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    70         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     70        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    7171        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    7272        );
     
    7474
    7575    private bool HasOneAdf(ISymbolicExpressionTree tree) {
    76       return tree.Root.SubTrees.Count() == 2;
     76      return tree.Root.Subtrees.Count() == 2;
    7777    }
    7878  }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubtreeCrossoverTest.cs

    r5686 r5733  
    8181        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
    8282        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
    83         Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
     83        Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
    8484        Util.GetTerminalDistributionString(trees) + Environment.NewLine
    8585        );
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Util.cs

    r5686 r5733  
    5353      for (int i = 0; i < trees.Count; i++) {
    5454        foreach (var node in trees[i].IterateNodesPrefix()) {
    55           if (node.SubTrees.Count() > 0) {
     55          if (node.Subtrees.Count() > 0) {
    5656            if (!occurances.ContainsKey(node.Symbol.Name))
    5757              occurances[node.Symbol.Name] = 0;
     
    7070    }
    7171
    72     public static string GetNumberOfSubTreesDistributionString(IList<ISymbolicExpressionTree> trees) {
     72    public static string GetNumberOfSubtreesDistributionString(IList<ISymbolicExpressionTree> trees) {
    7373      Dictionary<int, int> occurances = new Dictionary<int, int>();
    7474      double n = 0.0;
    7575      for (int i = 0; i < trees.Count; i++) {
    7676        foreach (var node in trees[i].IterateNodesPrefix()) {
    77           if (!occurances.ContainsKey(node.SubTrees.Count()))
    78             occurances[node.SubTrees.Count()] = 0;
    79           occurances[node.SubTrees.Count()]++;
     77          if (!occurances.ContainsKey(node.Subtrees.Count()))
     78            occurances[node.Subtrees.Count()] = 0;
     79          occurances[node.Subtrees.Count()]++;
    8080          n++;
    8181        }
     
    9696      for (int i = 0; i < trees.Count; i++) {
    9797        foreach (var node in trees[i].IterateNodesPrefix()) {
    98           if (node.SubTrees.Count() == 0) {
     98          if (node.Subtrees.Count() == 0) {
    9999            if (!occurances.ContainsKey(node.Symbol.Name))
    100100              occurances[node.Symbol.Name] = 0;
     
    118118      Assert.AreEqual(actualSize, reportedSize);
    119119
    120       foreach (var defunTreeNode in tree.Root.SubTrees.OfType<DefunTreeNode>()) {
     120      foreach (var defunTreeNode in tree.Root.Subtrees.OfType<DefunTreeNode>()) {
    121121        int arity = defunTreeNode.NumberOfArguments;
    122122
     
    133133
    134134        var invoke = new InvokeFunction(defunTreeNode.FunctionName);
    135         foreach (var otherRootNode in tree.Root.SubTrees) {
     135        foreach (var otherRootNode in tree.Root.Subtrees) {
    136136          if (otherRootNode.Grammar.ContainsSymbol(invoke)) {
    137137            Assert.IsTrue(otherRootNode.Grammar.GetMinimumSubtreeCount(invoke) == arity);
     
    141141
    142142      }
    143       foreach (var subtree in tree.Root.SubTrees) {
     143      foreach (var subtree in tree.Root.Subtrees) {
    144144        Assert.AreNotSame(subtree.Grammar, tree.Root.Grammar);
    145145        IsValid(subtree.Grammar);
     
    165165                            where symb.Name == treeNode.Symbol.Name
    166166                            select symb).SingleOrDefault();
    167       Assert.IsTrue(treeNode.SubTrees.Count() >= treeNode.Grammar.GetMinimumSubtreeCount(matchingSymbol));
    168       Assert.IsTrue(treeNode.SubTrees.Count() <= treeNode.Grammar.GetMaximumSubtreeCount(matchingSymbol));
     167      Assert.IsTrue(treeNode.Subtrees.Count() >= treeNode.Grammar.GetMinimumSubtreeCount(matchingSymbol));
     168      Assert.IsTrue(treeNode.Subtrees.Count() <= treeNode.Grammar.GetMaximumSubtreeCount(matchingSymbol));
    169169      Assert.AreNotEqual(0.0, matchingSymbol.InitialFrequency); // check that no deactivated symbols occur in the tree
    170       for (int i = 0; i < treeNode.SubTrees.Count(); i++) {
    171         Assert.IsTrue(treeNode.Grammar.GetAllowedChildSymbols(treeNode.Symbol, i).Select(x => x.Name).Contains(treeNode.GetSubTree(i).Symbol.Name));
    172         IsValid(treeNode.GetSubTree(i));
     170      for (int i = 0; i < treeNode.Subtrees.Count(); i++) {
     171        Assert.IsTrue(treeNode.Grammar.GetAllowedChildSymbols(treeNode.Symbol, i).Select(x => x.Name).Contains(treeNode.GetSubtree(i).Symbol.Name));
     172        IsValid(treeNode.GetSubtree(i));
    173173      }
    174174    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/AntInterpreter.cs

    r5517 r5733  
    5151
    5252    private SymbolicExpressionTreeNode FindMatchingFunction(string name) {
    53       foreach (var defunBranch in expression.Root.SubTrees.OfType<DefunTreeNode>()) {
     53      foreach (var defunBranch in expression.Root.Subtrees.OfType<DefunTreeNode>()) {
    5454        if (defunBranch.FunctionName == name) return defunBranch;
    5555      }
     
    9393      // expression evaluated completly => start at root again
    9494      if (nodeStack.Count == 0) {
    95         nodeStack.Push(Expression.Root.GetSubTree(0).GetSubTree(0));
     95        nodeStack.Push(Expression.Root.GetSubtree(0).GetSubtree(0));
    9696      }
    9797
     
    114114        NextField(out nextAntLocationRow, out nextAntLocationColumn);
    115115        if (World[nextAntLocationRow, nextAntLocationColumn]) {
    116           nodeStack.Push(currentNode.GetSubTree(0));
     116          nodeStack.Push(currentNode.GetSubtree(0));
    117117        } else {
    118           nodeStack.Push(currentNode.GetSubTree(1));
     118          nodeStack.Push(currentNode.GetSubtree(1));
    119119        }
    120120      } else if (currentNode.Symbol is Prog2) {
    121         nodeStack.Push(currentNode.GetSubTree(1));
    122         nodeStack.Push(currentNode.GetSubTree(0));
     121        nodeStack.Push(currentNode.GetSubtree(1));
     122        nodeStack.Push(currentNode.GetSubtree(0));
    123123        return;
    124124      } else if (currentNode.Symbol is Prog3) {
    125         nodeStack.Push(currentNode.GetSubTree(2));
    126         nodeStack.Push(currentNode.GetSubTree(1));
    127         nodeStack.Push(currentNode.GetSubTree(0));
     125        nodeStack.Push(currentNode.GetSubtree(2));
     126        nodeStack.Push(currentNode.GetSubtree(1));
     127        nodeStack.Push(currentNode.GetSubtree(0));
    128128        return;
    129129      } else if (currentNode.Symbol is InvokeFunction) {
     
    131131        var functionDefinition = (SymbolicExpressionTreeNode)FindMatchingFunction(invokeNode.Symbol.FunctionName).Clone();
    132132        var argumentCutPoints = (from node in functionDefinition.IterateNodesPrefix()
    133                                  where node.SubTrees.Count() > 0
    134                                  from subtree in node.SubTrees
     133                                 where node.Subtrees.Count() > 0
     134                                 from subtree in node.Subtrees
    135135                                 where subtree is ArgumentTreeNode
    136                                  select new { Parent = node, Argument = subtree.Symbol as Argument, ChildIndex = node.IndexOfSubTree(subtree) }).ToList();
     136                                 select new { Parent = node, Argument = subtree.Symbol as Argument, ChildIndex = node.IndexOfSubtree(subtree) }).ToList();
    137137        foreach (var cutPoint in argumentCutPoints) {
    138           cutPoint.Parent.RemoveSubTree(cutPoint.ChildIndex);
    139           cutPoint.Parent.InsertSubTree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubTree(cutPoint.Argument.ArgumentIndex).Clone());
     138          cutPoint.Parent.RemoveSubtree(cutPoint.ChildIndex);
     139          cutPoint.Parent.InsertSubtree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubtree(cutPoint.Argument.ArgumentIndex).Clone());
    140140        }
    141         nodeStack.Push(functionDefinition.GetSubTree(0));
     141        nodeStack.Push(functionDefinition.GetSubtree(0));
    142142      } else {
    143143        throw new InvalidOperationException(currentNode.Symbol.ToString());
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs

    r5722 r5733  
    3030  [StorableClass]
    3131  [Creatable("Problems")]
    32   public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {
     32  public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem {
    3333    private const double PunishmentFactor = 10;
    3434    private const int InitialMaximumTreeDepth = 8;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r5722 r5733  
    3030  [StorableClass]
    3131  [Creatable("Problems")]
    32   public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {
     32  public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem {
    3333    private const double PunishmentFactor = 10;
    3434    private const int InitialMaximumTreeDepth = 8;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r5729 r5733  
    111111    <Compile Include="SymbolicRegressionModel.cs" />
    112112    <Compile Include="Interfaces\ISymbolicRegressionModel.cs" />
    113     <Compile Include="Interfaces\ISymbolicRegressionProblem.cs" />
    114     <Compile Include="Interfaces\ISymbolicRegressionSingleObjectiveProblem.cs" />
    115113    <Compile Include="Interfaces\ISymbolicRegressionSolution.cs" />
    116114    <Compile Include="Interfaces\ISymbolicRegressionEvaluator.cs" />
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs

    r5722 r5733  
    3131  [StorableClass]
    3232  [Creatable("Problems")]
    33   public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {
     33  public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem {
    3434    private const double PunishmentFactor = 10;
    3535    private const int InitialMaximumTreeDepth = 8;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r5722 r5733  
    3131  [StorableClass]
    3232  [Creatable("Problems")]
    33   public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {
     33  public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>,IRegressionProblem {
    3434    private const double PunishmentFactor = 10;
    3535    private const int InitialMaximumTreeDepth = 8;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r5729 r5733  
    7373      ConstantTreeNode betaTreeNode = null;
    7474      // check if model has been scaled previously by analyzing the structure of the tree
    75       var startNode = Model.SymbolicExpressionTree.Root.GetSubTree(0);
    76       if (startNode.GetSubTree(0).Symbol is Addition) {
    77         var addNode = startNode.GetSubTree(0);
    78         if (addNode.SubtreesCount == 2 && addNode.GetSubTree(0).Symbol is Multiplication && addNode.GetSubTree(1).Symbol is Constant) {
    79           alphaTreeNode = addNode.GetSubTree(1) as ConstantTreeNode;
    80           var mulNode = addNode.GetSubTree(0);
    81           if (mulNode.SubtreesCount == 2 && mulNode.GetSubTree(1).Symbol is Constant) {
    82             betaTreeNode = mulNode.GetSubTree(1) as ConstantTreeNode;
     75      var startNode = Model.SymbolicExpressionTree.Root.GetSubtree(0);
     76      if (startNode.GetSubtree(0).Symbol is Addition) {
     77        var addNode = startNode.GetSubtree(0);
     78        if (addNode.SubtreesCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {
     79          alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;
     80          var mulNode = addNode.GetSubtree(0);
     81          if (mulNode.SubtreesCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {
     82            betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;
    8383          }
    8484        }
     
    9090        alphaTreeNode.Value += alpha;
    9191      } else {
    92         var mainBranch = startNode.GetSubTree(0);
    93         startNode.RemoveSubTree(0);
     92        var mainBranch = startNode.GetSubtree(0);
     93        startNode.RemoveSubtree(0);
    9494        var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha);
    95         startNode.AddSubTree(scaledMainBranch);
     95        startNode.AddSubtree(scaledMainBranch);
    9696      }
    9797
     
    105105        var node = (new Addition()).CreateTreeNode();
    106106        var alphaConst = MakeConstant(alpha);
    107         node.AddSubTree(treeNode);
    108         node.AddSubTree(alphaConst);
     107        node.AddSubtree(treeNode);
     108        node.AddSubtree(alphaConst);
    109109        return node;
    110110      }
     
    117117        var node = (new Multiplication()).CreateTreeNode();
    118118        var betaConst = MakeConstant(beta);
    119         node.AddSubTree(treeNode);
    120         node.AddSubTree(betaConst);
     119        node.AddSubtree(treeNode);
     120        node.AddSubtree(betaConst);
    121121        return node;
    122122      }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs

    r5732 r5733  
    153153        var varCondNode = node as VariableConditionTreeNode;
    154154        IncReferenceCount(references, varCondNode.VariableName, currentLag);
    155         GetVariableReferences(references, node.GetSubTree(0), currentLag);
    156         GetVariableReferences(references, node.GetSubTree(1), currentLag);
     155        GetVariableReferences(references, node.GetSubtree(0), currentLag);
     156        GetVariableReferences(references, node.GetSubtree(1), currentLag);
    157157      } else if (node.Symbol is Integral) {
    158158        var laggedNode = node as LaggedTreeNode;
    159159        for (int l = laggedNode.Lag; l <= 0; l++) {
    160           GetVariableReferences(references, node.GetSubTree(0), currentLag + l);
     160          GetVariableReferences(references, node.GetSubtree(0), currentLag + l);
    161161        }
    162162      } else if (node.Symbol is Derivative) {
    163163        var laggedNode = node as LaggedTreeNode;
    164164        for (int l = laggedNode.Lag; l <= 0; l++) {
    165           GetVariableReferences(references, node.GetSubTree(0), currentLag + l);
     165          GetVariableReferences(references, node.GetSubtree(0), currentLag + l);
    166166        }
    167167      } else if (node.Symbol is TimeLag) {
    168168        var laggedNode = node as LaggedTreeNode;
    169         GetVariableReferences(references, node.GetSubTree(0), currentLag + laggedNode.Lag);
     169        GetVariableReferences(references, node.GetSubtree(0), currentLag + laggedNode.Lag);
    170170      }
    171171    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r5720 r5733  
    185185    <Compile Include="Interfaces\ISymbolicDataAnalysisSolution.cs" />
    186186    <Compile Include="Interfaces\ISymbolicDataAnalysisSolutionCreator.cs" />
    187     <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" />
    188187    <Compile Include="Properties\AssemblyInfo.cs" />
    189188  </ItemGroup>
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r5574 r5733  
    5555      var clone = (ISymbolicExpressionTreeNode)originalTree.Root.Clone();
    5656      // macro expand (initially no argument trees)
    57       var macroExpandedTree = MacroExpand(clone, clone.GetSubTree(0), new List<ISymbolicExpressionTreeNode>());
     57      var macroExpandedTree = MacroExpand(clone, clone.GetSubtree(0), new List<ISymbolicExpressionTreeNode>());
    5858      ISymbolicExpressionTreeNode rootNode = (new ProgramRootSymbol()).CreateTreeNode();
    59       rootNode.AddSubTree(GetSimplifiedTree(macroExpandedTree));
     59      rootNode.AddSubtree(GetSimplifiedTree(macroExpandedTree));
    6060      return new SymbolicExpressionTree(rootNode);
    6161    }
     
    6363    // the argumentTrees list contains already expanded trees used as arguments for invocations
    6464    private ISymbolicExpressionTreeNode MacroExpand(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode node, IList<ISymbolicExpressionTreeNode> argumentTrees) {
    65       List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.SubTrees);
    66       while (node.SubTrees.Count() > 0) node.RemoveSubTree(0);
     65      List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);
     66      while (node.SubtreesCount > 0) node.RemoveSubtree(0);
    6767      if (node.Symbol is InvokeFunction) {
    6868        var invokeSym = node.Symbol as InvokeFunction;
     
    8080        // recursive application
    8181        foreach (var subtree in subtrees) {
    82           node.AddSubTree(MacroExpand(root, subtree, argumentTrees));
     82          node.AddSubtree(MacroExpand(root, subtree, argumentTrees));
    8383        }
    8484        return node;
     
    8787
    8888    private ISymbolicExpressionTreeNode FindFunctionDefinition(ISymbolicExpressionTreeNode root, string functionName) {
    89       foreach (var subtree in root.SubTrees.OfType<DefunTreeNode>()) {
    90         if (subtree.FunctionName == functionName) return subtree.GetSubTree(0);
     89      foreach (var subtree in root.Subtrees.OfType<DefunTreeNode>()) {
     90        if (subtree.FunctionName == functionName) return subtree.GetSubtree(0);
    9191      }
    9292
     
    232232    private ISymbolicExpressionTreeNode SimplifyAny(ISymbolicExpressionTreeNode original) {
    233233      // can't simplify this function but simplify all subtrees
    234       List<ISymbolicExpressionTreeNode> subTrees = new List<ISymbolicExpressionTreeNode>(original.SubTrees);
    235       while (original.SubTrees.Count() > 0) original.RemoveSubTree(0);
     234      List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(original.Subtrees);
     235      while (original.Subtrees.Count() > 0) original.RemoveSubtree(0);
    236236      var clone = (SymbolicExpressionTreeNode)original.Clone();
    237       List<ISymbolicExpressionTreeNode> simplifiedSubTrees = new List<ISymbolicExpressionTreeNode>();
    238       foreach (var subTree in subTrees) {
    239         simplifiedSubTrees.Add(GetSimplifiedTree(subTree));
    240         original.AddSubTree(subTree);
    241       }
    242       foreach (var simplifiedSubtree in simplifiedSubTrees) {
    243         clone.AddSubTree(simplifiedSubtree);
    244       }
    245       if (simplifiedSubTrees.TrueForAll(t => IsConstant(t))) {
     237      List<ISymbolicExpressionTreeNode> simplifiedSubtrees = new List<ISymbolicExpressionTreeNode>();
     238      foreach (var subtree in subtrees) {
     239        simplifiedSubtrees.Add(GetSimplifiedTree(subtree));
     240        original.AddSubtree(subtree);
     241      }
     242      foreach (var simplifiedSubtree in simplifiedSubtrees) {
     243        clone.AddSubtree(simplifiedSubtree);
     244      }
     245      if (simplifiedSubtrees.TrueForAll(t => IsConstant(t))) {
    246246        SimplifyConstantExpression(clone);
    247247      }
     
    255255
    256256    private ISymbolicExpressionTreeNode SimplifyAverage(ISymbolicExpressionTreeNode original) {
    257       if (original.SubTrees.Count() == 1) {
    258         return GetSimplifiedTree(original.GetSubTree(0));
     257      if (original.Subtrees.Count() == 1) {
     258        return GetSimplifiedTree(original.GetSubtree(0));
    259259      } else {
    260260        // simplify expressions x0..xn
    261261        // make sum(x0..xn) / n
    262         Trace.Assert(original.SubTrees.Count() > 1);
    263         var sum = original.SubTrees
     262        Trace.Assert(original.Subtrees.Count() > 1);
     263        var sum = original.Subtrees
    264264          .Select(x => GetSimplifiedTree(x))
    265265          .Aggregate((a, b) => MakeSum(a, b));
    266         return MakeFraction(sum, MakeConstant(original.SubTrees.Count()));
     266        return MakeFraction(sum, MakeConstant(original.Subtrees.Count()));
    267267      }
    268268    }
    269269
    270270    private ISymbolicExpressionTreeNode SimplifyDivision(ISymbolicExpressionTreeNode original) {
    271       if (original.SubTrees.Count() == 1) {
    272         return Invert(GetSimplifiedTree(original.GetSubTree(0)));
     271      if (original.Subtrees.Count() == 1) {
     272        return Invert(GetSimplifiedTree(original.GetSubtree(0)));
    273273      } else {
    274274        // simplify expressions x0..xn
    275275        // make multiplication (x0 * 1/(x1 * x1 * .. * xn))
    276         Trace.Assert(original.SubTrees.Count() > 1);
    277         var simplifiedTrees = original.SubTrees.Select(x => GetSimplifiedTree(x));
     276        Trace.Assert(original.Subtrees.Count() > 1);
     277        var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x));
    278278        return
    279279          MakeProduct(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate((a, b) => MakeProduct(a, b))));
     
    282282
    283283    private ISymbolicExpressionTreeNode SimplifyMultiplication(ISymbolicExpressionTreeNode original) {
    284       if (original.SubTrees.Count() == 1) {
    285         return GetSimplifiedTree(original.GetSubTree(0));
    286       } else {
    287         Trace.Assert(original.SubTrees.Count() > 1);
    288         return original.SubTrees
     284      if (original.Subtrees.Count() == 1) {
     285        return GetSimplifiedTree(original.GetSubtree(0));
     286      } else {
     287        Trace.Assert(original.Subtrees.Count() > 1);
     288        return original.Subtrees
    289289          .Select(x => GetSimplifiedTree(x))
    290290          .Aggregate((a, b) => MakeProduct(a, b));
     
    293293
    294294    private ISymbolicExpressionTreeNode SimplifySubtraction(ISymbolicExpressionTreeNode original) {
    295       if (original.SubTrees.Count() == 1) {
    296         return Negate(GetSimplifiedTree(original.GetSubTree(0)));
     295      if (original.Subtrees.Count() == 1) {
     296        return Negate(GetSimplifiedTree(original.GetSubtree(0)));
    297297      } else {
    298298        // simplify expressions x0..xn
    299299        // make addition (x0,-x1..-xn)
    300         Trace.Assert(original.SubTrees.Count() > 1);
    301         var simplifiedTrees = original.SubTrees.Select(x => GetSimplifiedTree(x));
     300        Trace.Assert(original.Subtrees.Count() > 1);
     301        var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x));
    302302        return simplifiedTrees.Take(1)
    303303          .Concat(simplifiedTrees.Skip(1).Select(x => Negate(x)))
     
    307307
    308308    private ISymbolicExpressionTreeNode SimplifyAddition(ISymbolicExpressionTreeNode original) {
    309       if (original.SubTrees.Count() == 1) {
    310         return GetSimplifiedTree(original.GetSubTree(0));
     309      if (original.Subtrees.Count() == 1) {
     310        return GetSimplifiedTree(original.GetSubtree(0));
    311311      } else {
    312312        // simplify expression x0..xn
    313313        // make addition (x0..xn)
    314         Trace.Assert(original.SubTrees.Count() > 1);
    315         return original.SubTrees
     314        Trace.Assert(original.Subtrees.Count() > 1);
     315        return original.Subtrees
    316316          .Select(x => GetSimplifiedTree(x))
    317317          .Aggregate((a, b) => MakeSum(a, b));
     
    320320
    321321    private ISymbolicExpressionTreeNode SimplifyNot(ISymbolicExpressionTreeNode original) {
    322       return MakeNot(GetSimplifiedTree(original.GetSubTree(0)));
     322      return MakeNot(GetSimplifiedTree(original.GetSubtree(0)));
    323323    }
    324324    private ISymbolicExpressionTreeNode SimplifyOr(ISymbolicExpressionTreeNode original) {
    325       return original.SubTrees
     325      return original.Subtrees
    326326        .Select(x => GetSimplifiedTree(x))
    327327        .Aggregate((a, b) => MakeOr(a, b));
    328328    }
    329329    private ISymbolicExpressionTreeNode SimplifyAnd(ISymbolicExpressionTreeNode original) {
    330       return original.SubTrees
     330      return original.Subtrees
    331331        .Select(x => GetSimplifiedTree(x))
    332332        .Aggregate((a, b) => MakeAnd(a, b));
    333333    }
    334334    private ISymbolicExpressionTreeNode SimplifyLessThan(ISymbolicExpressionTreeNode original) {
    335       return MakeLessThan(GetSimplifiedTree(original.GetSubTree(0)), GetSimplifiedTree(original.GetSubTree(1)));
     335      return MakeLessThan(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)));
    336336    }
    337337    private ISymbolicExpressionTreeNode SimplifyGreaterThan(ISymbolicExpressionTreeNode original) {
    338       return MakeGreaterThan(GetSimplifiedTree(original.GetSubTree(0)), GetSimplifiedTree(original.GetSubTree(1)));
     338      return MakeGreaterThan(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)));
    339339    }
    340340    private ISymbolicExpressionTreeNode SimplifyIfThenElse(ISymbolicExpressionTreeNode original) {
    341       return MakeIfThenElse(GetSimplifiedTree(original.GetSubTree(0)), GetSimplifiedTree(original.GetSubTree(1)), GetSimplifiedTree(original.GetSubTree(2)));
     341      return MakeIfThenElse(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)), GetSimplifiedTree(original.GetSubtree(2)));
    342342    }
    343343    private ISymbolicExpressionTreeNode SimplifyTangent(ISymbolicExpressionTreeNode original) {
    344       return MakeTangent(GetSimplifiedTree(original.GetSubTree(0)));
     344      return MakeTangent(GetSimplifiedTree(original.GetSubtree(0)));
    345345    }
    346346    private ISymbolicExpressionTreeNode SimplifyCosine(ISymbolicExpressionTreeNode original) {
    347       return MakeCosine(GetSimplifiedTree(original.GetSubTree(0)));
     347      return MakeCosine(GetSimplifiedTree(original.GetSubtree(0)));
    348348    }
    349349    private ISymbolicExpressionTreeNode SimplifySine(ISymbolicExpressionTreeNode original) {
    350       return MakeSine(GetSimplifiedTree(original.GetSubTree(0)));
     350      return MakeSine(GetSimplifiedTree(original.GetSubtree(0)));
    351351    }
    352352    private ISymbolicExpressionTreeNode SimplifyExp(ISymbolicExpressionTreeNode original) {
    353       return MakeExp(GetSimplifiedTree(original.GetSubTree(0)));
     353      return MakeExp(GetSimplifiedTree(original.GetSubtree(0)));
    354354    }
    355355
    356356    private ISymbolicExpressionTreeNode SimplifyLog(ISymbolicExpressionTreeNode original) {
    357       return MakeLog(GetSimplifiedTree(original.GetSubTree(0)));
     357      return MakeLog(GetSimplifiedTree(original.GetSubtree(0)));
    358358    }
    359359    private ISymbolicExpressionTreeNode SimplifyRoot(ISymbolicExpressionTreeNode original) {
    360       return MakeRoot(GetSimplifiedTree(original.GetSubTree(0)), GetSimplifiedTree(original.GetSubTree(1)));
     360      return MakeRoot(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)));
    361361    }
    362362
    363363    private ISymbolicExpressionTreeNode SimplifyPower(ISymbolicExpressionTreeNode original) {
    364       return MakePower(GetSimplifiedTree(original.GetSubTree(0)), GetSimplifiedTree(original.GetSubTree(1)));
     364      return MakePower(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)));
    365365    }
    366366    #endregion
     
    373373        else return MakeConstant(1.0);
    374374      } else if (IsNot(t)) {
    375         return t.GetSubTree(0);
     375        return t.GetSubtree(0);
    376376      } else if (!IsBoolean(t)) {
    377377        var gtNode = gtSymbol.CreateTreeNode();
    378         gtNode.AddSubTree(t); gtNode.AddSubTree(MakeConstant(0.0));
     378        gtNode.AddSubtree(t); gtNode.AddSubtree(MakeConstant(0.0));
    379379        var notNode = notSymbol.CreateTreeNode();
    380         notNode.AddSubTree(gtNode);
     380        notNode.AddSubtree(gtNode);
    381381        return notNode;
    382382      } else {
    383383        var notNode = notSymbol.CreateTreeNode();
    384         notNode.AddSubTree(t);
     384        notNode.AddSubtree(t);
    385385        return notNode;
    386386      }
     
    406406          // the constant value has no effect on the result of the boolean condition so we can drop the constant term
    407407          var orNode = orSymbol.CreateTreeNode();
    408           orNode.AddSubTree(a);
     408          orNode.AddSubtree(a);
    409409          return orNode;
    410410        }
    411411      } else {
    412412        var orNode = orSymbol.CreateTreeNode();
    413         orNode.AddSubTree(a);
    414         orNode.AddSubTree(b);
     413        orNode.AddSubtree(a);
     414        orNode.AddSubtree(b);
    415415        return orNode;
    416416      }
     
    432432          // the constant value has no effect on the result of the boolean condition so we can drop the constant term
    433433          var andNode = andSymbol.CreateTreeNode();
    434           andNode.AddSubTree(a);
     434          andNode.AddSubtree(a);
    435435          return andNode;
    436436        } else {
     
    440440      } else {
    441441        var andNode = andSymbol.CreateTreeNode();
    442         andNode.AddSubTree(a);
    443         andNode.AddSubTree(b);
     442        andNode.AddSubtree(a);
     443        andNode.AddSubtree(b);
    444444        return andNode;
    445445      }
     
    453453      } else {
    454454        var ltNode = ltSymbol.CreateTreeNode();
    455         ltNode.AddSubTree(leftSide);
    456         ltNode.AddSubTree(rightSide);
     455        ltNode.AddSubtree(leftSide);
     456        ltNode.AddSubtree(rightSide);
    457457        return ltNode;
    458458      }
     
    466466      } else {
    467467        var gtNode = gtSymbol.CreateTreeNode();
    468         gtNode.AddSubTree(leftSide);
    469         gtNode.AddSubTree(rightSide);
     468        gtNode.AddSubtree(leftSide);
     469        gtNode.AddSubtree(rightSide);
    470470        return gtNode;
    471471      }
     
    479479        var ifNode = ifThenElseSymbol.CreateTreeNode();
    480480        if (IsBoolean(condition)) {
    481           ifNode.AddSubTree(condition);
     481          ifNode.AddSubtree(condition);
    482482        } else {
    483483          var gtNode = gtSymbol.CreateTreeNode();
    484           gtNode.AddSubTree(condition); gtNode.AddSubTree(MakeConstant(0.0));
    485           ifNode.AddSubTree(gtNode);
    486         }
    487         ifNode.AddSubTree(trueBranch);
    488         ifNode.AddSubTree(falseBranch);
     484          gtNode.AddSubtree(condition); gtNode.AddSubtree(MakeConstant(0.0));
     485          ifNode.AddSubtree(gtNode);
     486        }
     487        ifNode.AddSubtree(trueBranch);
     488        ifNode.AddSubtree(falseBranch);
    489489        return ifNode;
    490490      }
     
    497497      } else {
    498498        var sineNode = sineSymbol.CreateTreeNode();
    499         sineNode.AddSubTree(node);
     499        sineNode.AddSubtree(node);
    500500        return sineNode;
    501501      }
     
    507507      } else {
    508508        var tanNode = tanSymbol.CreateTreeNode();
    509         tanNode.AddSubTree(node);
     509        tanNode.AddSubtree(node);
    510510        return tanNode;
    511511      }
     
    517517      } else {
    518518        var cosNode = cosineSymbol.CreateTreeNode();
    519         cosNode.AddSubTree(node);
     519        cosNode.AddSubtree(node);
    520520        return cosNode;
    521521      }
     
    526526        return MakeConstant(Math.Exp(constT.Value));
    527527      } else if (IsLog(node)) {
    528         return node.GetSubTree(0);
     528        return node.GetSubtree(0);
    529529      } else if (IsAddition(node)) {
    530         return node.SubTrees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, t));
     530        return node.Subtrees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, t));
    531531      } else if (IsSubtraction(node)) {
    532         return node.SubTrees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, Negate(t)));
     532        return node.Subtrees.Select(s => MakeExp(s)).Aggregate((s, t) => MakeProduct(s, Negate(t)));
    533533      } else {
    534534        var expNode = expSymbol.CreateTreeNode();
    535         expNode.AddSubTree(node);
     535        expNode.AddSubtree(node);
    536536        return expNode;
    537537      }
     
    542542        return MakeConstant(Math.Log(constT.Value));
    543543      } else if (IsExp(node)) {
    544         return node.GetSubTree(0);
     544        return node.GetSubtree(0);
    545545      } else if (IsMultiplication(node)) {
    546         return node.SubTrees.Select(s => MakeLog(s)).Aggregate((x, y) => MakeSum(x, y));
     546        return node.Subtrees.Select(s => MakeLog(s)).Aggregate((x, y) => MakeSum(x, y));
    547547      } else if (IsDivision(node)) {
    548548        var subtractionNode = subSymbol.CreateTreeNode();
    549         foreach (var subTree in node.SubTrees) {
    550           subtractionNode.AddSubTree(MakeLog(subTree));
     549        foreach (var subtree in node.Subtrees) {
     550          subtractionNode.AddSubtree(MakeLog(subtree));
    551551        }
    552552        return subtractionNode;
    553553      } else {
    554554        var logNode = logSymbol.CreateTreeNode();
    555         logNode.AddSubTree(node);
     555        logNode.AddSubtree(node);
    556556        return logNode;
    557557      }
     
    573573        } else if (constBValue < 0) {
    574574          var rootNode = rootSymbol.CreateTreeNode();
    575           rootNode.AddSubTree(a);
    576           rootNode.AddSubTree(MakeConstant(-1.0 * constBValue));
     575          rootNode.AddSubtree(a);
     576          rootNode.AddSubtree(MakeConstant(-1.0 * constBValue));
    577577          return MakeFraction(MakeConstant(1.0), rootNode);
    578578        } else {
    579579          var rootNode = rootSymbol.CreateTreeNode();
    580           rootNode.AddSubTree(a);
    581           rootNode.AddSubTree(MakeConstant(constBValue));
     580          rootNode.AddSubtree(a);
     581          rootNode.AddSubtree(MakeConstant(constBValue));
    582582          return rootNode;
    583583        }
    584584      } else {
    585585        var rootNode = rootSymbol.CreateTreeNode();
    586         rootNode.AddSubTree(a);
    587         rootNode.AddSubTree(b);
     586        rootNode.AddSubtree(a);
     587        rootNode.AddSubtree(b);
    588588        return rootNode;
    589589      }
     
    605605        } else if (exponent < 0) {
    606606          var powNode = powSymbol.CreateTreeNode();
    607           powNode.AddSubTree(a);
    608           powNode.AddSubTree(MakeConstant(-1.0 * exponent));
     607          powNode.AddSubtree(a);
     608          powNode.AddSubtree(MakeConstant(-1.0 * exponent));
    609609          return MakeFraction(MakeConstant(1.0), powNode);
    610610        } else {
    611611          var powNode = powSymbol.CreateTreeNode();
    612           powNode.AddSubTree(a);
    613           powNode.AddSubTree(MakeConstant(exponent));
     612          powNode.AddSubtree(a);
     613          powNode.AddSubtree(MakeConstant(exponent));
    614614          return powNode;
    615615        }
    616616      } else {
    617617        var powNode = powSymbol.CreateTreeNode();
    618         powNode.AddSubTree(a);
    619         powNode.AddSubTree(b);
     618        powNode.AddSubtree(a);
     619        powNode.AddSubtree(b);
    620620        return powNode;
    621621      }
     
    641641        return MakeConstant(aVar.Weight / bVar.Weight);
    642642      } else if (IsAddition(a) && IsConstant(b)) {
    643         return a.SubTrees
     643        return a.Subtrees
    644644          .Select(x => GetSimplifiedTree(x))
    645645         .Select(x => MakeFraction(x, b))
     
    649649      } else if (IsDivision(a) && IsConstant(b)) {
    650650        // (a1 / a2) / c => (a1 / (a2 * c))
    651         Trace.Assert(a.SubTrees.Count() == 2);
    652         return MakeFraction(a.GetSubTree(0), MakeProduct(a.GetSubTree(1), b));
     651        Trace.Assert(a.Subtrees.Count() == 2);
     652        return MakeFraction(a.GetSubtree(0), MakeProduct(a.GetSubtree(1), b));
    653653      } else if (IsDivision(a) && IsDivision(b)) {
    654654        // (a1 / a2) / (b1 / b2) =>
    655         Trace.Assert(a.SubTrees.Count() == 2);
    656         Trace.Assert(b.SubTrees.Count() == 2);
    657         return MakeFraction(MakeProduct(a.GetSubTree(0), b.GetSubTree(1)), MakeProduct(a.GetSubTree(1), b.GetSubTree(0)));
     655        Trace.Assert(a.Subtrees.Count() == 2);
     656        Trace.Assert(b.Subtrees.Count() == 2);
     657        return MakeFraction(MakeProduct(a.GetSubtree(0), b.GetSubtree(1)), MakeProduct(a.GetSubtree(1), b.GetSubtree(0)));
    658658      } else if (IsDivision(a)) {
    659659        // (a1 / a2) / b => (a1 / (a2 * b))
    660         Trace.Assert(a.SubTrees.Count() == 2);
    661         return MakeFraction(a.GetSubTree(0), MakeProduct(a.GetSubTree(1), b));
     660        Trace.Assert(a.Subtrees.Count() == 2);
     661        return MakeFraction(a.GetSubtree(0), MakeProduct(a.GetSubtree(1), b));
    662662      } else if (IsDivision(b)) {
    663663        // a / (b1 / b2) => (a * b2) / b1
    664         Trace.Assert(b.SubTrees.Count() == 2);
    665         return MakeFraction(MakeProduct(a, b.GetSubTree(1)), b.GetSubTree(0));
     664        Trace.Assert(b.Subtrees.Count() == 2);
     665        return MakeFraction(MakeProduct(a, b.GetSubtree(1)), b.GetSubtree(0));
    666666      } else {
    667667        var div = divSymbol.CreateTreeNode();
    668         div.AddSubTree(a);
    669         div.AddSubTree(b);
     668        div.AddSubtree(a);
     669        div.AddSubtree(b);
    670670        return div;
    671671      }
     
    688688        var add = addSymbol.CreateTreeNode();
    689689        // add all sub trees except for the last
    690         for (int i = 0; i < a.SubTrees.Count() - 1; i++) add.AddSubTree(a.GetSubTree(i));
    691         for (int i = 0; i < b.SubTrees.Count() - 1; i++) add.AddSubTree(b.GetSubTree(i));
    692         if (IsConstant(a.SubTrees.Last()) && IsConstant(b.SubTrees.Last())) {
    693           add.AddSubTree(MakeSum(a.SubTrees.Last(), b.SubTrees.Last()));
    694         } else if (IsConstant(a.SubTrees.Last())) {
    695           add.AddSubTree(b.SubTrees.Last());
    696           add.AddSubTree(a.SubTrees.Last());
    697         } else {
    698           add.AddSubTree(a.SubTrees.Last());
    699           add.AddSubTree(b.SubTrees.Last());
     690        for (int i = 0; i < a.Subtrees.Count() - 1; i++) add.AddSubtree(a.GetSubtree(i));
     691        for (int i = 0; i < b.Subtrees.Count() - 1; i++) add.AddSubtree(b.GetSubtree(i));
     692        if (IsConstant(a.Subtrees.Last()) && IsConstant(b.Subtrees.Last())) {
     693          add.AddSubtree(MakeSum(a.Subtrees.Last(), b.Subtrees.Last()));
     694        } else if (IsConstant(a.Subtrees.Last())) {
     695          add.AddSubtree(b.Subtrees.Last());
     696          add.AddSubtree(a.Subtrees.Last());
     697        } else {
     698          add.AddSubtree(a.Subtrees.Last());
     699          add.AddSubtree(b.Subtrees.Last());
    700700        }
    701701        MergeVariablesInSum(add);
    702         if (add.SubTrees.Count() == 1) {
    703           return add.GetSubTree(0);
     702        if (add.Subtrees.Count() == 1) {
     703          return add.GetSubtree(0);
    704704        } else {
    705705          return add;
     
    711711        var add = addSymbol.CreateTreeNode();
    712712        // add all sub trees except for the last
    713         for (int i = 0; i < a.SubTrees.Count() - 1; i++) add.AddSubTree(a.GetSubTree(i));
    714         if (IsConstant(a.SubTrees.Last()))
    715           add.AddSubTree(MakeSum(a.SubTrees.Last(), b));
     713        for (int i = 0; i < a.Subtrees.Count() - 1; i++) add.AddSubtree(a.GetSubtree(i));
     714        if (IsConstant(a.Subtrees.Last()))
     715          add.AddSubtree(MakeSum(a.Subtrees.Last(), b));
    716716        else {
    717           add.AddSubTree(a.SubTrees.Last());
    718           add.AddSubTree(b);
     717          add.AddSubtree(a.Subtrees.Last());
     718          add.AddSubtree(b);
    719719        }
    720720        return add;
     
    722722        // a is already an addition => append b
    723723        var add = addSymbol.CreateTreeNode();
    724         add.AddSubTree(b);
    725         foreach (var subTree in a.SubTrees) {
    726           add.AddSubTree(subTree);
     724        add.AddSubtree(b);
     725        foreach (var subtree in a.Subtrees) {
     726          add.AddSubtree(subtree);
    727727        }
    728728        MergeVariablesInSum(add);
    729         if (add.SubTrees.Count() == 1) {
    730           return add.GetSubTree(0);
     729        if (add.Subtrees.Count() == 1) {
     730          return add.GetSubtree(0);
    731731        } else {
    732732          return add;
     
    734734      } else {
    735735        var add = addSymbol.CreateTreeNode();
    736         add.AddSubTree(a);
    737         add.AddSubTree(b);
     736        add.AddSubtree(a);
     737        add.AddSubtree(b);
    738738        MergeVariablesInSum(add);
    739         if (add.SubTrees.Count() == 1) {
    740           return add.GetSubTree(0);
     739        if (add.Subtrees.Count() == 1) {
     740          return add.GetSubtree(0);
    741741        } else {
    742742          return add;
     
    748748    // possible improvement: combine sums of products where the products only reference the same variable
    749749    private void MergeVariablesInSum(ISymbolicExpressionTreeNode sum) {
    750       var subtrees = new List<ISymbolicExpressionTreeNode>(sum.SubTrees);
    751       while (sum.SubTrees.Count() > 0) sum.RemoveSubTree(0);
     750      var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Subtrees);
     751      while (sum.Subtrees.Count() > 0) sum.RemoveSubtree(0);
    752752      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
    753753                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
    754754                            group node by node.VariableName + lag into g
    755755                            select g;
    756       var unchangedSubTrees = subtrees.Where(t => !(t is VariableTreeNode));
     756      var unchangedSubtrees = subtrees.Where(t => !(t is VariableTreeNode));
    757757
    758758      foreach (var variableNodeGroup in groupedVarNodes) {
     
    760760        var representative = variableNodeGroup.First();
    761761        representative.Weight = weightSum;
    762         sum.AddSubTree(representative);
    763       }
    764       foreach (var unchangedSubtree in unchangedSubTrees)
    765         sum.AddSubTree(unchangedSubtree);
     762        sum.AddSubtree(representative);
     763      }
     764      foreach (var unchangedSubtree in unchangedSubtrees)
     765        sum.AddSubtree(unchangedSubtree);
    766766    }
    767767
     
    784784      } else if (IsConstant(b) && IsAddition(a)) {
    785785        // multiply constants into additions
    786         return a.SubTrees.Select(x => MakeProduct(x, b)).Aggregate((c, d) => MakeSum(c, d));
     786        return a.Subtrees.Select(x => MakeProduct(x, b)).Aggregate((c, d) => MakeSum(c, d));
    787787      } else if (IsDivision(a) && IsDivision(b)) {
    788788        // (a1 / a2) * (b1 / b2) => (a1 * b1) / (a2 * b2)
    789         Trace.Assert(a.SubTrees.Count() == 2);
    790         Trace.Assert(b.SubTrees.Count() == 2);
    791         return MakeFraction(MakeProduct(a.GetSubTree(0), b.GetSubTree(0)), MakeProduct(a.GetSubTree(1), b.GetSubTree(1)));
     789        Trace.Assert(a.Subtrees.Count() == 2);
     790        Trace.Assert(b.Subtrees.Count() == 2);
     791        return MakeFraction(MakeProduct(a.GetSubtree(0), b.GetSubtree(0)), MakeProduct(a.GetSubtree(1), b.GetSubtree(1)));
    792792      } else if (IsDivision(a)) {
    793793        // (a1 / a2) * b => (a1 * b) / a2
    794         Trace.Assert(a.SubTrees.Count() == 2);
    795         return MakeFraction(MakeProduct(a.GetSubTree(0), b), a.GetSubTree(1));
     794        Trace.Assert(a.Subtrees.Count() == 2);
     795        return MakeFraction(MakeProduct(a.GetSubtree(0), b), a.GetSubtree(1));
    796796      } else if (IsDivision(b)) {
    797797        // a * (b1 / b2) => (b1 * a) / b2
    798         Trace.Assert(b.SubTrees.Count() == 2);
    799         return MakeFraction(MakeProduct(b.GetSubTree(0), a), b.GetSubTree(1));
     798        Trace.Assert(b.Subtrees.Count() == 2);
     799        return MakeFraction(MakeProduct(b.GetSubtree(0), a), b.GetSubtree(1));
    800800      } else if (IsMultiplication(a) && IsMultiplication(b)) {
    801801        // merge multiplications (make sure constants are merged)
    802802        var mul = mulSymbol.CreateTreeNode();
    803         for (int i = 0; i < a.SubTrees.Count(); i++) mul.AddSubTree(a.GetSubTree(i));
    804         for (int i = 0; i < b.SubTrees.Count(); i++) mul.AddSubTree(b.GetSubTree(i));
     803        for (int i = 0; i < a.Subtrees.Count(); i++) mul.AddSubtree(a.GetSubtree(i));
     804        for (int i = 0; i < b.Subtrees.Count(); i++) mul.AddSubtree(b.GetSubtree(i));
    805805        MergeVariablesAndConstantsInProduct(mul);
    806806        return mul;
     
    809809      } else if (IsMultiplication(a)) {
    810810        // a is already an multiplication => append b
    811         a.AddSubTree(b);
     811        a.AddSubtree(b);
    812812        MergeVariablesAndConstantsInProduct(a);
    813813        return a;
    814814      } else {
    815815        var mul = mulSymbol.CreateTreeNode();
    816         mul.AddSubTree(a);
    817         mul.AddSubTree(b);
     816        mul.AddSubtree(a);
     817        mul.AddSubtree(b);
    818818        MergeVariablesAndConstantsInProduct(mul);
    819819        return mul;
     
    842842    // helper to combine the constant factors in products and to combine variables (powers of 2, 3...)
    843843    private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) {
    844       var subtrees = new List<ISymbolicExpressionTreeNode>(prod.SubTrees);
    845       while (prod.SubTrees.Count() > 0) prod.RemoveSubTree(0);
     844      var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees);
     845      while (prod.Subtrees.Count() > 0) prod.RemoveSubtree(0);
    846846      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
    847847                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
     
    856856                            .Aggregate((c1, c2) => c1 * c2);
    857857
    858       var unchangedSubTrees = from tree in subtrees
     858      var unchangedSubtrees = from tree in subtrees
    859859                              where !(tree is VariableTreeNode)
    860860                              where !(tree is ConstantTreeNode)
     
    867867          var poly = mulSymbol.CreateTreeNode();
    868868          for (int p = 0; p < variableNodeGroup.Count(); p++) {
    869             poly.AddSubTree((ISymbolicExpressionTreeNode)representative.Clone());
     869            poly.AddSubtree((ISymbolicExpressionTreeNode)representative.Clone());
    870870          }
    871           prod.AddSubTree(poly);
    872         } else {
    873           prod.AddSubTree(representative);
    874         }
    875       }
    876 
    877       foreach (var unchangedSubtree in unchangedSubTrees)
    878         prod.AddSubTree(unchangedSubtree);
     871          prod.AddSubtree(poly);
     872        } else {
     873          prod.AddSubtree(representative);
     874        }
     875      }
     876
     877      foreach (var unchangedSubtree in unchangedSubtrees)
     878        prod.AddSubtree(unchangedSubtree);
    879879
    880880      if (!constantProduct.IsAlmost(1.0)) {
    881         prod.AddSubTree(MakeConstant(constantProduct));
     881        prod.AddSubtree(MakeConstant(constantProduct));
    882882      }
    883883    }
     
    898898      } else if (IsAddition(x)) {
    899899        // (x0 + x1 + .. + xn) * -1 => (-x0 + -x1 + .. + -xn)       
    900         List<ISymbolicExpressionTreeNode> subTrees = new List<ISymbolicExpressionTreeNode>(x.SubTrees);
    901         while (x.SubTrees.Count() > 0) x.RemoveSubTree(0);
    902         foreach (var subTree in subTrees) {
    903           x.AddSubTree(Negate(subTree));
     900        List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees);
     901        while (x.Subtrees.Count() > 0) x.RemoveSubtree(0);
     902        foreach (var subtree in subtrees) {
     903          x.AddSubtree(Negate(subtree));
    904904        }
    905905      } else if (IsMultiplication(x) || IsDivision(x)) {
    906906        // x0 * x1 * .. * xn * -1 => x0 * x1 * .. * -xn
    907         x.RemoveSubTree(x.SubTrees.Count() - 1);
    908         x.AddSubTree(Negate(x.SubTrees.Last())); // last is maybe a constant, prefer to negate the constant
     907        x.RemoveSubtree(x.Subtrees.Count() - 1);
     908        x.AddSubtree(Negate(x.Subtrees.Last())); // last is maybe a constant, prefer to negate the constant
    909909      } else {
    910910        // any other function
     
    924924        return MakeConstant(1.0 / ((ConstantTreeNode)x).Value);
    925925      } else if (IsDivision(x)) {
    926         Trace.Assert(x.SubTrees.Count() == 2);
    927         return MakeFraction(x.GetSubTree(1), x.GetSubTree(0));
     926        Trace.Assert(x.Subtrees.Count() == 2);
     927        return MakeFraction(x.GetSubtree(1), x.GetSubtree(0));
    928928      } else {
    929929        // any other function
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r5726 r5733  
    3838namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3939  [StorableClass]
    40   public abstract class SymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, ISymbolicDataAnalysisProblem, IStorableContent
     40  public abstract class SymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, IDataAnalysisProblem, IStorableContent
    4141    where T : class,IDataAnalysisProblemData
    4242    where U : class, ISymbolicDataAnalysisEvaluator<T>
     
    5050    private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions";
    5151    private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments";
     52    private const string RelativeNumberOfEvaluatedSamples = "RelativeNumberOfEvaluatedSamples";
     53    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
     54    private const string ModelSelectionPartitionParamterName = "ModelSelectionPartition";
    5255
    5356    private const string ProblemDataParameterDescription = "";
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/SymbolicExpressionImporter.cs

    r5574 r5733  
    7676      } else {
    7777        // only a main branch was given => insert the main branch into the default tree template
    78         root.AddSubTree(start);
    79         start.AddSubTree(mainBranch);
     78        root.AddSubtree(start);
     79        start.AddSubtree(mainBranch);
    8080      }
    8181      return new SymbolicExpressionTree(root);
     
    9999          tree = ParseDefun(tokens);
    100100          while (!tokens.Peek().Equals(Token.RPAR)) {
    101             tree.AddSubTree(ParseSexp(tokens));
     101            tree.AddSubtree(ParseSexp(tokens));
    102102          }
    103103        } else if (tokens.Peek().StringValue.StartsWith(ARGSTART)) {
     
    106106          tree = ParseInvoke(tokens);
    107107          while (!tokens.Peek().Equals(Token.RPAR)) {
    108             tree.AddSubTree(ParseSexp(tokens));
     108            tree.AddSubtree(ParseSexp(tokens));
    109109          }
    110110        } else {
     
    112112          tree = CreateTree(curToken);
    113113          while (!tokens.Peek().Equals(Token.RPAR)) {
    114             tree.AddSubTree(ParseSexp(tokens));
     114            tree.AddSubtree(ParseSexp(tokens));
    115115          }
    116116        }
Note: See TracChangeset for help on using the changeset viewer.