• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang goga.Optimiser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cpmech/goga.Optimiser的典型用法代码示例。如果您正苦于以下问题:Golang Optimiser类的具体用法?Golang Optimiser怎么用?Golang Optimiser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Optimiser类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: get_femsim_data

// get_femsim_data allocates FE solvers and returns FORM data
func get_femsim_data(opt *goga.Optimiser, fnkey string) (lsft LSF_T, vars rnd.Variables) {
	FEMDATA = make([]*FemData, opt.Ncpu)
	for i := 0; i < opt.Ncpu; i++ {
		FEMDATA[i] = NewData(fnkey, i)
	}
	lsft = RunFEA
	vars = FEMDATA[0].Vars
	opt.RptName = fnkey
	opt.RptFref = []float64{FEMDATA[0].BetRef}
	return
}
开发者ID:cpmech,项目名称:goga,代码行数:12,代码来源:fesim.go


示例2: DTLZ2mGenerator

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
}
开发者ID:cpmech,项目名称:goga,代码行数:52,代码来源:many-obj.go


示例3: plot2

func plot2(opt *goga.Optimiser, onlyFront0 bool) {

	// plot reference values
	f0 := utl.DblsGetColumn(0, opt.Multi_fStar)
	f1 := utl.DblsGetColumn(1, opt.Multi_fStar)
	plt.Plot(f0, f1, "'b-', label='reference'")

	// plot goga values
	fmt := &plt.Fmt{C: "r", M: "o", Ms: 3, L: "goga", Ls: "None"}
	opt.PlotAddOvaOva(0, 1, opt.Solutions, true, fmt)
	plt.Gll("$f_0$", "$f_1$", "")
	plt.SaveD("/tmp/goga", io.Sf("m2_%s.eps", opt.RptName))
}
开发者ID:cpmech,项目名称:goga,代码行数:13,代码来源:auxplot.go


示例4: main

func main() {

	buf := goga.TexDocumentStart()

	io.Ff(buf, `
\begin{table} [!t] \centering
\caption{Random variables used in benchmark tests.}

\begin{tabular}[c]{ccccccc} \toprule
P & var & $\mu$ & $\sigma$ & distr & min & max \\ \hline
`)

	for i := 1; i < 19; i++ {
		opt := new(goga.Optimiser)
		opt.ProbNum = i
		_, vars := get_simple_data(opt)
		v := vars[0]
		io.Pforan("vars = %v\n", vars)
		io.Ff(buf, `%d & $x_0$ & %g & %g & %s & %g & %g \\`, i, v.M, v.S, rnd.GetDistrName(v.D), v.Min, v.Max)
		for j := 1; j < len(vars); j++ {
			v = vars[j]
			io.Ff(buf, ` & $x_%d$ & %g & %g & %s & %g & %g \\`, j, v.M, v.S, rnd.GetDistrName(v.D), v.Min, v.Max)
			io.Ff(buf, "\n")
		}
		io.Ff(buf, " \\hline\n\n")
	}

	io.Ff(buf, `
\end{tabular}
\label{tab:prms-simple}
\end{table}
`)

	goga.TexDocumentEnd(buf)
	io.WriteFileVD("/tmp/goga", "prms-table-simple.tex", buf)
}
开发者ID:cpmech,项目名称:goga,代码行数:36,代码来源:table-of-prms.go


示例5: runone

func runone(ncpu int) (nsol, tf int, elaspsedTime time.Duration) {

	// input filename
	fn, fnkey := io.ArgToFilename(0, "ground10", ".sim", true)

	// GA parameters
	var opt goga.Optimiser
	opt.Read("ga-" + fnkey + ".json")
	opt.GenType = "rnd"
	nsol, tf = opt.Nsol, opt.Tf
	postproc := true
	if ncpu > 0 {
		opt.Ncpu = ncpu
		postproc = false
	}

	// FEM
	data := make([]*FemData, opt.Ncpu)
	for i := 0; i < opt.Ncpu; i++ {
		data[i] = NewData(fn, fnkey, i)
	}
	io.Pforan("MaxWeight = %v\n", data[0].MaxWeight)

	// set integers
	if data[0].Opt.BinInt {
		opt.CxInt = goga.CxInt
		opt.MtInt = goga.MtIntBin
		opt.BinInt = data[0].Ncells
	}

	// set floats
	opt.FltMin = make([]float64, data[0].Nareas)
	opt.FltMax = make([]float64, data[0].Nareas)
	for i := 0; i < data[0].Nareas; i++ {
		opt.FltMin[i] = data[0].Opt.Amin
		opt.FltMax[i] = data[0].Opt.Amax
	}

	// initialise optimiser
	opt.Nova = 2 // weight and deflection
	opt.Noor = 4 // mobility, feasibility, maxdeflection, stress
	opt.Init(goga.GenTrialSolutions, func(sol *goga.Solution, cpu int) {
		mob, fail, weight, umax, _, errU, errS := data[cpu].RunFEM(sol.Int, sol.Flt, 0, false)
		sol.Ova[0] = weight
		sol.Ova[1] = umax
		sol.Oor[0] = mob
		sol.Oor[1] = fail
		sol.Oor[2] = errU
		sol.Oor[3] = errS
	}, nil, 0, 0, 0)

	// initial solutions
	var sols0 []*goga.Solution
	if false {
		sols0 = opt.GetSolutionsCopy()
	}

	// benchmark
	initialTime := time.Now()
	defer func() {
		elaspsedTime = time.Now().Sub(initialTime)
	}()

	// solve
	opt.Verbose = true
	opt.Solve()
	goga.SortByOva(opt.Solutions, 0)

	// post processing
	if !postproc {
		return
	}

	// check
	nfailed, front0 := goga.CheckFront0(&opt, true)

	// save results
	var log, res bytes.Buffer
	io.Ff(&log, opt.LogParams())
	io.Ff(&res, PrintSolutions(data[0], opt.Solutions))
	io.Ff(&res, io.Sf("\n\nnfailed = %d\n", nfailed))
	io.WriteFileVD("/tmp/goga", fnkey+".log", &log)
	io.WriteFileVD("/tmp/goga", fnkey+".res", &res)

	// plot Pareto-optimal front
	feasibleOnly := true
	plt.SetForEps(0.8, 350)
	if strings.HasPrefix(fnkey, "ground10") {
		_, ref, _ := io.ReadTable("p460_fig300.dat")
		plt.Plot(ref["w"], ref["u"], "'b-', label='reference'")
	}
	fmtAll := &plt.Fmt{L: "final solutions", M: ".", C: "orange", Ls: "none", Ms: 3}
	fmtFront := &plt.Fmt{L: "final Pareto front", C: "r", M: "o", Ms: 3, Ls: "none"}
	goga.PlotOvaOvaPareto(&opt, sols0, 0, 1, feasibleOnly, fmtAll, fmtFront)
	plt.Gll("weight ($f_0$)", "deflection ($f_1)$", "") //, "leg_out=1, leg_ncol=4, leg_hlen=1.5")
	if strings.HasPrefix(fnkey, "ground10") {
		plt.AxisRange(1800, 14000, 1, 6)
	}

	// plot selected results
//.........这里部分代码省略.........
开发者ID:cpmech,项目名称:goga,代码行数:101,代码来源:topology.go


示例6: vtk_plot3

func vtk_plot3(opt *goga.Optimiser, αcone, ptRad float64, onlyFront0, twice bool) {

	// results
	var X, Y, Z []float64
	if onlyFront0 {
		for _, sol := range opt.Solutions {
			if sol.Feasible() && sol.FrontId == 0 {
				X = append(X, sol.Ova[0])
				Y = append(Y, sol.Ova[1])
				Z = append(Z, sol.Ova[2])
			}
		}
	} else {
		X, Y, Z = make([]float64, opt.Nsol), make([]float64, opt.Nsol), make([]float64, opt.Nsol)
		for i, sol := range opt.Solutions {
			X[i], Y[i], Z[i] = sol.Ova[0], sol.Ova[1], sol.Ova[2]
		}
	}

	// create a new VTK Scene
	scn := vtk.NewScene()
	scn.HydroLine = false
	scn.FullAxes = false
	scn.AxesLen = 1.1
	scn.WithPlanes = false
	scn.LblX = io.Sf("f%d", 0)
	scn.LblY = io.Sf("f%d", 1)
	scn.LblZ = io.Sf("f%d", 2)
	scn.LblSz = 20
	if opt.RptName == "DTLZ1" {
		scn.AxesLen = 0.6
	}

	// optimal Pareto front
	front := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
		f = opt.Multi_fcnErr(x)
		return
	})
	front.Limits = []float64{opt.RptFmin[0], opt.RptFmax[0], opt.RptFmin[1], opt.RptFmax[1], opt.RptFmin[2], opt.RptFmax[2]}
	front.Color = []float64{0.45098039, 0.70588235, 1., 0.8}
	front.CmapNclrs = 0 // use this to use specified color
	front.Ndiv = []int{61, 61, 61}
	front.AddTo(scn)

	// cone
	if opt.RptName == "DTLZ2c" {
		cone := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
			f = cone_angle(x) - math.Tan(αcone)
			return
		})
		cone.Limits = []float64{0, -1, 0, 1, 0, 360}
		cone.Ndiv = []int{61, 61, 81}
		cone.OctRotate = true
		cone.GridShowPts = false
		cone.Color = []float64{0.96862745, 0.75294118, 0.40784314, 0.5}
		cone.CmapNclrs = 0 // use this to use specified color
		cone.AddTo(scn)    // remember to add to Scene
	}

	// particles
	var P vtk.Spheres
	P.X, P.Y, P.Z = X, Y, Z
	P.R = utl.DblVals(len(X), ptRad)
	P.Color = []float64{1, 0, 0, 1}
	P.AddTo(scn)

	// start interactive mode
	scn.SaveEps = false
	scn.SavePng = true
	scn.PngMag = 2
	scn.Fnk = io.Sf("/tmp/goga/vtk_%s_A", opt.RptName)
	scn.Run()
	if twice {
		scn.Fnk = io.Sf("/tmp/goga/vtk_%s_B", opt.RptName)
		scn.Run()
	}
}
开发者ID:cpmech,项目名称:goga,代码行数:77,代码来源:auxplot.go


示例7: main

func main() {

	// GA parameters
	opt := new(goga.Optimiser)
	opt.Default()
	opt.Nsol = 6
	opt.Ncpu = 1
	opt.Tf = 10
	opt.EpsH = 1e-3
	opt.Verbose = true
	opt.GenType = "latin"
	//opt.GenType = "halton"
	//opt.GenType = "rnd"
	opt.NormFlt = false
	opt.UseMesh = true
	opt.Nbry = 3

	// define problem
	opt.RptName = "9"
	opt.RptFref = []float64{0.0539498478}
	opt.RptXref = []float64{-1.717143, 1.595709, 1.827247, -0.7636413, -0.7636450}
	opt.FltMin = []float64{-2.3, -2.3, -3.2, -3.2, -3.2}
	opt.FltMax = []float64{+2.3, +2.3, +3.2, +3.2, +3.2}
	ng, nh := 0, 3
	fcn := func(f, g, h, x []float64, ξ []int, cpu int) {
		f[0] = math.Exp(x[0] * x[1] * x[2] * x[3] * x[4])
		h[0] = x[0]*x[0] + x[1]*x[1] + x[2]*x[2] + x[3]*x[3] + x[4]*x[4] - 10.0
		h[1] = x[1]*x[2] - 5.0*x[3]*x[4]
		h[2] = math.Pow(x[0], 3.0) + math.Pow(x[1], 3.0) + 1.0
	}

	// check
	if false {
		f := make([]float64, 1)
		h := make([]float64, 3)
		fcn(f, nil, h, opt.RptXref, nil, 0)
		io.Pforan("f(xref)  = %g  (%g)\n", f[0], opt.RptFref[0])
		io.Pforan("h0(xref) = %g\n", h[0])
		io.Pforan("h1(xref) = %g\n", h[1])
		io.Pforan("h2(xref) = %g\n", h[2])
	}

	// initialise optimiser
	nf := 1
	opt.Init(goga.GenTrialSolutions, nil, fcn, nf, ng, nh)

	// output function
	T := make([]float64, opt.Tf+1)                    // [nT]
	X := utl.Deep3alloc(opt.Nflt, opt.Nsol, opt.Tf+1) // [nx][nsol][nT]
	F := utl.Deep3alloc(opt.Nova, opt.Nsol, opt.Tf+1) // [nf][nsol][nT]
	U := utl.Deep3alloc(opt.Noor, opt.Nsol, opt.Tf+1) // [nu][nsol][nT]
	opt.Output = func(time int, sols []*goga.Solution) {
		T[time] = float64(time)
		for j, s := range sols {
			for i := 0; i < opt.Nflt; i++ {
				X[i][j][time] = s.Flt[i]
			}
			for i := 0; i < opt.Nova; i++ {
				F[i][j][time] = s.Ova[i]
			}
			for i := 0; i < opt.Noor; i++ {
				U[i][j][time] = s.Oor[i]
			}
		}
	}

	// initial population
	fnk := "one-obj-prob9-dbg"
	//S0 := opt.GetSolutionsCopy()
	goga.WriteAllValues("/tmp/goga", fnk, opt)

	// solve
	opt.Solve()

	// print
	if false {
		io.Pf("%13s%13s%13s%13s%10s\n", "f0", "u0", "u1", "u2", "feasible")
		for _, s := range opt.Solutions {
			io.Pf("%13.5e%13.5e%13.5e%13.5e%10v\n", s.Ova[0], s.Oor[0], s.Oor[1], s.Oor[2], s.Feasible())
		}
	}

	// plot: time series
	//a, b := 100, len(T)
	a, b := 0, 1 //len(T)
	if false {
		plt.SetForEps(2.0, 400)
		nrow := opt.Nflt + opt.Nova + opt.Noor
		for j := 0; j < opt.Nsol; j++ {
			for i := 0; i < opt.Nflt; i++ {
				plt.Subplot(nrow, 1, 1+i)
				plt.Plot(T[a:b], X[i][j][a:b], "")
				plt.Gll("$t$", io.Sf("$x_%d$", i), "")
			}
		}
		for j := 0; j < opt.Nsol; j++ {
			for i := 0; i < opt.Nova; i++ {
				plt.Subplot(nrow, 1, 1+opt.Nflt+i)
				plt.Plot(T[a:b], F[i][j][a:b], "")
				plt.Gll("$t$", io.Sf("$f_%d$", i), "")
//.........这里部分代码省略.........
开发者ID:cpmech,项目名称:goga,代码行数:101,代码来源:one-obj-prob9-dbg.go


示例8: get_simple_data

// Output:
//  lsf  -- limit state function
//  βref -- reference β (if available)
//  vars -- random variables data
func get_simple_data(opt *goga.Optimiser) (lsf LSF_T, vars rnd.Variables) {

	var desc string
	var βref float64
	var xref []float64
	switch opt.ProbNum {

	case 1:
		desc = "SMB1/BS5"
		lsf = func(x []float64, cpu int) (float64, float64) {
			return 0.1*math.Pow(x[0]-x[1], 2) - (x[0]+x[1])/SQ2 + 2.5, 0.0
		}
		βref = 2.5 // from SMB
		xref = []float64{1.7677, 1.7677}
		vars = rnd.Variables{
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
		}

	case 2:
		desc = "SMB2/BS6"
		lsf = func(x []float64, cpu int) (float64, float64) {
			return -0.5*math.Pow(x[0]-x[1], 2) - (x[0]+x[1])/SQ2 + 3, 0.0
		}
		βref = 1.658 // from BS6
		xref = []float64{-0.7583, 1.4752}
		vars = rnd.Variables{
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
		}

	case 3:
		desc = "SMB3/GR6"
		lsf = func(x []float64, cpu int) (float64, float64) {
			return 2 - x[1] - 0.1*math.Pow(x[0], 2) + 0.06*math.Pow(x[0], 3), 0.0
		}
		βref = 2 // from SMB
		xref = []float64{0, 2}
		vars = rnd.Variables{
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
		}

	case 4:
		desc = "SMB4/GR8"
		lsf = func(x []float64, cpu int) (float64, float64) {
			return 3 - x[1] + 256*math.Pow(x[0], 4), 0.0
		}
		βref = 3 // from SMB
		xref = []float64{0, 3}
		vars = rnd.Variables{
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
		}

	case 5:
		desc = "SMB5/GW1" // modified GW1
		shift := 0.0      // 0.1
		lsf = func(x []float64, cpu int) (float64, float64) {
			return 1 + math.Pow(x[0]+x[1]+shift, 2)/4 - 4*math.Pow(x[0]-x[1]+shift, 2), 0.0
		}
		βref = 0.3536 // from SMB
		xref = []float64{-βref * SQ2 / 2.0, βref * SQ2 / 2.0}
		vars = rnd.Variables{
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
			&rnd.VarData{D: rnd.D_Normal, M: 0, S: 1, Min: -20, Max: 20},
		}

	case 6:
		desc = "SMB7/SSGK1a" // SSGK case 1
		lsf = func(x []float64, cpu int) (float64, float64) {
			return math.Pow(x[0], 3) + math.Pow(x[1], 3) - 18, 0.0
		}
		βref = 2.2401 // from SMB
		vars = rnd.Variables{
			&rnd.VarData{D: rnd.D_Normal, M: 10, S: 5, Min: -50, Max: 50},
			&rnd.VarData{D: rnd.D_Normal, M: 10, S: 5, Min: -50, Max: 50},
		}

	case 7:
		desc = "SMB8/SSGK1b" // SSGK case 2
		lsf = func(x []float64, cpu int) (float64, float64) {
			return math.Pow(x[0], 3) + math.Pow(x[1], 3) - 18, 0.0
		}
		βref = 2.2260 // from SMB
		vars = rnd.Variables{
			&rnd.VarData{D: rnd.D_Normal, M: 10, S: 5, Min: -50, Max: 50},
			&rnd.VarData{D: rnd.D_Normal, M: 9.9, S: 5, Min: -50, Max: 50},
		}

	case 8:
		desc = "SMB9/GR7"
		lsf = func(x []float64, cpu int) (float64, float64) {
			return 2.5 - 0.2357*(x[0]-x[1]) + 0.0046*math.Pow(x[0]+x[1]-20, 4), 0.0
		}
		βref = 2.5 // from SMB
//.........这里部分代码省略.........
开发者ID:cpmech,项目名称:goga,代码行数:101,代码来源:simple.go


示例9: main

func main() {

	// GA parameters
	opt := new(goga.Optimiser)
	opt.Default()
	opt.Nsol = 50
	opt.Ncpu = 1
	opt.Tf = 1000
	opt.Nsamples = 10
	opt.EpsH = 1e-3
	opt.Verbose = false
	opt.GenType = "latin"
	opt.NormFlt = false

	// options for report
	opt.HistNsta = 6
	opt.HistLen = 13
	opt.RptFmtF = "%.5f"
	opt.RptFmtFdev = "%.2e"
	opt.RptFmtX = "%.3f"

	opt.RptName = "9"
	opt.RptFref = []float64{0.0539498478}
	opt.RptXref = []float64{-1.717143, 1.595709, 1.827247, -0.7636413, -0.7636450}
	opt.FltMin = []float64{-2.3, -2.3, -3.2, -3.2, -3.2}
	opt.FltMax = []float64{+2.3, +2.3, +3.2, +3.2, +3.2}
	ng, nh := 0, 3
	fcn := func(f, g, h, x []float64, ξ []int, cpu int) {
		f[0] = math.Exp(x[0] * x[1] * x[2] * x[3] * x[4])
		h[0] = x[0]*x[0] + x[1]*x[1] + x[2]*x[2] + x[3]*x[3] + x[4]*x[4] - 10.0
		h[1] = x[1]*x[2] - 5.0*x[3]*x[4]
		h[2] = math.Pow(x[0], 3.0) + math.Pow(x[1], 3.0) + 1.0
	}

	// check
	if false {
		f := make([]float64, 1)
		h := make([]float64, 3)
		fcn(f, nil, h, opt.RptXref, nil, 0)
		io.Pforan("f(xref)  = %g  (%g)\n", f[0], opt.RptFref[0])
		io.Pforan("h0(xref) = %g\n", h[0])
		io.Pforan("h1(xref) = %g\n", h[1])
		io.Pforan("h2(xref) = %g\n", h[2])
		return
	}

	// initialise optimiser
	nf := 1
	opt.Init(goga.GenTrialSolutions, nil, fcn, nf, ng, nh)

	// solve
	//opt.RunMany("/tmp/goga", "functions")
	opt.RunMany("", "")
	goga.StatF(opt, 0, true)
	opts := []*goga.Optimiser{opt}
	textSize := `\scriptsize  \setlength{\tabcolsep}{0.5em}`
	miniPageSz, histTextSize := "4.1cm", `\fontsize{5pt}{6pt}`
	nRowPerTab := 9
	title := "Constrained single objective problem 9"
	goga.TexReport("/tmp/goga", "tmp_one-obj-prob9", title, "one-ob-prob9", 1, nRowPerTab, true, false, textSize, miniPageSz, histTextSize, opts)
	goga.TexReport("/tmp/goga", "one-obj-prob9", title, "one-obj-prob9", 1, nRowPerTab, false, false, textSize, miniPageSz, histTextSize, opts)
}
开发者ID:cpmech,项目名称:goga,代码行数:62,代码来源:one-obj-prob9.go


示例10: main

func main() {

	// GA parameters
	opt := new(goga.Optimiser)
	opt.Default()
	opt.Tf = 500
	opt.Nsamples = 1000
	opt.Verbose = false
	opt.GenType = "latin"

	// enlarge box; add more constraint equations
	strategy2 := true

	// options for report
	opt.HistNsta = 6
	opt.HistLen = 13
	opt.RptFmtF = "%.5f"
	opt.RptFmtFdev = "%.2e"
	opt.RptFmtX = "%.3f"

	opt.Ncpu = 4
	opt.RptName = "2"
	opt.RptFref = []float64{-15.0}
	opt.RptXref = []float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1}
	opt.FltMin = make([]float64, 13)
	opt.FltMax = make([]float64, 13)
	xmin, xmax := 0.0, 1.0
	if strategy2 {
		xmin, xmax = -0.5, 1.5
	}
	for i := 0; i < 9; i++ {
		opt.FltMin[i], opt.FltMax[i] = xmin, xmax
	}
	opt.FltMin[12], opt.FltMax[12] = xmin, xmax
	xmin, xmax = 0, 100
	if strategy2 {
		xmin, xmax = -1, 101
	}
	for i := 9; i < 12; i++ {
		opt.FltMin[i], opt.FltMax[i] = xmin, xmax
	}
	ng := 9
	if strategy2 {
		ng += 9 + 9 + 3 + 3 + 2
	}
	fcn := func(f, g, h, x []float64, ξ []int, cpu int) {
		s1, s2, s3 := 0.0, 0.0, 0.0
		for i := 0; i < 4; i++ {
			s1 += x[i]
			s2 += x[i] * x[i]
		}
		for i := 4; i < 13; i++ {
			s3 += x[i]
		}
		f[0] = 5.0*(s1-s2) - s3
		g[0] = 10.0 - 2.0*x[0] - 2.0*x[1] - x[9] - x[10]
		g[1] = 10.0 - 2.0*x[0] - 2.0*x[2] - x[9] - x[11]
		g[2] = 10.0 - 2.0*x[1] - 2.0*x[2] - x[10] - x[11]
		g[3] = 8.0*x[0] - x[9]
		g[4] = 8.0*x[1] - x[10]
		g[5] = 8.0*x[2] - x[11]
		g[6] = 2.0*x[3] + x[4] - x[9]
		g[7] = 2.0*x[5] + x[6] - x[10]
		g[8] = 2.0*x[7] + x[8] - x[11]
		if strategy2 {
			for i := 0; i < 9; i++ {
				g[9+i] = x[i]
				g[18+i] = 1.0 - x[i]
			}
			for i := 0; i < 3; i++ {
				g[27+i] = x[9+i]
				g[30+i] = 100.0 - x[9+i]
			}
			g[33] = x[12]
			g[34] = 1.0 - x[12]
		}
	}

	// number of trial solutions
	opt.Nsol = len(opt.FltMin) * 10

	// initialise optimiser
	nf, nh := 1, 0
	opt.Init(goga.GenTrialSolutions, nil, fcn, nf, ng, nh)

	// solve
	opt.RunMany("", "")
	goga.StatF(opt, 0, true)
	opts := []*goga.Optimiser{opt}
	textSize := `\scriptsize  \setlength{\tabcolsep}{0.5em}`
	miniPageSz, histTextSize := "4.1cm", `\fontsize{5pt}{6pt}`
	nRowPerTab := 9
	title := "Constrained single objective problem 2"
	goga.TexReport("/tmp/goga", "tmp_one-obj-prob2", title, "one-ob-prob2", 1, nRowPerTab, true, false, textSize, miniPageSz, histTextSize, opts)
	goga.TexReport("/tmp/goga", "one-obj-prob2", title, "one-obj-prob2", 1, nRowPerTab, false, false, textSize, miniPageSz, histTextSize, opts)
}
开发者ID:cpmech,项目名称:goga,代码行数:96,代码来源:one-obj-prob2.go



注:本文中的github.com/cpmech/goga.Optimiser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang chk.AnaNum函数代码示例发布时间:2022-05-23
下一篇:
Golang ana.CteStressPstrain类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap