Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/PGE.cs
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/PGE.cs	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/PGE.cs	(revision 16231)
@@ -37,5 +37,5 @@
 
     [DllImport("go-pge.dll", EntryPoint = "stepW", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
-    public static extern void StepW();
+    public static extern int StepW();
 
     [DllImport("go-pge.dll", EntryPoint = "getStepResult", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
@@ -278,10 +278,10 @@
 
     protected override void Run(CancellationToken cancellationToken) {
-
       // TODO: the following is potentially problematic for other go processes run on the same machine at the same time
+      // shouldn't be problematic bc is inherited only, normally only child processes are affected
       Environment.SetEnvironmentVariable("GOGC", "off");
       Environment.SetEnvironmentVariable("GODEBUG", "cgocheck=0");
       Environment.SetEnvironmentVariable("CGO_ENABLED", "1");
-
+      Environment.SetEnvironmentVariable("PGEDEBUG", "0");
 
 
@@ -301,4 +301,7 @@
       IntPtr testData = GetData(problemData.Dataset, variables, problemData.TestIndices, out nTestData);
 
+      nTrainData = Problem.ProblemData.TrainingPartition.Size;
+      nTestData = Problem.ProblemData.TestPartition.Size;
+
       var inputVariableNames = string.Join(" ", problemData.AllowedInputVariables); 
       // TODO: does this work when input variables contain spaces?
@@ -322,5 +325,4 @@
 
 
-
       AddTestData(cIndepNames, cDependentNames, testData, nTestData);
 
@@ -343,7 +345,7 @@
         curItersItem.Value = iter;
 
-        StepW();  // TODO: alg crashes here
-
-        for (int iPeel = 0; iPeel < PeelCnt; iPeel++) {
+        int nResults = StepW();
+
+        for (int iResult = 0; iResult < nResults; iResult++) { 
           int nobestpush = 0;       //bool
           int bestNewMinError = 0;  //bool
@@ -357,28 +359,20 @@
           string eqnStr = Marshal.PtrToStringAnsi(eqn);
 
-          if (nobestpush == 1) 
-          {
-            Console.WriteLine("No best push");
-          } else {
-            Console.WriteLine("Push/Pop (" + bestlen1 + "," + bestlen2 + ") " + eqnStr);
-
-            StringBuilder sb = new StringBuilder("");
-            for (int iCoeff = 0; iCoeff < nCoeff; iCoeff++) {
-              double coeffVal = GetCoeffResult();
-              Console.WriteLine("Coeff: " + coeffVal);
-              sb.Append(coeffVal + "; ");
-            }
-
-            var curItersResult = new Result("Iteration " + iter + " " + iPeel, curItersItem);
-            var coeffItersResult = new Result("Coeff " + iter + " " + iPeel, new StringValue(sb.ToString()));
-
-            var bestQualityItem = new StringValue(eqnStr);
-            var bestQualityResult = new Result("Best quality " + iter + " " + iPeel, bestQualityItem);
-            Results.Add(curItersResult);
-            Results.Add(coeffItersResult);
-            Results.Add(bestQualityResult);
-   
+          Console.WriteLine("Push/Pop (" + bestlen1 + "," + bestlen2 + ") " + eqnStr);
+          StringBuilder sb = new StringBuilder("");
+          for (int iCoeff = 0; iCoeff < nCoeff; iCoeff++) {
+            double coeffVal = GetCoeffResult();
+            Console.WriteLine("Coeff: " + coeffVal);
+            sb.Append(coeffVal + "; ");
           }
 
+          var curItersResult = new Result("Iteration " + iter + " " + iResult, curItersItem);
+          var coeffItersResult = new Result("Coeff " + iter + " " + iResult, new StringValue(sb.ToString()));
+
+          var bestQualityItem = new StringValue(eqnStr);
+          var bestQualityResult = new Result("Best quality " + iter + " " + iResult, bestQualityItem);
+          Results.Add(curItersResult);
+          Results.Add(coeffItersResult);
+          Results.Add(bestQualityResult);
         }
 
@@ -389,4 +383,19 @@
       Marshal.FreeHGlobal(trainData);
       Marshal.FreeHGlobal(testData);
+
+      Marshal.FreeHGlobal(cIndepNames);
+      Marshal.FreeHGlobal(cDependentNames);
+
+      Marshal.FreeHGlobal(cInitMethod);
+      Marshal.FreeHGlobal(cGrowMethod);
+
+      Marshal.FreeHGlobal(cRoots);
+      Marshal.FreeHGlobal(cNodes);
+      Marshal.FreeHGlobal(cNonTrig);
+      Marshal.FreeHGlobal(cLeafs);
+
+      Marshal.FreeHGlobal(cName);
+      Marshal.FreeHGlobal(cProblemTypeString);
+
       // Results.Add(new Result("Execution time", new TimeSpanValue(this.ExecutionTime)));
     }
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/README.md
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/README.md	(revision 16230)
+++ 	(revision )
@@ -1,7 +1,0 @@
-go-pesr
-=======
-
-a Go library for Prioritized Enumeration based Symbolic Regression
-
-Prioritized enumeration is a deterministic algorithm for uncovering
-symbolic equations from data sets. PESR is inspired by dynamic programming.
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/bbsr.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/bbsr.go	(revision 16230)
+++ 	(revision )
@@ -1,94 +1,0 @@
-package pge
-
-import (
-	"fmt"
-	// "sort"
-
-	probs "github.com/verdverm/go-pge/problems"
-	expr "github.com/verdverm/go-symexpr"
-)
-
-func (PS *PgeSearch) GenInitExpr() *probs.ReportQueue {
-	switch PS.cnfg.initMethod {
-	case "method1":
-		return PS.GenInitExprMethod1()
-	case "method2":
-		return PS.GenInitExprMethod2()
-	case "method3":
-		return PS.GenInitExprMethod3()
-	default:
-		fmt.Println("Unknown init method")
-	}
-	return nil
-}
-
-func (PS *PgeSearch) Expand(O expr.Expr) (ret []expr.Expr) {
-	var exprs []expr.Expr
-
-	switch PS.cnfg.growMethod {
-	case "method1":
-		exprs = PS.ExpandMethod1(O)
-	case "method2":
-		exprs = PS.ExpandMethod2(O)
-	case "method3":
-		exprs = PS.ExpandMethod3(O)
-	default:
-		fmt.Println("Unknown expand method")
-	}
-
-	// convert and simplify
-	for i, e := range exprs {
-		if e == nil {
-			continue
-		}
-		defer func() {
-			if r := recover(); r != nil {
-				fmt.Printf("Recovered in Expand %v   %d %v", r, i, e)
-				exprs[i] = nil
-			}
-		}()
-		c := make([]float64, 0)
-		// fmt.Printf("Preconv   %v\n", e)
-		c, eqn := e.ConvertToConstants(c)
-		e.CalcExprStats()
-		// fmt.Printf("Postconv  %v\n", eqn)
-
-		// fmt.Printf("Presimp  %v\n", eqn)
-		exprs[i] = eqn.Simplify(PS.cnfg.simprules)
-		// fmt.Printf("Postsimp  %v\n\n", exprs[i])
-		// serial := make([]int, 0, 64)
-		// serial = exprs[i].Serial(serial)
-		// fmt.Printf("Postsimp  %v   %v\n\n", exprs[i], serial)
-	}
-
-	// sort.Sort(expr.ExprArray(exprs))
-
-	// remove duplicates
-
-	// last := 0
-	// for last < len(exprs) && exprs[last] == nil {
-	// 	last++
-	// }
-	// for i := last + 1; i < len(exprs); i++ {
-	// 	if exprs[i] == nil {
-	// 		continue
-	// 	}
-	// 	if exprs[i].AmIAlmostSame(exprs[last]) {
-	// 		exprs[i] = nil
-	// 	} else {
-	// 		last = i
-	// 	}
-	// }
-
-	// copy to ret, ignoring nil & bad expressions ...
-	for _, e := range exprs {
-		if e == nil {
-			continue
-		}
-		// if !PS.cnfg.treecfg.CheckExpr(e) {
-		// 	continue
-		// }
-		ret = append(ret, e)
-	}
-	return ret
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/ipre_trie.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/ipre_trie.go	(revision 16230)
+++ 	(revision )
@@ -1,42 +1,0 @@
-package pge
-
-type IpreNode struct {
-	val int
-	cnt int
-	vst int
-
-	next map[int]*IpreNode
-}
-
-func (n *IpreNode) InsertSerial(s []int) (did_ins bool) {
-	in, _ := n.next[s[0]]
-
-	// does this branch exist?
-	if in == nil {
-		in = new(IpreNode)
-		in.val = s[0]
-		in.next = make(map[int]*IpreNode)
-		n.next[s[0]] = in
-		did_ins = true
-	}
-
-	// recursive call to insert
-	if len(s) > 1 {
-		did_ins = in.InsertSerial(s[1:]) || did_ins
-	}
-
-	// visitation accounting  
-	// (-1 is the root of the memoization tree)
-	in.vst++
-	if n.val == -1 {
-		n.vst++
-	}
-	if did_ins {
-		in.cnt++
-		if n.val == -1 {
-			n.cnt++
-		}
-	}
-
-	return did_ins
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_expand_method_1.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_expand_method_1.go	(revision 16230)
+++ 	(revision )
@@ -1,247 +1,0 @@
-package pge
-
-import (
-	// "fmt"
-	"sort"
-
-	expr "github.com/verdverm/go-symexpr"
-)
-
-func (PS *PgeSearch) ExpandMethod1(O expr.Expr) (ret []expr.Expr) {
-	O.Sort()
-	ret = make([]expr.Expr, 0)
-	// fmt.Printf("Expanding expression:  %v\n", O)
-
-	for i := 0; i < O.Size(); i++ {
-		I := i
-		E := O.GetExpr(&I)
-		switch E.ExprType() {
-		case expr.ADD:
-			tmp := PS.AddTermToExprMethod1(O, E, i)
-			ret = append(ret, tmp[:]...)
-
-		case expr.MUL:
-			tmp := PS.WidenTermInExprMethod1(O, E, i)
-			ret = append(ret, tmp[:]...)
-
-		case expr.VAR:
-			tmp := PS.DeepenTermInExprMethod1(O, E, i)
-			ret = append(ret, tmp[:]...)
-
-		default: // expr.DIV,expr.COS,expr.SIN,expr.EXP,expr.LOG,expr.ABS,expr.POW
-			continue
-
-		}
-	}
-
-	return ret
-}
-
-// add another term to an add expr
-func (PS *PgeSearch) AddTermToExprMethod1(O, E expr.Expr, pos int) (ret []expr.Expr) {
-	ret = make([]expr.Expr, 0)
-	A := E.(*expr.Add)
-
-	// f() + cL
-	for _, L := range PS.GenLeafs {
-		c := new(expr.Constant)
-		c.P = -1
-		l := L.Clone()
-
-		// mul it
-		M := expr.NewMul()
-		M.Insert(c)
-		M.Insert(l)
-
-		// skip if the same term already exists in the add
-		skip := false
-		for _, e := range A.CS {
-			if e == nil {
-				continue
-			}
-			// fmt.Printf("ACMP  %v  %v\n", M, e)
-			if e.AmIAlmostSame(M) || M.AmIAlmostSame(e) {
-				skip = true
-				break
-			}
-		}
-		if skip {
-			continue
-		}
-
-		C := O.Clone()
-		P := pos
-		AM := C.GetExpr(&P).(*expr.Add)
-		AM.Insert(M)
-		sort.Sort(AM)
-		C.CalcExprStats()
-		good := PS.cnfg.treecfg.CheckExpr(C)
-		if good {
-			ret = append(ret, C)
-		}
-	}
-
-	// f() + c*node(L)
-	for _, N := range PS.GenNodes {
-		for _, L := range PS.GenLeafs {
-
-			c := new(expr.Constant)
-			c.P = -1
-
-			l := L.Clone()
-			n := N.Clone()
-			p := 1
-			n.SetExpr(&p, l)
-
-			var E expr.Expr
-			if N.ExprType() == expr.DIV {
-				E = expr.NewDiv(c, l)
-			} else {
-				// mul it
-				M := expr.NewMul()
-				M.Insert(c)
-				M.Insert(n)
-				E = M
-			}
-
-			// skip if the same term already exists in the add
-			skip := false
-			for _, e := range A.CS {
-				if e == nil {
-					continue
-				}
-				// fmt.Printf("ACMP  %v  %v\n", M, e)
-				if e.AmIAlmostSame(E) || E.AmIAlmostSame(e) {
-					skip = true
-					break
-				}
-			}
-			if skip {
-				continue
-			}
-
-			// fmt.Println(E.String())
-
-			C := O.Clone()
-			P := pos
-			AM := C.GetExpr(&P).(*expr.Add)
-			AM.Insert(E)
-			sort.Sort(AM)
-			C.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(C)
-			if good {
-				ret = append(ret, C)
-			}
-		}
-	}
-
-	return ret
-}
-
-// add complexity to a single multiplication term
-func (PS *PgeSearch) WidenTermInExprMethod1(O, E expr.Expr, pos int) (ret []expr.Expr) {
-	ret = make([]expr.Expr, 0)
-
-	// insert leafs  f()*L
-	for _, L := range PS.GenLeafs {
-		l := L.Clone()
-		C := O.Clone()
-		P := pos
-		e := C.GetExpr(&P)
-		// fmt.Printf("pos(%d): %v\n", pos, e)
-		M := e.(*expr.Mul)
-		M.Insert(l)
-		sort.Sort(M)
-		C.CalcExprStats()
-		good := PS.cnfg.treecfg.CheckExpr(C)
-		if good {
-			ret = append(ret, C)
-		}
-	}
-
-	// insert node(L)  :  f() * c*node(L)
-	for _, N := range PS.GenNodes {
-		for _, L := range PS.GenLeafs {
-			c := new(expr.Constant)
-			c.P = -1
-
-			l := L.Clone()
-			n := N.Clone()
-			p := 1
-			n.SetExpr(&p, l)
-
-			var E expr.Expr
-			if N.ExprType() == expr.DIV {
-				E = expr.NewDiv(c, l)
-			} else {
-				// mul it
-				M := expr.NewMul()
-				M.Insert(c)
-				M.Insert(n)
-				E = M
-			}
-
-			C := O.Clone()
-			P := pos
-			e := C.GetExpr(&P)
-			// fmt.Printf("pos(%d): %v\n", pos, e)
-			M := e.(*expr.Mul)
-
-			M.Insert(E)
-			sort.Sort(M)
-			C.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(C)
-			if good {
-				ret = append(ret, C)
-			}
-		}
-	}
-	return ret
-}
-
-// change any term to something more complex...
-func (PS *PgeSearch) DeepenTermInExprMethod1(O, E expr.Expr, pos int) []expr.Expr {
-	exprs := make([]expr.Expr, 0)
-
-	// make into add
-	A := expr.NewAdd()
-	A.Insert(E.Clone())
-	OA := A.Clone()
-	exprs = append(exprs, PS.AddTermToExprMethod1(OA, A, 0)[:]...)
-
-	// make into mul
-	M := expr.NewMul()
-	M.Insert(E.Clone())
-	OM := M.Clone()
-	exprs = append(exprs, PS.WidenTermInExprMethod1(OM, M, 0)[:]...)
-
-	// // make into div
-	// if E.ExprType() != expr.DIV {
-	// 	D := new(expr.Div)
-	// 	c := new(expr.Constant)
-	// 	c.P = -1
-	// 	D.Numer = c
-	// 	D.Denom = E.Clone()
-	// 	exprs = append(exprs, D)
-	// }
-
-	// make inside of nodes
-	for _, N := range PS.GenNodes {
-		if N.ExprType() == expr.DIV {
-			continue
-		}
-		T := N.Clone()
-		P := 1
-		T.SetExpr(&P, E.Clone())
-		exprs = append(exprs, T)
-	}
-
-	ret := make([]expr.Expr, 0)
-	for _, e := range exprs {
-		C := O.Clone()
-		P := pos
-		C.SetExpr(&P, e)
-		ret = append(ret, C)
-	}
-	return ret
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_expand_method_2.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_expand_method_2.go	(revision 16230)
+++ 	(revision )
@@ -1,203 +1,0 @@
-package pge
-
-import (
-	// "fmt"
-	"sort"
-
-	expr "github.com/verdverm/go-symexpr"
-)
-
-func (PS *PgeSearch) ExpandMethod2(O expr.Expr) (ret []expr.Expr) {
-	O.Sort()
-	ret = make([]expr.Expr, 0)
-	// fmt.Printf("Expanding expression:  %v\n", O)
-
-	add := O.(*expr.Add)
-
-	// adding term to addition
-	for _, B := range PS.ffxBases {
-		found := false
-		for _, C := range add.CS {
-			// fmt.Printf("checking %v in %v\n", B, add)
-			if C.AmISame(B) {
-				// fmt.Println("found\n\n")
-				found = true
-				break
-			}
-		}
-		if !found {
-			e := O.Clone()
-			a := e.(*expr.Add)
-			a.Insert(B.Clone())
-			sort.Sort(a)
-			a.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(a)
-			if good {
-				ret = append(ret, a)
-			}
-			// fmt.Printf("grew  %v\n\n", a)
-			// ret = append(ret, a)
-		}
-	}
-
-	// extending terms in addition
-	for _, B := range PS.ffxBases {
-		for i, C := range add.CS {
-			if C.ExprType() == expr.MUL {
-				m := C.(*expr.Mul)
-				if len(m.CS) > 3 {
-					continue
-				}
-			}
-			e := O.Clone()
-			a := e.(*expr.Add)
-			mul := expr.NewMul()
-			mul.Insert(a.CS[i])
-			mul.Insert(B.Clone())
-			a.CS[i] = mul
-			sort.Sort(a)
-			a.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(a)
-			if good {
-				ret = append(ret, a)
-			}
-			// fmt.Printf("grew  %v\n\n", a)
-			ret = append(ret, a)
-		}
-	}
-
-	// deepening terms 
-	// if len(add.CS) < 2 {
-	// 	return ret
-	// }
-	for i, C := range add.CS {
-		if C.ExprType() == expr.MUL {
-			m := C.(*expr.Mul)
-			if len(m.CS) != 2 {
-				continue
-			}
-			if m.CS[1].ExprType() == expr.ADD {
-				continue
-			}
-		} else {
-			continue
-		}
-
-		for _, B := range PS.ffxBases {
-			e := O.Clone()
-			a := e.(*expr.Add)
-			m := a.CS[i].(*expr.Mul)
-			n := m.CS[1]
-
-			switch n.ExprType() {
-			case expr.SQRT:
-				A := expr.NewAdd()
-				A.Insert(n.(*expr.Sqrt).C)
-				A.Insert(B.Clone())
-				n.(*expr.Sqrt).C = A
-			case expr.SIN:
-				A := expr.NewAdd()
-				A.Insert(n.(*expr.Sin).C)
-				A.Insert(B.Clone())
-				n.(*expr.Sin).C = A
-			case expr.COS:
-				A := expr.NewAdd()
-				A.Insert(n.(*expr.Cos).C)
-				A.Insert(B.Clone())
-				n.(*expr.Cos).C = A
-			case expr.TAN:
-				A := expr.NewAdd()
-				A.Insert(n.(*expr.Tan).C)
-				A.Insert(B.Clone())
-				n.(*expr.Tan).C = A
-			case expr.EXP:
-				A := expr.NewAdd()
-				A.Insert(n.(*expr.Exp).C)
-				A.Insert(B.Clone())
-				n.(*expr.Exp).C = A
-			case expr.LOG:
-				A := expr.NewAdd()
-				A.Insert(n.(*expr.Log).C)
-				A.Insert(B.Clone())
-				n.(*expr.Log).C = A
-
-			default:
-				A := expr.NewAdd()
-				A.Insert(m.CS[1])
-				A.Insert(B.Clone())
-				m.CS[1] = A
-			}
-			sort.Sort(a)
-			a.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(a)
-			if good {
-				ret = append(ret, a)
-			}
-			// fmt.Printf("grew  %v\n", a)
-			ret = append(ret, a)
-		}
-	}
-	for i, C := range add.CS {
-		if C.ExprType() == expr.MUL {
-			m := C.(*expr.Mul)
-			if len(m.CS) != 2 {
-				continue
-			}
-			if m.CS[1].ExprType() == expr.ADD {
-				continue
-			}
-		} else {
-			continue
-		}
-
-		for _, B := range PS.ffxBases {
-			e := O.Clone()
-			a := e.(*expr.Add)
-			m := a.CS[i].(*expr.Mul)
-			n := m.CS[1]
-
-			switch n.ExprType() {
-			case expr.SQRT:
-				M := expr.NewMul()
-				M.Insert(n.(*expr.Sqrt).C)
-				M.Insert(B.Clone())
-				n.(*expr.Sqrt).C = M
-			case expr.SIN:
-				M := expr.NewMul()
-				M.Insert(n.(*expr.Sin).C)
-				M.Insert(B.Clone())
-				n.(*expr.Sin).C = M
-			case expr.COS:
-				M := expr.NewMul()
-				M.Insert(n.(*expr.Cos).C)
-				M.Insert(B.Clone())
-				n.(*expr.Cos).C = M
-			case expr.TAN:
-				M := expr.NewMul()
-				M.Insert(n.(*expr.Tan).C)
-				M.Insert(B.Clone())
-				n.(*expr.Tan).C = M
-			case expr.EXP:
-				M := expr.NewMul()
-				M.Insert(n.(*expr.Exp).C)
-				M.Insert(B.Clone())
-				n.(*expr.Exp).C = M
-			case expr.LOG:
-				M := expr.NewMul()
-				M.Insert(n.(*expr.Log).C)
-				M.Insert(B.Clone())
-				n.(*expr.Log).C = M
-			}
-			sort.Sort(a)
-			a.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(a)
-			if good {
-				ret = append(ret, a)
-			}
-			// fmt.Printf("grew  %v\n", a)
-			ret = append(ret, a)
-		}
-	}
-	// fmt.Println("Len of ret = ", len(ret))
-	return ret
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_expand_method_3.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_expand_method_3.go	(revision 16230)
+++ 	(revision )
@@ -1,71 +1,0 @@
-package pge
-
-import (
-	// "fmt"
-	"sort"
-
-	expr "github.com/verdverm/go-symexpr"
-)
-
-func (PS *PgeSearch) ExpandMethod3(O expr.Expr) (ret []expr.Expr) {
-	O.Sort()
-	ret = make([]expr.Expr, 0)
-	// fmt.Printf("Expanding expression:  %v\n", O)
-
-	add := O.(*expr.Add)
-
-	// adding term to addition
-	for _, B := range PS.ffxBases {
-		found := false
-		for _, C := range add.CS {
-			// fmt.Printf("checking %v in %v\n", B, add)
-			if C.AmISame(B) {
-				// fmt.Println("found\n\n")
-				found = true
-				break
-			}
-		}
-		if !found {
-			e := O.Clone()
-			a := e.(*expr.Add)
-			a.Insert(B.Clone())
-			sort.Sort(a)
-			a.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(a)
-			if good {
-				ret = append(ret, a)
-			}
-			// fmt.Printf("grew  %v\n\n", a)
-			// ret = append(ret, a)
-		}
-	}
-
-	// extending terms in addition
-	for _, B := range PS.ffxBases {
-		for i, C := range add.CS {
-			if C.ExprType() == expr.MUL {
-				m := C.(*expr.Mul)
-				if len(m.CS) > 3 {
-					continue
-				}
-			}
-			e := O.Clone()
-			a := e.(*expr.Add)
-			mul := expr.NewMul()
-			mul.Insert(a.CS[i])
-			mul.Insert(B.Clone())
-			a.CS[i] = mul
-			sort.Sort(a)
-			a.CalcExprStats()
-			good := PS.cnfg.treecfg.CheckExpr(a)
-			if good {
-				ret = append(ret, a)
-			}
-			// fmt.Printf("grew  %v\n\n", a)
-			ret = append(ret, a)
-		}
-	}
-
-	// fmt.Println("Len of ret = ", len(ret))
-	return ret
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_init_method_1.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_init_method_1.go	(revision 16230)
+++ 	(revision )
@@ -1,117 +1,0 @@
-package pge
-
-import (
-	"fmt"
-
-	probs "github.com/verdverm/go-pge/problems"
-	expr "github.com/verdverm/go-symexpr"
-)
-
-func (PS *PgeSearch) GenInitExprMethod1() *probs.ReportQueue {
-	fmt.Printf("generating initial expressions\n")
-
-	GP := PS.cnfg.treecfg
-	fmt.Printf("%v\n", GP)
-
-	eList := make([]expr.Expr, 0)
-
-	for _, T := range GP.Roots {
-		switch T.ExprType() {
-		case expr.ADD:
-			eList = append(eList, PS.GenInitExprAddMethod1()[:]...)
-		case expr.MUL:
-			eList = append(eList, PS.GenInitExprMulMethod1()[:]...)
-		case expr.DIV:
-			eList = append(eList, PS.GenInitExprDivMethod1()[:]...)
-		default:
-			fmt.Printf("Error in GenInitExpr: unknown ROOT %d\n", T)
-		}
-	}
-
-	exprs := probs.NewReportQueue()
-	// exprs.SetSort(PS.cnfg.sortType)
-	exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
-
-	for i, e := range eList {
-		fmt.Printf("%d:  %v\n", i, e)
-		serial := make([]int, 0, 64)
-		serial = e.Serial(serial)
-		PS.Trie.InsertSerial(serial)
-		// on train data
-		re := RegressExpr(e, PS.prob)
-		re.SetUnitID(i)
-		exprs.Push(re)
-	}
-	exprs.Sort()
-	return exprs
-}
-
-func (PS *PgeSearch) GenInitExprAddMethod1() []expr.Expr {
-
-	exprs := make([]expr.Expr, 0)
-
-	// WARNING adding a single coefficient results in the same traversal but with the added extra coefficient
-	cf := new(expr.Constant)
-	cf.P = 1
-	af := new(expr.Add)
-	af.Insert(cf)
-	exprs = append(exprs, af)
-
-	for _, i := range PS.cnfg.treecfg.UsableVars {
-		c := new(expr.Constant)
-		c.P = -1
-		v := new(expr.Var)
-		v.P = i
-
-		m := expr.NewMul()
-		m.Insert(c)
-		m.Insert(v)
-
-		a := expr.NewAdd()
-		a.Insert(m)
-		exprs = append(exprs, a)
-	}
-
-	fmt.Println("Initial Add:  ", exprs)
-	return exprs
-}
-
-func (PS *PgeSearch) GenInitExprMulMethod1() []expr.Expr {
-	exprs := make([]expr.Expr, 0)
-
-	for _, i := range PS.cnfg.treecfg.UsableVars {
-		c := new(expr.Constant)
-		c.P = -1
-		v := new(expr.Var)
-		v.P = i
-
-		m := expr.NewMul()
-		m.Insert(c)
-		m.Insert(v)
-
-		exprs = append(exprs, m)
-	}
-
-	fmt.Println("Initial Mul:  ", exprs)
-	return exprs
-}
-
-func (PS *PgeSearch) GenInitExprDivMethod1() []expr.Expr {
-	exprs := make([]expr.Expr, 0)
-
-	for _, i := range PS.cnfg.treecfg.UsableVars {
-		c := new(expr.Constant)
-		c.P = -1
-		v := new(expr.Var)
-		v.P = i
-
-		d := new(expr.Div)
-		d.Numer = c
-		d.Denom = v
-
-		exprs = append(exprs, d)
-	}
-
-	fmt.Println("Initial Div:  ", exprs)
-	return exprs
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_init_method_2.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_init_method_2.go	(revision 16230)
+++ 	(revision )
@@ -1,92 +1,0 @@
-package pge
-
-import (
-	"fmt"
-
-	probs "github.com/verdverm/go-pge/problems"
-	expr "github.com/verdverm/go-symexpr"
-)
-
-// This is the FFXish style init function
-func (PS *PgeSearch) GenInitExprMethod2() *probs.ReportQueue {
-	fmt.Printf("generating initial expressions\n")
-
-	GP := PS.cnfg.treecfg
-	fmt.Printf("%v\n", GP)
-
-	bases := make([]expr.Expr, 0)
-
-	// single constant
-	bases = append(bases, expr.NewConstant(-1))
-
-	// c*x_i
-	for _, v := range PS.prob.UsableVars {
-		mul := expr.NewMul()
-		mul.Insert(expr.NewConstant(-1))
-		mul.Insert(expr.NewVar(v))
-		bases = append(bases, mul)
-	}
-
-	// c*x_i^p & c*x_i^-p
-	for p := 2; p <= 4; p++ {
-		for _, v := range PS.prob.UsableVars {
-			// positive powers
-			mul := expr.NewMul()
-			mul.Insert(expr.NewConstant(-1))
-			mul.Insert(expr.NewPowI(expr.NewVar(v), p))
-			bases = append(bases, mul)
-
-			// negative powers
-			nul := expr.NewMul()
-			nul.Insert(expr.NewConstant(-1))
-			nul.Insert(expr.NewPowI(expr.NewVar(v), -p))
-			bases = append(bases, nul)
-		}
-	}
-
-	// c*N(d*x_i)
-	for _, N := range PS.GenNodes {
-		if N.ExprType() == expr.DIV || N.ExprType() == expr.ADD || N.ExprType() == expr.MUL {
-			continue
-		}
-		for _, v := range PS.prob.UsableVars {
-			// positive powers
-			mul := expr.NewMul()
-			mul.Insert(expr.NewConstant(-1))
-
-			nul := expr.NewMul()
-			nul.Insert(expr.NewConstant(-1))
-			nul.Insert(expr.NewVar(v))
-
-			n := N.Clone()
-			p := 1
-			n.SetExpr(&p, nul)
-			mul.Insert(n)
-			bases = append(bases, mul)
-		}
-	}
-
-	// copy bases for use later in expand
-	PS.ffxBases = make([]expr.Expr, len(bases))
-	for i, b := range bases {
-		PS.ffxBases[i] = b.Clone()
-	}
-
-	exprs := probs.NewReportQueue()
-	// exprs.SetSort(PS.cnfg.sortType)
-	exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
-
-	for i, e := range bases {
-		fmt.Printf("%d:  %v\n", i, e)
-		serial := make([]int, 0, 64)
-		serial = e.Serial(serial)
-		PS.Trie.InsertSerial(serial)
-		// on train data
-		re := RegressExpr(e, PS.prob)
-		re.SetUnitID(i)
-		exprs.Push(re)
-	}
-	exprs.Sort()
-
-	return exprs
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_init_method_3.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_init_method_3.go	(revision 16230)
+++ 	(revision )
@@ -1,92 +1,0 @@
-package pge
-
-import (
-	"fmt"
-
-	probs "github.com/verdverm/go-pge/problems"
-	expr "github.com/verdverm/go-symexpr"
-)
-
-// This is the FFXish style init function
-func (PS *PgeSearch) GenInitExprMethod3() *probs.ReportQueue {
-	fmt.Printf("generating initial expressions\n")
-
-	GP := PS.cnfg.treecfg
-	fmt.Printf("%v\n", GP)
-
-	bases := make([]expr.Expr, 0)
-
-	// single constant
-	bases = append(bases, expr.NewConstant(-1))
-
-	// c*x_i
-	for _, v := range PS.prob.UsableVars {
-		mul := expr.NewMul()
-		mul.Insert(expr.NewConstant(-1))
-		mul.Insert(expr.NewVar(v))
-		bases = append(bases, mul)
-	}
-
-	// c*x_i^p & c*x_i^-p
-	for p := 2; p <= 4; p++ {
-		for _, v := range PS.prob.UsableVars {
-			// positive powers
-			mul := expr.NewMul()
-			mul.Insert(expr.NewConstant(-1))
-			mul.Insert(expr.NewPowI(expr.NewVar(v), p))
-			bases = append(bases, mul)
-
-			// negative powers
-			nul := expr.NewMul()
-			nul.Insert(expr.NewConstant(-1))
-			nul.Insert(expr.NewPowI(expr.NewVar(v), -p))
-			bases = append(bases, nul)
-		}
-	}
-
-	// c*N(d*x_i)
-	for _, N := range PS.GenNodes {
-		if N.ExprType() == expr.DIV || N.ExprType() == expr.ADD || N.ExprType() == expr.MUL {
-			continue
-		}
-		for _, v := range PS.prob.UsableVars {
-			// positive powers
-			mul := expr.NewMul()
-			mul.Insert(expr.NewConstant(-1))
-
-			nul := expr.NewMul()
-			nul.Insert(expr.NewConstant(-1))
-			nul.Insert(expr.NewVar(v))
-
-			n := N.Clone()
-			p := 1
-			n.SetExpr(&p, nul)
-			mul.Insert(n)
-			bases = append(bases, mul)
-		}
-	}
-
-	// copy bases for use later in expand
-	PS.ffxBases = make([]expr.Expr, len(bases))
-	for i, b := range bases {
-		PS.ffxBases[i] = b.Clone()
-	}
-
-	exprs := probs.NewReportQueue()
-	// exprs.SetSort(PS.cnfg.sortType)
-	exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
-
-	for i, e := range bases {
-		fmt.Printf("%d:  %v\n", i, e)
-		serial := make([]int, 0, 64)
-		serial = e.Serial(serial)
-		PS.Trie.InsertSerial(serial)
-		// on train data
-		re := RegressExpr(e, PS.prob)
-		re.SetUnitID(i)
-		exprs.Push(re)
-	}
-	exprs.Sort()
-
-	return exprs
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_search.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_search.go	(revision 16230)
+++ 	(revision )
@@ -1,909 +1,0 @@
-package pge
-
-import (
-	"bufio"
-	"fmt"
-	"io/ioutil"
-	"log"
-	"math"
-	"os"
-	"strconv"
-	"strings"
-
-	levmar "github.com/verdverm/go-levmar"
-	config "github.com/verdverm/go-pge/config"
-	probs "github.com/verdverm/go-pge/problems"
-	expr "github.com/verdverm/go-symexpr"
-)
-
-type PgeConfig struct {
-	// search params
-	maxGen        int
-	pgeRptEpoch   int
-	pgeRptCount   int
-	pgeArchiveCap int
-
-	simprules expr.SimpRules
-	treecfg   *probs.TreeParams
-
-	// PGE specific options
-	peelCnt     int
-	sortType    probs.SortType
-	zeroEpsilon float64
-
-	initMethod string
-	growMethod string
-
-	evalrCount int
-}
-
-func pgeConfigParser(field, value string, config interface{}) (err error) {
-
-	PC := config.(*PgeConfig)
-
-	switch strings.ToUpper(field) {
-	case "MAXGEN":
-		PC.maxGen, err = strconv.Atoi(value)
-	case "PGERPTEPOCH":
-		PC.pgeRptEpoch, err = strconv.Atoi(value)
-	case "PGERPTCOUNT":
-		PC.pgeRptCount, err = strconv.Atoi(value)
-	case "PGEARCHIVECAP":
-		PC.pgeArchiveCap, err = strconv.Atoi(value)
-
-	case "PEELCOUNT":
-		PC.peelCnt, err = strconv.Atoi(value)
-
-	case "EVALRCOUNT":
-		PC.evalrCount, err = strconv.Atoi(value)
-
-	case "SORTTYPE":
-		switch strings.ToLower(value) {
-		case "paretotrainerror":
-			PC.sortType = probs.PESORT_PARETO_TRN_ERR
-		case "paretotesterror":
-			PC.sortType = probs.PESORT_PARETO_TST_ERR
-
-		default:
-			log.Printf("PGE Config Not Implemented: %s, %s\n\n", field, value)
-		}
-
-	case "ZEROEPSILON":
-		PC.zeroEpsilon, err = strconv.ParseFloat(value, 64)
-
-	default:
-		// check augillary parsable structures [only TreeParams for now]
-		if PC.treecfg == nil {
-			PC.treecfg = new(probs.TreeParams)
-		}
-		found, ferr := probs.ParseTreeParams(field, value, PC.treecfg)
-		if ferr != nil {
-			log.Fatalf("error parsing PGE - treecfg Config\n")
-			return ferr
-		}
-		if !found {
-			log.Printf("PGE Config Not Implemented: %s, %s\n\n", field, value)
-		}
-
-	}
-	return
-}
-
-type PgeSearch struct {
-	id   int
-	cnfg PgeConfig
-	prob *probs.ExprProblem
-	iter int
-	stop bool
-
-	// comm up
-	commup *probs.ExprProblemComm
-
-	// comm down
-
-	// best exprs
-	Best *probs.ReportQueue
-
-	// training data in C format
-	c_input  []levmar.C_double
-	c_ygiven []levmar.C_double
-
-	// logs
-	logDir     string
-	mainLog    *log.Logger
-	mainLogBuf *bufio.Writer
-	eqnsLog    *log.Logger
-	eqnsLogBuf *bufio.Writer
-	errLog     *log.Logger
-	errLogBuf  *bufio.Writer
-
-	fitnessLog    *log.Logger
-	fitnessLogBuf *bufio.Writer
-	ipreLog       *log.Logger
-	ipreLogBuf    *bufio.Writer
-
-	// equations visited
-	Trie  *IpreNode
-	Queue *probs.ReportQueue
-
-	// eval channels
-	eval_in  chan expr.Expr
-	eval_out chan *probs.ExprReport
-
-	// genStuff
-	GenRoots   []expr.Expr
-	GenLeafs   []expr.Expr
-	GenNodes   []expr.Expr
-	GenNonTrig []expr.Expr
-
-	// FFXish stuff
-	ffxBases []expr.Expr
-
-	// statistics
-	neqns    int
-	ipreCnt  int
-	maxSize  int
-	maxScore int
-	minError float64
-}
-
-func (PS *PgeSearch) GetMaxIter() int {
-	return PS.cnfg.maxGen
-}
-func (PS *PgeSearch) GetPeelCount() int {
-	return PS.cnfg.peelCnt
-}
-func (PS *PgeSearch) SetMaxIter(iter int) {
-	PS.cnfg.maxGen = iter
-}
-func (PS *PgeSearch) SetPeelCount(cnt int) {
-	PS.cnfg.peelCnt = cnt
-}
-func (PS *PgeSearch) SetInitMethod(init string) {
-	PS.cnfg.initMethod = init
-}
-func (PS *PgeSearch) SetGrowMethod(grow string) {
-	PS.cnfg.growMethod = grow
-}
-func (PS *PgeSearch) SetEvalrCount(cnt int) {
-	PS.cnfg.evalrCount = cnt
-}
-
-func (PS *PgeSearch) ParseConfig(filename string) {
-	fmt.Printf("Parsing PGE Config: %s\n", filename)
-	data, err := ioutil.ReadFile(filename)
-	if err != nil {
-		log.Fatal(err)
-	}
-	err = config.ParseConfig(data, pgeConfigParser, &PS.cnfg)
-	if err != nil {
-		log.Fatal(err)
-	}
-}
-
-func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) {
-
-	//fmt.Printf("Init'n PGE\n")
-	// setup data
-
-	// open logs
-	PS.initLogs(logdir)
-	
-	PS.stop = false
-
-	// copy in common config options
-	PS.prob = prob
-	if PS.cnfg.treecfg == nil {
-		PS.cnfg.treecfg = PS.prob.TreeCfg.Clone()
-	}
-	srules := expr.DefaultRules()
-	srules.ConvertConsts = true
-	PS.cnfg.simprules = srules
-
-	//fmt.Println("Roots:   ", PS.cnfg.treecfg.RootsS)
-	//fmt.Println("Nodes:   ", PS.cnfg.treecfg.NodesS)
-	//fmt.Println("Leafs:   ", PS.cnfg.treecfg.LeafsS)
-	//fmt.Println("NonTrig: ", PS.cnfg.treecfg.NonTrigS)
-
-	PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots))
-	for i := 0; i < len(PS.GenRoots); i++ {
-		PS.GenRoots[i] = PS.cnfg.treecfg.Roots[i].Clone()
-	}
-	PS.GenNodes = make([]expr.Expr, len(PS.cnfg.treecfg.Nodes))
-	for i := 0; i < len(PS.GenNodes); i++ {
-		PS.GenNodes[i] = PS.cnfg.treecfg.Nodes[i].Clone()
-	}
-	PS.GenNonTrig = make([]expr.Expr, len(PS.cnfg.treecfg.NonTrig))
-	for i := 0; i < len(PS.GenNonTrig); i++ {
-		PS.GenNonTrig[i] = PS.cnfg.treecfg.NonTrig[i].Clone()
-	}
-	
-	fmt.Printf("Init1 %v\n", len(PS.cnfg.treecfg.LeafsT))
-
-	PS.GenLeafs = make([]expr.Expr, 0)
-	for _, t := range PS.cnfg.treecfg.LeafsT {
-		switch t {
-		case expr.TIME:
-			PS.GenLeafs = append(PS.GenLeafs, expr.NewTime())
-
-		case expr.VAR:
-			//fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)
-			for _, i := range PS.cnfg.treecfg.UsableVars {
-				PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i))
-			}
-
-		case expr.SYSTEM:
-			for i := 0; i < PS.prob.Train[0].NumSys(); i++ {
-				PS.GenLeafs = append(PS.GenLeafs, expr.NewSystem(i))
-			}
-
-		}
-	}
-	fmt.Printf("Init2\n")
-	/*** FIX ME
-	PS.GenLeafs = make([]expr.Expr, len(PS.cnfg.treecfg.Leafs))
-	for i := 0; i < len(PS.GenLeafs); i++ {
-		PS.GenLeafs[i] = PS.cnfg.treecfg.Leafs[i].Clone()
-	}
-	***/
-	
-	fmt.Printf("Init3\n")
-
-	//fmt.Println("Roots:   ", PS.GenRoots)
-	//fmt.Println("Nodes:   ", PS.GenNodes)
-	//fmt.Println("Leafs:   ", PS.GenLeafs)
-	//fmt.Println("NonTrig: ", PS.GenNonTrig)
-
-	// setup communication struct
-	PS.commup = input.(*probs.ExprProblemComm)
-
-	// initialize bbq
-	PS.Trie = new(IpreNode)
-	PS.Trie.val = -1
-	PS.Trie.next = make(map[int]*IpreNode)
-
-	PS.Best = probs.NewReportQueue()
-	PS.Best.SetSort(probs.GPSORT_PARETO_TST_ERR)
-	fmt.Printf("Init4\n")
-
-	PS.Queue = PS.GenInitExpr()
-	PS.Queue.SetSort(probs.PESORT_PARETO_TST_ERR)
-
-	PS.neqns = PS.Queue.Len()
-
-	PS.minError = math.Inf(1)
-
-	PS.eval_in = make(chan expr.Expr, 4048)
-	PS.eval_out = make(chan *probs.ExprReport, 4048)
-
-	fmt.Printf("Init5a\n")
-	for i := 0; i < PS.cnfg.evalrCount; i++ {
-		go PS.Evaluate()
-	}
-	fmt.Printf("Init5\n")
-}
-
-func (PS *PgeSearch) Evaluate() {
-
-	for !PS.stop {
-		e := <-PS.eval_in
-		if e == nil {
-			continue
-		}
-		re := RegressExpr(e, PS.prob)
-		//fmt.Printf("reg: %v\n", re)
-		PS.eval_out <- re
-	}
-
-}
-
-func (PS *PgeSearch) Run() {
-	fmt.Printf("Running PGE\n")
-
-	PS.Loop()
-
-	fmt.Println("PGE exitting")
-
-	PS.Clean()
-	PS.commup.Cmds <- -1
-}
-
-func (PS *PgeSearch) Loop() {
-
-	PS.checkMessages()
-	for !PS.stop {
-
-		fmt.Println("in: PS.step() ", PS.iter)
-		PS.Step()
-
-		// if PS.iter%PS.cnfg.pgeRptEpoch == 0 {
-		PS.reportExpr()
-		// }
-
-		// report current iteration
-		PS.commup.Gen <- [2]int{PS.id, PS.iter}
-		PS.iter++
-
-		PS.Clean()
-
-		PS.checkMessages()
-
-	}
-
-	// done expanding, pull the rest of the regressed solutions from the queue
-	p := 0
-	for PS.Queue.Len() > 0 {
-		e := PS.Queue.Pop().(*probs.ExprReport)
-
-		bPush := true
-		if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {
-			// fmt.Println("No Best Push")
-			bPush = false
-		}
-
-		if bPush {
-			// fmt.Printf("pop/push(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
-			PS.Best.Push(e)
-			p++
-		}
-
-		if e.TestScore() > PS.maxScore {
-			PS.maxScore = e.TestScore()
-		}
-		if e.TestError() < PS.minError {
-			PS.minError = e.TestError()
-			fmt.Printf("EXITING New Min Error:  %v\n", e)
-		}
-		if e.Size() > PS.maxSize {
-			PS.maxSize = e.Size()
-		}
-	}
-
-	fmt.Println("PGE sending last report")
-	PS.reportExpr()
-
-}
-
-func (PS *PgeSearch) Step() {
-	loop := 0
-	eval_cnt := 0 // for channeled eval
-
-	es := PS.peel()
-
-	ex := PS.expandPeeled(es)
-
-	for cnt := range ex {
-		E := ex[cnt]
-
-		if E == nil {
-			continue
-		}
-
-		for _, e := range E {
-			if e == nil {
-				continue
-			}
-			if !PS.cnfg.treecfg.CheckExpr(e) {
-				continue
-			}
-
-			// check ipre_trie
-			serial := make([]int, 0, 64)
-			serial = e.Serial(serial)
-			ins := PS.Trie.InsertSerial(serial)
-			if !ins {
-				continue
-			}
-
-			// for serial eval
-			// re := RegressExpr(e, PS.prob)
-
-			// start channeled eval
-			PS.eval_in <- e
-			eval_cnt++
-		}
-	}
-	for i := 0; i < eval_cnt; i++ {
-		re := <-PS.eval_out
-		// end channeled eval
-
-		// check for NaN/Inf in re.error  and  if so, skip
-		if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) {
-			// fmt.Printf("Bad Error\n%v\n", re)
-			continue
-		}
-
-		if re.TestError() < PS.minError {
-			PS.minError = re.TestError()
-		}
-
-		// check for coeff == 0
-		doIns := true
-		for _, c := range re.Coeff() {
-			// i > 0 for free coeff
-			if math.Abs(c) < PS.cnfg.zeroEpsilon {
-				doIns = false
-				break
-			}
-		}
-
-		if doIns {
-			re.SetProcID(PS.id)
-			re.SetIterID(PS.iter)
-			re.SetUnitID(loop)
-			re.SetUniqID(PS.neqns)
-			loop++
-			PS.neqns++
-			// fmt.Printf("Queue.Push(): %v\n%v\n\n", re.Expr(), serial)
-			// fmt.Printf("Queue.Push(): %v\n", re)
-			// fmt.Printf("Queue.Push(): %v\n", re.Expr())
-
-			PS.Queue.Push(re)
-
-		}
-	}
-	// } // for sequential eval
-	PS.Queue.Sort()
-}
-
-func (PS *PgeSearch) peel() []*probs.ExprReport {
-	es := make([]*probs.ExprReport, PS.cnfg.peelCnt)
-	for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ {
-		e := PS.Queue.Pop().(*probs.ExprReport)
-		bPush := true
-		if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {
-			fmt.Println("No Best Push")
-			p--
-			continue
-		}
-
-		if bPush {
-			fmt.Printf("pop/push DO(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
-			PS.Best.Push(e)
-		}
-
-		es[p] = e
-
-		if e.TestScore() > PS.maxScore {
-			PS.maxScore = e.TestScore()
-		}
-		if e.TestError() < PS.minError {
-			PS.minError = e.TestError()
-			fmt.Printf("Best New Min Error:  %v\n", e)
-		}
-		if e.Size() > PS.maxSize {
-			PS.maxSize = e.Size()
-		}
-
-	}
-	return es
-}
-
-
-type PeelResult struct {
-	Es *probs.ExprReport
-
-	Nobestpush bool
-	BestNewMinErr bool
-	
-	Bestlen1 int
-	Bestlen2 int
-	
-	Coeff []float64
-	TestScore int
-	
-	Expre expr.Expr
-	ExpreRe *probs.ExprReport
-}
-
-//Problem
-func (PS *PgeSearch) SingleStep() []*PeelResult {
-	if os.Getenv("PGEDEBUG") == "1" {
-		fmt.Printf("Init PgeSearch: %#v \n", PS)
-		fmt.Printf("Init PgeProblem: %#v \n", PS.prob)
-	}
-
-
-	loop := 0
-	eval_cnt := 0
-	PR := PS.peelRes()
-	
-	es := make([]*probs.ExprReport, len(PR))
-	
-	for i, elem := range PR {
-    if(elem != nil) {
-			es[i] = elem.ExpreRe
-		//} else {
-    //  es[i] = new(probs.ExprReport)
-    }
-	}
-	
-	ex := PS.expandPeeled(es)
-
-	for cnt := range ex {
-		E := ex[cnt]
-		if E == nil {
-			continue
-		}
-		for _, e := range E {
-			if e == nil {
-				continue
-			}
-			if !PS.cnfg.treecfg.CheckExpr(e) {
-				continue
-			}
-			serial := make([]int, 0, 64)
-			serial = e.Serial(serial)
-			ins := PS.Trie.InsertSerial(serial)
-			
-			if !ins {
-				continue
-			}
-			PS.eval_in <- e
-			eval_cnt++
-		}
-	}
-	for i := 0; i < eval_cnt; i++ {
-		re := <-PS.eval_out
-		if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) {
-			continue
-		}
-		if re.TestError() < PS.minError {
-			PS.minError = re.TestError()
-		}
-		doIns := true
-		for _, c := range re.Coeff() {
-			if math.Abs(c) < PS.cnfg.zeroEpsilon {
-				doIns = false
-				break
-			}
-		}
-		if doIns {
-			re.SetProcID(PS.id)
-			re.SetIterID(PS.iter)
-			re.SetUnitID(loop)
-			re.SetUniqID(PS.neqns)
-			loop++
-			PS.neqns++
-			PS.Queue.Push(re)
-		}
-	}
-	PS.Queue.Sort()
-
-	PS.reportExpr()	
-	PS.iter++
-	
-	return PR
-}
-
-//Problem
-func (PS *PgeSearch) peelRes() []*PeelResult {
-	//es := make([]*probs.ExprReport, PS.cnfg.peelCnt)
-	PRes := make([]*PeelResult, PS.cnfg.peelCnt)
-	
-	for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ {
-		PR := new(PeelResult)
-			
-		PR.BestNewMinErr = false
-		PR.Nobestpush = false
-		
-		e := PS.Queue.Pop().(*probs.ExprReport)
-		
-		bPush := true
-		if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {
-			//fmt.Println("No Best Push")
-			PR.Nobestpush = true
-			p--
-			continue
-		}
-
-		if bPush {
-			//fmt.Printf("pop/push (%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
-			PS.Best.Push(e)
-		}
-
-		//es[p] = e
-    PR.Bestlen1 = p
-		PR.Bestlen2 = PS.Best.Len()
-		PR.Expre = e.Expr()
-		PR.ExpreRe = e
-		PR.Es = e
-		PR.Coeff = e.Coeff()
-		PR.TestScore = e.TestScore()
-		
-		
-		if e.TestScore() > PS.maxScore {
-			PS.maxScore = e.TestScore()
-		}
-		if e.TestError() < PS.minError {
-			PS.minError = e.TestError()
-			PR.BestNewMinErr = true
-			//fmt.Printf("Best New Min Error:  %v\n", e)
-		}
-		if e.Size() > PS.maxSize {
-			PS.maxSize = e.Size()
-		}
-		
-		PRes[p] = PR
-	}
-	
-	return PRes
-}
-
-
-func (PS *PgeSearch) expandPeeled(es []*probs.ExprReport) [][]expr.Expr {
-	eqns := make([][]expr.Expr, PS.cnfg.peelCnt)
-	for p := 0; p < PS.cnfg.peelCnt; p++ {
-		if es[p] == nil {
-			continue
-		}
-		// fmt.Printf("expand(%d): %v\n", p, es[p].Expr())
-		if es[p].Expr().ExprType() != expr.ADD {
-			add := expr.NewAdd()
-			add.Insert(es[p].Expr())
-			add.CalcExprStats()
-			es[p].SetExpr(add)
-		}
-		eqns[p] = PS.Expand(es[p].Expr())
-		// fmt.Printf("Results:\n")
-		// for i, e := range eqns[p] {
-		// 	fmt.Printf("%d,%d:  %v\n", p, i, e)
-		// }
-		// fmt.Println()
-	}
-	return eqns
-}
-
-func (PS *PgeSearch) reportExpr() {
-
-	cnt := PS.cnfg.pgeRptCount
-	PS.Best.Sort()
-
-	// repot best equations
-	rpt := make(probs.ExprReportArray, cnt)
-	if PS.Best.Len() < cnt {
-		cnt = PS.Best.Len()
-	}
-	copy(rpt, PS.Best.GetQueue()[:cnt])
-
-	errSum, errCnt := 0.0, 0
-	PS.eqnsLog.Println("\n\nReport", PS.iter)
-	for i, r := range rpt {
-		PS.eqnsLog.Printf("\n%d:  %v\n", i, r)
-		if r != nil && r.Expr() != nil {
-			errSum += r.TestError()
-			errCnt++
-		}
-	}
-
-	PS.mainLog.Printf("Iter: %d  %f  %f\n", PS.iter, errSum/float64(errCnt), PS.minError)
-
-	PS.ipreLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst)
-	PS.fitnessLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst, errSum/float64(errCnt), PS.minError)
-
-	PS.commup.Rpts <- &rpt
-
-}
-
-func (PS *PgeSearch) Clean() {
-	PS.errLogBuf.Flush()
-	PS.mainLogBuf.Flush()
-	PS.eqnsLogBuf.Flush()
-	PS.fitnessLogBuf.Flush()
-	PS.ipreLogBuf.Flush()
-}
-
-func (PS *PgeSearch) initLogs(logdir string) {
-	// open logs
-	PS.logDir = logdir + "pge/"
-	os.Mkdir(PS.logDir, os.ModePerm)
-	tmpF0, err5 := os.Create(PS.logDir + "pge:err.log")
-	if err5 != nil {
-		log.Fatal("couldn't create errs log")
-	}
-	PS.errLogBuf = bufio.NewWriter(tmpF0)
-	PS.errLogBuf.Flush()
-	PS.errLog = log.New(PS.errLogBuf, "", log.LstdFlags)
-
-	tmpF1, err1 := os.Create(PS.logDir + "pge:main.log")
-	if err1 != nil {
-		log.Fatal("couldn't create main log")
-	}
-	PS.mainLogBuf = bufio.NewWriter(tmpF1)
-	PS.mainLogBuf.Flush()
-	PS.mainLog = log.New(PS.mainLogBuf, "", log.LstdFlags)
-
-	tmpF2, err2 := os.Create(PS.logDir + "pge:eqns.log")
-	if err2 != nil {
-		log.Fatal("couldn't create eqns log")
-	}
-	PS.eqnsLogBuf = bufio.NewWriter(tmpF2)
-	PS.eqnsLogBuf.Flush()
-	PS.eqnsLog = log.New(PS.eqnsLogBuf, "", 0)
-
-	tmpF3, err3 := os.Create(PS.logDir + "pge:fitness.log")
-	if err3 != nil {
-		log.Fatal("couldn't create eqns log")
-	}
-	PS.fitnessLogBuf = bufio.NewWriter(tmpF3)
-	PS.fitnessLogBuf.Flush()
-	PS.fitnessLog = log.New(PS.fitnessLogBuf, "", log.Ltime|log.Lmicroseconds)
-
-	tmpF4, err4 := os.Create(PS.logDir + "pge:ipre.log")
-	if err4 != nil {
-		log.Fatal("couldn't create eqns log")
-	}
-	PS.ipreLogBuf = bufio.NewWriter(tmpF4)
-	PS.ipreLogBuf.Flush()
-	PS.ipreLog = log.New(PS.ipreLogBuf, "", log.Ltime|log.Lmicroseconds)
-}
-
-func (PS *PgeSearch) checkMessages() {
-
-	// check messages from superior
-	select {
-	case cmd, ok := <-PS.commup.Cmds:
-		if ok {
-			if cmd == -1 {
-				fmt.Println("PGE: stop sig recv'd")
-				PS.stop = true
-				return
-			}
-		}
-	default:
-		return
-	}
-}
-
-var c_input, c_ygiven []levmar.C_double
-
-func RegressExpr(E expr.Expr, P *probs.ExprProblem) (R *probs.ExprReport) {
-
-	guess := make([]float64, 0)
-	guess, eqn := E.ConvertToConstants(guess)
-
-	var coeff []float64
-	if len(guess) > 0 {
-
-		//fmt.Printf("IMREGEXP %v %v\n", P.SearchType, P.SearchVar)
-		//fmt.Printf("REGPTrain %T | %#v | %v\n", P.Train, P.Train, P.Train)
-		//fmt.Printf("eqn %T | %#v | %v\n", eqn, eqn, eqn)
-		//fmt.Printf("guess %T | %#v | %v\n", guess, guess, guess)
-
-		// Callback version
-		
-		
-		coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test)
-		
-
-		// Stack version
-		// x_dim := P.Train[0].NumDim()
-		// if c_input == nil {
-		// 	ps := P.Train[0].NumPoints()
-		// 	PS := len(P.Train) * ps
-		// 	x_tot := PS * x_dim
-
-		// 	c_input = make([]levmar.C_double, x_tot)
-		// 	c_ygiven = make([]levmar.C_double, PS)
-
-		// 	for i1, T := range P.Train {
-		// 		for i2, p := range T.Points() {
-		// 			i := i1*ps + i2
-		// 			c_ygiven[i] = levmar.MakeCDouble(p.Depnd(P.SearchVar))
-		// 			for i3, x_p := range p.Indeps() {
-		// 				j := i1*ps*x_dim + i2*x_dim + i3
-		// 				c_input[j] = levmar.MakeCDouble(x_p)
-		// 			}
-		// 		}
-		// 	}
-		// }
-		// coeff = levmar.StackLevmarExpr(eqn, x_dim, guess, c_ygiven, c_input)
-
-		// serial := make([]int, 0)
-		// serial = eqn.StackSerial(serial)
-		// fmt.Printf("StackSerial: %v\n", serial)
-		// fmt.Printf("%v\n%v\n%v\n\n", eqn, coeff, steff)
-	}
-
-	R = new(probs.ExprReport)
-	R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/
-
-	R.SetCoeff(coeff)
-	R.Expr().CalcExprStats()
-
-	// hitsL1, hitsL2, evalCnt, nanCnt, infCnt, l1_err, l2_err := scoreExpr(E, P, coeff)
-	_, _, _, trnNanCnt, _, trn_l1_err, _ := scoreExpr(E, P, P.Train, coeff)
-	_, _, tstEvalCnt, tstNanCnt, _, tst_l1_err, tst_l2_err := scoreExpr(E, P, P.Test, coeff)
-
-	R.SetTrainScore(trnNanCnt)
-	R.SetTrainError(trn_l1_err)
-
-	R.SetPredScore(tstNanCnt)
-	R.SetTestScore(tstEvalCnt)
-	R.SetTestError(tst_l1_err)
-	R.SetPredError(tst_l2_err)
-
-	return R
-}
-
-func scoreExpr(e expr.Expr, P *probs.ExprProblem, dataSets []*probs.PointSet, coeff []float64) (hitsL1, hitsL2, evalCnt, nanCnt, infCnt int, l1_err, l2_err float64) {
-	var l1_sum, l2_sum float64
-	for _, PS := range dataSets {
-		for _, p := range PS.Points() {
-			y := p.Depnd(P.SearchVar)
-			var out float64
-			if P.SearchType == probs.ExprBenchmark {
-				out = e.Eval(0, p.Indeps(), coeff, PS.SysVals())
-			} else if P.SearchType == probs.ExprDiffeq {
-				out = e.Eval(p.Indep(0), p.Indeps()[1:], coeff, PS.SysVals())
-			}
-
-			if math.IsNaN(out) {
-				nanCnt++
-				continue
-			} else if math.IsInf(out, 0) {
-				infCnt++
-				continue
-			} else {
-				evalCnt++
-			}
-
-			diff := out - y
-			l1_val := math.Abs(diff)
-			l2_val := diff * diff
-			l1_sum += l1_val
-			l2_sum += l2_val
-
-			if l1_val < P.HitRatio {
-				hitsL1++
-			}
-			if l2_val < P.HitRatio {
-				hitsL2++
-			}
-		}
-	}
-
-	if evalCnt == 0 {
-		l1_err = math.NaN()
-		l2_err = math.NaN()
-	} else {
-		fEvalCnt := float64(evalCnt + 1)
-		l1_err = l1_sum / fEvalCnt
-		l2_err = math.Sqrt(l2_sum / fEvalCnt)
-	}
-
-	return
-}
-
-func (PS *PgeSearch) CreateDS(maxGen int, pgeRptEpoch int, pgeRptCount int, pgeArchiveCap int, peelCnt int, evalrCount int, zeroEpsilon float64, initMethod string, growMethod string, sortType int) {
-	PS.id = 0 //maxGen
-	
-	var PC PgeConfig
-	
-	PC.pgeRptEpoch = pgeRptEpoch
-	PC.pgeRptCount = pgeRptCount
-	PC.pgeArchiveCap = pgeArchiveCap
-	PC.peelCnt = peelCnt
-	PC.evalrCount = evalrCount
-	PC.zeroEpsilon = zeroEpsilon
-	PC.initMethod = initMethod
-	PC.growMethod = growMethod
-
-	if sortType == 1 {
-		PC.sortType = probs.PESORT_PARETO_TRN_ERR
-	} else {	
-		PC.sortType = probs.PESORT_PARETO_TST_ERR
-	}
-
-	PC.maxGen = maxGen
-	PS.cnfg = PC
-		
-	PS.iter = 0
-}
-
-func (PS *PgeSearch) SetProb(ep *probs.ExprProblem) {
-	PS.prob = ep
-}
-func (PS *PgeSearch) GetIter() int {
-	return PS.iter
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/bbsr.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/bbsr.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/bbsr.go	(revision 16231)
@@ -10,8 +10,4 @@
 
 func (PS *PgeSearch) GenInitExpr() *probs.ReportQueue {
-
-	fmt.Println("Call gen method")
-
-
 	switch PS.cnfg.initMethod {
 	case "method1":
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge.go	(revision 16231)
@@ -32,10 +32,12 @@
 var probDepndNames []string
 
-var stepResult []*pge.PeelResult
-var lastStepRes *pge.PeelResult
+var stepResult probs.ExprReportArray
+var lastStepRes *probs.ExprReport
 var resultNr int
 
 var nCurrentCoeff int 
 var nMaxCoeff int
+
+var nLastResults int
 
 //export InitSearch
@@ -48,5 +50,5 @@
 	testDatasN = 0 
 	trainDatasN = 0
-
+	nLastResults = 0
 	cps.CreateDS(maxGen, pgeRptEpoch, pgeRptCount, pgeArchiveCap, peelCnt, evalrCount, zeroEpsilon, goInitMethod, goGrowMethod, sortType)
 	
@@ -79,5 +81,5 @@
 	probDepndNames = goDepndNames
 	
-	trainData.InitTrainDataF(goIndepNames, goDepndNames, matrix, nEntries)
+	trainData.InitTrainData(goIndepNames, goDepndNames, matrix, nEntries)
 	
 	trainDatas[trainDatasN] = trainData
@@ -93,5 +95,5 @@
 	goDepndNames := strings.Split(C.GoString(depndNames), " ")
 	
-	testData.InitTestDataF(goIndepNames, goDepndNames, matrix, nEntries)
+	testData.InitTrainData(goIndepNames, goDepndNames, matrix, nEntries)
 	testDatas[testDatasN] = testData
 	testDatasN++
@@ -135,4 +137,5 @@
     epcomm.Rpts = make(chan *probs.ExprReportArray, 64)
 	epcomm.Gen = make(chan [2]int, 64)
+	
 	fmt.Printf("6\n")
 	
@@ -195,23 +198,24 @@
 	*testscore = 0
 	
-	if resultNr < cps.GetPeelCount() {
+	if resultNr < len(stepResult) && stepResult != nil {
 		elem := stepResult[resultNr]
 		resultNr++
 		lastStepRes = elem
+		*bestlen1 = len(stepResult)
 		if(elem != nil) {
-			if elem.Nobestpush {
-				*nobestpush = 1;
-			} else {
-				if elem.BestNewMinErr {
-					*bestnewminerr = 1
-				}
-				*testscore = elem.TestScore
-				*ncoeff = len(elem.Coeff)
+			//if elem.Nobestpush {
+			//	*nobestpush = 1;
+			//} else {
+			//	if elem.BestNewMinErr {
+					*bestnewminerr = int(elem.TestError())
+			//	}
+				*testscore = elem.TestScore()
+				*ncoeff = len(elem.Coeff())
 				nCurrentCoeff = 0
-				nMaxCoeff = len(elem.Coeff)
-				*bestlen1 = elem.Bestlen1
-				*bestlen2 = elem.Bestlen2
-				return C.CString(elem.Expre.String())
-			}
+				nMaxCoeff = len(elem.Coeff())
+				//*bestlen1 = 0 //elem.Bestlen1
+				*bestlen2 = 0 //elem.Bestlen2
+				return C.CString(elem.Expr().String())
+			//}
 		}
 	}
@@ -226,5 +230,6 @@
 		//*item = elem.Coeff[i]
 		
-		res = lastStepRes.Coeff[nCurrentCoeff]
+		coeffs := lastStepRes.Coeff()
+		res = coeffs[nCurrentCoeff]
 	}
 	nCurrentCoeff++
@@ -233,7 +238,23 @@
 
 //export StepW
-func StepW() {
+func StepW() int {
 	resultNr = 0
-	stepResult = cps.SingleStep()
+	stepResult = nil
+	nRes := cps.Step()
+	
+	resu, ok := <-epcomm.Rpts
+	
+	//_ = ok
+	
+	resultNr = nLastResults
+	
+	nNew := 0
+	if ok && resu != nil {
+		stepResult = *resu
+		nNew = nRes - nLastResults
+		nLastResults = nRes
+	}
+		
+	return nNew
 }
 
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_init_method_1.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_init_method_1.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_init_method_1.go	(revision 16231)
@@ -12,4 +12,5 @@
 
 	GP := PS.cnfg.treecfg
+	fmt.Printf("%v\n", GP)
 
 	eList := make([]expr.Expr, 0)
@@ -31,20 +32,15 @@
 	// exprs.SetSort(PS.cnfg.sortType)
 	exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
-	
+
 	for i, e := range eList {
-	
+		fmt.Printf("%d:  %v\n", i, e)
 		serial := make([]int, 0, 64)
 		serial = e.Serial(serial)
 		PS.Trie.InsertSerial(serial)
 		// on train data
-
-		//fmt.Printf("RegressExpr:  e: %v  || PS.prob: %v\n", e, PS.prob)
-		re := RegressExpr(e, PS.prob)  //DER DO
-		//fmt.Printf("RegressExpr:  e: %v  || PS.prob: %v || %v \n", e, PS.prob, re)
-		
+		re := RegressExpr(e, PS.prob)
 		re.SetUnitID(i)
 		exprs.Push(re)
 	}
-
 	exprs.Sort()
 	return exprs
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go	(revision 16231)
@@ -17,5 +17,5 @@
 )
 
-type PgeConfig struct {
+type pgeConfig struct {
 	// search params
 	maxGen        int
@@ -40,5 +40,5 @@
 func pgeConfigParser(field, value string, config interface{}) (err error) {
 
-	PC := config.(*PgeConfig)
+	PC := config.(*pgeConfig)
 
 	switch strings.ToUpper(field) {
@@ -92,5 +92,5 @@
 type PgeSearch struct {
 	id   int
-	cnfg PgeConfig
+	cnfg pgeConfig
 	prob *probs.ExprProblem
 	iter int
@@ -151,7 +151,4 @@
 	return PS.cnfg.maxGen
 }
-func (PS *PgeSearch) GetPeelCount() int {
-	return PS.cnfg.peelCnt
-}
 func (PS *PgeSearch) SetMaxIter(iter int) {
 	PS.cnfg.maxGen = iter
@@ -183,12 +180,9 @@
 
 func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) {
-
-	//fmt.Printf("Init'n PGE\n")
+	fmt.Printf("Init'n PGE\n")
 	// setup data
 
 	// open logs
 	PS.initLogs(logdir)
-	
-	PS.stop = false
 
 	// copy in common config options
@@ -201,8 +195,8 @@
 	PS.cnfg.simprules = srules
 
-	//fmt.Println("Roots:   ", PS.cnfg.treecfg.RootsS)
-	//fmt.Println("Nodes:   ", PS.cnfg.treecfg.NodesS)
-	//fmt.Println("Leafs:   ", PS.cnfg.treecfg.LeafsS)
-	//fmt.Println("NonTrig: ", PS.cnfg.treecfg.NonTrigS)
+	fmt.Println("Roots:   ", PS.cnfg.treecfg.RootsS)
+	fmt.Println("Nodes:   ", PS.cnfg.treecfg.NodesS)
+	fmt.Println("Leafs:   ", PS.cnfg.treecfg.LeafsS)
+	fmt.Println("NonTrig: ", PS.cnfg.treecfg.NonTrigS)
 
 	PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots))
@@ -226,5 +220,5 @@
 
 		case expr.VAR:
-			//fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)
+			fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)
 			for _, i := range PS.cnfg.treecfg.UsableVars {
 				PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i))
@@ -245,8 +239,8 @@
 	***/
 
-	//fmt.Println("Roots:   ", PS.GenRoots)
-	//fmt.Println("Nodes:   ", PS.GenNodes)
-	//fmt.Println("Leafs:   ", PS.GenLeafs)
-	//fmt.Println("NonTrig: ", PS.GenNonTrig)
+	fmt.Println("Roots:   ", PS.GenRoots)
+	fmt.Println("Nodes:   ", PS.GenNodes)
+	fmt.Println("Leafs:   ", PS.GenLeafs)
+	fmt.Println("NonTrig: ", PS.GenNonTrig)
 
 	// setup communication struct
@@ -260,5 +254,4 @@
 	PS.Best = probs.NewReportQueue()
 	PS.Best.SetSort(probs.GPSORT_PARETO_TST_ERR)
-
 	PS.Queue = PS.GenInitExpr()
 	PS.Queue.SetSort(probs.PESORT_PARETO_TST_ERR)
@@ -283,7 +276,5 @@
 			continue
 		}
-		re := RegressExpr(e, PS.prob)
-		//fmt.Printf("reg: %v\n", re)
-		PS.eval_out <- re
+		PS.eval_out <- RegressExpr(e, PS.prob)
 	}
 
@@ -293,5 +284,5 @@
 	fmt.Printf("Running PGE\n")
 
-	PS.Loop()
+	PS.loop()
 
 	fmt.Println("PGE exitting")
@@ -301,5 +292,5 @@
 }
 
-func (PS *PgeSearch) Loop() {
+func (PS *PgeSearch) loop() {
 
 	PS.checkMessages()
@@ -307,5 +298,5 @@
 
 		fmt.Println("in: PS.step() ", PS.iter)
-		PS.Step()
+		PS.step()
 
 		// if PS.iter%PS.cnfg.pgeRptEpoch == 0 {
@@ -357,5 +348,6 @@
 }
 
-func (PS *PgeSearch) Step() {
+func (PS *PgeSearch) step() {
+
 	loop := 0
 	eval_cnt := 0 // for channeled eval
@@ -437,4 +429,5 @@
 	// } // for sequential eval
 	PS.Queue.Sort()
+
 }
 
@@ -442,5 +435,7 @@
 	es := make([]*probs.ExprReport, PS.cnfg.peelCnt)
 	for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ {
+
 		e := PS.Queue.Pop().(*probs.ExprReport)
+
 		bPush := true
 		if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {
@@ -451,5 +446,5 @@
 
 		if bPush {
-			fmt.Printf("pop/push DO(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
+			fmt.Printf("pop/push(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
 			PS.Best.Push(e)
 		}
@@ -471,145 +466,4 @@
 	return es
 }
-
-
-type PeelResult struct {
-	Es *probs.ExprReport
-
-	Nobestpush bool
-	BestNewMinErr bool
-	
-	Bestlen1 int
-	Bestlen2 int
-	
-	Coeff []float64
-	TestScore int
-	
-	Expre expr.Expr
-	ExpreRe *probs.ExprReport
-}
-
-
-func (PS *PgeSearch) SingleStep() []*PeelResult {
-	loop := 0
-	eval_cnt := 0
-	PR := PS.peelRes()
-	
-	es := make([]*probs.ExprReport, len(PR))
-	
-	for i, elem := range PR {
-		es[i] = elem.ExpreRe
-	}
-	
-	ex := PS.expandPeeled(es)
-
-	for cnt := range ex {
-		E := ex[cnt]
-		if E == nil {
-			continue
-		}
-		for _, e := range E {
-			if e == nil {
-				continue
-			}
-			if !PS.cnfg.treecfg.CheckExpr(e) {
-				continue
-			}
-			serial := make([]int, 0, 64)
-			serial = e.Serial(serial)
-			ins := PS.Trie.InsertSerial(serial)
-			
-			if !ins {
-				continue
-			}
-			PS.eval_in <- e
-			eval_cnt++
-		}
-	}
-	for i := 0; i < eval_cnt; i++ {
-		re := <-PS.eval_out
-		if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) {
-			continue
-		}
-		if re.TestError() < PS.minError {
-			PS.minError = re.TestError()
-		}
-		doIns := true
-		for _, c := range re.Coeff() {
-			if math.Abs(c) < PS.cnfg.zeroEpsilon {
-				doIns = false
-				break
-			}
-		}
-		if doIns {
-			re.SetProcID(PS.id)
-			re.SetIterID(PS.iter)
-			re.SetUnitID(loop)
-			re.SetUniqID(PS.neqns)
-			loop++
-			PS.neqns++
-			PS.Queue.Push(re)
-		}
-	}
-	PS.Queue.Sort()
-
-	PS.reportExpr()	
-	PS.iter++
-	
-	return PR
-}
-
-func (PS *PgeSearch) peelRes() []*PeelResult {
-	//es := make([]*probs.ExprReport, PS.cnfg.peelCnt)
-	PRes := make([]*PeelResult, PS.cnfg.peelCnt)
-	
-	for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ {
-		PR := new(PeelResult)
-		
-		PR.BestNewMinErr = false
-		PR.Nobestpush = false
-		
-		e := PS.Queue.Pop().(*probs.ExprReport)
-		
-		bPush := true
-		if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {
-			//fmt.Println("No Best Push")
-			PR.Nobestpush = true
-			p--
-			continue
-		}
-
-		if bPush {
-			//fmt.Printf("pop/push (%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
-			PR.Bestlen1 = p
-			PR.Bestlen2 = PS.Best.Len()
-			PR.Expre = e.Expr()
-			PR.ExpreRe = e
-			PS.Best.Push(e)
-		}
-
-		//es[p] = e
-		PR.Es = e
-		PR.Coeff = e.Coeff()
-		PR.TestScore = e.TestScore()
-		
-		
-		if e.TestScore() > PS.maxScore {
-			PS.maxScore = e.TestScore()
-		}
-		if e.TestError() < PS.minError {
-			PS.minError = e.TestError()
-			PR.BestNewMinErr = true
-			//fmt.Printf("Best New Min Error:  %v\n", e)
-		}
-		if e.Size() > PS.maxSize {
-			PS.maxSize = e.Size()
-		}
-		
-		PRes[p] = PR
-	}
-	
-	return PRes
-}
-
 
 func (PS *PgeSearch) expandPeeled(es []*probs.ExprReport) [][]expr.Expr {
@@ -633,4 +487,5 @@
 		// fmt.Println()
 	}
+	fmt.Println("\n")
 	return eqns
 }
@@ -668,4 +523,6 @@
 
 func (PS *PgeSearch) Clean() {
+	// fmt.Printf("Cleaning PGE\n")
+
 	PS.errLogBuf.Flush()
 	PS.mainLogBuf.Flush()
@@ -673,4 +530,5 @@
 	PS.fitnessLogBuf.Flush()
 	PS.ipreLogBuf.Flush()
+
 }
 
@@ -747,14 +605,8 @@
 	if len(guess) > 0 {
 
-		//fmt.Printf("IMREGEXP %v %v\n", P.SearchType, P.SearchVar)
-		//fmt.Printf("REGPTrain %T | %#v | %v\n", P.Train, P.Train, P.Train)
-		//fmt.Printf("eqn %T | %#v | %v\n", eqn, eqn, eqn)
-		//fmt.Printf("guess %T | %#v | %v\n", guess, guess, guess)
+		// fmt.Printf("x_dims:  %d  %d\n", x_dim, x_dim2)
 
 		// Callback version
-		
-		
 		coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test)
-		
 
 		// Stack version
@@ -789,5 +641,4 @@
 	R = new(probs.ExprReport)
 	R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/
-
 	R.SetCoeff(coeff)
 	R.Expr().CalcExprStats()
@@ -856,35 +707,2 @@
 	return
 }
-
-func (PS *PgeSearch) CreateDS(maxGen int, pgeRptEpoch int, pgeRptCount int, pgeArchiveCap int, peelCnt int, evalrCount int, zeroEpsilon float64, initMethod string, growMethod string, sortType int) {
-	PS.id = 0 //maxGen
-	
-	var PC PgeConfig
-	
-	PC.pgeRptEpoch = pgeRptEpoch
-	PC.pgeRptCount = pgeRptCount
-	PC.pgeArchiveCap = pgeArchiveCap
-	PC.peelCnt = peelCnt
-	PC.evalrCount = evalrCount
-	PC.zeroEpsilon = zeroEpsilon
-	PC.initMethod = initMethod
-	PC.growMethod = growMethod
-
-	if sortType == 1 {
-		PC.sortType = probs.PESORT_PARETO_TRN_ERR
-	} else {	
-		PC.sortType = probs.PESORT_PARETO_TST_ERR
-	}
-
-	PC.maxGen = maxGen
-	PS.cnfg = PC
-		
-	PS.iter = 0
-}
-
-func (PS *PgeSearch) SetProb(ep *probs.ExprProblem) {
-	PS.prob = ep
-}
-func (PS *PgeSearch) GetIter() int {
-	return PS.iter
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/benchmarks.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/benchmarks.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/benchmarks.go	(revision 16231)
@@ -3,5 +3,5 @@
 import (
 	// "fmt"
-	expr "github.com/verdverm/go-symexpr"
+	expr "github.com_del/verdverm/go-symexpr"
 	"math"
 	"math/rand"
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/data.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/data.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/data.go	(revision 16231)
@@ -8,6 +8,4 @@
 	"math/rand"
 	"os"
-	"C"
-	"unsafe"
 )
 
@@ -128,57 +126,4 @@
 }
 
-func (trainData *PointSet) InitTrainDataF(indepNames []string, depndNames []string, matrix unsafe.Pointer, nEntries int) {
-	trainData.ReadPointSet("C:/Users/Hansi/Desktop/Data.trn")
-}
-
-func (trainData *PointSet) InitTestDataF(indepNames []string, depndNames []string, matrix unsafe.Pointer, nEntries int) {
-	trainData.ReadPointSet("C:/Users/Hansi/Desktop/Data.tst")
-}
-
-func (trainData *PointSet) InitTrainData(indepNames []string, depndNames []string, matrix unsafe.Pointer, nEntries int) {
-	trainData.indepNames = indepNames  //First line in .trn file
-	trainData.numDim = len(trainData.indepNames)
-	trainData.depndNames = depndNames //Second line in .trn file
-	
-	fmt.Printf("Var Names = %v | %v\n", trainData.depndNames, trainData.indepNames)
-	var nClum int = len(indepNames) + len(depndNames)
-
-	for i := 0; i < nEntries; i++ {
-		var pnt Point 
-		for j := 0; j < len(trainData.indepNames); j++ {
-			elemNr := i * nClum + j
-			item := (*float64) (unsafe.Pointer( uintptr(unsafe.Pointer(matrix)) + unsafe.Sizeof(float64(0)) * uintptr(elemNr) ))
-			pnt.indep = append(pnt.indep, *item)
-			
-			if os.Getenv("PGEDEBUG") == "1" {
-				fmt.Printf("Adding independend Test/Train Data (%v,%v): %v\n", i, j, *item)
-			}
-		}
-
-		for j := len(trainData.indepNames); j < (len(trainData.indepNames) + len(trainData.depndNames)); j++ {
-			elemNr := i * nClum + j
-			item := (*float64) (unsafe.Pointer( uintptr(unsafe.Pointer(matrix)) + unsafe.Sizeof(float64(0)) * uintptr(elemNr) ))
-			pnt.depnd = append(pnt.depnd, *item )
-			
-			if os.Getenv("PGEDEBUG") == "1" {
-				fmt.Printf("Adding dependend (right side) Test/Train Data (%v, %v): %v\n", i, j, *item)
-			}
-		}
-
-		if len(pnt.indep) > 0 {
-			trainData.dataPoints = append(trainData.dataPoints, pnt)
-		}
-	}
-	fmt.Printf("Num Points: %v\n", len(trainData.dataPoints))
-	
-	//if os.Getenv("PGEDEBUG") == "2" {
-	//	DebugPrint(trainData)
-	//}
-}
-
-//func (trainData *PointSet) DebugPrint() {
-//	for index, elem in range 
-//}
-
 func (d *PointSet) ReadPointSet(filename string) {
 	ftotal, err := os.OpenFile(filename, os.O_RDONLY, 0)
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/problem.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/problem.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/problem.go	(revision 16231)
@@ -7,5 +7,5 @@
 	"strings"
 
-	expr "github.com/verdverm/go-symexpr"
+	expr "github.com_del/verdverm/go-symexpr"
 )
 
@@ -166,15 +166,2 @@
 	return list[0:i]
 }
-
-
-func (ep *ExprProblem) CreatePS(Name string, MaxIter int, HitRatio float64, SearchVar int, ProblemTypeString string) {	//IndepNames []string, DepndNames []string, SysNames []string
-	ep.SearchType = ProblemTypeFromString(ProblemTypeString)
-	ep.Name = Name
-	
-	ep.TrainFns = append(ep.TrainFns, "dummy")
-	ep.TestFns = append(ep.TestFns, "dummy")
-		
-	ep.MaxIter = MaxIter
-	ep.HitRatio = HitRatio
-	ep.SearchVar = SearchVar
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/report.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/report.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/report.go	(revision 16231)
@@ -4,5 +4,5 @@
 	"container/list"
 	"fmt"
-	expr "github.com/verdverm/go-symexpr"
+	expr "github.com_del/verdverm/go-symexpr"
 	"sort"
 )
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/treeparams.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/treeparams.go	(revision 16230)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/treeparams.go	(revision 16231)
@@ -8,5 +8,5 @@
 	"strings"
 
-	expr "github.com/verdverm/go-symexpr"
+	expr "github.com_del/verdverm/go-symexpr"
 )
 
@@ -297,24 +297,2 @@
 	tp.TmpMinSize, tp.TmpMinDepth = tp.MinSize, tp.MinDepth
 }
-
-
-func (TP *TreeParams) CreateTreeParams(Roots string, Nodes string, NonTrig string, Leafs string, UsableVars []int, MaxSize int, MinSize int, MaxDepth int, MinDepth int) {
-	TP.RootsS = strings.Fields(Roots)
-	TP.RootsT, TP.Roots = fillExprStuff(TP.RootsS)
-	
-	TP.NodesS = strings.Fields(Nodes)
-	TP.NodesT, TP.Nodes = fillExprStuff(TP.NodesS)
-	
-	TP.NonTrigS = strings.Fields(NonTrig)
-	TP.NonTrigT, TP.NonTrig = fillExprStuff(TP.NonTrigS)
-	
-	TP.LeafsS = strings.Fields(Leafs)
-	TP.LeafsT, TP.Leafs = fillExprStuff(TP.LeafsS)
-
-	TP.UsableVars = UsableVars
-
-	TP.MaxSize = MaxSize
-	TP.MinSize = MinSize
-	TP.MaxDepth = MaxDepth
-	TP.MinDepth = MinDepth
-}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/bbsr.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/bbsr.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/bbsr.go	(revision 16231)
@@ -0,0 +1,94 @@
+package pge
+
+import (
+	"fmt"
+	// "sort"
+
+	probs "github.com/verdverm/go-pge/problems"
+	expr "github.com/verdverm/go-symexpr"
+)
+
+func (PS *PgeSearch) GenInitExpr() *probs.ReportQueue {
+	switch PS.cnfg.initMethod {
+	case "method1":
+		return PS.GenInitExprMethod1()
+	case "method2":
+		return PS.GenInitExprMethod2()
+	case "method3":
+		return PS.GenInitExprMethod3()
+	default:
+		fmt.Println("Unknown init method")
+	}
+	return nil
+}
+
+func (PS *PgeSearch) Expand(O expr.Expr) (ret []expr.Expr) {
+	var exprs []expr.Expr
+
+	switch PS.cnfg.growMethod {
+	case "method1":
+		exprs = PS.ExpandMethod1(O)
+	case "method2":
+		exprs = PS.ExpandMethod2(O)
+	case "method3":
+		exprs = PS.ExpandMethod3(O)
+	default:
+		fmt.Println("Unknown expand method")
+	}
+
+	// convert and simplify
+	for i, e := range exprs {
+		if e == nil {
+			continue
+		}
+		defer func() {
+			if r := recover(); r != nil {
+				fmt.Printf("Recovered in Expand %v   %d %v", r, i, e)
+				exprs[i] = nil
+			}
+		}()
+		c := make([]float64, 0)
+		// fmt.Printf("Preconv   %v\n", e)
+		c, eqn := e.ConvertToConstants(c)
+		e.CalcExprStats()
+		// fmt.Printf("Postconv  %v\n", eqn)
+
+		// fmt.Printf("Presimp  %v\n", eqn)
+		exprs[i] = eqn.Simplify(PS.cnfg.simprules)
+		// fmt.Printf("Postsimp  %v\n\n", exprs[i])
+		// serial := make([]int, 0, 64)
+		// serial = exprs[i].Serial(serial)
+		// fmt.Printf("Postsimp  %v   %v\n\n", exprs[i], serial)
+	}
+
+	// sort.Sort(expr.ExprArray(exprs))
+
+	// remove duplicates
+
+	// last := 0
+	// for last < len(exprs) && exprs[last] == nil {
+	// 	last++
+	// }
+	// for i := last + 1; i < len(exprs); i++ {
+	// 	if exprs[i] == nil {
+	// 		continue
+	// 	}
+	// 	if exprs[i].AmIAlmostSame(exprs[last]) {
+	// 		exprs[i] = nil
+	// 	} else {
+	// 		last = i
+	// 	}
+	// }
+
+	// copy to ret, ignoring nil & bad expressions ...
+	for _, e := range exprs {
+		if e == nil {
+			continue
+		}
+		// if !PS.cnfg.treecfg.CheckExpr(e) {
+		// 	continue
+		// }
+		ret = append(ret, e)
+	}
+	return ret
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/ipre_trie.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/ipre_trie.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/ipre_trie.go	(revision 16231)
@@ -0,0 +1,42 @@
+package pge
+
+type IpreNode struct {
+	val int
+	cnt int
+	vst int
+
+	next map[int]*IpreNode
+}
+
+func (n *IpreNode) InsertSerial(s []int) (did_ins bool) {
+	in, _ := n.next[s[0]]
+
+	// does this branch exist?
+	if in == nil {
+		in = new(IpreNode)
+		in.val = s[0]
+		in.next = make(map[int]*IpreNode)
+		n.next[s[0]] = in
+		did_ins = true
+	}
+
+	// recursive call to insert
+	if len(s) > 1 {
+		did_ins = in.InsertSerial(s[1:]) || did_ins
+	}
+
+	// visitation accounting  
+	// (-1 is the root of the memoization tree)
+	in.vst++
+	if n.val == -1 {
+		n.vst++
+	}
+	if did_ins {
+		in.cnt++
+		if n.val == -1 {
+			n.cnt++
+		}
+	}
+
+	return did_ins
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_1.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_1.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_1.go	(revision 16231)
@@ -0,0 +1,247 @@
+package pge
+
+import (
+	// "fmt"
+	"sort"
+
+	expr "github.com/verdverm/go-symexpr"
+)
+
+func (PS *PgeSearch) ExpandMethod1(O expr.Expr) (ret []expr.Expr) {
+	O.Sort()
+	ret = make([]expr.Expr, 0)
+	// fmt.Printf("Expanding expression:  %v\n", O)
+
+	for i := 0; i < O.Size(); i++ {
+		I := i
+		E := O.GetExpr(&I)
+		switch E.ExprType() {
+		case expr.ADD:
+			tmp := PS.AddTermToExprMethod1(O, E, i)
+			ret = append(ret, tmp[:]...)
+
+		case expr.MUL:
+			tmp := PS.WidenTermInExprMethod1(O, E, i)
+			ret = append(ret, tmp[:]...)
+
+		case expr.VAR:
+			tmp := PS.DeepenTermInExprMethod1(O, E, i)
+			ret = append(ret, tmp[:]...)
+
+		default: // expr.DIV,expr.COS,expr.SIN,expr.EXP,expr.LOG,expr.ABS,expr.POW
+			continue
+
+		}
+	}
+
+	return ret
+}
+
+// add another term to an add expr
+func (PS *PgeSearch) AddTermToExprMethod1(O, E expr.Expr, pos int) (ret []expr.Expr) {
+	ret = make([]expr.Expr, 0)
+	A := E.(*expr.Add)
+
+	// f() + cL
+	for _, L := range PS.GenLeafs {
+		c := new(expr.Constant)
+		c.P = -1
+		l := L.Clone()
+
+		// mul it
+		M := expr.NewMul()
+		M.Insert(c)
+		M.Insert(l)
+
+		// skip if the same term already exists in the add
+		skip := false
+		for _, e := range A.CS {
+			if e == nil {
+				continue
+			}
+			// fmt.Printf("ACMP  %v  %v\n", M, e)
+			if e.AmIAlmostSame(M) || M.AmIAlmostSame(e) {
+				skip = true
+				break
+			}
+		}
+		if skip {
+			continue
+		}
+
+		C := O.Clone()
+		P := pos
+		AM := C.GetExpr(&P).(*expr.Add)
+		AM.Insert(M)
+		sort.Sort(AM)
+		C.CalcExprStats()
+		good := PS.cnfg.treecfg.CheckExpr(C)
+		if good {
+			ret = append(ret, C)
+		}
+	}
+
+	// f() + c*node(L)
+	for _, N := range PS.GenNodes {
+		for _, L := range PS.GenLeafs {
+
+			c := new(expr.Constant)
+			c.P = -1
+
+			l := L.Clone()
+			n := N.Clone()
+			p := 1
+			n.SetExpr(&p, l)
+
+			var E expr.Expr
+			if N.ExprType() == expr.DIV {
+				E = expr.NewDiv(c, l)
+			} else {
+				// mul it
+				M := expr.NewMul()
+				M.Insert(c)
+				M.Insert(n)
+				E = M
+			}
+
+			// skip if the same term already exists in the add
+			skip := false
+			for _, e := range A.CS {
+				if e == nil {
+					continue
+				}
+				// fmt.Printf("ACMP  %v  %v\n", M, e)
+				if e.AmIAlmostSame(E) || E.AmIAlmostSame(e) {
+					skip = true
+					break
+				}
+			}
+			if skip {
+				continue
+			}
+
+			// fmt.Println(E.String())
+
+			C := O.Clone()
+			P := pos
+			AM := C.GetExpr(&P).(*expr.Add)
+			AM.Insert(E)
+			sort.Sort(AM)
+			C.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(C)
+			if good {
+				ret = append(ret, C)
+			}
+		}
+	}
+
+	return ret
+}
+
+// add complexity to a single multiplication term
+func (PS *PgeSearch) WidenTermInExprMethod1(O, E expr.Expr, pos int) (ret []expr.Expr) {
+	ret = make([]expr.Expr, 0)
+
+	// insert leafs  f()*L
+	for _, L := range PS.GenLeafs {
+		l := L.Clone()
+		C := O.Clone()
+		P := pos
+		e := C.GetExpr(&P)
+		// fmt.Printf("pos(%d): %v\n", pos, e)
+		M := e.(*expr.Mul)
+		M.Insert(l)
+		sort.Sort(M)
+		C.CalcExprStats()
+		good := PS.cnfg.treecfg.CheckExpr(C)
+		if good {
+			ret = append(ret, C)
+		}
+	}
+
+	// insert node(L)  :  f() * c*node(L)
+	for _, N := range PS.GenNodes {
+		for _, L := range PS.GenLeafs {
+			c := new(expr.Constant)
+			c.P = -1
+
+			l := L.Clone()
+			n := N.Clone()
+			p := 1
+			n.SetExpr(&p, l)
+
+			var E expr.Expr
+			if N.ExprType() == expr.DIV {
+				E = expr.NewDiv(c, l)
+			} else {
+				// mul it
+				M := expr.NewMul()
+				M.Insert(c)
+				M.Insert(n)
+				E = M
+			}
+
+			C := O.Clone()
+			P := pos
+			e := C.GetExpr(&P)
+			// fmt.Printf("pos(%d): %v\n", pos, e)
+			M := e.(*expr.Mul)
+
+			M.Insert(E)
+			sort.Sort(M)
+			C.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(C)
+			if good {
+				ret = append(ret, C)
+			}
+		}
+	}
+	return ret
+}
+
+// change any term to something more complex...
+func (PS *PgeSearch) DeepenTermInExprMethod1(O, E expr.Expr, pos int) []expr.Expr {
+	exprs := make([]expr.Expr, 0)
+
+	// make into add
+	A := expr.NewAdd()
+	A.Insert(E.Clone())
+	OA := A.Clone()
+	exprs = append(exprs, PS.AddTermToExprMethod1(OA, A, 0)[:]...)
+
+	// make into mul
+	M := expr.NewMul()
+	M.Insert(E.Clone())
+	OM := M.Clone()
+	exprs = append(exprs, PS.WidenTermInExprMethod1(OM, M, 0)[:]...)
+
+	// // make into div
+	// if E.ExprType() != expr.DIV {
+	// 	D := new(expr.Div)
+	// 	c := new(expr.Constant)
+	// 	c.P = -1
+	// 	D.Numer = c
+	// 	D.Denom = E.Clone()
+	// 	exprs = append(exprs, D)
+	// }
+
+	// make inside of nodes
+	for _, N := range PS.GenNodes {
+		if N.ExprType() == expr.DIV {
+			continue
+		}
+		T := N.Clone()
+		P := 1
+		T.SetExpr(&P, E.Clone())
+		exprs = append(exprs, T)
+	}
+
+	ret := make([]expr.Expr, 0)
+	for _, e := range exprs {
+		C := O.Clone()
+		P := pos
+		C.SetExpr(&P, e)
+		ret = append(ret, C)
+	}
+	return ret
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_2.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_2.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_2.go	(revision 16231)
@@ -0,0 +1,203 @@
+package pge
+
+import (
+	// "fmt"
+	"sort"
+
+	expr "github.com/verdverm/go-symexpr"
+)
+
+func (PS *PgeSearch) ExpandMethod2(O expr.Expr) (ret []expr.Expr) {
+	O.Sort()
+	ret = make([]expr.Expr, 0)
+	// fmt.Printf("Expanding expression:  %v\n", O)
+
+	add := O.(*expr.Add)
+
+	// adding term to addition
+	for _, B := range PS.ffxBases {
+		found := false
+		for _, C := range add.CS {
+			// fmt.Printf("checking %v in %v\n", B, add)
+			if C.AmISame(B) {
+				// fmt.Println("found\n\n")
+				found = true
+				break
+			}
+		}
+		if !found {
+			e := O.Clone()
+			a := e.(*expr.Add)
+			a.Insert(B.Clone())
+			sort.Sort(a)
+			a.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(a)
+			if good {
+				ret = append(ret, a)
+			}
+			// fmt.Printf("grew  %v\n\n", a)
+			// ret = append(ret, a)
+		}
+	}
+
+	// extending terms in addition
+	for _, B := range PS.ffxBases {
+		for i, C := range add.CS {
+			if C.ExprType() == expr.MUL {
+				m := C.(*expr.Mul)
+				if len(m.CS) > 3 {
+					continue
+				}
+			}
+			e := O.Clone()
+			a := e.(*expr.Add)
+			mul := expr.NewMul()
+			mul.Insert(a.CS[i])
+			mul.Insert(B.Clone())
+			a.CS[i] = mul
+			sort.Sort(a)
+			a.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(a)
+			if good {
+				ret = append(ret, a)
+			}
+			// fmt.Printf("grew  %v\n\n", a)
+			ret = append(ret, a)
+		}
+	}
+
+	// deepening terms 
+	// if len(add.CS) < 2 {
+	// 	return ret
+	// }
+	for i, C := range add.CS {
+		if C.ExprType() == expr.MUL {
+			m := C.(*expr.Mul)
+			if len(m.CS) != 2 {
+				continue
+			}
+			if m.CS[1].ExprType() == expr.ADD {
+				continue
+			}
+		} else {
+			continue
+		}
+
+		for _, B := range PS.ffxBases {
+			e := O.Clone()
+			a := e.(*expr.Add)
+			m := a.CS[i].(*expr.Mul)
+			n := m.CS[1]
+
+			switch n.ExprType() {
+			case expr.SQRT:
+				A := expr.NewAdd()
+				A.Insert(n.(*expr.Sqrt).C)
+				A.Insert(B.Clone())
+				n.(*expr.Sqrt).C = A
+			case expr.SIN:
+				A := expr.NewAdd()
+				A.Insert(n.(*expr.Sin).C)
+				A.Insert(B.Clone())
+				n.(*expr.Sin).C = A
+			case expr.COS:
+				A := expr.NewAdd()
+				A.Insert(n.(*expr.Cos).C)
+				A.Insert(B.Clone())
+				n.(*expr.Cos).C = A
+			case expr.TAN:
+				A := expr.NewAdd()
+				A.Insert(n.(*expr.Tan).C)
+				A.Insert(B.Clone())
+				n.(*expr.Tan).C = A
+			case expr.EXP:
+				A := expr.NewAdd()
+				A.Insert(n.(*expr.Exp).C)
+				A.Insert(B.Clone())
+				n.(*expr.Exp).C = A
+			case expr.LOG:
+				A := expr.NewAdd()
+				A.Insert(n.(*expr.Log).C)
+				A.Insert(B.Clone())
+				n.(*expr.Log).C = A
+
+			default:
+				A := expr.NewAdd()
+				A.Insert(m.CS[1])
+				A.Insert(B.Clone())
+				m.CS[1] = A
+			}
+			sort.Sort(a)
+			a.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(a)
+			if good {
+				ret = append(ret, a)
+			}
+			// fmt.Printf("grew  %v\n", a)
+			ret = append(ret, a)
+		}
+	}
+	for i, C := range add.CS {
+		if C.ExprType() == expr.MUL {
+			m := C.(*expr.Mul)
+			if len(m.CS) != 2 {
+				continue
+			}
+			if m.CS[1].ExprType() == expr.ADD {
+				continue
+			}
+		} else {
+			continue
+		}
+
+		for _, B := range PS.ffxBases {
+			e := O.Clone()
+			a := e.(*expr.Add)
+			m := a.CS[i].(*expr.Mul)
+			n := m.CS[1]
+
+			switch n.ExprType() {
+			case expr.SQRT:
+				M := expr.NewMul()
+				M.Insert(n.(*expr.Sqrt).C)
+				M.Insert(B.Clone())
+				n.(*expr.Sqrt).C = M
+			case expr.SIN:
+				M := expr.NewMul()
+				M.Insert(n.(*expr.Sin).C)
+				M.Insert(B.Clone())
+				n.(*expr.Sin).C = M
+			case expr.COS:
+				M := expr.NewMul()
+				M.Insert(n.(*expr.Cos).C)
+				M.Insert(B.Clone())
+				n.(*expr.Cos).C = M
+			case expr.TAN:
+				M := expr.NewMul()
+				M.Insert(n.(*expr.Tan).C)
+				M.Insert(B.Clone())
+				n.(*expr.Tan).C = M
+			case expr.EXP:
+				M := expr.NewMul()
+				M.Insert(n.(*expr.Exp).C)
+				M.Insert(B.Clone())
+				n.(*expr.Exp).C = M
+			case expr.LOG:
+				M := expr.NewMul()
+				M.Insert(n.(*expr.Log).C)
+				M.Insert(B.Clone())
+				n.(*expr.Log).C = M
+			}
+			sort.Sort(a)
+			a.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(a)
+			if good {
+				ret = append(ret, a)
+			}
+			// fmt.Printf("grew  %v\n", a)
+			ret = append(ret, a)
+		}
+	}
+	// fmt.Println("Len of ret = ", len(ret))
+	return ret
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_3.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_3.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_expand_method_3.go	(revision 16231)
@@ -0,0 +1,71 @@
+package pge
+
+import (
+	// "fmt"
+	"sort"
+
+	expr "github.com/verdverm/go-symexpr"
+)
+
+func (PS *PgeSearch) ExpandMethod3(O expr.Expr) (ret []expr.Expr) {
+	O.Sort()
+	ret = make([]expr.Expr, 0)
+	// fmt.Printf("Expanding expression:  %v\n", O)
+
+	add := O.(*expr.Add)
+
+	// adding term to addition
+	for _, B := range PS.ffxBases {
+		found := false
+		for _, C := range add.CS {
+			// fmt.Printf("checking %v in %v\n", B, add)
+			if C.AmISame(B) {
+				// fmt.Println("found\n\n")
+				found = true
+				break
+			}
+		}
+		if !found {
+			e := O.Clone()
+			a := e.(*expr.Add)
+			a.Insert(B.Clone())
+			sort.Sort(a)
+			a.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(a)
+			if good {
+				ret = append(ret, a)
+			}
+			// fmt.Printf("grew  %v\n\n", a)
+			// ret = append(ret, a)
+		}
+	}
+
+	// extending terms in addition
+	for _, B := range PS.ffxBases {
+		for i, C := range add.CS {
+			if C.ExprType() == expr.MUL {
+				m := C.(*expr.Mul)
+				if len(m.CS) > 3 {
+					continue
+				}
+			}
+			e := O.Clone()
+			a := e.(*expr.Add)
+			mul := expr.NewMul()
+			mul.Insert(a.CS[i])
+			mul.Insert(B.Clone())
+			a.CS[i] = mul
+			sort.Sort(a)
+			a.CalcExprStats()
+			good := PS.cnfg.treecfg.CheckExpr(a)
+			if good {
+				ret = append(ret, a)
+			}
+			// fmt.Printf("grew  %v\n\n", a)
+			ret = append(ret, a)
+		}
+	}
+
+	// fmt.Println("Len of ret = ", len(ret))
+	return ret
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_1.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_1.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_1.go	(revision 16231)
@@ -0,0 +1,117 @@
+package pge
+
+import (
+	"fmt"
+
+	probs "github.com/verdverm/go-pge/problems"
+	expr "github.com/verdverm/go-symexpr"
+)
+
+func (PS *PgeSearch) GenInitExprMethod1() *probs.ReportQueue {
+	fmt.Printf("generating initial expressions\n")
+
+	GP := PS.cnfg.treecfg
+	fmt.Printf("%v\n", GP)
+
+	eList := make([]expr.Expr, 0)
+
+	for _, T := range GP.Roots {
+		switch T.ExprType() {
+		case expr.ADD:
+			eList = append(eList, PS.GenInitExprAddMethod1()[:]...)
+		case expr.MUL:
+			eList = append(eList, PS.GenInitExprMulMethod1()[:]...)
+		case expr.DIV:
+			eList = append(eList, PS.GenInitExprDivMethod1()[:]...)
+		default:
+			fmt.Printf("Error in GenInitExpr: unknown ROOT %d\n", T)
+		}
+	}
+
+	exprs := probs.NewReportQueue()
+	// exprs.SetSort(PS.cnfg.sortType)
+	exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
+
+	for i, e := range eList {
+		fmt.Printf("%d:  %v\n", i, e)
+		serial := make([]int, 0, 64)
+		serial = e.Serial(serial)
+		PS.Trie.InsertSerial(serial)
+		// on train data
+		re := RegressExpr(e, PS.prob)
+		re.SetUnitID(i)
+		exprs.Push(re)
+	}
+	exprs.Sort()
+	return exprs
+}
+
+func (PS *PgeSearch) GenInitExprAddMethod1() []expr.Expr {
+
+	exprs := make([]expr.Expr, 0)
+
+	// WARNING adding a single coefficient results in the same traversal but with the added extra coefficient
+	cf := new(expr.Constant)
+	cf.P = 1
+	af := new(expr.Add)
+	af.Insert(cf)
+	exprs = append(exprs, af)
+
+	for _, i := range PS.cnfg.treecfg.UsableVars {
+		c := new(expr.Constant)
+		c.P = -1
+		v := new(expr.Var)
+		v.P = i
+
+		m := expr.NewMul()
+		m.Insert(c)
+		m.Insert(v)
+
+		a := expr.NewAdd()
+		a.Insert(m)
+		exprs = append(exprs, a)
+	}
+
+	fmt.Println("Initial Add:  ", exprs)
+	return exprs
+}
+
+func (PS *PgeSearch) GenInitExprMulMethod1() []expr.Expr {
+	exprs := make([]expr.Expr, 0)
+
+	for _, i := range PS.cnfg.treecfg.UsableVars {
+		c := new(expr.Constant)
+		c.P = -1
+		v := new(expr.Var)
+		v.P = i
+
+		m := expr.NewMul()
+		m.Insert(c)
+		m.Insert(v)
+
+		exprs = append(exprs, m)
+	}
+
+	fmt.Println("Initial Mul:  ", exprs)
+	return exprs
+}
+
+func (PS *PgeSearch) GenInitExprDivMethod1() []expr.Expr {
+	exprs := make([]expr.Expr, 0)
+
+	for _, i := range PS.cnfg.treecfg.UsableVars {
+		c := new(expr.Constant)
+		c.P = -1
+		v := new(expr.Var)
+		v.P = i
+
+		d := new(expr.Div)
+		d.Numer = c
+		d.Denom = v
+
+		exprs = append(exprs, d)
+	}
+
+	fmt.Println("Initial Div:  ", exprs)
+	return exprs
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_2.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_2.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_2.go	(revision 16231)
@@ -0,0 +1,92 @@
+package pge
+
+import (
+	"fmt"
+
+	probs "github.com/verdverm/go-pge/problems"
+	expr "github.com/verdverm/go-symexpr"
+)
+
+// This is the FFXish style init function
+func (PS *PgeSearch) GenInitExprMethod2() *probs.ReportQueue {
+	fmt.Printf("generating initial expressions\n")
+
+	GP := PS.cnfg.treecfg
+	fmt.Printf("%v\n", GP)
+
+	bases := make([]expr.Expr, 0)
+
+	// single constant
+	bases = append(bases, expr.NewConstant(-1))
+
+	// c*x_i
+	for _, v := range PS.prob.UsableVars {
+		mul := expr.NewMul()
+		mul.Insert(expr.NewConstant(-1))
+		mul.Insert(expr.NewVar(v))
+		bases = append(bases, mul)
+	}
+
+	// c*x_i^p & c*x_i^-p
+	for p := 2; p <= 4; p++ {
+		for _, v := range PS.prob.UsableVars {
+			// positive powers
+			mul := expr.NewMul()
+			mul.Insert(expr.NewConstant(-1))
+			mul.Insert(expr.NewPowI(expr.NewVar(v), p))
+			bases = append(bases, mul)
+
+			// negative powers
+			nul := expr.NewMul()
+			nul.Insert(expr.NewConstant(-1))
+			nul.Insert(expr.NewPowI(expr.NewVar(v), -p))
+			bases = append(bases, nul)
+		}
+	}
+
+	// c*N(d*x_i)
+	for _, N := range PS.GenNodes {
+		if N.ExprType() == expr.DIV || N.ExprType() == expr.ADD || N.ExprType() == expr.MUL {
+			continue
+		}
+		for _, v := range PS.prob.UsableVars {
+			// positive powers
+			mul := expr.NewMul()
+			mul.Insert(expr.NewConstant(-1))
+
+			nul := expr.NewMul()
+			nul.Insert(expr.NewConstant(-1))
+			nul.Insert(expr.NewVar(v))
+
+			n := N.Clone()
+			p := 1
+			n.SetExpr(&p, nul)
+			mul.Insert(n)
+			bases = append(bases, mul)
+		}
+	}
+
+	// copy bases for use later in expand
+	PS.ffxBases = make([]expr.Expr, len(bases))
+	for i, b := range bases {
+		PS.ffxBases[i] = b.Clone()
+	}
+
+	exprs := probs.NewReportQueue()
+	// exprs.SetSort(PS.cnfg.sortType)
+	exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
+
+	for i, e := range bases {
+		fmt.Printf("%d:  %v\n", i, e)
+		serial := make([]int, 0, 64)
+		serial = e.Serial(serial)
+		PS.Trie.InsertSerial(serial)
+		// on train data
+		re := RegressExpr(e, PS.prob)
+		re.SetUnitID(i)
+		exprs.Push(re)
+	}
+	exprs.Sort()
+
+	return exprs
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_3.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_3.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_3.go	(revision 16231)
@@ -0,0 +1,92 @@
+package pge
+
+import (
+	"fmt"
+
+	probs "github.com/verdverm/go-pge/problems"
+	expr "github.com/verdverm/go-symexpr"
+)
+
+// This is the FFXish style init function
+func (PS *PgeSearch) GenInitExprMethod3() *probs.ReportQueue {
+	fmt.Printf("generating initial expressions\n")
+
+	GP := PS.cnfg.treecfg
+	fmt.Printf("%v\n", GP)
+
+	bases := make([]expr.Expr, 0)
+
+	// single constant
+	bases = append(bases, expr.NewConstant(-1))
+
+	// c*x_i
+	for _, v := range PS.prob.UsableVars {
+		mul := expr.NewMul()
+		mul.Insert(expr.NewConstant(-1))
+		mul.Insert(expr.NewVar(v))
+		bases = append(bases, mul)
+	}
+
+	// c*x_i^p & c*x_i^-p
+	for p := 2; p <= 4; p++ {
+		for _, v := range PS.prob.UsableVars {
+			// positive powers
+			mul := expr.NewMul()
+			mul.Insert(expr.NewConstant(-1))
+			mul.Insert(expr.NewPowI(expr.NewVar(v), p))
+			bases = append(bases, mul)
+
+			// negative powers
+			nul := expr.NewMul()
+			nul.Insert(expr.NewConstant(-1))
+			nul.Insert(expr.NewPowI(expr.NewVar(v), -p))
+			bases = append(bases, nul)
+		}
+	}
+
+	// c*N(d*x_i)
+	for _, N := range PS.GenNodes {
+		if N.ExprType() == expr.DIV || N.ExprType() == expr.ADD || N.ExprType() == expr.MUL {
+			continue
+		}
+		for _, v := range PS.prob.UsableVars {
+			// positive powers
+			mul := expr.NewMul()
+			mul.Insert(expr.NewConstant(-1))
+
+			nul := expr.NewMul()
+			nul.Insert(expr.NewConstant(-1))
+			nul.Insert(expr.NewVar(v))
+
+			n := N.Clone()
+			p := 1
+			n.SetExpr(&p, nul)
+			mul.Insert(n)
+			bases = append(bases, mul)
+		}
+	}
+
+	// copy bases for use later in expand
+	PS.ffxBases = make([]expr.Expr, len(bases))
+	for i, b := range bases {
+		PS.ffxBases[i] = b.Clone()
+	}
+
+	exprs := probs.NewReportQueue()
+	// exprs.SetSort(PS.cnfg.sortType)
+	exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
+
+	for i, e := range bases {
+		fmt.Printf("%d:  %v\n", i, e)
+		serial := make([]int, 0, 64)
+		serial = e.Serial(serial)
+		PS.Trie.InsertSerial(serial)
+		// on train data
+		re := RegressExpr(e, PS.prob)
+		re.SetUnitID(i)
+		exprs.Push(re)
+	}
+	exprs.Sort()
+
+	return exprs
+}
Index: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_search.go
===================================================================
--- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_search.go	(revision 16231)
+++ branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_search.go	(revision 16231)
@@ -0,0 +1,708 @@
+package pge
+
+import (
+	"bufio"
+	"fmt"
+	"io/ioutil"
+	"log"
+	"math"
+	"os"
+	"strconv"
+	"strings"
+
+	levmar "github.com/verdverm/go-levmar"
+	config "github.com/verdverm/go-pge/config"
+	probs "github.com/verdverm/go-pge/problems"
+	expr "github.com/verdverm/go-symexpr"
+)
+
+type pgeConfig struct {
+	// search params
+	maxGen        int
+	pgeRptEpoch   int
+	pgeRptCount   int
+	pgeArchiveCap int
+
+	simprules expr.SimpRules
+	treecfg   *probs.TreeParams
+
+	// PGE specific options
+	peelCnt     int
+	sortType    probs.SortType
+	zeroEpsilon float64
+
+	initMethod string
+	growMethod string
+
+	evalrCount int
+}
+
+func pgeConfigParser(field, value string, config interface{}) (err error) {
+
+	PC := config.(*pgeConfig)
+
+	switch strings.ToUpper(field) {
+	case "MAXGEN":
+		PC.maxGen, err = strconv.Atoi(value)
+	case "PGERPTEPOCH":
+		PC.pgeRptEpoch, err = strconv.Atoi(value)
+	case "PGERPTCOUNT":
+		PC.pgeRptCount, err = strconv.Atoi(value)
+	case "PGEARCHIVECAP":
+		PC.pgeArchiveCap, err = strconv.Atoi(value)
+
+	case "PEELCOUNT":
+		PC.peelCnt, err = strconv.Atoi(value)
+
+	case "EVALRCOUNT":
+		PC.evalrCount, err = strconv.Atoi(value)
+
+	case "SORTTYPE":
+		switch strings.ToLower(value) {
+		case "paretotrainerror":
+			PC.sortType = probs.PESORT_PARETO_TRN_ERR
+		case "paretotesterror":
+			PC.sortType = probs.PESORT_PARETO_TST_ERR
+
+		default:
+			log.Printf("PGE Config Not Implemented: %s, %s\n\n", field, value)
+		}
+
+	case "ZEROEPSILON":
+		PC.zeroEpsilon, err = strconv.ParseFloat(value, 64)
+
+	default:
+		// check augillary parsable structures [only TreeParams for now]
+		if PC.treecfg == nil {
+			PC.treecfg = new(probs.TreeParams)
+		}
+		found, ferr := probs.ParseTreeParams(field, value, PC.treecfg)
+		if ferr != nil {
+			log.Fatalf("error parsing PGE - treecfg Config\n")
+			return ferr
+		}
+		if !found {
+			log.Printf("PGE Config Not Implemented: %s, %s\n\n", field, value)
+		}
+
+	}
+	return
+}
+
+type PgeSearch struct {
+	id   int
+	cnfg pgeConfig
+	prob *probs.ExprProblem
+	iter int
+	stop bool
+
+	// comm up
+	commup *probs.ExprProblemComm
+
+	// comm down
+
+	// best exprs
+	Best *probs.ReportQueue
+
+	// training data in C format
+	c_input  []levmar.C_double
+	c_ygiven []levmar.C_double
+
+	// logs
+	logDir     string
+	mainLog    *log.Logger
+	mainLogBuf *bufio.Writer
+	eqnsLog    *log.Logger
+	eqnsLogBuf *bufio.Writer
+	errLog     *log.Logger
+	errLogBuf  *bufio.Writer
+
+	fitnessLog    *log.Logger
+	fitnessLogBuf *bufio.Writer
+	ipreLog       *log.Logger
+	ipreLogBuf    *bufio.Writer
+
+	// equations visited
+	Trie  *IpreNode
+	Queue *probs.ReportQueue
+
+	// eval channels
+	eval_in  chan expr.Expr
+	eval_out chan *probs.ExprReport
+
+	// genStuff
+	GenRoots   []expr.Expr
+	GenLeafs   []expr.Expr
+	GenNodes   []expr.Expr
+	GenNonTrig []expr.Expr
+
+	// FFXish stuff
+	ffxBases []expr.Expr
+
+	// statistics
+	neqns    int
+	ipreCnt  int
+	maxSize  int
+	maxScore int
+	minError float64
+}
+
+func (PS *PgeSearch) GetMaxIter() int {
+	return PS.cnfg.maxGen
+}
+func (PS *PgeSearch) SetMaxIter(iter int) {
+	PS.cnfg.maxGen = iter
+}
+func (PS *PgeSearch) SetPeelCount(cnt int) {
+	PS.cnfg.peelCnt = cnt
+}
+func (PS *PgeSearch) SetInitMethod(init string) {
+	PS.cnfg.initMethod = init
+}
+func (PS *PgeSearch) SetGrowMethod(grow string) {
+	PS.cnfg.growMethod = grow
+}
+func (PS *PgeSearch) SetEvalrCount(cnt int) {
+	PS.cnfg.evalrCount = cnt
+}
+
+func (PS *PgeSearch) ParseConfig(filename string) {
+	fmt.Printf("Parsing PGE Config: %s\n", filename)
+	data, err := ioutil.ReadFile(filename)
+	if err != nil {
+		log.Fatal(err)
+	}
+	err = config.ParseConfig(data, pgeConfigParser, &PS.cnfg)
+	if err != nil {
+		log.Fatal(err)
+	}
+}
+
+func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) {
+	fmt.Printf("Init'n PGE\n")
+	// setup data
+
+	// open logs
+	PS.initLogs(logdir)
+
+	// copy in common config options
+	PS.prob = prob
+	if PS.cnfg.treecfg == nil {
+		PS.cnfg.treecfg = PS.prob.TreeCfg.Clone()
+	}
+	srules := expr.DefaultRules()
+	srules.ConvertConsts = true
+	PS.cnfg.simprules = srules
+
+	fmt.Println("Roots:   ", PS.cnfg.treecfg.RootsS)
+	fmt.Println("Nodes:   ", PS.cnfg.treecfg.NodesS)
+	fmt.Println("Leafs:   ", PS.cnfg.treecfg.LeafsS)
+	fmt.Println("NonTrig: ", PS.cnfg.treecfg.NonTrigS)
+
+	PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots))
+	for i := 0; i < len(PS.GenRoots); i++ {
+		PS.GenRoots[i] = PS.cnfg.treecfg.Roots[i].Clone()
+	}
+	PS.GenNodes = make([]expr.Expr, len(PS.cnfg.treecfg.Nodes))
+	for i := 0; i < len(PS.GenNodes); i++ {
+		PS.GenNodes[i] = PS.cnfg.treecfg.Nodes[i].Clone()
+	}
+	PS.GenNonTrig = make([]expr.Expr, len(PS.cnfg.treecfg.NonTrig))
+	for i := 0; i < len(PS.GenNonTrig); i++ {
+		PS.GenNonTrig[i] = PS.cnfg.treecfg.NonTrig[i].Clone()
+	}
+
+	PS.GenLeafs = make([]expr.Expr, 0)
+	for _, t := range PS.cnfg.treecfg.LeafsT {
+		switch t {
+		case expr.TIME:
+			PS.GenLeafs = append(PS.GenLeafs, expr.NewTime())
+
+		case expr.VAR:
+			fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)
+			for _, i := range PS.cnfg.treecfg.UsableVars {
+				PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i))
+			}
+
+		case expr.SYSTEM:
+			for i := 0; i < PS.prob.Train[0].NumSys(); i++ {
+				PS.GenLeafs = append(PS.GenLeafs, expr.NewSystem(i))
+			}
+
+		}
+	}
+	/*** FIX ME
+	PS.GenLeafs = make([]expr.Expr, len(PS.cnfg.treecfg.Leafs))
+	for i := 0; i < len(PS.GenLeafs); i++ {
+		PS.GenLeafs[i] = PS.cnfg.treecfg.Leafs[i].Clone()
+	}
+	***/
+
+	fmt.Println("Roots:   ", PS.GenRoots)
+	fmt.Println("Nodes:   ", PS.GenNodes)
+	fmt.Println("Leafs:   ", PS.GenLeafs)
+	fmt.Println("NonTrig: ", PS.GenNonTrig)
+
+	// setup communication struct
+	PS.commup = input.(*probs.ExprProblemComm)
+
+	// initialize bbq
+	PS.Trie = new(IpreNode)
+	PS.Trie.val = -1
+	PS.Trie.next = make(map[int]*IpreNode)
+
+	PS.Best = probs.NewReportQueue()
+	PS.Best.SetSort(probs.GPSORT_PARETO_TST_ERR)
+	PS.Queue = PS.GenInitExpr()
+	PS.Queue.SetSort(probs.PESORT_PARETO_TST_ERR)
+
+	PS.neqns = PS.Queue.Len()
+
+	PS.minError = math.Inf(1)
+
+	PS.eval_in = make(chan expr.Expr, 4048)
+	PS.eval_out = make(chan *probs.ExprReport, 4048)
+
+	for i := 0; i < PS.cnfg.evalrCount; i++ {
+		go PS.Evaluate()
+	}
+}
+
+func (PS *PgeSearch) Evaluate() {
+
+	for !PS.stop {
+		e := <-PS.eval_in
+		if e == nil {
+			continue
+		}
+		PS.eval_out <- RegressExpr(e, PS.prob)
+	}
+
+}
+
+func (PS *PgeSearch) Run() {
+	fmt.Printf("Running PGE\n")
+
+	PS.loop()
+
+	fmt.Println("PGE exitting")
+
+	PS.Clean()
+	PS.commup.Cmds <- -1
+}
+
+func (PS *PgeSearch) loop() {
+
+	PS.checkMessages()
+	for !PS.stop {
+
+		fmt.Println("in: PS.step() ", PS.iter)
+		PS.step()
+
+		// if PS.iter%PS.cnfg.pgeRptEpoch == 0 {
+		PS.reportExpr()
+		// }
+
+		// report current iteration
+		PS.commup.Gen <- [2]int{PS.id, PS.iter}
+		PS.iter++
+
+		PS.Clean()
+
+		PS.checkMessages()
+
+	}
+
+	// done expanding, pull the rest of the regressed solutions from the queue
+	p := 0
+	for PS.Queue.Len() > 0 {
+		e := PS.Queue.Pop().(*probs.ExprReport)
+
+		bPush := true
+		if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {
+			// fmt.Println("No Best Push")
+			bPush = false
+		}
+
+		if bPush {
+			// fmt.Printf("pop/push(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
+			PS.Best.Push(e)
+			p++
+		}
+
+		if e.TestScore() > PS.maxScore {
+			PS.maxScore = e.TestScore()
+		}
+		if e.TestError() < PS.minError {
+			PS.minError = e.TestError()
+			fmt.Printf("EXITING New Min Error:  %v\n", e)
+		}
+		if e.Size() > PS.maxSize {
+			PS.maxSize = e.Size()
+		}
+	}
+
+	fmt.Println("PGE sending last report")
+	PS.reportExpr()
+
+}
+
+func (PS *PgeSearch) step() {
+
+	loop := 0
+	eval_cnt := 0 // for channeled eval
+
+	es := PS.peel()
+
+	ex := PS.expandPeeled(es)
+
+	for cnt := range ex {
+		E := ex[cnt]
+
+		if E == nil {
+			continue
+		}
+
+		for _, e := range E {
+			if e == nil {
+				continue
+			}
+			if !PS.cnfg.treecfg.CheckExpr(e) {
+				continue
+			}
+
+			// check ipre_trie
+			serial := make([]int, 0, 64)
+			serial = e.Serial(serial)
+			ins := PS.Trie.InsertSerial(serial)
+			if !ins {
+				continue
+			}
+
+			// for serial eval
+			// re := RegressExpr(e, PS.prob)
+
+			// start channeled eval
+			PS.eval_in <- e
+			eval_cnt++
+		}
+	}
+	for i := 0; i < eval_cnt; i++ {
+		re := <-PS.eval_out
+		// end channeled eval
+
+		// check for NaN/Inf in re.error  and  if so, skip
+		if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) {
+			// fmt.Printf("Bad Error\n%v\n", re)
+			continue
+		}
+
+		if re.TestError() < PS.minError {
+			PS.minError = re.TestError()
+		}
+
+		// check for coeff == 0
+		doIns := true
+		for _, c := range re.Coeff() {
+			// i > 0 for free coeff
+			if math.Abs(c) < PS.cnfg.zeroEpsilon {
+				doIns = false
+				break
+			}
+		}
+
+		if doIns {
+			re.SetProcID(PS.id)
+			re.SetIterID(PS.iter)
+			re.SetUnitID(loop)
+			re.SetUniqID(PS.neqns)
+			loop++
+			PS.neqns++
+			// fmt.Printf("Queue.Push(): %v\n%v\n\n", re.Expr(), serial)
+			// fmt.Printf("Queue.Push(): %v\n", re)
+			// fmt.Printf("Queue.Push(): %v\n", re.Expr())
+
+			PS.Queue.Push(re)
+
+		}
+	}
+	// } // for sequential eval
+	PS.Queue.Sort()
+
+}
+
+func (PS *PgeSearch) peel() []*probs.ExprReport {
+	es := make([]*probs.ExprReport, PS.cnfg.peelCnt)
+	for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ {
+
+		e := PS.Queue.Pop().(*probs.ExprReport)
+
+		bPush := true
+		if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {
+			fmt.Println("No Best Push")
+			p--
+			continue
+		}
+
+		if bPush {
+			fmt.Printf("pop/push(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())
+			PS.Best.Push(e)
+		}
+
+		es[p] = e
+
+		if e.TestScore() > PS.maxScore {
+			PS.maxScore = e.TestScore()
+		}
+		if e.TestError() < PS.minError {
+			PS.minError = e.TestError()
+			fmt.Printf("Best New Min Error:  %v\n", e)
+		}
+		if e.Size() > PS.maxSize {
+			PS.maxSize = e.Size()
+		}
+
+	}
+	return es
+}
+
+func (PS *PgeSearch) expandPeeled(es []*probs.ExprReport) [][]expr.Expr {
+	eqns := make([][]expr.Expr, PS.cnfg.peelCnt)
+	for p := 0; p < PS.cnfg.peelCnt; p++ {
+		if es[p] == nil {
+			continue
+		}
+		// fmt.Printf("expand(%d): %v\n", p, es[p].Expr())
+		if es[p].Expr().ExprType() != expr.ADD {
+			add := expr.NewAdd()
+			add.Insert(es[p].Expr())
+			add.CalcExprStats()
+			es[p].SetExpr(add)
+		}
+		eqns[p] = PS.Expand(es[p].Expr())
+		// fmt.Printf("Results:\n")
+		// for i, e := range eqns[p] {
+		// 	fmt.Printf("%d,%d:  %v\n", p, i, e)
+		// }
+		// fmt.Println()
+	}
+	fmt.Println("\n")
+	return eqns
+}
+
+func (PS *PgeSearch) reportExpr() {
+
+	cnt := PS.cnfg.pgeRptCount
+	PS.Best.Sort()
+
+	// repot best equations
+	rpt := make(probs.ExprReportArray, cnt)
+	if PS.Best.Len() < cnt {
+		cnt = PS.Best.Len()
+	}
+	copy(rpt, PS.Best.GetQueue()[:cnt])
+
+	errSum, errCnt := 0.0, 0
+	PS.eqnsLog.Println("\n\nReport", PS.iter)
+	for i, r := range rpt {
+		PS.eqnsLog.Printf("\n%d:  %v\n", i, r)
+		if r != nil && r.Expr() != nil {
+			errSum += r.TestError()
+			errCnt++
+		}
+	}
+
+	PS.mainLog.Printf("Iter: %d  %f  %f\n", PS.iter, errSum/float64(errCnt), PS.minError)
+
+	PS.ipreLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst)
+	PS.fitnessLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst, errSum/float64(errCnt), PS.minError)
+
+	PS.commup.Rpts <- &rpt
+
+}
+
+func (PS *PgeSearch) Clean() {
+	// fmt.Printf("Cleaning PGE\n")
+
+	PS.errLogBuf.Flush()
+	PS.mainLogBuf.Flush()
+	PS.eqnsLogBuf.Flush()
+	PS.fitnessLogBuf.Flush()
+	PS.ipreLogBuf.Flush()
+
+}
+
+func (PS *PgeSearch) initLogs(logdir string) {
+	// open logs
+	PS.logDir = logdir + "pge/"
+	os.Mkdir(PS.logDir, os.ModePerm)
+	tmpF0, err5 := os.Create(PS.logDir + "pge:err.log")
+	if err5 != nil {
+		log.Fatal("couldn't create errs log")
+	}
+	PS.errLogBuf = bufio.NewWriter(tmpF0)
+	PS.errLogBuf.Flush()
+	PS.errLog = log.New(PS.errLogBuf, "", log.LstdFlags)
+
+	tmpF1, err1 := os.Create(PS.logDir + "pge:main.log")
+	if err1 != nil {
+		log.Fatal("couldn't create main log")
+	}
+	PS.mainLogBuf = bufio.NewWriter(tmpF1)
+	PS.mainLogBuf.Flush()
+	PS.mainLog = log.New(PS.mainLogBuf, "", log.LstdFlags)
+
+	tmpF2, err2 := os.Create(PS.logDir + "pge:eqns.log")
+	if err2 != nil {
+		log.Fatal("couldn't create eqns log")
+	}
+	PS.eqnsLogBuf = bufio.NewWriter(tmpF2)
+	PS.eqnsLogBuf.Flush()
+	PS.eqnsLog = log.New(PS.eqnsLogBuf, "", 0)
+
+	tmpF3, err3 := os.Create(PS.logDir + "pge:fitness.log")
+	if err3 != nil {
+		log.Fatal("couldn't create eqns log")
+	}
+	PS.fitnessLogBuf = bufio.NewWriter(tmpF3)
+	PS.fitnessLogBuf.Flush()
+	PS.fitnessLog = log.New(PS.fitnessLogBuf, "", log.Ltime|log.Lmicroseconds)
+
+	tmpF4, err4 := os.Create(PS.logDir + "pge:ipre.log")
+	if err4 != nil {
+		log.Fatal("couldn't create eqns log")
+	}
+	PS.ipreLogBuf = bufio.NewWriter(tmpF4)
+	PS.ipreLogBuf.Flush()
+	PS.ipreLog = log.New(PS.ipreLogBuf, "", log.Ltime|log.Lmicroseconds)
+}
+
+func (PS *PgeSearch) checkMessages() {
+
+	// check messages from superior
+	select {
+	case cmd, ok := <-PS.commup.Cmds:
+		if ok {
+			if cmd == -1 {
+				fmt.Println("PGE: stop sig recv'd")
+				PS.stop = true
+				return
+			}
+		}
+	default:
+		return
+	}
+}
+
+var c_input, c_ygiven []levmar.C_double
+
+func RegressExpr(E expr.Expr, P *probs.ExprProblem) (R *probs.ExprReport) {
+
+	guess := make([]float64, 0)
+	guess, eqn := E.ConvertToConstants(guess)
+
+	var coeff []float64
+	if len(guess) > 0 {
+
+		// fmt.Printf("x_dims:  %d  %d\n", x_dim, x_dim2)
+
+		// Callback version
+		coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test)
+
+		// Stack version
+		// x_dim := P.Train[0].NumDim()
+		// if c_input == nil {
+		// 	ps := P.Train[0].NumPoints()
+		// 	PS := len(P.Train) * ps
+		// 	x_tot := PS * x_dim
+
+		// 	c_input = make([]levmar.C_double, x_tot)
+		// 	c_ygiven = make([]levmar.C_double, PS)
+
+		// 	for i1, T := range P.Train {
+		// 		for i2, p := range T.Points() {
+		// 			i := i1*ps + i2
+		// 			c_ygiven[i] = levmar.MakeCDouble(p.Depnd(P.SearchVar))
+		// 			for i3, x_p := range p.Indeps() {
+		// 				j := i1*ps*x_dim + i2*x_dim + i3
+		// 				c_input[j] = levmar.MakeCDouble(x_p)
+		// 			}
+		// 		}
+		// 	}
+		// }
+		// coeff = levmar.StackLevmarExpr(eqn, x_dim, guess, c_ygiven, c_input)
+
+		// serial := make([]int, 0)
+		// serial = eqn.StackSerial(serial)
+		// fmt.Printf("StackSerial: %v\n", serial)
+		// fmt.Printf("%v\n%v\n%v\n\n", eqn, coeff, steff)
+	}
+
+	R = new(probs.ExprReport)
+	R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/
+	R.SetCoeff(coeff)
+	R.Expr().CalcExprStats()
+
+	// hitsL1, hitsL2, evalCnt, nanCnt, infCnt, l1_err, l2_err := scoreExpr(E, P, coeff)
+	_, _, _, trnNanCnt, _, trn_l1_err, _ := scoreExpr(E, P, P.Train, coeff)
+	_, _, tstEvalCnt, tstNanCnt, _, tst_l1_err, tst_l2_err := scoreExpr(E, P, P.Test, coeff)
+
+	R.SetTrainScore(trnNanCnt)
+	R.SetTrainError(trn_l1_err)
+
+	R.SetPredScore(tstNanCnt)
+	R.SetTestScore(tstEvalCnt)
+	R.SetTestError(tst_l1_err)
+	R.SetPredError(tst_l2_err)
+
+	return R
+}
+
+func scoreExpr(e expr.Expr, P *probs.ExprProblem, dataSets []*probs.PointSet, coeff []float64) (hitsL1, hitsL2, evalCnt, nanCnt, infCnt int, l1_err, l2_err float64) {
+	var l1_sum, l2_sum float64
+	for _, PS := range dataSets {
+		for _, p := range PS.Points() {
+			y := p.Depnd(P.SearchVar)
+			var out float64
+			if P.SearchType == probs.ExprBenchmark {
+				out = e.Eval(0, p.Indeps(), coeff, PS.SysVals())
+			} else if P.SearchType == probs.ExprDiffeq {
+				out = e.Eval(p.Indep(0), p.Indeps()[1:], coeff, PS.SysVals())
+			}
+
+			if math.IsNaN(out) {
+				nanCnt++
+				continue
+			} else if math.IsInf(out, 0) {
+				infCnt++
+				continue
+			} else {
+				evalCnt++
+			}
+
+			diff := out - y
+			l1_val := math.Abs(diff)
+			l2_val := diff * diff
+			l1_sum += l1_val
+			l2_sum += l2_val
+
+			if l1_val < P.HitRatio {
+				hitsL1++
+			}
+			if l2_val < P.HitRatio {
+				hitsL2++
+			}
+		}
+	}
+
+	if evalCnt == 0 {
+		l1_err = math.NaN()
+		l2_err = math.NaN()
+	} else {
+		fEvalCnt := float64(evalCnt + 1)
+		l1_err = l1_sum / fEvalCnt
+		l2_err = math.Sqrt(l2_sum / fEvalCnt)
+	}
+
+	return
+}
