Search code examples
python-3.xcvxopt

How to solve this optimization problem with cvxopt


I have a non-linear optimization problem which, in Mathematica, could be solved as:

FindMaximum[{(81 x + 19)^0.4 + (80 (1 - x) + 20)^0.6, 0 <= x <= 1}, x‬‬]

However, now I am on a computer without Mathematica and I would like to solve a similar problem in Python, using the CVXOPT module. I looked at the examples and found linear programs, quadratic programs, and other kinds of programs, but could not find this simple program.

Can I solve such a program with CVXOPT?


Solution

  • I did not find a solution with cvxopt, but I found a much better alternative - cvxpy:

    import cvxpy as cp
    
    x = cp.Variable()
    
    prob = cp.Problem(
        cp.Maximize((81*x + 19)**0.6 + (80*(1-x)+20)**0.6),
        [0 <= x, x <= 1])
    prob.solve()  # Returns the optimal value.
    print("status:", prob.status)
    print("optimal value", prob.value)
    print("optimal var", x.value)
    

    Prints:

    status: optimal
    optimal value 23.27298502822502
    optimal var 0.5145387371825181