示例#1
0
func main() {
	blas.PanicOnError(true)
	matrix.PanicOnError(true)

	var data *matrix.FloatMatrix = nil
	flag.Parse()
	if len(dataVal) > 0 {
		data, _ = matrix.FloatParse(dataVal)
		if data == nil {
			fmt.Printf("could not parse:\n%s\n", dataVal)
			return
		}
	} else {
		data = matrix.FloatNormal(20, 20)
	}

	if len(spPath) > 0 {
		checkpnt.Reset(spPath)
		checkpnt.Activate()
		checkpnt.Verbose(spVerbose)
		checkpnt.Format("%.7f")
	}

	sol, err := mcsdp(data)
	if sol != nil && sol.Status == cvx.Optimal {
		x := sol.Result.At("x")[0]
		z := sol.Result.At("z")[0]
		matrix.Reshape(z, data.Rows(), data.Rows())
		fmt.Printf("x=\n%v\n", x.ToString("%.9f"))
		//fmt.Printf("z=\n%v\n", z.ToString("%.9f"))
		check(x, z)
	} else {
		fmt.Printf("status: %v\n", err)
	}
}
示例#2
0
func main() {

	var A, b *matrix.FloatMatrix = nil, nil
	m, n := 20, 20

	blas.PanicOnError(true)
	matrix.PanicOnError(true)

	flag.Parse()
	if len(spPath) > 0 {
		checkpnt.Reset(spPath)
		checkpnt.Activate()
		checkpnt.Verbose(spVerbose)
		checkpnt.Format("%.17f")
	}
	if len(AVal) > 0 {
		A, _ = matrix.FloatParse(AVal)
		if A == nil {
			fmt.Printf("could not parse:\n%s\n", AVal)
			return
		}
	} else {
		A = matrix.FloatNormal(m, n)
	}
	if len(bVal) > 0 {
		b, _ = matrix.FloatParse(bVal)
		if b == nil {
			fmt.Printf("could not parse:\n%s\n", bVal)
			return
		}
	} else {
		b = matrix.FloatNormal(m, 1)
	}

	sol, err := qcl1(A, b)
	if sol != nil {
		r := sol.Result.At("x")[0]
		x := matrix.FloatVector(r.FloatArray()[:A.Cols()])
		r = sol.Result.At("z")[0]
		z := matrix.FloatVector(r.FloatArray()[r.NumElements()-A.Rows():])
		fmt.Printf("x=\n%v\n", x.ToString("%.9f"))
		fmt.Printf("z=\n%v\n", z.ToString("%.9f"))
		check(x, z)
	} else {
		fmt.Printf("status: %v\n", err)
	}
}