コード例 #1
0
ファイル: minimizer.go プロジェクト: ziutek/de
// 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
}