示例#1
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})
示例#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']
    })
示例#3
0
def rungotest(sol):
    print "\n *** running GO test ***"
    helpers.run_go_test("../testconelp", {
        'x': sol['x'],
        's': sol['s'],
        'z': sol['z']
    })
示例#4
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]
        })
示例#5
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]
        })
示例#6
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']})
示例#7
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]})
示例#8
0
def rungo(sol):
    helpers.run_go_test(
        "../testsdp", {
            'x': sol['x'],
            'ss0': sol['ss'][0],
            'ss1': sol['ss'][1],
            'zs0': sol['zs'][0],
            'zs1': sol['zs'][1]
        })
示例#9
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']})
示例#10
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']
    })
示例#11
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']})
示例#12
0
文件: testcp.py 项目: hrautila/go.opt
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']})
示例#13
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]})
示例#14
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']})
示例#15
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']})
示例#16
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"]})
示例#17
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']})
示例#18
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})
示例#19
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")
示例#20
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")
示例#21
0
def rungotest(sol):
    print "\n *** running GO test ***"
    helpers.run_go_test("../testconelp", {"x": sol["x"], "s": sol["s"], "z": sol["z"]})
示例#22
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})
示例#23
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})
示例#24
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")
helpers.run_go_test("../testcpl", {'x': Xall})

示例#25
0
def rungo(sol):
    helpers.run_go_test(
        "../testsdp",
        {"x": sol["x"], "ss0": sol["ss"][0], "ss1": sol["ss"][1], "zs0": sol["zs"][0], "zs1": sol["zs"][1]},
    )
示例#26
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})