Esempio n. 1
0
func Test_data3d(tst *testing.T) {

	// data
	prob := "CF9"
	dat := PFdata(prob)
	X := utl.DblsGetColumn(0, dat)
	Y := utl.DblsGetColumn(1, dat)
	Z := utl.DblsGetColumn(2, dat)

	// figure
	plt.SetForEps(1.0, 400)
	plt.Plot3dPoints(X, Y, Z, "s=0.05, color='r', facecolor='r', edgecolor='r', xlbl='$f_1$', ylbl='$f_2$', zlbl='$f_3$'")
	plt.AxisRange3d(0, 1, 0, 1, 0, 1)
	plt.Camera(10, -135, "")
	//plt.Camera(10, 45, "")
	plt.SaveD("/tmp/goga", io.Sf("cec09-%s.eps", prob))

	// interactive
	if false {
		r := 0.005
		scn := vtk.NewScene()
		P := vtk.Spheres{X: X, Y: Y, Z: Z, R: utl.DblVals(len(X), r), Color: []float64{1, 0, 0, 1}}
		P.AddTo(scn)
		scn.Run()
	}
}
Esempio n. 2
0
func Test_igd01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("igd. igd metric with star equal to trial => igd=0")

	// load star values
	prob := "UF1"
	fStar, err := io.ReadMatrix(io.Sf("./examples/mulobj-cec09/cec09/pf_data/%s.dat", prob))
	if err != nil {
		tst.Errorf("cannot read fStar matrix:\n%v", err)
		return
	}
	npts := len(fStar)

	// optimiser
	var opt Optimiser
	opt.Default()
	opt.Nsol = npts
	opt.Ncpu = 1
	opt.FltMin = []float64{0, 0} // used to store fStar
	opt.FltMax = []float64{1, 1} // used to store fStar
	nf, ng, nh := 2, 0, 0

	// generator (store fStar into Flt)
	gen := func(sols []*Solution, prms *Parameters) {
		for i, sol := range sols {
			sol.Flt[0], sol.Flt[1] = fStar[i][0], fStar[i][1]
		}
	}

	// objective function (copy fStar from Flt into Ova)
	obj := func(f, g, h, x []float64, ξ []int, cpu int) {
		f[0], f[1] = x[0], x[1]
	}

	// initialise optimiser
	opt.Init(gen, nil, obj, nf, ng, nh)

	// compute igd
	igd := StatIgd(&opt, fStar)
	io.Pforan("igd = %v\n", igd)
	chk.Scalar(tst, "igd", 1e-15, igd, 0)

	// plot
	if chk.Verbose {
		fmt := &plt.Fmt{C: "red", M: ".", Ms: 1, Ls: "None", L: "solutions"}
		fS0 := utl.DblsGetColumn(0, fStar)
		fS1 := utl.DblsGetColumn(1, fStar)
		io.Pforan("len(fS0) = %v\n", len(fS0))
		plt.SetForEps(0.75, 300)
		opt.PlotAddOvaOva(0, 1, opt.Solutions, true, fmt)
		plt.Plot(fS0, fS1, io.Sf("'b.', ms=2, label='star(%s)', clip_on=0", prob))
		plt.Gll("$f_0$", "$f_1$", "")
		plt.SaveD("/tmp/goga", "igd01.eps")
	}
}
Esempio n. 3
0
func Test_data2d(tst *testing.T) {
	prob := "CF4"
	dat := PFdata(prob)
	X := utl.DblsGetColumn(0, dat)
	Y := utl.DblsGetColumn(1, dat)
	plt.SetForEps(1.0, 250)
	plt.Plot(X, Y, "'r.'")
	plt.Gll("$f_1$", "$f_2$", "")
	plt.SaveD("/tmp/goga", io.Sf("cec09-%s.eps", prob))
}
Esempio n. 4
0
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))
}
Esempio n. 5
0
func Test_flt04(tst *testing.T) {

	//verbose()
	chk.PrintTitle("flt04. two-bar truss. Pareto-optimal")

	// configuration
	C := NewConfParams()
	C.Nisl = 4
	C.Ninds = 24
	C.GAtype = "crowd"
	C.DiffEvol = true
	C.CrowdSize = 3
	C.ParetoPhi = 0.05
	C.Tf = 100
	C.Dtmig = 25
	C.RangeFlt = [][]float64{{0.1, 2.25}, {0.5, 2.5}}
	C.PopFltGen = PopFltGen
	C.CalcDerived()
	rnd.Init(C.Seed)

	// data
	// from Coelho (2007) page 19
	ρ := 0.283 // lb/in³
	H := 100.0 // in
	P := 1e4   // lb
	E := 3e7   // lb/in²
	σ0 := 2e4  // lb/in²

	// functions
	TSQ2 := 2.0 * math.Sqrt2
	fcn := func(f, g, h []float64, x []float64) {
		f[0] = 2.0 * ρ * H * x[1] * math.Sqrt(1.0+x[0]*x[0])
		f[1] = P * H * math.Pow(1.0+x[0]*x[0], 1.5) * math.Sqrt(1.0+math.Pow(x[0], 4.0)) / (TSQ2 * E * x[0] * x[0] * x[1])
		g[0] = σ0 - P*(1.0+x[0])*math.Sqrt(1.0+x[0]*x[0])/(TSQ2*x[0]*x[1])
		g[1] = σ0 - P*(1.0-x[0])*math.Sqrt(1.0+x[0]*x[0])/(TSQ2*x[0]*x[1])
	}

	// objective value function
	C.OvaOor = func(ind *Individual, idIsland, t int, report *bytes.Buffer) {
		x := ind.GetFloats()
		f := make([]float64, 2)
		g := make([]float64, 2)
		fcn(f, g, nil, x)
		ind.Ovas[0] = f[0]
		ind.Ovas[1] = f[1]
		ind.Oors[0] = utl.GtePenalty(g[0], 0, 1)
		ind.Oors[1] = utl.GtePenalty(g[1], 0, 1)
	}

	// simple problem
	sim := NewSimpleFltProb(fcn, 2, 2, 0, C)
	sim.Run(chk.Verbose)

	// results
	if chk.Verbose {

		// reference data
		_, dat, _ := io.ReadTable("data/coelho-fig1.6.dat")

		// Pareto-front
		feasible := sim.Evo.GetFeasible()
		ovas, _ := sim.Evo.GetResults(feasible)
		ovafront, _ := sim.Evo.GetParetoFront(feasible, ovas, nil)
		xova, yova := sim.Evo.GetFrontOvas(0, 1, ovafront)

		// plot
		plt.SetForEps(0.75, 355)
		plt.Plot(dat["f1"], dat["f2"], "'k+',ms=3")
		x := utl.DblsGetColumn(0, ovas)
		y := utl.DblsGetColumn(1, ovas)
		plt.Plot(x, y, "'r.'")
		plt.Plot(xova, yova, "'ko',markerfacecolor='none',ms=6")
		plt.Gll("$f_1$", "$f_2$", "")
		plt.SaveD("/tmp/goga", "test_flt04.eps")
	}
}