当前位置: 首页>>代码示例>>Golang>>正文


Golang Optimiser.Multi_fcnErr方法代码示例

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


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

示例1: 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

示例2: 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


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