예제 #1
0
파일: ReliabFORM.go 프로젝트: cpmech/goga
func solve_problem(fnkey string, problem int) (opt *goga.Optimiser) {

	// GA parameters
	opt = new(goga.Optimiser)
	opt.Default()

	// options for report
	opt.RptFmtF = "%.4f"
	opt.RptFmtX = "%.3f"
	opt.RptFmtFdev = "%.1e"
	opt.RptWordF = "\\beta"
	opt.HistFmt = "%.2f"
	opt.HistNdig = 3
	opt.HistDelFmin = 0.005
	opt.HistDelFmax = 0.005

	// FORM data
	var lsft LSF_T
	var vars rnd.Variables

	// simple problem or FEM sim
	if fnkey == "simple" {
		opt.Read("ga-simple.json")
		opt.ProbNum = problem
		lsft, vars = get_simple_data(opt)
		fnkey += io.Sf("-%d", opt.ProbNum)
		io.Pf("\n----------------------------------- simple problem %d --------------------------------\n", opt.ProbNum)
	} else {
		opt.Read("ga-" + fnkey + ".json")
		lsft, vars = get_femsim_data(opt, fnkey)
		io.Pf("\n----------------------------------- femsim %s --------------------------------\n", fnkey)
	}

	// set limits
	nx := len(vars)
	opt.FltMin = make([]float64, nx)
	opt.FltMax = make([]float64, nx)
	for i, dat := range vars {
		opt.FltMin[i] = dat.Min
		opt.FltMax[i] = dat.Max
	}

	// log input
	var buf bytes.Buffer
	io.Ff(&buf, "%s", opt.LogParams())
	io.WriteFileVD("/tmp/gosl", fnkey+".log", &buf)

	// initialise distributions
	err := vars.Init()
	if err != nil {
		chk.Panic("cannot initialise distributions:\n%v", err)
	}

	// plot distributions
	if opt.PlotSet1 {
		io.Pf(". . . . . . . .  plot distributions  . . . . . . . .\n")
		np := 201
		for i, dat := range vars {
			plt.SetForEps(0.75, 250)
			dat.PlotPdf(np, "'b-',lw=2,zorder=1000")
			//plt.AxisXrange(dat.Min, dat.Max)
			plt.SetXnticks(15)
			plt.SaveD("/tmp/sims", io.Sf("distr-%s-%d.eps", fnkey, i))
		}
		return
	}

	// objective function
	nf := 1
	var ng, nh int
	var fcn goga.MinProb_t
	var obj goga.ObjFunc_t
	switch opt.Strategy {

	// argmin_x{ β(y(x)) | lsf(x) ≤ 0 }
	//  f ← sqrt(y dot y)
	//  g ← -lsf(x) ≥ 0
	//  h ← out-of-range in case Transform fails
	case 0:
		ng, nh = 1, 1
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {

			// original and normalised variables
			h[0] = 0
			y, invalid := vars.Transform(x)
			if invalid {
				h[0] = 1
				return
			}

			// objective value
			f[0] = math.Sqrt(la.VecDot(y, y)) // β

			// inequality constraint
			lsf, failed := lsft(x, cpu)
			g[0] = -lsf
			h[0] = failed
		}

	// argmin_x{ β(y(x)) | lsf(x) = 0 }
	//  f  ← sqrt(y dot y)
	//  h0 ← lsf(x)
	//  h1 ← out-of-range in case Transform fails
	case 1:
		ng, nh = 0, 2
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {

			// original and normalised variables
			h[0], h[1] = 0, 0
			y, invalid := vars.Transform(x)
			if invalid {
				h[0], h[1] = 1, 1
				return
			}

			// objective value
			f[0] = math.Sqrt(la.VecDot(y, y)) // β

			// equality constraint
			lsf, failed := lsft(x, cpu)
			h[0] = lsf
			h[1] = failed

			// induce minmisation of h0
			//f[0] += math.Abs(lsf)
		}

	case 2:
		opt.Nova = 1
		opt.Noor = 2
		obj = func(sol *goga.Solution, cpu int) {

			// clear out-of-range values
			sol.Oor[0] = 0 // invalid transformation or FEM failed
			sol.Oor[1] = 0 // g(x) ≤ 0 was violated

			// original and normalised variables
			x := sol.Flt
			y, invalid := vars.Transform(x)
			if invalid {
				sol.Oor[0] = goga.INF
				sol.Oor[1] = goga.INF
				return
			}

			// objective value
			sol.Ova[0] = math.Sqrt(la.VecDot(y, y)) // β

			// inequality constraint
			lsf, failed := lsft(x, cpu)
			sol.Oor[0] = failed
			sol.Oor[1] = fun.Ramp(lsf)
		}

	default:
		chk.Panic("strategy %d is not available", opt.Strategy)
	}

	// initialise optimiser
	opt.Init(goga.GenTrialSolutions, obj, fcn, nf, ng, nh)

	// solve
	io.Pf(". . . . . . . .  running  . . . . . . . .\n")
	opt.RunMany("", "")
	goga.StatF(opt, 0, true)
	io.Pfblue2("Tsys = %v\n", opt.SysTimeAve)

	// check
	goga.CheckFront0(opt, true)

	// results
	sols := goga.GetFeasible(opt.Solutions)
	if len(sols) > 0 {
		goga.SortByOva(sols, 0)
		best := sols[0]
		io.Pforan("x    = %.6f\n", best.Flt)
		io.Pforan("xref = %.6f\n", opt.RptXref)
		io.Pforan("β = %v  (%v)\n", best.Ova[0], opt.RptFref[0])
	}
	return
}
예제 #2
0
파일: topology.go 프로젝트: cpmech/goga
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
	ia, ib, ic, id, ie := 0, 0, 0, 0, 0
	nfront0 := len(front0)
	io.Pforan("nfront0 = %v\n", nfront0)
	if nfront0 > 4 {
		ib = nfront0 / 10
		ic = nfront0 / 5
		id = nfront0 / 2
		ie = nfront0 - 1
	}
	A := front0[ia]
	B := front0[ib]
	C := front0[ic]
	D := front0[id]
	E := front0[ie]
	wid, hei := 0.20, 0.10
	draw_truss(data[0], "A", A, 0.17, 0.75, wid, hei)
	draw_truss(data[0], "B", B, 0.20, 0.55, wid, hei)
	draw_truss(data[0], "C", C, 0.28, 0.33, wid, hei)
	draw_truss(data[0], "D", D, 0.47, 0.22, wid, hei)
	draw_truss(data[0], "E", E, 0.70, 0.18, wid, hei)

	// save figure
	plt.SaveD("/tmp/goga", fnkey+".eps")

	// tex file
	title := "Shape and topology optimisation. Results."
	label := "topoFront"
	document := true
	compact := true
	tex_results("/tmp/goga", "tmp_"+fnkey, title, label, data[0], A, B, C, D, E, document, compact)
	document = false
	tex_results("/tmp/goga", fnkey, title, label, data[0], A, B, C, D, E, document, compact)
	return
}
예제 #3
0
파일: three-obj.go 프로젝트: cpmech/goga
func solve_problem(problem int) (opt *goga.Optimiser) {

	io.Pf("\n\n------------------------------------- problem = %d ---------------------------------------\n", problem)

	// GA parameters
	opt = new(goga.Optimiser)
	opt.Default()
	opt.Nsol = 200
	opt.Ncpu = 5
	opt.Tf = 500
	opt.Nsamples = 2
	opt.DEC = 0.01

	// options for report
	opt.HistNsta = 6
	opt.HistLen = 13
	opt.RptFmtE = "%.4e"
	opt.RptFmtL = "%.4e"
	opt.RptFmtEdev = "%.3e"
	opt.RptFmtLdev = "%.3e"
	opt.RptFmin = make([]float64, 3)
	opt.RptFmax = make([]float64, 3)
	for i := 0; i < 3; i++ {
		opt.RptFmax[i] = 1
	}

	// problem variables
	var αcone float64        // cone half-opening angle
	var nf, ng, nh int       // number of functions
	var fcn goga.MinProb_t   // functions
	var plot_solution func() // plot solution in 3D

	// problems
	switch problem {

	// DTLZ1
	case 1:
		opt.RptName = "DTLZ1"
		opt.FltMin = make([]float64, 7)
		opt.FltMax = make([]float64, 7)
		for i := 0; i < 7; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		nf, ng, nh = 3, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			c := 5.0
			for i := 2; i < 7; i++ {
				c += math.Pow((x[i]-0.5), 2.0) - math.Cos(20.0*PI*(x[i]-0.5))
			}
			c *= 100.0
			f[0] = 0.5 * x[0] * x[1] * (1.0 + c)
			f[1] = 0.5 * x[0] * (1.0 - x[1]) * (1.0 + c)
			f[2] = 0.5 * (1.0 - x[0]) * (1.0 + c)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return f[0] + f[1] + f[2] - 0.5
		}
		plot_solution = func() { plot_plane(false) }
		opt.RptFmax = []float64{0.5, 0.5, 0.5}

	// DTLZ2
	case 2:
		opt.RptName = "DTLZ2"
		opt.FltMin = make([]float64, 12)
		opt.FltMax = make([]float64, 12)
		for i := 0; i < 12; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		nf, ng, nh = 3, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			var c float64
			for i := 2; i < 12; i++ {
				c += math.Pow((x[i] - 0.5), 2.0)
			}
			f[0] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Cos(x[1]*PI/2.0)
			f[1] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Sin(x[1]*PI/2.0)
			f[2] = (1.0 + c) * math.Sin(x[0]*PI/2.0)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return f[0]*f[0] + f[1]*f[1] + f[2]*f[2] - 1.0
		}
		plot_solution = func() { plot_sphere(false) }

	// DTLZ3
	case 3:
		opt.RptName = "DTLZ3"
		opt.FltMin = make([]float64, 12)
		opt.FltMax = make([]float64, 12)
		for i := 0; i < 12; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		nf, ng, nh = 3, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			c := 10.0
			for i := 2; i < 12; i++ {
				c += math.Pow((x[i]-0.5), 2.0) - math.Cos(20.0*PI*(x[i]-0.5))
			}
			c *= 100.0
			f[0] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Cos(x[1]*PI/2.0)
			f[1] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Sin(x[1]*PI/2.0)
			f[2] = (1.0 + c) * math.Sin(x[0]*PI/2.0)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return f[0]*f[0] + f[1]*f[1] + f[2]*f[2] - 1.0
		}
		plot_solution = func() { plot_sphere(false) }

	// DTLZ4
	case 4:
		opt.RptName = "DTLZ4"
		opt.FltMin = make([]float64, 12)
		opt.FltMax = make([]float64, 12)
		for i := 0; i < 12; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		nf, ng, nh = 3, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			var c float64
			for i := 2; i < 12; i++ {
				c += math.Pow((x[i] - 0.5), 2.0)
			}
			a := 100.0
			f[0] = (1.0 + c) * math.Cos(math.Pow(x[0], a)*PI/2.0) * math.Cos(math.Pow(x[1], a)*PI/2.0)
			f[1] = (1.0 + c) * math.Cos(math.Pow(x[0], a)*PI/2.0) * math.Sin(math.Pow(x[1], a)*PI/2.0)
			f[2] = (1.0 + c) * math.Sin(math.Pow(x[0], a)*PI/2.0)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return f[0]*f[0] + f[1]*f[1] + f[2]*f[2] - 1.0
		}
		plot_solution = func() { plot_sphere(false) }

	// DTLZ2x (convex)
	case 5:
		opt.RptName = "DTLZ2x"
		opt.FltMin = make([]float64, 12)
		opt.FltMax = make([]float64, 12)
		for i := 0; i < 12; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		nf, ng, nh = 3, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			var c float64
			for i := 2; i < 12; i++ {
				c += math.Pow((x[i] - 0.5), 2.0)
			}
			f[0] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Cos(x[1]*PI/2.0)
			f[1] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Sin(x[1]*PI/2.0)
			f[2] = (1.0 + c) * math.Sin(x[0]*PI/2.0)
			f[0] = math.Pow(f[0], 4.0)
			f[1] = math.Pow(f[1], 4.0)
			f[2] = math.Pow(f[2], 2.0)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return math.Pow(math.Abs(f[0]), 0.5) + math.Pow(math.Abs(f[1]), 0.5) + f[2] - 1.0
		}
		plot_solution = func() { plot_convex(1.0, false) }

	// DTLZ2c (constraint)
	case 6:
		opt.RptName = "DTLZ2c"
		opt.FltMin = make([]float64, 12)
		opt.FltMax = make([]float64, 12)
		for i := 0; i < 12; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		nf, ng, nh = 3, 1, 0
		//αcone = math.Atan(1.0 / SQ2) // <<< touches lower plane
		//αcone = PI/2.0 - αcone // <<< touches upper plane
		αcone = 15.0 * PI / 180.0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			var c float64
			for i := 2; i < 12; i++ {
				c += math.Pow((x[i] - 0.5), 2.0)
			}
			f[0] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Cos(x[1]*PI/2.0)
			f[1] = (1.0 + c) * math.Cos(x[0]*PI/2.0) * math.Sin(x[1]*PI/2.0)
			f[2] = (1.0 + c) * math.Sin(x[0]*PI/2.0)
			g[0] = math.Tan(αcone) - cone_angle(f)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return f[0]*f[0] + f[1]*f[1] + f[2]*f[2] - 1.0
		}
		plot_solution = func() {
			plot_sphere(false)
			plot_cone(αcone, true)
		}

	// Superquadric 1
	case 7:
		opt.RptName = "SUQ1"
		opt.FltMin = make([]float64, 12)
		opt.FltMax = make([]float64, 12)
		for i := 0; i < 12; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		a, b, c := 0.5, 0.5, 0.5
		A, B, C := 2.0/a, 2.0/b, 2.0/c
		nf, ng, nh = 3, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			var c float64
			for i := 2; i < 12; i++ {
				c += math.Pow((x[i] - 0.5), 2.0)
			}
			f[0] = (1.0 + c) * cosX(x[0]*PI/2.0, A) * cosX(x[1]*PI/2.0, A)
			f[1] = (1.0 + c) * cosX(x[0]*PI/2.0, B) * sinX(x[1]*PI/2.0, B)
			f[2] = (1.0 + c) * sinX(x[0]*PI/2.0, C)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return math.Pow(math.Abs(f[0]), a) + math.Pow(math.Abs(f[1]), b) + math.Pow(math.Abs(f[2]), c) - 1.0
		}
		plot_solution = func() { plot_superquadric(a, b, c, false) }

	// Superquadric 2
	case 8:
		opt.RptName = "SUQ2"
		opt.FltMin = make([]float64, 12)
		opt.FltMax = make([]float64, 12)
		for i := 0; i < 12; i++ {
			opt.FltMin[i], opt.FltMax[i] = 0, 1
		}
		a, b, c := 2.0, 1.0, 0.5
		A, B, C := 2.0/a, 2.0/b, 2.0/c
		nf, ng, nh = 3, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			var c float64
			for i := 2; i < 12; i++ {
				c += math.Pow((x[i] - 0.5), 2.0)
			}
			f[0] = (1.0 + c) * cosX(x[0]*PI/2.0, A) * cosX(x[1]*PI/2.0, A)
			f[1] = (1.0 + c) * cosX(x[0]*PI/2.0, B) * sinX(x[1]*PI/2.0, B)
			f[2] = (1.0 + c) * sinX(x[0]*PI/2.0, C)
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return math.Pow(math.Abs(f[0]), a) + math.Pow(math.Abs(f[1]), b) + math.Pow(math.Abs(f[2]), c) - 1.0
		}
		plot_solution = func() { plot_superquadric(a, b, c, false) }

	default:
		chk.Panic("problem %d is not available", problem)
	}

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

	// solve
	opt.RunMany("", "")
	goga.StatMulti(opt, true)

	// check
	goga.CheckFront0(opt, true)

	// print results
	if false {
		goga.SortByOva(opt.Solutions, 0)
		m, l := opt.Nsol/2, opt.Nsol-1
		A, B, C := opt.Solutions[0], opt.Solutions[m], opt.Solutions[l]
		io.Pforan("A = %v\n", A.Flt)
		io.Pforan("B = %v\n", B.Flt)
		io.Pforan("C = %v\n", C.Flt)
	}

	// plot results
	if false {
		py_plot3(0, 1, nf-1, opt, plot_solution, true, true)
	}

	// vtk
	if false {
		ptRad := 0.015
		if opt.RptName == "DTLZ1" {
			ptRad = 0.01
		}
		vtk_plot3(opt, αcone, ptRad, true, true)
	}

	// star plot
	if false {
		plt.SetForEps(1, 300)
		goga.PlotStar(opt)
		plt.SaveD("/tmp/goga", io.Sf("starplot_%s.eps", opt.RptName))
	}

	// write all results
	if false {
		goga.WriteAllValues("/tmp/goga", "res_three-obj", opt)
	}
	return
}
예제 #4
0
파일: two-obj.go 프로젝트: cpmech/goga
func solve_problem(problem int) (opt *goga.Optimiser) {

	io.Pf("\n\n------------------------------------- problem = %d ---------------------------------------\n", problem)

	// parameters
	opt = new(goga.Optimiser)
	opt.Default()
	opt.Ncpu = 1
	opt.Tf = 500
	opt.Verbose = false
	opt.Nsamples = 2
	opt.GenType = "latin"
	opt.DEC = 0.1

	// options for report
	opt.HistNsta = 6
	opt.HistLen = 13
	opt.RptFmtE = "%.4e"
	opt.RptFmtL = "%.4e"
	opt.RptFmtEdev = "%.3e"
	opt.RptFmtLdev = "%.3e"

	// problem variables
	var fmin, fmax []float64
	var nf, ng, nh int
	var fcn goga.MinProb_t

	// problems
	switch problem {

	// problem # 1 -- ZDT1, Deb 2001, p356
	case 1:
		opt.Ncpu = 6
		opt.RptName = "ZDT1"
		n := 30
		opt.FltMin = make([]float64, n)
		opt.FltMax = make([]float64, n)
		for i := 0; i < n; i++ {
			opt.FltMin[i] = 0
			opt.FltMax[i] = 1
		}
		nf, ng, nh = 2, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			f[0] = x[0]
			sum := 0.0
			for i := 1; i < n; i++ {
				sum += x[i]
			}
			c0 := 1.0 + 9.0*sum/float64(n-1)
			c1 := 1.0 - math.Sqrt(f[0]/c0)
			f[1] = c0 * c1
		}
		fmin = []float64{0, 0}
		fmax = []float64{1, 1}
		opt.F1F0_func = func(f0 float64) float64 {
			return 1.0 - math.Sqrt(f0)
		}
		// arc length = sqrt(5)/2 + log(sqrt(5)+2)/4 ≈ 1.4789428575445975
		opt.F1F0_arcLenRef = math.Sqrt(5.0)/2.0 + math.Log(math.Sqrt(5.0)+2.0)/4.0

	// problem # 2 -- ZDT2, Deb 2001, p356
	case 2:
		opt.Ncpu = 6
		opt.RptName = "ZDT2"
		n := 30
		opt.FltMin = make([]float64, n)
		opt.FltMax = make([]float64, n)
		for i := 0; i < n; i++ {
			opt.FltMin[i] = 0
			opt.FltMax[i] = 1
		}
		nf, ng, nh = 2, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			f[0] = x[0]
			sum := 0.0
			for i := 1; i < n; i++ {
				sum += x[i]
			}
			c0 := 1.0 + 9.0*sum/float64(n-1)
			c1 := 1.0 - math.Pow(f[0]/c0, 2.0)
			f[1] = c0 * c1
		}
		fmin = []float64{0, 0}
		fmax = []float64{1, 1}
		opt.F1F0_func = func(f0 float64) float64 {
			return 1.0 - math.Pow(f0, 2.0)
		}
		// arc length = sqrt(5)/2 + log(sqrt(5)+2)/4 ≈ 1.4789428575445975
		opt.F1F0_arcLenRef = math.Sqrt(5.0)/2.0 + math.Log(math.Sqrt(5.0)+2.0)/4.0

	// problem # 3 -- ZDT3, Deb 2001, p356
	case 3:
		opt.Ncpu = 6
		opt.RptName = "ZDT3"
		n := 30
		opt.FltMin = make([]float64, n)
		opt.FltMax = make([]float64, n)
		for i := 0; i < n; i++ {
			opt.FltMin[i] = 0
			opt.FltMax[i] = 1
		}
		nf, ng, nh = 2, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			f[0] = x[0]
			sum := 0.0
			for i := 1; i < n; i++ {
				sum += x[i]
			}
			c0 := 1.0 + 9.0*sum/float64(n-1)
			c1 := 1.0 - math.Sqrt(f[0]/c0) - math.Sin(10.0*math.Pi*f[0])*f[0]/c0
			f[1] = c0 * c1
		}
		fmin = []float64{0, -1}
		fmax = []float64{1, 1}
		opt.F1F0_func = func(f0 float64) float64 {
			return 1.0 - math.Sqrt(f0) - math.Sin(10.0*math.Pi*f0)*f0
		}
		opt.F1F0_f0ranges = [][]float64{
			{0.000000100000000, 0.083001534925223},
			{0.182228728029413, 0.257762363387862},
			{0.409313674808657, 0.453882104088830},
			{0.618396794416602, 0.652511703804663},
			{0.823331798326633, 0.851832865436414},
		}
		opt.F1F0_arcLenRef = 1.811

	// problem # 4 -- ZDT4, Deb 2001, p358
	case 4:
		opt.Ncpu = 2
		opt.RptName = "ZDT4"
		n := 10
		opt.FltMin = make([]float64, n)
		opt.FltMax = make([]float64, n)
		opt.FltMin[0] = 0
		opt.FltMax[0] = 1
		for i := 1; i < n; i++ {
			opt.FltMin[i] = -5
			opt.FltMax[i] = 5
		}
		nf, ng, nh = 2, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			f[0] = x[0]
			sum := 0.0
			w := 4.0 * math.Pi
			for i := 1; i < n; i++ {
				sum += x[i]*x[i] - 10.0*math.Cos(w*x[i])
			}
			c0 := 1.0 + 10.0*float64(n-1) + sum
			c1 := 1.0 - math.Sqrt(f[0]/c0)
			f[1] = c0 * c1
		}
		fmin = []float64{0, 0}
		fmax = []float64{1, 1}
		opt.F1F0_func = func(f0 float64) float64 {
			return 1.0 - math.Sqrt(f0)
		}
		// arc length = sqrt(5)/2 + log(sqrt(5)+2)/4 ≈ 1.4789428575445975
		opt.F1F0_arcLenRef = math.Sqrt(5.0)/2.0 + math.Log(math.Sqrt(5.0)+2.0)/4.0

	// problem # 5 -- FON (Fonseca and Fleming 1995), Deb 2001, p339
	case 5:
		opt.DEC = 0.8
		opt.Ncpu = 2
		opt.RptName = "FON"
		n := 10
		opt.FltMin = make([]float64, n)
		opt.FltMax = make([]float64, n)
		for i := 0; i < n; i++ {
			opt.FltMin[i] = -4
			opt.FltMax[i] = 4
		}
		nf, ng, nh = 2, 0, 0
		coef := 1.0 / math.Sqrt(float64(n))
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			sum0, sum1 := 0.0, 0.0
			for i := 0; i < n; i++ {
				sum0 += math.Pow(x[i]-coef, 2.0)
				sum1 += math.Pow(x[i]+coef, 2.0)
			}
			f[0] = 1.0 - math.Exp(-sum0)
			f[1] = 1.0 - math.Exp(-sum1)
		}
		fmin = []float64{0, 0}
		fmax = []float64{0.98, 1}
		opt.F1F0_func = func(f0 float64) float64 {
			return 1.0 - math.Exp(-math.Pow(2.0-math.Sqrt(-math.Log(1.0-f0)), 2.0))
		}
		opt.F1F0_arcLenRef = 1.45831385

	// problem # 6 -- ZDT6, Deb 2001, p360
	case 6:
		opt.Ncpu = 2
		opt.RptName = "ZDT6"
		n := 10
		opt.FltMin = make([]float64, n)
		opt.FltMax = make([]float64, n)
		for i := 0; i < n; i++ {
			opt.FltMin[i] = 0
			opt.FltMax[i] = 1
		}
		nf, ng, nh = 2, 0, 0
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			w := 6.0 * math.Pi
			f[0] = 1.0 - math.Exp(-4.0*x[0])*math.Pow(math.Sin(w*x[0]), 6.0)
			sum := 0.0
			for i := 1; i < n; i++ {
				sum += x[i]
			}
			w = float64(n - 1)
			c0 := 1.0 + 9.0*math.Pow(sum/w, 0.25)
			c1 := 1.0 - math.Pow(f[0]/c0, 2.0)
			f[1] = c0 * c1
		}
		opt.F1F0_func = func(f0 float64) float64 {
			return 1.0 - math.Pow(f0, 2.0)
		}
		xs := math.Atan(9.0*math.Pi) / (6.0 * math.Pi)
		f0min := 1.0 - math.Exp(-4.0*xs)*math.Pow(math.Sin(6.0*math.Pi*xs), 6.0)
		f1max := opt.F1F0_func(f0min)
		io.Pforan("xs=%v f0min=%v f1max=%v\n", xs, f0min, f1max)
		// xs=0.08145779687998356 f0min=0.2807753188153699 f1max=0.9211652203441274
		fmin = []float64{f0min, 0}
		fmax = []float64{1, 1}
		opt.F1F0_arcLenRef = 1.184

	default:
		chk.Panic("problem %d is not available", problem)
	}

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

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

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

	// solve
	opt.RunMany("", "")
	goga.StatF1F0(opt, true)

	// check
	goga.CheckFront0(opt, true)

	// plot
	if true {
		feasibleOnly := true
		plt.SetForEps(0.8, 300)
		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)
		np := 201
		F0 := utl.LinSpace(fmin[0], fmax[0], np)
		F1 := make([]float64, np)
		for i := 0; i < np; i++ {
			F1[i] = opt.F1F0_func(F0[i])
		}
		plt.Plot(F0, F1, io.Sf("'b-', label='%s'", opt.RptName))
		for _, f0vals := range opt.F1F0_f0ranges {
			f0A, f0B := f0vals[0], f0vals[1]
			f1A, f1B := opt.F1F0_func(f0A), opt.F1F0_func(f0B)
			plt.PlotOne(f0A, f1A, "'g_', mew=1.5, ms=10, clip_on=0")
			plt.PlotOne(f0B, f1B, "'g|', mew=1.5, ms=10, clip_on=0")
		}
		plt.AxisRange(fmin[0], fmax[0], fmin[1], fmax[1])
		plt.Gll("$f_0$", "$f_1$", "")
		plt.SaveD("/tmp/goga", io.Sf("%s.eps", opt.RptName))
	}
	return
}
예제 #5
0
파일: ct-two-obj.go 프로젝트: cpmech/goga
func solve_problem(problem int) (opt *goga.Optimiser) {

	io.Pf("\n\n------------------------------------- problem = %d ---------------------------------------\n", problem)

	// parameters
	opt = new(goga.Optimiser)
	opt.Default()
	opt.Ncpu = 3
	opt.Tf = 500
	opt.Verbose = false
	opt.Nsamples = 1000
	opt.GenType = "latin"
	opt.DEC = 0.1

	// options for report
	opt.HistNsta = 6
	opt.HistLen = 13
	opt.RptFmtE = "%.4e"
	opt.RptFmtL = "%.4e"
	opt.RptFmtEdev = "%.3e"
	opt.RptFmtLdev = "%.3e"

	// problem variables
	nx := 10
	opt.RptName = io.Sf("CTP%d", problem)
	opt.Nsol = 120
	opt.FltMin = make([]float64, nx)
	opt.FltMax = make([]float64, nx)
	for i := 0; i < nx; i++ {
		opt.FltMin[i] = 0
		opt.FltMax[i] = 1
	}
	nf, ng, nh := 2, 1, 0

	// extra problem variables
	var f1max float64
	var fcn goga.MinProb_t
	var extraplot func()

	// problems
	switch problem {

	// problem # 0 -- TNK
	case 0:
		ng = 2
		f1max = 1.21
		opt.RptName = "TNK"
		opt.FltMin = []float64{0, 0}
		opt.FltMax = []float64{PI, PI}
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			f[0] = x[0]
			f[1] = x[1]
			g[0] = x[0]*x[0] + x[1]*x[1] - 1.0 - 0.1*math.Cos(16.0*math.Atan2(x[0], x[1]))
			g[1] = 0.5 - math.Pow(x[0]-0.5, 2.0) - math.Pow(x[1]-0.5, 2.0)
		}
		extraplot = func() {
			np := 301
			X, Y := utl.MeshGrid2D(0, 1.3, 0, 1.3, np, np)
			Z1, Z2, Z3 := utl.DblsAlloc(np, np), utl.DblsAlloc(np, np), utl.DblsAlloc(np, np)
			for j := 0; j < np; j++ {
				for i := 0; i < np; i++ {
					g1 := 0.5 - math.Pow(X[i][j]-0.5, 2.0) - math.Pow(Y[i][j]-0.5, 2.0)
					if g1 >= 0 {
						Z1[i][j] = X[i][j]*X[i][j] + Y[i][j]*Y[i][j] - 1.0 - 0.1*math.Cos(16.0*math.Atan2(Y[i][j], X[i][j]))
					} else {
						Z1[i][j] = -1
					}
					Z2[i][j] = X[i][j]*X[i][j] + Y[i][j]*Y[i][j] - 1.0 - 0.1*math.Cos(16.0*math.Atan2(Y[i][j], X[i][j]))
					Z3[i][j] = g1
				}
			}
			plt.Contour(X, Y, Z1, "levels=[0,2],cbar=0,lwd=0.5,fsz=5,cmapidx=6")
			plt.Text(0.3, 0.95, "0.000", "size=5,rotation=10")
			plt.ContourSimple(X, Y, Z2, false, 7, "linestyles=['-'], linewidths=[0.7], colors=['k'], levels=[0]")
			plt.ContourSimple(X, Y, Z3, false, 7, "linestyles=['-'], linewidths=[1.0], colors=['k'], levels=[0]")
		}
		opt.Multi_fcnErr = func(f []float64) float64 {
			return f[0]*f[0] + f[1]*f[1] - 1.0 - 0.1*math.Cos(16.0*math.Atan2(f[0], f[1]))
		}

	// problem # 1 -- CTP1, Deb 2001, p367, fig 225
	case 1:
		ng = 2
		f1max = 1.0
		a0, b0 := 0.858, 0.541
		a1, b1 := 0.728, 0.295
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			c0 := 1.0
			for i := 1; i < len(x); i++ {
				c0 += x[i]
			}
			f[0] = x[0]
			f[1] = c0 * math.Exp(-x[0]/c0)
			if true {
				g[0] = f[1] - a0*math.Exp(-b0*f[0])
				g[1] = f[1] - a1*math.Exp(-b1*f[0])
			}
		}
		f0a := math.Log(a0) / (b0 - 1.0)
		f1a := math.Exp(-f0a)
		f0b := math.Log(a0/a1) / (b0 - b1)
		f1b := a0 * math.Exp(-b0*f0b)
		opt.Multi_fcnErr = func(f []float64) float64 {
			if f[0] < f0a {
				return f[1] - math.Exp(-f[0])
			}
			if f[0] < f0b {
				return f[1] - a0*math.Exp(-b0*f[0])
			}
			return f[1] - a1*math.Exp(-b1*f[0])
		}
		extraplot = func() {
			np := 201
			X, Y := utl.MeshGrid2D(0, 1, 0, 1, np, np)
			Z := utl.DblsAlloc(np, np)
			for j := 0; j < np; j++ {
				for i := 0; i < np; i++ {
					Z[i][j] = opt.Multi_fcnErr([]float64{X[i][j], Y[i][j]})
				}
			}
			plt.Contour(X, Y, Z, "levels=[0,0.6],cbar=0,lwd=0.5,fsz=5,cmapidx=6")
			F0 := utl.LinSpace(0, 1, 21)
			F1r := make([]float64, len(F0))
			F1s := make([]float64, len(F0))
			F1t := make([]float64, len(F0))
			for i, f0 := range F0 {
				F1r[i] = math.Exp(-f0)
				F1s[i] = a0 * math.Exp(-b0*f0)
				F1t[i] = a1 * math.Exp(-b1*f0)
			}
			plt.Plot(F0, F1r, "'k--',color='blue'")
			plt.Plot(F0, F1s, "'k--',color='green'")
			plt.Plot(F0, F1t, "'k--',color='gray'")
			plt.PlotOne(f0a, f1a, "'k|', ms=20")
			plt.PlotOne(f0b, f1b, "'k|', ms=20")
		}

	// problem # 2 -- CTP2, Deb 2001, p368/369, fig 226
	case 2:
		f1max = 1.2
		θ, a, b := -0.2*PI, 0.2, 10.0
		c, d, e := 1.0, 6.0, 1.0
		fcn = CTPgenerator(θ, a, b, c, d, e)
		extraplot = CTPplotter(θ, a, b, c, d, e, f1max)
		opt.Multi_fcnErr = CTPerror1(θ, a, b, c, d, e)

	// problem # 3 -- CTP3, Deb 2001, p368/370, fig 227
	case 3:
		f1max = 1.2
		θ, a, b := -0.2*PI, 0.1, 10.0
		c, d, e := 1.0, 0.5, 1.0
		fcn = CTPgenerator(θ, a, b, c, d, e)
		extraplot = CTPplotter(θ, a, b, c, d, e, f1max)
		opt.Multi_fcnErr = CTPerror1(θ, a, b, c, d, e)

	// problem # 4 -- CTP4, Deb 2001, p368/370, fig 228
	case 4:
		f1max = 2.0
		θ, a, b := -0.2*PI, 0.75, 10.0
		c, d, e := 1.0, 0.5, 1.0
		fcn = CTPgenerator(θ, a, b, c, d, e)
		extraplot = CTPplotter(θ, a, b, c, d, e, f1max)
		opt.Multi_fcnErr = CTPerror1(θ, a, b, c, d, e)

	// problem # 5 -- CTP5, Deb 2001, p368/371, fig 229
	case 5:
		f1max = 1.2
		θ, a, b := -0.2*PI, 0.1, 10.0
		c, d, e := 2.0, 0.5, 1.0
		fcn = CTPgenerator(θ, a, b, c, d, e)
		extraplot = CTPplotter(θ, a, b, c, d, e, f1max)
		opt.Multi_fcnErr = CTPerror1(θ, a, b, c, d, e)

	// problem # 6 -- CTP6, Deb 2001, p368/372, fig 230
	case 6:
		f1max = 5.0
		θ, a, b := 0.1*PI, 40.0, 0.5
		c, d, e := 1.0, 2.0, -2.0
		fcn = CTPgenerator(θ, a, b, c, d, e)
		extraplot = func() {
			np := 201
			X, Y := utl.MeshGrid2D(0, 1, 0, 20, np, np)
			Z := utl.DblsAlloc(np, np)
			for j := 0; j < np; j++ {
				for i := 0; i < np; i++ {
					Z[i][j] = CTPconstraint(θ, a, b, c, d, e, X[i][j], Y[i][j])
				}
			}
			plt.Contour(X, Y, Z, "levels=[-30,-15,0,15,30],cbar=0,lwd=0.5,fsz=5,cmapidx=6")
		}
		opt.Multi_fcnErr = CTPerror1(θ, a, b, c, d, e)

	// problem # 7 -- CTP7, Deb 2001, p368/373, fig 231
	case 7:
		f1max = 1.2
		θ, a, b := -0.05*PI, 40.0, 5.0
		c, d, e := 1.0, 6.0, 0.0
		fcn = CTPgenerator(θ, a, b, c, d, e)
		opt.Multi_fcnErr = func(f []float64) float64 { return f[1] - (1.0 - f[0]) }
		extraplot = func() {
			np := 201
			X, Y := utl.MeshGrid2D(0, 1, 0, f1max, np, np)
			Z1 := utl.DblsAlloc(np, np)
			Z2 := utl.DblsAlloc(np, np)
			for j := 0; j < np; j++ {
				for i := 0; i < np; i++ {
					Z1[i][j] = opt.Multi_fcnErr([]float64{X[i][j], Y[i][j]})
					Z2[i][j] = CTPconstraint(θ, a, b, c, d, e, X[i][j], Y[i][j])
				}
			}
			plt.Contour(X, Y, Z2, "levels=[0,3],cbar=0,lwd=0.5,fsz=5,cmapidx=6")
			plt.ContourSimple(X, Y, Z1, false, 7, "linestyles=['--'], linewidths=[0.7], colors=['b'], levels=[0]")
		}

	// problem # 8 -- CTP8, Deb 2001, p368/373, fig 232
	case 8:
		ng = 2
		f1max = 5.0
		θ1, a, b := 0.1*PI, 40.0, 0.5
		c, d, e := 1.0, 2.0, -2.0
		θ2, A, B := -0.05*PI, 40.0, 2.0
		C, D, E := 1.0, 6.0, 0.0
		sin1, cos1 := math.Sin(θ1), math.Cos(θ1)
		sin2, cos2 := math.Sin(θ2), math.Cos(θ2)
		fcn = func(f, g, h, x []float64, ξ []int, cpu int) {
			c0 := 1.0
			for i := 1; i < len(x); i++ {
				c0 += x[i]
			}
			f[0] = x[0]
			f[1] = c0 * (1.0 - f[0]/c0)
			if true {
				c1 := cos1*(f[1]-e) - sin1*f[0]
				c2 := sin1*(f[1]-e) + cos1*f[0]
				c3 := math.Sin(b * PI * math.Pow(c2, c))
				g[0] = c1 - a*math.Pow(math.Abs(c3), d)
				d1 := cos2*(f[1]-E) - sin2*f[0]
				d2 := sin2*(f[1]-E) + cos2*f[0]
				d3 := math.Sin(B * PI * math.Pow(d2, C))
				g[1] = d1 - A*math.Pow(math.Abs(d3), D)
			}
		}
		extraplot = func() {
			np := 401
			X, Y := utl.MeshGrid2D(0, 1, 0, 20, np, np)
			Z1 := utl.DblsAlloc(np, np)
			Z2 := utl.DblsAlloc(np, np)
			Z3 := utl.DblsAlloc(np, np)
			for j := 0; j < np; j++ {
				for i := 0; i < np; i++ {
					c1 := cos1*(Y[i][j]-e) - sin1*X[i][j]
					c2 := sin1*(Y[i][j]-e) + cos1*X[i][j]
					c3 := math.Sin(b * PI * math.Pow(c2, c))
					d1 := cos2*(Y[i][j]-E) - sin2*X[i][j]
					d2 := sin2*(Y[i][j]-E) + cos2*X[i][j]
					d3 := math.Sin(B * PI * math.Pow(d2, C))
					Z1[i][j] = c1 - a*math.Pow(math.Abs(c3), d)
					Z2[i][j] = d1 - A*math.Pow(math.Abs(d3), D)
					if Z1[i][j] >= 0 && Z2[i][j] >= 0 {
						Z3[i][j] = 1
					} else {
						Z3[i][j] = -1
					}
				}
			}
			plt.Contour(X, Y, Z3, "colors=['white','gray'],clabels=0,cbar=0,lwd=0.5,fsz=5")
			plt.ContourSimple(X, Y, Z1, false, 7, "linestyles=['--'], linewidths=[0.7], colors=['gray'], levels=[0]")
			plt.ContourSimple(X, Y, Z2, false, 7, "linestyles=['--'], linewidths=[0.7], colors=['gray'], levels=[0]")
		}
		opt.Multi_fcnErr = CTPerror1(θ1, a, b, c, d, e)

	default:
		chk.Panic("problem %d is not available", problem)
	}

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

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

	// solve
	opt.RunMany("", "")
	goga.StatMulti(opt, true)
	io.PfYel("Tsys = %v\n", opt.SysTime)

	// check
	goga.CheckFront0(opt, true)

	// plot
	if true {
		feasibleOnly := false
		plt.SetForEps(0.8, 300)
		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)
		extraplot()
		//plt.AxisYrange(0, f1max)
		if problem > 0 && problem < 6 {
			plt.Text(0.05, 0.05, "unfeasible", "color='gray', ha='left',va='bottom'")
			plt.Text(0.95, f1max-0.05, "feasible", "color='white', ha='right',va='top'")
		}
		if opt.RptName == "CTP6" {
			plt.Text(0.02, 0.15, "unfeasible", "rotation=-7,color='gray', ha='left',va='bottom'")
			plt.Text(0.02, 6.50, "unfeasible", "rotation=-7,color='gray', ha='left',va='bottom'")
			plt.Text(0.02, 13.0, "unfeasible", "rotation=-7,color='gray', ha='left',va='bottom'")
			plt.Text(0.50, 2.40, "feasible", "rotation=-7,color='white', ha='center',va='bottom'")
			plt.Text(0.50, 8.80, "feasible", "rotation=-7,color='white', ha='center',va='bottom'")
			plt.Text(0.50, 15.30, "feasible", "rotation=-7,color='white', ha='center',va='bottom'")
		}
		if opt.RptName == "TNK" {
			plt.Text(0.05, 0.05, "unfeasible", "color='gray', ha='left',va='bottom'")
			plt.Text(0.80, 0.85, "feasible", "color='white', ha='left',va='top'")
			plt.Equal()
			plt.AxisRange(0, 1.22, 0, 1.22)
		}
		plt.SaveD("/tmp/goga", io.Sf("%s.eps", opt.RptName))
	}
	return
}
예제 #6
0
파일: many-obj.go 프로젝트: cpmech/goga
func solve_problem(problem int) (opt *goga.Optimiser) {

	io.Pf("\n\n------------------------------------- problem = %d ---------------------------------------\n", problem)

	// GA parameters
	opt = new(goga.Optimiser)
	opt.Default()
	opt.Nsol = 300
	opt.Ncpu = 6
	opt.Tf = 500
	opt.Nsamples = 2
	opt.DEC = 0.01

	// options for report
	opt.HistNsta = 6
	opt.HistLen = 13
	opt.RptFmtE = "%.4e"
	opt.RptFmtL = "%.4e"
	opt.RptFmtEdev = "%.3e"
	opt.RptFmtLdev = "%.3e"

	// problem variables
	var nf, ng, nh int     // number of functions
	var fcn goga.MinProb_t // functions

	// problems
	switch problem {
	case 1:
		nf = 5
		opt.RptName = io.Sf("DTLZ2m%d", nf)
		ng, fcn = DTLZ2mGenerator(opt, nf)

	case 2:
		nf = 7
		opt.RptName = io.Sf("DTLZ2m%d", nf)
		ng, fcn = DTLZ2mGenerator(opt, nf)

	case 3:
		nf = 10
		opt.RptName = io.Sf("DTLZ2m%d", nf)
		ng, fcn = DTLZ2mGenerator(opt, nf)

	case 4:
		nf = 13
		opt.RptName = io.Sf("DTLZ2m%d", nf)
		ng, fcn = DTLZ2mGenerator(opt, nf)

	case 5:
		nf = 15
		opt.RptName = io.Sf("DTLZ2m%d", nf)
		ng, fcn = DTLZ2mGenerator(opt, nf)

	case 6:
		nf = 20
		opt.RptName = io.Sf("DTLZ2m%d", nf)
		ng, fcn = DTLZ2mGenerator(opt, nf)

	default:
		chk.Panic("problem %d is not available", problem)
	}

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

	// solve
	opt.RunMany("", "")
	goga.StatMulti(opt, true)

	// check
	goga.CheckFront0(opt, true)

	// star plot
	if true {
		plt.SetForEps(1, 300)
		goga.PlotStar(opt)
		plt.SaveD("/tmp/goga", io.Sf("starplot_%s.eps", opt.RptName))
	}
	return
}
예제 #7
0
파일: mulobj-cec09.go 프로젝트: cpmech/goga
func solve_problem(problem string) (opt *goga.Optimiser) {

	// GA parameters
	opt = new(goga.Optimiser)
	opt.Default()
	opt.RptName = problem
	opt.EpsH = 0.0001
	opt.Nsamples = 1
	opt.Tf = 5000

	// problem data
	opt.FltMin = cec09.Xmin[problem]
	opt.FltMax = cec09.Xmax[problem]
	nx := cec09.Nx[problem]
	nf := cec09.Nf[problem]
	ng := cec09.Nf[problem]
	nh := cec09.Nf[problem]
	chk.IntAssert(nx, len(opt.FltMin))
	chk.IntAssert(nx, len(opt.FltMax))

	// function
	var fcn goga.MinProb_t
	switch problem {
	case "UF1":
		fcn = cec09.UF1
	case "UF2":
		fcn = cec09.UF2
	case "UF3":
		fcn = cec09.UF3
	default:
		chk.Panic("problem %d is not available", problem)
	}

	nx = 3

	// load reference values
	opt.Multi_fStar = cec09.PFdata(problem)

	// number of trial solutions
	opt.Nsol = 600
	opt.Ncpu = 16
	if nf == 3 {
		opt.Nsol = 150
		opt.Ncpu = 3
	}
	if nf > 3 {
		opt.Nsol = 800
		opt.Ncpu = 8
	}

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

	// solve
	opt.RunMany("", "")
	goga.StatMulti(opt, true)

	// check
	goga.CheckFront0(opt, true)

	// plot
	if nf == 2 {
		plot2(opt, true)
	}
	plot3x(opt, false, 0, 1, 2, 0.02)
	return
}