func ExprGen(egp *prob.TreeParams, srules SimpRules, rng *rand.Rand) Expr { var ret Expr good := false cnt := 0 for !good { egp.ResetCurr() egp.ResetTemp() // eqn := ExprGenStats( &egp, rng ) eqn := exprGrow(-1, ExprGenDepth, egp, rng) eqn.CalcExprStats(0) // fmt.Printf( "%v\n", eqn) ret = eqn.Simplify(srules) ret.CalcExprStats(0) // fmt.Printf( "%v\n\n", ret) // check eqn after simp good = egp.CheckExpr(ret) cnt++ } return ret }
func InjectEqn_Vanilla(p1 Expr, egp *prob.TreeParams, rng *rand.Rand) Expr { eqn := p1.Clone() eqn.CalcExprStats(0) s1 := rng.Intn(eqn.Size()) s2 := s1 e2 := eqn.GetExpr(&s2) egp.CurrSize = eqn.Size() - e2.Size() egp.CurrDepth = e2.Depth() egp.ResetTemp() // not correct (should be size based) new_eqn := exprGrow(-1, ExprGenDepth, egp, rng) // eqn.SetExpr(&s1, new_eqn ) SwapExpr(eqn, new_eqn, s1) eqn.CalcExprStats(0) return eqn }
func InjectEqn_50_150(p1 Expr, egp *prob.TreeParams, rng *rand.Rand) Expr { eqn := p1.Clone() eqn.CalcExprStats(0) // begin loop s1 := rng.Intn(eqn.Size()) s1_tmp := s1 e1 := eqn.GetExpr(&s1_tmp) egp.ResetCurr() egp.ResetTemp() egp.TmpMinSize = e1.Size() / 2 egp.TmpMaxSize = (e1.Size() * 3) / 2 // loop if min/max out of bounds // and select new subtree // not correct (should be size based) new_eqn := exprGrow(-1, ExprGenDepth, egp, rng) // eqn.SetExpr(&s1, new_eqn ) SwapExpr(eqn, new_eqn, s1) eqn.CalcExprStats(0) return eqn }