Index: /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
===================================================================
--- /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs	(revision 14559)
+++ /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs	(revision 14560)
@@ -28,5 +28,4 @@
 using HeuristicLab.Core;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
-using HeuristicLab.Optimization.Operators;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
 
@@ -52,5 +51,5 @@
       while (dividend > 0) {
         int modulo = (dividend - 1) % 26;
-        columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
+        columnName = Convert.ToChar(65 + modulo) + columnName;
         dividend = (int)((dividend - modulo) / 26);
       }
@@ -61,10 +60,10 @@
     private readonly Dictionary<string, string> variableNameMapping = new Dictionary<string, string>();
     private int currentVariableIndex = 0;
-    private string GetColumnToVariableName(string variabelName) {
-      if (!variableNameMapping.ContainsKey(variabelName)) {
+    private string GetColumnToVariableName(string varName) {
+      if (!variableNameMapping.ContainsKey(varName)) {
         currentVariableIndex++;
-        variableNameMapping.Add(variabelName, GetExcelColumnName(currentVariableIndex));
-      }
-      return string.Format("${0}1", variableNameMapping[variabelName]);
+        variableNameMapping.Add(varName, GetExcelColumnName(currentVariableIndex));
+      }
+      return string.Format("${0}1", variableNameMapping[varName]);
     }
     public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
@@ -75,10 +74,18 @@
     public string Format(ISymbolicExpressionTree symbolicExpressionTree, IDataset dataset) {
       var stringBuilder = new StringBuilder();
-      if (dataset != null) CalculateVariableMapping(symbolicExpressionTree, dataset);
-
+      if (dataset != null)
+        return FormatWithMapping(symbolicExpressionTree, CalculateVariableMapping(symbolicExpressionTree, dataset));
+      else return FormatWithMapping(symbolicExpressionTree, new Dictionary<string, string>());
+
+    }
+    public string FormatWithMapping(ISymbolicExpressionTree symbolicExpressionTree, Dictionary<string,string> variableNameMapping)
+    {
+      foreach(var kvp in variableNameMapping) this.variableNameMapping.Add(kvp.Key,kvp.Value);
+      var stringBuilder = new StringBuilder();
+      
       stringBuilder.Append("=");
       stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root));
 
-      foreach (var variable in variableNameMapping) {
+      foreach (var variable in this.variableNameMapping) {
         stringBuilder.AppendLine();
         stringBuilder.Append(variable.Key + " = " + variable.Value);
@@ -87,14 +94,14 @@
     }
 
-    private void CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
-      int columnIndex = 0;
+    private Dictionary<string,string> CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
+      var mapping = new Dictionary<string,string>();
       int inputIndex = 0;
-      var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct();
+      var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct().ToArray();
       foreach (var variable in dataset.VariableNames) {
-        columnIndex++;
         if (!usedVariables.Contains(variable)) continue;
         inputIndex++;
-        variableNameMapping[variable] = GetExcelColumnName(inputIndex);
-      }
+        mapping[variable] = GetExcelColumnName(inputIndex);
+      }
+      return mapping;
     }
 
@@ -192,5 +199,5 @@
         stringBuilder.Append(variableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
         stringBuilder.Append("*");
-        stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName)); // + LagToString(currentLag));
+        stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName));
       } else if (symbol is BinaryFactorVariable) {
         var binFactorNode = node as BinaryFactorVariableTreeNode;
