Example #1
0
func TestElitePool(t *testing.T) {
	pop := dummies()
	pool := sel.ElitePool(5, 10)
	for i := range pop {
		pool.Put(pop[i])
	}
	for i := dummy(9); 4 < i; i-- {
		if pool.Get().(dummy) != i {
			t.Fail()
			return
		}
	}
}
Example #2
0
	bounds    = 30    // Bounds of object parameters.
	precision = 1e-16 // Desired precision.
)

// Global objects
var (
	// Count of the number of fitness evaluations.
	count struct {
		sync.Mutex
		n int
	}

	// Each of the 40 members of the population generates 7 children and adds
	// them to this pool. This pool returns to each member a different one of
	// most fit to be their replacement in the next generation.
	selector = sel.ElitePool(40, 280)

	// A free-list used to recycle memory.
	vectors = sync.Pool{
		New: func() interface{} {
			return make(real.Vector, dim)
		},
	}
)

// The ackley type specifies our genome. We evolve a real-valued vector that
// optimizes the ackley function. Each genome also contains a vector of strategy
// parameters used with a self-adaptive evolution strategy.
type ackley struct {
	gene  real.Vector // the object vector to optimize
	steps real.Vector // strategy parameters for mutation