Beispiel #1
0
// Creates new minimizer
// cost - function to minimize
// n - number of entities in population
// min, max - area for initial population
func NewMinimizer(cost Cost, n int, min, max *matrix.Dense) *Minimizer {
	if n < 4 {
		log.Panic("population too small: ", n)
	}
	m := new(Minimizer)
	m.CR = 0.9
	m.Pop = make([]*Agent, n)
	// Initialization of population
	max.AddTo(min, -1) // calculate width of initial area
	for i := range m.Pop {
		m.Pop[i] = newAgent(min, max, cost)
	}
	m.rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
	return m
}
Beispiel #2
0
func newAgent(min, width *matrix.Dense, cost Cost) *Agent {
	a := new(Agent)
	a.X = matrix.DenseZero(min.Size())
	a.x = a.X.Hvec() // crossover operates on vectorized matrix
	a.in = make(chan args, 1)
	a.out = make(chan float64, 1)
	a.rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
	a.cost = cost
	// Place this agent in random place on the initial area
	a.x.Rand(0, 1)
	a.X.MulBy(width)
	a.X.AddTo(min, 1)
	// Run crossover loop
	go a.crossoverLoop()
	return a
}
Beispiel #3
0
Datei: main.go Projekt: ziutek/de
func cost(m *matrix.Dense) float64 {
	return Cost(m.Elems())
}
Beispiel #4
0
func perturb(u *matrix.Dense, in args, start, stop int) {
	v := u.Vslice(start, stop)
	v.Sub(in.b.Vslice(start, stop), in.c.Vslice(start, stop), in.f)
	v.AddTo(in.a.Vslice(start, stop), 1)
}