MILP using CVXPY

148 views
Skip to first unread message

Pravin Bezwada

unread,
Mar 28, 2017, 10:25:08 AM3/28/17
to cvxpy
Hi,

I have the following method that tried to solve a linear problem and has constraints on the absolute value of weight. Since SOS1 constraints are not supported by CVXPY, I used binary variables (y) to recreate SOS1 constraints. The problem solves are returns status as 'optimal' but when I check the value of variable y which is defined as an Int, the values are 0.5. How is that possible? Please let me know if I missed something.

Best regards,
Pravin
import cvxpy as cvx

def getW(betas, signal, P):
    (m, n) = betas.shape
    x = cvx.Variable(4 * m)
    objective = cvx.Maximize(signal.T * x[2*m:-m])
    y = cvx.Int(2*m)
    
    constraints = [x[:m] >= 0, x[m:2*m] <= 0, P.T * x[2*m:-m] == 0, y <= 1, y >= 0]
    
    for i in range(0, n):
        constraints.append(betas[:, i].T * x[2*m:-m] == 0)
    
    for i in range(0, m):
        constraints.append(x[i] - x[m+i] - x[2*m+i] == 0)
        constraints.append(x[i] + x[m+i] - x[3*m+i] == 0)
        constraints.append(x[i] <= y[i])
        constraints.append(-x[m+i] <= y[m+i])
        constraints.append(y[i] + y[m+i] == 1)
        #constraints.append(P[i] * x[3*m+i] < 0.1 * P.T * x[-m:])
        
    prob = cvx.Problem(objective, constraints)
    prob.solve()
    print prob.status
    return np.squeeze(np.asarray(x.value[2*m:-m]))


Steven Diamond

unread,
Mar 28, 2017, 12:44:42 PM3/28/17
to cvxpy
I don't know why ``y`` wouldn't be an int after solve. I need a fully self-contained example script to say more about this problem.
Reply all
Reply to author
Forward
0 new messages