Example #1
0
def testqp(opts):
    A = matrix([ [ .3, -.4,  -.2,  -.4,  1.3 ], 
                 [ .6, 1.2, -1.7,   .3,  -.3 ],
                 [-.3,  .0,   .6, -1.2, -2.0 ] ])
    b = matrix([ 1.5, .0, -1.2, -.7, .0])
    m, n = A.size

    I = matrix(0.0, (n,n))
    I[::n+1] = 1.0
    G = matrix([-I, matrix(0.0, (1,n)), I])
    h = matrix(n*[0.0] + [1.0] + n*[0.0])
    dims = {'l': n, 'q': [n+1], 's': []}
    P = A.T*A
    q = -A.T*b

    #localcones.options.update(opts)
    #sol = localcones.coneqp(P, q, G, h, dims, kktsolver='chol')
    solvers.options.update(opts)
    sol = solvers.coneqp(P, q, G, h, dims)
    if sol['status'] == 'optimal':
        print "x=\n", helpers.strSpe(sol['x'], "%.5f")
        print "s=\n", helpers.strSpe(sol['s'], "%.5f")
        print "z=\n", helpers.strSpe(sol['z'], "%.5f")
        print "\n *** running GO test ***"
        helpers.run_go_test("../testconeqp", {'x': sol['x'], 's': sol['s'], 'z': sol['z']})
Example #2
0
def solve(opts):
    c = matrix([-6., -4., -5.])

    G = matrix([[
        16., 7., 24., -8., 8., -1., 0., -1., 0., 0., 7., -5., 1., -5., 1., -7.,
        1., -7., -4.
    ],
                [
                    -14., 2., 7., -13., -18., 3., 0., 0., -1., 0., 3., 13.,
                    -6., 13., 12., -10., -6., -10., -28.
                ],
                [
                    5., 0., -15., 12., -6., 17., 0., 0., 0., -1., 9., 6., -6.,
                    6., -7., -7., -6., -7., -11.
                ]])
    h = matrix([
        -3., 5., 12., -2., -14., -13., 10., 0., 0., 0., 68., -30., -19., -30.,
        99., 23., -19., 23., 10.
    ])

    A = matrix(0.0, (0, c.size[0]))
    b = matrix(0.0, (0, 1))

    dims = {'l': 2, 'q': [4, 4], 's': [3]}

    #localcones.options.update(opts)
    #sol = localcones.conelp(c, G, h, dims, kktsolver='qr')
    solvers.options.update(opts)
    sol = solvers.conelp(c, G, h, dims)
    print("\nStatus: " + sol['status'])
    if sol['status'] == 'optimal':
        print "x=\n", helpers.strSpe(sol['x'], "%.5f")
        print "s=\n", helpers.strSpe(sol['s'], "%.5f")
        print "z=\n", helpers.strSpe(sol['z'], "%.5f")
        rungotest(sol)
Example #3
0
def testgp(opts):
    Aflr  = 1000.0  
    Awall = 100.0  
    alpha = 0.5  
    beta  = 2.0  
    gamma = 0.5  
    delta = 2.0  
 
    F = matrix( [[-1., 1., 1., 0., -1.,  1.,  0.,  0.],  
                 [-1., 1., 0., 1.,  1., -1.,  1., -1.],  
                 [-1., 0., 1., 1.,  0.,  0., -1.,  1.]])  
    g = log( matrix( [1.0, 2/Awall, 2/Awall, 1/Aflr, alpha, 1/beta, gamma, 
                      1/delta]) )  
    K = [1, 2, 1, 1, 1, 1, 1]  
    solvers.options.update(opts)
    sol = solvers.gp(K, F, g)
    #localcvx.options.update(opts)
    #sol = localcvx.gp(K, F, g, kktsolver='chol')
    if sol['status'] == 'optimal':
        x = sol['x']
        print "x=\n", helpers.strSpe(x, "%.17f")
        h, w, d = exp(x)
        print("\n h = %f,  w = %f, d = %f.\n" %(h,w,d))   
        print "\n *** running GO test ***"
        helpers.run_go_test("../testgp", {'x': x})
Example #4
0
def testcp(opts):
    G = matrix(
        [[0., -1., 0., 0., -21., -11., 0., -11., 10., 8., 0., 8., 5.],
         [0., 0., -1., 0., 0., 10., 16., 10., -10., -10., 16., -10., 3.],
         [0., 0., 0., -1., -5., 2., -17., 2., -6., 8., -17., -7., 6.]])
    h = matrix(
        [1.0, 0.0, 0.0, 0.0, 20., 10., 40., 10., 80., 10., 40., 10., 15.])
    dims = {'l': 0, 'q': [4], 's': [3]}
    if opts:
        solvers.options.update(opts)
    sol = solvers.cp(F, G, h, dims)
    #sol = localcvx.cp(F, G, h, dims)
    if sol['status'] == 'optimal':
        print("\nx = \n")
        print helpers.strSpe(sol['x'], "%.17f")
        print helpers.strSpe(sol['znl'], "%.17f")
        print "\n *** running GO test ***"
        helpers.run_go_test("../testcp", {'x': sol['x']})
Example #5
0
def testcp(opts):
     G = matrix([ 
               [0., -1.,  0.,  0., -21., -11.,   0., -11.,  10.,   8.,   0.,   8., 5.],
               [0.,  0., -1.,  0.,   0.,  10.,  16.,  10., -10., -10.,  16., -10., 3.],
               [0.,  0.,  0., -1.,  -5.,   2., -17.,   2.,  -6.,   8., -17.,  -7., 6.]
               ])  
     h = matrix(
          [1.0, 0.0, 0.0, 0.0, 20., 10., 40., 10., 80., 10., 40., 10., 15.])  
     dims = {'l': 0, 'q': [4], 's':  [3]}  
     if opts:
          solvers.options.update(opts)
     sol = solvers.cp(F, G, h, dims)  
     #sol = localcvx.cp(F, G, h, dims)  
     if sol['status'] == 'optimal':
          print("\nx = \n") 
          print helpers.strSpe(sol['x'], "%.17f")
          print helpers.strSpe(sol['znl'], "%.17f")
          print "\n *** running GO test ***"
          helpers.run_go_test("../testcp", {'x': sol['x']})
Example #6
0
def testqp(opts):
    A = matrix([[0.3, -0.4, -0.2, -0.4, 1.3], [0.6, 1.2, -1.7, 0.3, -0.3], [-0.3, 0.0, 0.6, -1.2, -2.0]])
    b = matrix([1.5, 0.0, -1.2, -0.7, 0.0])
    m, n = A.size

    I = matrix(0.0, (n, n))
    I[:: n + 1] = 1.0
    G = matrix([-I, matrix(0.0, (1, n)), I])
    h = matrix(n * [0.0] + [1.0] + n * [0.0])
    dims = {"l": n, "q": [n + 1], "s": []}
    P = A.T * A
    q = -A.T * b

    # localcones.options.update(opts)
    # sol = localcones.coneqp(P, q, G, h, dims, kktsolver='chol')
    solvers.options.update(opts)
    sol = solvers.coneqp(P, q, G, h, dims)
    if sol["status"] == "optimal":
        print "x=\n", helpers.strSpe(sol["x"], "%.5f")
        print "s=\n", helpers.strSpe(sol["s"], "%.5f")
        print "z=\n", helpers.strSpe(sol["z"], "%.5f")
        print "\n *** running GO test ***"
        helpers.run_go_test("../testconeqp", {"x": sol["x"], "s": sol["s"], "z": sol["z"]})
Example #7
0
    x0 = matrix(-lmbda[0]+1.0, (n,1)) 
    s0 = +w
    s0[::n+1] += x0
    # Initial feasible z is identity.
    z0 = matrix(0.0, (n,n))
    z0[::n+1] = 1.0

    dims = {'l': 0, 'q': [], 's': [n]}
    sol = solvers.conelp(c, Fs, w[:], dims, kktsolver = Fkkt,
        primalstart = {'x': x0, 's': s0[:]}, dualstart = {'z': z0[:]})
    return sol['x'], matrix(sol['z'], (n,n))


n = 10
w = normal(n,n)
run_go = True
if len(sys.argv[1:]) > 0:
    if sys.argv[1] == "-sp":
        helpers.sp_reset("./sp.data")
        helpers.sp_activate()
        run_go = False

x, z = mcsdp(w)
if run_go:
    print "\n *** running GO test ***"
    helpers.run_go_test("../testmcsdp", {'x': x, 'z': z, 'data': w})
else:
    print "w ", helpers.strSpe(w, "%.17f")
    #print "x=\n", helpers.strSpe(x, "%.17f")
    #print "z=\n", helpers.strSpe(z, "%.17f")
Example #8
0
def rungo(A, b, x, z):
    print "\n ** running Go test ..."
    helpers.run_go_test("../testqcl1", {'x': x, 'z': z, 'A': A, 'b': b})


setseed()
#m, n = 100, 100
m, n = 10, 10
A, b = normal(m, n), normal(m, 1)

run_go = True
if len(sys.argv[1:]) > 0 and sys.argv[1] == '-sp':
    helpers.sp_reset("./sp.data")
    helpers.sp_activate()
    run_go = False

x, z = qcl1(A, b)
if x is None:
    print("infeasible")
    x = matrix(0.0, (0, 1))
    z = matrix(0.0, (0, 1))
else:
    print "x\n", helpers.str2(x, "%.9f")
    print "z\n", helpers.str2(z, "%.9f")

if run_go:
    rungo(A, b, x, z)
else:
    print "A ", helpers.strSpe(A)
    print "b ", helpers.strSpe(b)
Example #9
0
    print "\n ** running Go test ..."
    helpers.run_go_test("../testqcl1", {'x': x, 'z': z, 'A': A, 'b': b})



setseed()
#m, n = 100, 100
m, n = 10, 10
A, b = normal(m,n), normal(m,1)

run_go = True
if len(sys.argv[1:]) > 0 and sys.argv[1] == '-sp':
    helpers.sp_reset("./sp.data")
    helpers.sp_activate()
    run_go = False

x, z = qcl1(A, b)
if x is None:
    print("infeasible")
    x = matrix(0.0, (0, 1))
    z = matrix(0.0, (0, 1))
else:
    print "x\n", helpers.str2(x, "%.9f")
    print "z\n", helpers.str2(z, "%.9f")

if run_go:
    rungo(A, b, x, z)
else:
    print "A ", helpers.strSpe(A)
    print "b ", helpers.strSpe(b)
Example #10
0
def solve(opts):
    c = matrix([-6.0, -4.0, -5.0])

    G = matrix(
        [
            [16.0, 7.0, 24.0, -8.0, 8.0, -1.0, 0.0, -1.0, 0.0, 0.0, 7.0, -5.0, 1.0, -5.0, 1.0, -7.0, 1.0, -7.0, -4.0],
            [
                -14.0,
                2.0,
                7.0,
                -13.0,
                -18.0,
                3.0,
                0.0,
                0.0,
                -1.0,
                0.0,
                3.0,
                13.0,
                -6.0,
                13.0,
                12.0,
                -10.0,
                -6.0,
                -10.0,
                -28.0,
            ],
            [
                5.0,
                0.0,
                -15.0,
                12.0,
                -6.0,
                17.0,
                0.0,
                0.0,
                0.0,
                -1.0,
                9.0,
                6.0,
                -6.0,
                6.0,
                -7.0,
                -7.0,
                -6.0,
                -7.0,
                -11.0,
            ],
        ]
    )
    h = matrix(
        [
            -3.0,
            5.0,
            12.0,
            -2.0,
            -14.0,
            -13.0,
            10.0,
            0.0,
            0.0,
            0.0,
            68.0,
            -30.0,
            -19.0,
            -30.0,
            99.0,
            23.0,
            -19.0,
            23.0,
            10.0,
        ]
    )

    A = matrix(0.0, (0, c.size[0]))
    b = matrix(0.0, (0, 1))

    dims = {"l": 2, "q": [4, 4], "s": [3]}

    # localcones.options.update(opts)
    # sol = localcones.conelp(c, G, h, dims, kktsolver='qr')
    solvers.options.update(opts)
    sol = solvers.conelp(c, G, h, dims)
    print ("\nStatus: " + sol["status"])
    if sol["status"] == "optimal":
        print "x=\n", helpers.strSpe(sol["x"], "%.5f")
        print "s=\n", helpers.strSpe(sol["s"], "%.5f")
        print "z=\n", helpers.strSpe(sol["z"], "%.5f")
        rungotest(sol)
Example #11
0
    sol = solvers.conelp(c,
                         Fs,
                         w[:],
                         dims,
                         kktsolver=Fkkt,
                         primalstart={
                             'x': x0,
                             's': s0[:]
                         },
                         dualstart={'z': z0[:]})
    return sol['x'], matrix(sol['z'], (n, n))


n = 10
w = normal(n, n)
run_go = True
if len(sys.argv[1:]) > 0:
    if sys.argv[1] == "-sp":
        helpers.sp_reset("./sp.data")
        helpers.sp_activate()
        run_go = False

x, z = mcsdp(w)
if run_go:
    print "\n *** running GO test ***"
    helpers.run_go_test("../testmcsdp", {'x': x, 'z': z, 'data': w})
else:
    print "w ", helpers.strSpe(w, "%.17f")
    #print "x=\n", helpers.strSpe(x, "%.17f")
    #print "z=\n", helpers.strSpe(z, "%.17f")