Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}