Index: branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
===================================================================
--- branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs	(revision 14542)
+++ branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs	(revision 14719)
@@ -138,11 +138,11 @@
       // BackwardsCompatibility3.3
       #region Backwards compatible code, remove with 3.4
-      if (!Parameters.ContainsKey(RestartsParameterName))
+      if(!Parameters.ContainsKey(RestartsParameterName))
         Parameters.Add(new FixedValueParameter<IntValue>(RestartsParameterName, "The number of independent random restarts", new IntValue(1)));
-      if (!Parameters.ContainsKey(SeedParameterName))
+      if(!Parameters.ContainsKey(SeedParameterName))
         Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The PRNG seed value.", new IntValue()));
-      if (!Parameters.ContainsKey(SetSeedRandomlyParameterName))
+      if(!Parameters.ContainsKey(SetSeedRandomlyParameterName))
         Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "Switch to determine if the random number seed should be initialized randomly.", new BoolValue(true)));
-      if (!Parameters.ContainsKey(InitParamsRandomlyParameterName))
+      if(!Parameters.ContainsKey(InitParamsRandomlyParameterName))
         Parameters.Add(new FixedValueParameter<BoolValue>(InitParamsRandomlyParameterName, "Switch to determine if the numeric parameters of the model should be initialized randomly.", new BoolValue(false)));
 
@@ -161,5 +161,5 @@
     protected override void Run(CancellationToken cancellationToken) {
       IRegressionSolution bestSolution = null;
-      if (InitializeParametersRandomly) {
+      if(InitializeParametersRandomly) {
         var qualityTable = new DataTable("RMSE table");
         qualityTable.VisualProperties.YAxisLogScale = true;
@@ -172,14 +172,14 @@
         qualityTable.Rows.Add(testRMSERow);
         Results.Add(new Result(qualityTable.Name, qualityTable.Name + " for all restarts", qualityTable));
-        if (SetSeedRandomly) Seed = (new System.Random()).Next();
+        if(SetSeedRandomly) Seed = (new System.Random()).Next();
         var rand = new MersenneTwister((uint)Seed);
         bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand);
         trainRMSERow.Values.Add(bestSolution.TrainingRootMeanSquaredError);
         testRMSERow.Values.Add(bestSolution.TestRootMeanSquaredError);
-        for (int r = 0; r < Restarts; r++) {
+        for(int r = 0; r < Restarts; r++) {
           var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand);
           trainRMSERow.Values.Add(solution.TrainingRootMeanSquaredError);
           testRMSERow.Values.Add(solution.TestRootMeanSquaredError);
-          if (solution.TrainingRootMeanSquaredError < bestSolution.TrainingRootMeanSquaredError) {
+          if(solution.TrainingRootMeanSquaredError < bestSolution.TrainingRootMeanSquaredError) {
             bestSolution = solution;
           }
@@ -216,10 +216,14 @@
       factorSymbol.AllVariableNames = factorSymbol.VariableNames;
       factorSymbol.VariableValues =
-        factorSymbol.VariableNames.Select(name => new KeyValuePair<string, List<string>>(name, problemData.Dataset.GetReadOnlyStringValues(name).Distinct().ToList()));
-
-      foreach (var parent in tree.IterateNodesPrefix().ToArray()) {
-        for (int i = 0; i < parent.SubtreeCount; i++) {
+        factorSymbol.VariableNames.Select(name =>
+        new KeyValuePair<string, Dictionary<string, int>>(name,
+        problemData.Dataset.GetReadOnlyStringValues(name).Distinct()
+        .Select((n, i) => Tuple.Create(n, i))
+        .ToDictionary(tup => tup.Item1, tup => tup.Item2)));
+
+      foreach(var parent in tree.IterateNodesPrefix().ToArray()) {
+        for(int i = 0; i < parent.SubtreeCount; i++) {
           var child = parent.GetSubtree(i) as VariableTreeNode;
-          if (child != null && factorSymbol.VariableNames.Contains(child.VariableName)) {
+          if(child != null && factorSymbol.VariableNames.Contains(child.VariableName)) {
             parent.RemoveSubtree(i);
             var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode();
@@ -232,9 +236,9 @@
       }
 
-      if (!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure.");
+      if(!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure.");
 
       // initialize constants randomly
-      if (rand != null) {
-        foreach (var node in tree.IterateNodesPrefix().OfType<ConstantTreeNode>()) {
+      if(rand != null) {
+        foreach(var node in tree.IterateNodesPrefix().OfType<ConstantTreeNode>()) {
           double f = Math.Exp(NormalDistributedRandom.NextDouble(rand, 0, 1));
           double s = rand.NextDouble() < 0.5 ? -1 : 1;
