Search code examples
pythoncvxopt

Does anyone know how to do convex optimization in Python with CVXOPT module?


I want to maximize Ax = b where A is an m-by-n matrix and x is an n-vector. The constraints on x are that its entries sum to 1 and that A x >= 0.


Solution

  • Using CVXPY instead:

    from cvxpy import *
    import numpy as np
    
    m = 30
    n = 10
    
    # generate random data
    np.random.seed(1)
    A = np.random.randn(m,n)
    b = np.random.randn(m)
    
    # optimization variable
    x = Variable(n)
    
    # build optimization problem
    prob = Problem( Maximize(sum(A*x)), [ sum(x) == 1, A*x >= 0 ])
    
    # solve optimization problem and prints results
    result = prob.solve()
    print x.value
    

    This optimization problem is unbounded and, thus, there is no optimal solution.