Exemple #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

    solvers.options.update(opts)
    sol = solvers.coneqp(P, q, G, h, dims, kktsolver='ldl')
    if sol['status'] == 'optimal':
        print "x=\n", helpers.str2(sol['x'], "%.9f")
        print "s=\n", helpers.str2(sol['s'], "%.9f")
        print "z=\n", helpers.str2(sol['z'], "%.9f")
        helpers.run_go_test("../testconeqp", {
            'x': sol['x'],
            's': sol['s'],
            'z': sol['z']
        })
Exemple #2
0
def testsimple(opts):
    c = matrix([0., 1., 0.])
    A = matrix([[1., -1.], [0., 1.], [0., 1.0]])
    b = matrix([1., 0.])
    G = matrix([[0], [-1.], [1.]])
    h = matrix([0.])

    print "c=\n", c
    print "A=\n", A
    print "b=\n", b
    print "G=\n", G
    print "h=\n", h

    #localcones.options.update(opts)
    #sol = localcones.lp(c, G, h, A, b)
    solvers.options.update(opts)
    sol = solvers.lp(c, G, h, A, b)
    print "x = \n", helpers.str2(sol['x'], "%.9f")
    print "s = \n", helpers.str2(sol['s'], "%.9f")
    print "z = \n", helpers.str2(sol['z'], "%.9f")
    print "\n *** running GO test ***"
    helpers.run_go_test("../testsimple", {
        'x': sol['x'],
        's': sol['s'],
        'z': sol['z']
    })
Exemple #3
0
def testsocp(opts):
    c = matrix([-2., 1., 5.])  

    G  = [matrix( [[12., 13.,  12.],
                   [ 6., -3., -12.],
                   [-5., -5.,  6.]] ) ]  

    G += [matrix( [[ 3.,  3., -1.,  1.],
                   [-6., -6., -9., 19.],
                   [10., -2., -2., -3.]] ) ]  

    h = [ matrix( [-12., -3., -2.] ),
          matrix( [27., 0., 3., -42.] ) ]  

    solvers.options.update(opts)
    sol = solvers.socp(c, Gq = G, hq = h)  
    
    print "x = \n", helpers.str2(sol['x'], "%.9f")
    print "zq[0] = \n", helpers.str2(sol['zq'][0], "%.9f")
    print "zq[1] = \n", helpers.str2(sol['zq'][1], "%.9f")
    print "\n *** running GO test ***"
    helpers.run_go_test("../testsocp", {'x': sol['x'],
                                       'sq0': sol['sq'][0],
                                       'sq1': sol['sq'][1],
                                       'zq0': sol['zq'][0],
                                       'zq1': sol['zq'][1]})
Exemple #4
0
def testsocp(opts):
    c = matrix([-2., 1., 5.])

    G = [matrix([[12., 13., 12.], [6., -3., -12.], [-5., -5., 6.]])]

    G += [
        matrix([[3., 3., -1., 1.], [-6., -6., -9., 19.], [10., -2., -2., -3.]])
    ]

    h = [matrix([-12., -3., -2.]), matrix([27., 0., 3., -42.])]

    solvers.options.update(opts)
    sol = solvers.socp(c, Gq=G, hq=h)

    print "x = \n", helpers.str2(sol['x'], "%.9f")
    print "zq[0] = \n", helpers.str2(sol['zq'][0], "%.9f")
    print "zq[1] = \n", helpers.str2(sol['zq'][1], "%.9f")
    helpers.run_go_test(
        "../testsocp", {
            'x': sol['x'],
            'sq0': sol['sq'][0],
            'sq1': sol['sq'][1],
            'zq0': sol['zq'][0],
            'zq1': sol['zq'][1]
        })
Exemple #5
0
def testsdp(opts):
    c = matrix([1., -1., 1.])
    G = [
        matrix([[-7., -11., -11., 3.], [7., -18., -18., 8.],
                [-2., -8., -8., 1.]])
    ]
    G += [
        matrix([[-21., -11., 0., -11., 10., 8., 0., 8., 5.],
                [0., 10., 16., 10., -10., -10., 16., -10., 3.],
                [-5., 2., -17., 2., -6., 8., -17., -7., 6.]])
    ]
    h = [matrix([[33., -9.], [-9., 26.]])]
    h += [matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])]

    sol = solvers.sdp(c, Gs=G, hs=h)
    print "x = \n", str2(sol['x'], "%.9f")
    print "zs[0] = \n", helpers.str2(sol['zs'][0], "%.9f")
    print "zs[1] = \n", helpers.str2(sol['zs'][1], "%.9f")
    helpers.run_go_test(
        "../testsdp", {
            'x': sol['x'],
            'ss0': sol['ss'][0],
            'ss1': sol['ss'][1],
            'zs0': sol['zs'][0],
            'zs0': sol['zs'][1]
        })
Exemple #6
0
def testlp(opts):
    c = matrix([-4., -5.])  
    G = matrix([[2., 1., -1., 0.], [1., 2., 0., -1.]])  
    h = matrix([3., 3., 0., 0.])  
    solvers.options.update(opts)
    sol = solvers.lp(c, G, h)  
    print"x = \n", helpers.str2(sol['x'], "%.9f")
    print"s = \n", helpers.str2(sol['s'], "%.9f")
    print"z = \n", helpers.str2(sol['z'], "%.9f")
    helpers.run_go_test("../testlp", {'x': sol['x'], 's': sol['s'], 'z': sol['z']})
Exemple #7
0
def testlp(opts):
    c = matrix([-4., -5.])
    G = matrix([[2., 1., -1., 0.], [1., 2., 0., -1.]])
    h = matrix([3., 3., 0., 0.])
    solvers.options.update(opts)
    sol = solvers.lp(c, G, h)
    print "x = \n", helpers.str2(sol['x'], "%.9f")
    print "s = \n", helpers.str2(sol['s'], "%.9f")
    print "z = \n", helpers.str2(sol['z'], "%.9f")
    helpers.run_go_test("../testlp", {
        'x': sol['x'],
        's': sol['s'],
        'z': sol['z']
    })
Exemple #8
0
def main(args):
    # Generate an analytic centering problem
    #
    #    -b1 <=  Ar*x <= b2
    #
    # with random mxn Ar and random b1, b2.

    if len(args[0]) > 0 and args[0] == "reftest":
        m, n = 10, 5
        # matrix in column order
        A0 = matrix([[-7.44e-01, 4.59e-01, -2.95e-02, -7.75e-01, -1.80e+00],
                     [1.11e-01, 7.06e-01, -2.22e-01, 1.03e-01, 1.24e+00],
                     [1.29e+00, 3.16e-01, -2.07e-01, -1.22e+00, -2.61e+00],
                     [2.62e+00, -1.06e-01, -9.11e-01, -5.74e-01, -9.31e-01],
                     [-1.82e+00, 7.80e-01, -3.92e-01, -3.32e-01, -6.38e-01]])

        b0 = matrix([
            8.38e-01, 9.92e-01, 9.56e-01, 6.14e-01, 6.56e-01, 3.57e-01,
            6.36e-01, 5.08e-01, 8.81e-03, 7.08e-02
        ])
        A = matrix([A0, -A0])
        b = b0
    else:
        m, n = 500, 500
        Ar = base.normal(m, n)
        A = matrix([Ar, -Ar])
        b = base.uniform(2 * m, 1)

    x, ntdecrs = acent(A, b)
    print "solution:\n", helpers.str2(x, "%.17f")
    print "ntdecrs :\n", ntdecrs
Exemple #9
0
def testsdp(opts):
    c = matrix([1.,-1.,1.])  
    G = [ matrix([[-7., -11., -11., 3.],  
                  [ 7., -18., -18., 8.],  
                  [-2.,  -8.,  -8., 1.]]) ]  
    G += [ matrix([[-21., -11.,   0., -11.,  10.,   8.,   0.,   8., 5.],  
                   [  0.,  10.,  16.,  10., -10., -10.,  16., -10., 3.],  
                   [ -5.,   2., -17.,   2.,  -6.,   8., -17.,  -7., 6.]]) ]  
    h = [ matrix([[33., -9.], [-9., 26.]]) ]  
    h += [ matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]]) ]  

    sol = solvers.sdp(c, Gs=G, hs=h)  
    print "x = \n", str2(sol['x'], "%.9f")
    print "zs[0] = \n", helpers.str2(sol['zs'][0], "%.9f")
    print "zs[1] = \n", helpers.str2(sol['zs'][1], "%.9f")
    helpers.run_go_test("../testsdp", {'x': sol['x'],
                                       'ss0': sol['ss'][0],
                                       'ss1': sol['ss'][1],
                                       'zs0': sol['zs'][0],
                                       'zs0': sol['zs'][1]})
Exemple #10
0
def testsimple(opts):
    c = matrix([0., 1., 0.])
    A = matrix([[1., -1.], [0., 1.], [0., 1.0]])
    b = matrix([1., 0.])
    G = matrix([[0], [-1.], [1.]])
    h = matrix([0.])

    print "c=\n", c
    print "A=\n", A
    print "b=\n", b
    print "G=\n", G
    print "h=\n", h

    #localcones.options.update(opts)
    #sol = localcones.lp(c, G, h, A, b)  
    solvers.options.update(opts)
    sol = solvers.lp(c, G, h, A, b)  
    print"x = \n", helpers.str2(sol['x'], "%.9f")
    print"s = \n", helpers.str2(sol['s'], "%.9f")
    print"z = \n", helpers.str2(sol['z'], "%.9f")
    print "\n *** running GO test ***"
    helpers.run_go_test("../testsimple", {'x': sol['x'], 's': sol['s'], 'z': sol['z']})
Exemple #11
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

    solvers.options.update(opts)
    sol = solvers.coneqp(P, q, G, h, dims, kktsolver='ldl')
    if sol['status'] == 'optimal':
        print "x=\n", helpers.str2(sol['x'], "%.9f")
        print "s=\n", helpers.str2(sol['s'], "%.9f")
        print "z=\n", helpers.str2(sol['z'], "%.9f")
        helpers.run_go_test("../testconeqp", {'x': sol['x'], 's': sol['s'], 'z': sol['z']})
Exemple #12
0
def testsdp(opts):
    c = matrix([1., -1., 1.])
    G = [
        matrix([[-7., -11., -11., 3.], [7., -18., -18., 8.],
                [-2., -8., -8., 1.]])
    ]
    G += [
        matrix([[-21., -11., 0., -11., 10., 8., 0., 8., 5.],
                [0., 10., 16., 10., -10., -10., 16., -10., 3.],
                [-5., 2., -17., 2., -6., 8., -17., -7., 6.]])
    ]
    h = [matrix([[33., -9.], [-9., 26.]])]
    h += [matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])]

    solvers.options.update(opts)
    sol = solvers.sdp(c, Gs=G, hs=h)
    #localcones.options.update(opts)
    #sol = localcones.sdp(c, Gs=G, hs=h)
    print "x = \n", helpers.str2(sol['x'], "%.9f")
    print "zs[0] = \n", helpers.str2(sol['zs'][0], "%.9f")
    print "zs[1] = \n", helpers.str2(sol['zs'][1], "%.9f")
    print "\n *** running GO test ***"
    rungo(sol)
Exemple #13
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]}
    solvers.options.update(opts)
    sol = solvers.conelp(c, G, h, dims, kktsolver='ldl')
    print("\nStatus: " + sol['status'])
    if sol['status'] == 'optimal':
        print "x=\n", helpers.str2(sol['x'])
        print "s=\n", helpers.str2(sol['s'])
        print "z=\n", helpers.str2(sol['z'])
        helpers.run_go_test("../testconelp", {'x': sol['x'], 's': sol['s'], 'z': sol['z']})
Exemple #14
0
def testsdp(opts):
    c = matrix([1.0, -1.0, 1.0])
    G = [matrix([[-7.0, -11.0, -11.0, 3.0], [7.0, -18.0, -18.0, 8.0], [-2.0, -8.0, -8.0, 1.0]])]
    G += [
        matrix(
            [
                [-21.0, -11.0, 0.0, -11.0, 10.0, 8.0, 0.0, 8.0, 5.0],
                [0.0, 10.0, 16.0, 10.0, -10.0, -10.0, 16.0, -10.0, 3.0],
                [-5.0, 2.0, -17.0, 2.0, -6.0, 8.0, -17.0, -7.0, 6.0],
            ]
        )
    ]
    h = [matrix([[33.0, -9.0], [-9.0, 26.0]])]
    h += [matrix([[14.0, 9.0, 40.0], [9.0, 91.0, 10.0], [40.0, 10.0, 15.0]])]

    solvers.options.update(opts)
    sol = solvers.sdp(c, Gs=G, hs=h)
    # localcones.options.update(opts)
    # sol = localcones.sdp(c, Gs=G, hs=h)
    print "x = \n", helpers.str2(sol["x"], "%.9f")
    print "zs[0] = \n", helpers.str2(sol["zs"][0], "%.9f")
    print "zs[1] = \n", helpers.str2(sol["zs"][1], "%.9f")
    print "\n *** running GO test ***"
    rungo(sol)
Exemple #15
0
def main(args):
    # Generate an analytic centering problem  
    #
    #    -b1 <=  Ar*x <= b2 
    #
    # with random mxn Ar and random b1, b2.

    if len(args[0]) > 0 and args[0] == "reftest":
        m, n = 10, 5
        # matrix in column order
        A0 = matrix([[-7.44e-01,  4.59e-01, -2.95e-02, -7.75e-01, -1.80e+00],
                     [ 1.11e-01,  7.06e-01, -2.22e-01,  1.03e-01,  1.24e+00],
                     [ 1.29e+00,  3.16e-01, -2.07e-01, -1.22e+00, -2.61e+00],
                     [ 2.62e+00, -1.06e-01, -9.11e-01, -5.74e-01, -9.31e-01],
                     [-1.82e+00,  7.80e-01, -3.92e-01, -3.32e-01, -6.38e-01]])

        b0 = matrix([8.38e-01,
                     9.92e-01,
                     9.56e-01,
                     6.14e-01,
                     6.56e-01,
                     3.57e-01,
                     6.36e-01,
                     5.08e-01,
                     8.81e-03,
                     7.08e-02])
        A = matrix([A0, -A0])
        b = b0
    else:
        m, n  = 500, 500
        Ar = base.normal(m,n);
        A = matrix([Ar, -Ar])
        b = base.uniform(2*m,1)

    x, ntdecrs = acent(A, b)  
    print "solution:\n", helpers.str2(x, "%.17f")
    print "ntdecrs :\n", ntdecrs
Exemple #16
0
    # -w4  + h4/gamma <= 0
    G[22, [15, 19]] = -1.0, 1.0 / gamma

    #  w4 - gamma * h4 <= 0
    G[23, [15, 20]] = 1.0, -gamma

    # -w5 + h5/gamma <= 0
    G[24, [16, 21]] = -1.0, 1.0 / gamma

    #  w5 - gamma * h5 <= 0.0
    G[25, [16, 21]] = 1.0, -gamma

    # solve and return W, H, x, y, w, h

    solvers.options.update(opts)
    sol = solvers.cpl(c, F, G, h)
    return  sol['x'][0], sol['x'][1], sol['x'][2:7], sol['x'][7:12], \
        sol['x'][12:17], sol['x'][17:], sol['x']


Amin = matrix([100., 100., 100., 100., 100.])
W, H, x, y, w, h, Xall = floorplan(Amin, {'maxiters': 50})
print "W = %.5f H = %.5f" % (W, H)
print "x=\n", helpers.str2(x, "%.5f")
print "y=\n", helpers.str2(y, "%.5f")
print "w=\n", helpers.str2(w, "%.5f")
print "h=\n", helpers.str2(h, "%.5f")
print "\n *** running GO test ***"
helpers.run_go_test("../testcpl", {'x': Xall})
Exemple #17
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)
Exemple #18
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)
Exemple #19
0
    G[21, [14, 19]] = 1.0, -gamma

    # -w4  + h4/gamma <= 0
    G[22, [15, 19]] = -1.0, 1.0 / gamma

    #  w4 - gamma * h4 <= 0
    G[23, [15, 20]] = 1.0, -gamma

    # -w5 + h5/gamma <= 0
    G[24, [16, 21]] = -1.0, 1.0 / gamma

    #  w5 - gamma * h5 <= 0.0
    G[25, [16, 21]] = 1.0, -gamma

    # solve and return W, H, x, y, w, h

    solvers.options.update(opts)
    sol = solvers.cpl(c, F, G, h)
    return sol["x"][0], sol["x"][1], sol["x"][2:7], sol["x"][7:12], sol["x"][12:17], sol["x"][17:], sol["x"]


Amin = matrix([100.0, 100.0, 100.0, 100.0, 100.0])
W, H, x, y, w, h, Xall = floorplan(Amin, {"maxiters": 50})
print "W = %.5f H = %.5f" % (W, H)
print "x=\n", helpers.str2(x, "%.5f")
print "y=\n", helpers.str2(y, "%.5f")
print "w=\n", helpers.str2(w, "%.5f")
print "h=\n", helpers.str2(h, "%.5f")
print "\n *** running GO test ***"
helpers.run_go_test("../testcpl", {"x": Xall})