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 }
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() } }