Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs	(revision 18063)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs	(revision 18065)
@@ -24,5 +24,5 @@
     private const string GrammarParameterName = "Grammar";
     private const string StructureTemplateParameterName = "Structure Template";
-
+    private const string MainTreeResultParameterName = "Main Tree";
     #endregion
 
@@ -31,5 +31,6 @@
     public IFixedValueParameter<StringValue> StructureDefinitionParameter => (IFixedValueParameter<StringValue>)Parameters[StructureDefinitionParameterName];
     public IFixedValueParameter<StructureTemplate> StructureTemplateParameter => (IFixedValueParameter<StructureTemplate>)Parameters[StructureTemplateParameterName];
-    public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName]; // könnte auch weg?
+    public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName];
+    public IResultParameter<ISymbolicExpressionTree> MainTreeResultParameter => (IResultParameter<ISymbolicExpressionTree>)Parameters[MainTreeResultParameterName];
     #endregion
 
@@ -76,12 +77,19 @@
       varSym.Enabled = true;
 
+      var structureTemplate = new StructureTemplate();
+      structureTemplate.Changed += (sender, args) => {
+        foreach (var e in Encoding.Encodings.ToArray())
+          Encoding.Remove(e);
+
+        foreach(var sf in structureTemplate.SubFunctions.Values) {
+          Encoding.Add(new SymbolicExpressionTreeEncoding(sf.Name, sf.Grammar, sf.MaximumSymbolicExpressionTreeLength, sf.MaximumSymbolicExpressionTreeDepth));
+        }
+      };
+
       Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, problemData));
-      Parameters.Add(new FixedValueParameter<StringValue>(StructureDefinitionParameterName, new StringValue("e^f(x)/F(y)")));
-      Parameters.Add(new FixedValueParameter<StructureTemplate>(StructureTemplateParameterName, new StructureTemplate()));
+      Parameters.Add(new FixedValueParameter<StructureTemplate>(StructureTemplateParameterName, structureTemplate));
       Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, grammar));
-      var parser = new InfixExpressionParser();
-      var tree = parser.Parse(StructureDefinition); 
-      
-      GetSubFunctions(tree);
+      Parameters.Add(new ResultParameter<ISymbolicExpressionTree>(MainTreeResultParameterName, ""));
+      MainTreeResultParameter.DefaultValue = new SymbolicExpressionTree();
     }
 
@@ -90,18 +98,35 @@
     [StorableConstructor]
     protected StructuredSymbolicRegressionSingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
+    #endregion
 
+    #region Cloning
     public override IDeepCloneable Clone(Cloner cloner) =>
       new StructuredSymbolicRegressionSingleObjectiveProblem(this, cloner);
     #endregion
 
-    public void GetSubFunctions(ISymbolicExpressionTree tree) {
-      int count = 1;
-      foreach(var node in tree.IterateNodesPrefix())
-        if(node.Symbol is SubFunctionSymbol)
-          Encoding.Add(new SymbolicExpressionTreeEncoding($"f{count++}", Grammar/*new LinearScalingGrammar()*/, 25, 8));
-    }
+    public override double Evaluate(Individual individual, IRandom random) {
+      var templateTree = (ISymbolicExpressionTree)StructureTemplate.Tree.Clone();
+      var subFunctionDict = StructureTemplate.SubFunctions;
+          
+      // build main tree
+      foreach (var n in templateTree.IterateNodesPrefix()) {
+        if(n is SubFunctionTreeNode subFunctionTreeNode) {
+          if(subFunctionDict.TryGetValue(subFunctionTreeNode, out SubFunction subFunction)) {
+            var subFunctionTree = individual.SymbolicExpressionTree(subFunction.Name);
+            var parent = n.Parent;
+            // remove all subtrees
 
-    public override double Evaluate(Individual individual, IRandom random) {
-      Console.WriteLine(StructureTemplate.Template);
+            var subtreeCount = parent.SubtreeCount;
+            for (int idx = 0; idx < subtreeCount; ++idx)
+              parent.RemoveSubtree(idx);
+
+            // add new tree
+            parent.AddSubtree(subFunctionTree.Root);
+          }
+        }
+      }
+
+      MainTreeResultParameter.ActualValue = templateTree;
+      /*
       foreach (var kvp in individual.Values) {
         if(kvp.Value is SymbolicExpressionTree tree) {
@@ -111,7 +136,7 @@
             }
           }
-          Console.WriteLine(tree);
         }
       }
+      */
       return 0.0;
     }
Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs	(revision 18063)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs	(revision 18065)
@@ -21,8 +21,19 @@
     }
 
-
     public StructureTemplateView() {
       InitializeComponent();
       errorLabel.Text = "";
+    }
+
+    protected override void OnContentChanged() {
+      base.OnContentChanged();
+      if (Content == null) return;
+
+      expressionInput.Text = Content.Template;
+      symRegTreeChart.Content = Content.Tree;
+      subFunctionListView.Content = new ItemList<SubFunction>(Content.SubFunctions.Values).AsReadOnly();
+      
+      errorLabel.Text = "";
+      
     }
 
@@ -34,5 +45,5 @@
 
           var subFunctionList = new ItemList<SubFunction>();
-          foreach (var func in Content.SubFunctions)
+          foreach (var func in Content.SubFunctions.Values)
             subFunctionList.Add(func);
           subFunctionListView.Content = subFunctionList.AsReadOnly();
Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj	(revision 18063)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj	(revision 18065)
@@ -248,4 +248,5 @@
     <Compile Include="Symbols\HyperbolicTangent.cs" />
     <Compile Include="Symbols\SubFunctionSymbol.cs" />
+    <Compile Include="Symbols\SubFunctionTreeNode.cs" />
     <Compile Include="Symbols\VariableBase.cs" />
     <Compile Include="Symbols\VariableTreeNodeBase.cs" />
Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs	(revision 18063)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs	(revision 18065)
@@ -453,4 +453,13 @@
             laggedVarNode.Lag = (int)Math.Round(sign * lagToken.doubleVal);
             laggedVarNode.Weight = 1.0;
+          } else if (funcNode.Symbol is SubFunctionSymbol) {
+            var subFunction = funcNode as SubFunctionTreeNode;
+            // input arguments
+            var args = ParseArgList(tokens);
+            IList<string> functionArguments = new List<string>();
+            foreach (var arg in args) 
+              if(arg is VariableTreeNode varTreeNode)
+                functionArguments.Add(varTreeNode.VariableName);
+            subFunction.FunctionArguments = functionArguments;
           } else {
             // functions
@@ -458,5 +467,5 @@
             // check number of arguments
             if (funcNode.Symbol.MinimumArity > args.Length || funcNode.Symbol.MaximumArity < args.Length) {
-              throw new ArgumentException(string.Format("Symbol {0} requires between {1} and  {2} arguments.", funcId,
+              throw new ArgumentException(string.Format("Symbol {0} requires between {1} and {2} arguments.", funcId,
                 funcNode.Symbol.MinimumArity, funcNode.Symbol.MaximumArity));
             }
Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs	(revision 18063)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs	(revision 18065)
@@ -14,4 +14,5 @@
   public class StructureTemplate : Item {
 
+    #region Properties
     [Storable]
     private string template = "";
@@ -22,5 +23,6 @@
           template = value;
           tree = Parser.Parse(template);
-          subFunctions = GetSubFunctions(Tree);
+          GetSubFunctions(Tree);
+          OnChanged();
         }
       } 
@@ -31,13 +33,23 @@
     public ISymbolicExpressionTree Tree => tree;
 
+    //[Storable]
+    //private IDictionary<SubFunctionTreeNode, SubFunction> subFunctions;
     [Storable]
-    private IEnumerable<SubFunction> subFunctions;
-    public IEnumerable<SubFunction> SubFunctions => subFunctions;
+    public IDictionary<SubFunctionTreeNode, SubFunction> SubFunctions { get; private set; } = new Dictionary<SubFunctionTreeNode, SubFunction>();
+      //subFunctions == null ? new Dictionary<SubFunctionTreeNode, SubFunction>() : subFunctions;
 
     protected InfixExpressionParser Parser { get; set; } = new InfixExpressionParser();
+    #endregion
 
+    #region Events
+    public event EventHandler Changed;
+    
+    private void OnChanged() => Changed?.Invoke(this, EventArgs.Empty);
+    #endregion
 
     #region Constructors
-    public StructureTemplate() { }
+    public StructureTemplate() {
+      Template = "f(x)*f(y)+5";
+    }
 
     [StorableConstructor]
@@ -52,9 +64,15 @@
     #endregion
 
-    private IEnumerable<SubFunction> GetSubFunctions(ISymbolicExpressionTree tree) {
+    private void GetSubFunctions(ISymbolicExpressionTree tree) {
       int count = 1;
       foreach (var node in tree.IterateNodesPrefix())
-        if (node.Symbol is SubFunctionSymbol)
-          yield return new SubFunction() { Name = $"f{count++}" };
+        if (node is SubFunctionTreeNode subFunctionTreeNode) { 
+          var subFunction = new SubFunction() { 
+            Name = $"f{count++}({string.Join(",", subFunctionTreeNode.FunctionArguments)})", 
+            FunctionArguments = subFunctionTreeNode.FunctionArguments 
+          };
+          SubFunctions.Add(subFunctionTreeNode, subFunction);
+        }
+
     }
   }
Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs	(revision 18063)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs	(revision 18065)
@@ -18,4 +18,5 @@
     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
+    private const string FunctionArgumentsParameterName = "Function Arguments";
     #endregion
 
@@ -24,4 +25,5 @@
     public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName];
     public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName];
+    public IValueParameter<ReadOnlyItemList<StringValue>> FunctionArgumentsParameter => (IValueParameter<ReadOnlyItemList<StringValue>>)Parameters[FunctionArgumentsParameterName];
     #endregion
 
@@ -41,4 +43,19 @@
       set => MaximumSymbolicExpressionTreeLengthParameter.Value.Value = value;
     }
+
+    public IEnumerable<string> FunctionArguments {
+      get => FunctionArgumentsParameter.Value.Select(x => x.Value); 
+      set {
+        var varSym = (Variable)Grammar.GetSymbol("Variable");
+        if (varSym == null)
+          throw new ArgumentException($"No variable symbol existent.");
+
+        FunctionArgumentsParameter.Value = new ItemList<StringValue>(value.Select(x => new StringValue(x))).AsReadOnly();
+
+        varSym.AllVariableNames = FunctionArguments;
+        varSym.VariableNames = FunctionArguments;
+        varSym.Enabled = true;
+      } 
+    }
     #endregion
 
@@ -48,4 +65,5 @@
       Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(10)));
       Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(30)));
+      Parameters.Add(new ValueParameter<ReadOnlyItemList<StringValue>>(FunctionArgumentsParameterName, new ReadOnlyItemList<StringValue>()));
     }
 
Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionSymbol.cs
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionSymbol.cs	(revision 18063)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionSymbol.cs	(revision 18065)
@@ -1,3 +1,4 @@
-﻿using HEAL.Attic;
+﻿using System.Collections.Generic;
+using HEAL.Attic;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -9,5 +10,5 @@
   public class SubFunctionSymbol : Symbol {
     public override int MinimumArity => 1;
-    public override int MaximumArity => 1;
+    public override int MaximumArity => byte.MaxValue;
 
     public SubFunctionSymbol() : base("SubFunctionSymbol", "Symbol that represents a sub function.") { }
@@ -20,4 +21,6 @@
     public override IDeepCloneable Clone(Cloner cloner) =>
       new SubFunctionSymbol(this, cloner);
+
+    public override ISymbolicExpressionTreeNode CreateTreeNode() => new SubFunctionTreeNode(this);
   }
 }
Index: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionTreeNode.cs
===================================================================
--- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionTreeNode.cs	(revision 18065)
+++ branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionTreeNode.cs	(revision 18065)
@@ -0,0 +1,33 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HEAL.Attic;
+using HeuristicLab.Common;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+
+namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
+  [StorableType("05130B5F-0125-4367-A4E9-C42D1085024E")]
+  public class SubFunctionTreeNode : SymbolicExpressionTreeNode {
+
+    #region Properties
+    public new SubFunctionSymbol Symbol => (SubFunctionSymbol)base.Symbol;
+
+    public IEnumerable<string> FunctionArguments { get; set; } = Enumerable.Empty<string>();
+    #endregion
+
+    #region Constructors
+    public SubFunctionTreeNode(SubFunctionSymbol symbol) : base(symbol) { }
+
+    [StorableConstructor]
+    protected SubFunctionTreeNode(StorableConstructorFlag _) : base(_) { }
+
+    protected SubFunctionTreeNode(SubFunctionTreeNode original, Cloner cloner) : base(original, cloner) { }
+    #endregion
+
+    #region Cloning
+    public override IDeepCloneable Clone(Cloner cloner) => new SubFunctionTreeNode(this, cloner);
+    #endregion
+  }
+}
