Exemple #1
0
func main() {
	funcs := []gene.FuncWeight{
		{"Not", 1},
		{"And", 5},
		{"Or", 5},
	}
	e := model.New(funcs, bn.BoolAllGates, 30, 7, 1, 2, 0, "Or", validateNand)
	s := e.Evolve(1000)
	fmt.Printf("nand solution: %v, score=%v\n", s, validateNand(s))
}
Exemple #2
0
func main() {
	funcs := []gene.FuncWeight{
		{"+", 1},
		{"-", 1},
		{"*", 1},
		{"/", 1},
	}
	e := model.New(funcs, mn.Math, 30, 6, 1, 1, 0, "+", validateFunc)
	s := e.Evolve(10000)
	fmt.Printf("(a^4 + a^3 + a^2 + a) solution: %v, score=%v\n", s, validateFunc(s))
}
func BenchmarkValidateFunc(b *testing.B) {
	funcs := []gene.FuncWeight{
		{"+", 1},
		{"-", 1},
		{"*", 1},
	}
	e := model.New(funcs, mn.Math, 30, 8, 4, 1, 0, "+", nil)
	var v float64
	for i := 0; i < b.N; i++ {
		v = validateFunc(e.Genomes[0])
	}
	result = v
}
Exemple #4
0
func main() {
	funcs := []gene.FuncWeight{
		{"Not", 1},
		{"And", 5},
		{"Or", 5},
	}
	numIn := len(nandTests[0].in)
	e := model.New(funcs, bn.BoolAllGates, 30, 7, 1, numIn, 0, "Or", validateNand)
	s := e.Evolve(1000)

	// Write out the Go source code for the solution.
	gr, err := grammars.LoadGoBooleanAllGatesGrammar()
	if err != nil {
		log.Printf("unable to load Boolean grammar: %v", err)
	}
	fmt.Printf("\n// gepModel is auto-generated Go source code for the\n")
	fmt.Printf("// nand solution karva expression:\n// %q, score=%v\n", s, validateNand(s))
	s.Write(os.Stdout, gr)
}
Exemple #5
0
func main() {
	funcs := []gene.FuncWeight{
		{"+", 1},
		{"-", 1},
		{"*", 1},
	}
	numIn := len(srTests[0].in)
	e := model.New(funcs, mn.Math, 30, 8, 4, numIn, 0, "+", validateFunc)
	s := e.Evolve(10000)

	// Write out the Go source code for the solution.
	gr, err := grammars.LoadGoMathGrammar()
	if err != nil {
		log.Printf("unable to load Boolean grammar: %v", err)
	}
	fmt.Printf("\n// gepModel is auto-generated Go source code for the\n")
	fmt.Printf("// (a^4 + a^3 + a^2 + a) solution karva expression:\n// %q, score=%v\n", s, validateFunc(s))
	s.Write(os.Stdout, gr)
}