コード例 #1
0
ファイル: testcvx.go プロジェクト: hrautila/go.opt.old
func makeW() (W *cvx.FloatMatrixSet, err error) {
	var m *matrix.FloatMatrix

	d0_s := "{2 1 [5.277942305425358 5.468379387636596]}"
	di0_s := "{2 1 [0.189467777806527 0.182869535764269]}"
	//dnl0_s  := "{0 1 []}"
	//dnli0_s := "{0 1 []}"
	r0_s := "{3 3 [-2.249267570008489 2.361205104290289 0.913567958765254 -1.925574750121168 -2.172410611043159 0.173946992908080 0.559540271653776 -0.139584324205900 2.348303661399984]}"
	rti0_s := "{3 3 [-0.214383299026403 0.195042904770822 0.062675463930892 -0.239513204273735 -0.244613737625478 0.042529866033816 0.101143782396739 -0.057758767117156 0.398306137924685]}"
	v0_s := "{4 1 [1.114132558182145 0.355030258425681 -0.339080260926309 0.016414915590130]}"
	v1_s := "{4 1 [1.000014508170784 0.003059892342288 0.002220573368109 -0.003837012486999]}"
	beta_s := "{2 1 [2.33309421747982 6.1486663985292]}"

	W = cvx.FloatSetNew("d", "di", "r", "rti", "beta", "v", "dnl", "dnli")
	m, err = matrix.FloatParseSpe(d0_s)
	if err != nil {
		return
	}
	W.Append("d", m)

	m, err = matrix.FloatParseSpe(di0_s)
	if err != nil {
		return
	}
	W.Append("di", m)

	m, err = matrix.FloatParseSpe(r0_s)
	if err != nil {
		return
	}
	W.Append("r", m)

	m, err = matrix.FloatParseSpe(rti0_s)
	if err != nil {
		return
	}
	W.Append("rti", m)

	m, err = matrix.FloatParseSpe(beta_s)
	if err != nil {
		return
	}
	W.Append("beta", m)

	m, err = matrix.FloatParseSpe(v0_s)
	if err != nil {
		return
	}
	W.Append("v", m)

	m, err = matrix.FloatParseSpe(v1_s)
	if err != nil {
		return
	}
	W.Append("v", m)

	return
}
コード例 #2
0
ファイル: testsocp.go プロジェクト: hrautila/go.opt.old
func main() {
	flag.Parse()
	reftest := flag.NFlag() > 0

	gdata0 := [][]float64{
		[]float64{12., 13., 12.},
		[]float64{6., -3., -12.},
		[]float64{-5., -5., 6.}}

	gdata1 := [][]float64{
		[]float64{3., 3., -1., 1.},
		[]float64{-6., -6., -9., 19.},
		[]float64{10., -2., -2., -3.}}

	c := matrix.FloatVector([]float64{-2.0, 1.0, 5.0})
	g0 := matrix.FloatMatrixStacked(gdata0, matrix.ColumnOrder)
	g1 := matrix.FloatMatrixStacked(gdata1, matrix.ColumnOrder)
	Ghq := cvx.FloatSetNew("Gq", "hq")
	Ghq.Append("Gq", g0, g1)

	h0 := matrix.FloatVector([]float64{-12.0, -3.0, -2.0})
	h1 := matrix.FloatVector([]float64{27.0, 0.0, 3.0, -42.0})
	Ghq.Append("hq", h0, h1)

	var Gl, hl, A, b *matrix.FloatMatrix = nil, nil, nil, nil
	var solopts cvx.SolverOptions
	solopts.MaxIter = 30
	solopts.ShowProgress = true
	sol, err := cvx.Socp(c, Gl, hl, A, b, Ghq, &solopts, nil, nil)
	fmt.Printf("status: %v\n", err)
	if sol != nil && sol.Status == cvx.Optimal {
		x := sol.Result.At("x")[0]
		fmt.Printf("x=\n%v\n", x.ToString("%.9f"))
		for i, m := range sol.Result.At("sq") {
			fmt.Printf("sq[%d]=\n%v\n", i, m.ToString("%.9f"))
		}
		for i, m := range sol.Result.At("zq") {
			fmt.Printf("zq[%d]=\n%v\n", i, m.ToString("%.9f"))
		}
		if reftest {
			sq0 := sol.Result.At("sq")[0]
			sq1 := sol.Result.At("sq")[1]
			zq0 := sol.Result.At("zq")[0]
			zq1 := sol.Result.At("zq")[1]
			check(x, sq0, sq1, zq0, zq1)
		}
	}
}
コード例 #3
0
ファイル: testsdp.go プロジェクト: hrautila/go.opt.old
func main() {
	flag.Parse()
	reftest := flag.NFlag() > 0

	gdata0 := [][]float64{
		[]float64{-7., -11., -11., 3.},
		[]float64{7., -18., -18., 8.},
		[]float64{-2., -8., -8., 1.}}

	gdata1 := [][]float64{
		[]float64{-21., -11., 0., -11., 10., 8., 0., 8., 5.},
		[]float64{0., 10., 16., 10., -10., -10., 16., -10., 3.},
		[]float64{-5., 2., -17., 2., -6., 8., -17., -7., 6.}}

	hdata0 := [][]float64{
		[]float64{33., -9.},
		[]float64{-9., 26.}}

	hdata1 := [][]float64{
		[]float64{14., 9., 40.},
		[]float64{9., 91., 10.},
		[]float64{40., 10., 15.}}

	g0 := matrix.FloatMatrixStacked(gdata0, matrix.ColumnOrder)
	g1 := matrix.FloatMatrixStacked(gdata1, matrix.ColumnOrder)
	Ghs := cvx.FloatSetNew("Gs", "hs")
	Ghs.Append("Gs", g0, g1)

	h0 := matrix.FloatMatrixStacked(hdata0, matrix.ColumnOrder)
	h1 := matrix.FloatMatrixStacked(hdata1, matrix.ColumnOrder)
	Ghs.Append("hs", h0, h1)

	c := matrix.FloatVector([]float64{1.0, -1.0, 1.0})
	Ghs.Print()
	fmt.Printf("calling...\n")
	// nil variables
	var Gs, hs, A, b *matrix.FloatMatrix = nil, nil, nil, nil

	var solopts cvx.SolverOptions
	solopts.MaxIter = 30
	solopts.ShowProgress = true
	sol, err := cvx.Sdp(c, Gs, hs, A, b, Ghs, &solopts, nil, nil)
	if sol != nil && sol.Status == cvx.Optimal {
		x := sol.Result.At("x")[0]
		fmt.Printf("x=\n%v\n", x.ToString("%.9f"))
		for i, m := range sol.Result.At("ss") {
			fmt.Printf("ss[%d]=\n%v\n", i, m.ToString("%.9f"))
		}
		for i, m := range sol.Result.At("zs") {
			fmt.Printf("zs[%d]=\n%v\n", i, m.ToString("%.9f"))
		}
		if reftest {
			ss0 := sol.Result.At("ss")[0]
			ss1 := sol.Result.At("ss")[1]
			zs0 := sol.Result.At("zs")[0]
			zs1 := sol.Result.At("zs")[1]
			check(x, ss0, ss1, zs0, zs1)
		}
	} else {
		fmt.Printf("status: %v\n", err)
	}
}