Index: branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/SymbolicRegressionConstantOptimizationEvaluator.cs
===================================================================
--- branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/SymbolicRegressionConstantOptimizationEvaluator.cs	(revision 15313)
+++ branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/SymbolicRegressionConstantOptimizationEvaluator.cs	(revision 15314)
@@ -191,5 +191,5 @@
         //   , 0, s, 2, initialConstants.Length);
       }
-      s = Enumerable.Repeat(1.0, c.Length).ToArray();
+      s = Enumerable.Repeat(0.01, c.Length).ToArray();
 
       double[] originalConstants = (double[])c.Clone();
@@ -200,10 +200,11 @@
 
       IDataset ds = problemData.Dataset;
-      double[,] x = new double[rows.Count(), parameters.Count];
+      double[,] x = new double[ds.Rows, parameters.Count];
       int col = 0;
       int row = 0;
       foreach (var info in parameterEntries) {
         row = 0;
-        foreach (var r in rows) {
+        // copy training rows
+        foreach (var r in rows) { 
           if (ds.VariableHasType<double>(info.variableName)) {
             x[row, col] = ds.GetDoubleValue(info.variableName, r + info.lag);
@@ -218,5 +219,7 @@
 
       var target = problemData.TargetVariable;
-      var constraintRows = Enumerable.Range(0, problemData.Dataset.Rows).Where(rIdx => double.IsNaN(ds.GetDoubleValue(target, rIdx)));
+
+      // only count constraints
+      var constraintRows = Enumerable.Range(0, problemData.Dataset.Rows).Where(rIdx => !string.IsNullOrEmpty(ds.GetStringValue("f(x) constraint-type", rIdx)));
       double[,] constraints = new double[constraintRows.Count(), parameters.Count + 1]; // +1 for constraint for f(x)
       string[,] comp = new string[constraintRows.Count(), parameters.Count + 1];
@@ -243,4 +246,5 @@
         col++;
       }
+
       // f(x) constraint
       row = 0;
@@ -254,11 +258,7 @@
       }
 
-
       double[] y = ds.GetDoubleValues(problemData.TargetVariable, rows).ToArray();
-      int n = x.GetLength(0);
-      int m = x.GetLength(1);
-      int k = c.Length;
-
-      alglib.ndimensional_jac jac = CreateJac(x, y, constraints, comp, func, AD.Grad(func));
+
+      alglib.ndimensional_jac jac = CreateJac(x, y, ds, func);
       double rho = 1000;
       int outeriters = 3;
@@ -292,5 +292,7 @@
 
       if (!updateConstantsInTree) UpdateConstants(tree, originalConstants.Skip(2).ToArray(), updateVariableWeights);
-      if (originalQuality - quality > 0.001 || double.IsNaN(quality)) {
+      if (
+        // originalQuality - quality > 0.001 || 
+        double.IsNaN(quality)) {
         UpdateConstants(tree, originalConstants.Skip(2).ToArray(), updateVariableWeights);
         return originalQuality;
@@ -317,10 +319,10 @@
 
     private static alglib.ndimensional_jac CreateJac(
-      double[,] x, // x longer than y 
+      double[,] x, // x is larger than y 
       double[] y, // only targets
-      double[,] constraints, // df/d(xi), same order as for x
-      string[,] comparison, // {LEQ, GEQ, EQ }
-      Func<DV, D> func,
-      Func<DV, DV> func_grad) {
+      // double[,] constraints, // df/d(xi), same order as for x, same number of rows as x less columns
+      // string[,] comparison, // {LEQ, GEQ, EQ } same size as constraints
+      IDataset ds,
+      Func<DV, D> func) {
       return (double[] c, double[] fi, double[,] jac, object o) => {
         // objective function is sum of squared errors
@@ -338,5 +340,5 @@
 
           double f = (double)func(p);
-          double[] g = (double[])func_grad(p);
+          double[] g = (double[])AD.Grad(func, p);
           var e = y[rowIdx] - f;
           fi[0] += e * e;
@@ -348,10 +350,10 @@
 
         int fidx = 1;
-        int constraintRows = constraints.GetLength(0);
+        var constraintRows = Enumerable.Range(0, ds.Rows).Where(rIdx => !string.IsNullOrEmpty(ds.GetStringValue("f(x) constraint-type", rIdx))); 
 
         // eq constraints
-        for (int rowIdx = 0; rowIdx < constraintRows; rowIdx++) {
-          for (int colIdx = 0; colIdx < constraints.GetLength(1); colIdx++) {
-            if (comparison[rowIdx, colIdx] == "EQ") {
+        foreach (var rowIdx in constraintRows) {
+          foreach (var varName in ds.VariableNames.Where(vn => vn.EndsWith("constraint-type"))) {
+            if (ds.GetStringValue(varName, rowIdx) == "EQ") {
               throw new NotSupportedException();
             }
@@ -359,5 +361,6 @@
         }
         // ineq constraints
-        for (int rowIdx = 0; rowIdx < constraintRows; rowIdx++) {
+        foreach (var rowIdx in constraintRows) {
+XXX 
           for (int colIdx = 0; colIdx < constraints.GetLength(1); colIdx++) {
             // there is a constraint value
@@ -373,5 +376,5 @@
 
                 fi[fidx] = factor * ((double)(func(p)) - constraints[rowIdx, colIdx]);
-                var g = (double[])func_grad(p);
+                var g = (double[])AD.Grad(func, p);
                 for (int jacIdx = 0; jacIdx < c.Length; jacIdx++) {
                   jac[fidx, jacIdx] = factor * g[nParams + jacIdx]; // skip the elements for the variable values
@@ -380,5 +383,5 @@
               } else {
                 // df / dxi constraint
-                var g = (double[])func_grad(p);
+                var g = (double[])AD.Grad(func, p);
                 fi[fidx] = factor * g[colIdx];
                 var hess = AD.Hessian(func, p);
