示例#1
0
文件: many-obj.go 项目: cpmech/goga
func DTLZ2mGenerator(opt *goga.Optimiser, nf int) (ng int, fcn goga.MinProb_t) {
	nx := nf + 10
	ng = nx * 2
	opt.FltMin = make([]float64, nx)
	opt.FltMax = make([]float64, nx)
	for i := 0; i < nx; i++ {
		opt.FltMin[i], opt.FltMax[i] = -0.01, 1.01
	}
	fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
		var failed bool
		for i := 0; i < nx; i++ {
			g[0+i*2] = x[i]
			g[1+i*2] = 1.0 - x[i]
			if g[0+i*2] < 0 {
				failed = true
			}
			if g[1+i*2] < 0 {
				failed = true
			}
		}
		if failed {
			return
		}
		var c float64
		for i := nf - 1; i < nx; i++ {
			c += math.Pow((x[i] - 0.5), 2.0)
		}
		for i := 0; i < nf; i++ {
			f[i] = (1.0 + c)
			for j := 0; j < nf-1-i; j++ {
				f[i] *= math.Cos(x[j] * PI / 2.0)
			}
			if i > 0 {
				j := nf - 1 - i
				f[i] *= math.Sin(x[j] * PI / 2.0)
			}
		}
	}
	opt.Multi_fcnErr = func(f []float64) float64 {
		var sum float64
		for i := 0; i < nf; i++ {
			sum += f[i] * f[i]
		}
		return sum - 1.0
	}
	opt.RptFmin = make([]float64, nf)
	opt.RptFmax = make([]float64, nf)
	for i := 0; i < nf; i++ {
		opt.RptFmax[i] = 1
	}
	return
}