示例#1
0
func swarmsolver(fn bench.Func, db *sql.DB, n int) optim.Method {
	low, up := fn.Bounds()

	if n < 0 {
		n = 30 + 1*len(low)
		if n > maxeval/500 {
			n = maxeval / 500
		}
	}

	return swarm.New(
		swarm.NewPopulationRand(n, low, up),
		swarm.VmaxBounds(fn.Bounds()),
		swarm.DB(db),
	)
}
示例#2
0
文件: main.go 项目: gidden/cloudlus
func buildIter(lb, ub []float64) optim.Method {
	mask := make([]bool, len(ub))
	for i := range mask {
		mask[i] = lb[i] < ub[i]
	}

	n := 30 + 1*len(lb)
	if *npar != 0 {
		n = *npar
	} else if n < 30 {
		n = 30
	}

	fmt.Printf("swarming with %v particles\n", n)

	ev := optim.ParallelEvaler{ContinueOnErr: true}
	if *addr == "" {
		ev.NConcurrent = 8
	}

	pop := swarm.NewPopulationRand(n, lb, ub)
	swarm := swarm.New(
		pop,
		swarm.Evaler(ev),
		swarm.VmaxBounds(lb, ub),
		swarm.DB(db),
	)
	return pattern.New(pop[0].Point,
		pattern.ResetStep(.0001),
		pattern.NsuccessGrow(4),
		pattern.Evaler(ev),
		pattern.PollRandNMask(*pollrandn, mask),
		pattern.SearchMethod(swarm, pattern.Share),
		pattern.DB(db),
	)
}