I have the following program running correctly in Matlab.
cvx_begin gp
variables b(n,1) dc(n,1) v(n,1) p(n,1)
minimize(sum((1./dc)) + sum((1./b)))
subject to
(diag(b)*A+diag(dc))*v <= v;
p'*(diag(b)*A+diag(dc)) <= p';
v>=zeros(n,1);
bs*ones(n,1) <= b <= ba*ones(n,1);
(1-dehigh)*ones(n,1) <= dc <= (1-de)*ones(n,1);
cvx_end
where A, dehigh, de, bs, and ba have all been previously defined.
Now, I need to implement this in Python, and I am trying to use CVXPY.
b=cp.Variable(shape = (n,),pos=True)
dc=cp.Variable(shape = (n,),pos=True)
v=cp.Variable(shape = (n,),pos=True)
p=cp.Variable(shape = (n,),pos=True)
objective=cp.Minimize(cp.sum(cp.inv_pos(dc))+cp.sum(cp.inv_pos(b)))
constraints=[cp.diag(b)@A@v+cp.diag(dc)@v-v<=0,
[email protected](b)@[email protected](dc)-p.T<=0,
v>=0,
b>=bs,
b<=ba,
dc>=(1-dehigh),
dc<=(1-de)]
prob=cp.Problem(objective,constraints)
prob.solve(gp=True)
were, again, A, dehigh, de, bs, and ba have been previously defined. However, in this case, it does not work. I get the following error
raise DGPError("Problem does not follow DGP rules." + append)
DGPError: Problem does not follow DGP rules.The following constraints are not DGP:
diag_vec(reshape(var2532, (5,), F)) @ [[0.08165575 0.0299181 0.002247 0.0277268 0.
]
[0.02882425 0.0248519 0.0331365 0.0383574 0.00777085]
[0.002247 0.0367646 0.0001932 0.03324015 0.00627815]
[0.0276453 0.037173 0.03463015 0.078643 0.00359125]
[0. 0.00905125 0.00627695 0.00359315 0. ]] @ var2534 +diag_vec(reshape(var2533, (5,), F)) @ var2534 + -var2534 <= 0.0 , because the following subexpressions are not:
|-- [[0.08165575 0.0299181 0.002247 0.0277268 0. ]
[0.02882425 0.0248519 0.0331365 0.0383574 0.00777085]
[0.002247 0.0367646 0.0001932 0.03324015 0.00627815]
[0.0276453 0.037173 0.03463015 0.078643 0.00359125]
[0. 0.00905125 0.00627695 0.00359315 0. ]]
|-- -var2534
|-- 0.0
var2535 @ diag_vec(reshape(var2532, (5,), F)) @ [[0.08165575 0.0299181 0.002247 0.0277268 0. ]
[0.02882425 0.0248519 0.0331365 0.0383574 0.00777085]
[0.002247 0.0367646 0.0001932 0.03324015 0.00627815]
[0.0276453 0.037173 0.03463015 0.078643 0.00359125]
0. 0.00905125 0.00627695 0.00359315 0. ]] + var2535 @
diag_vec(reshape(var2533, (5,), F)) + -var2535 <= 0.0 , because the following subexpressions are not:
|-- [[0.08165575 0.0299181 0.002247 0.0277268 0. ]
[0.02882425 0.0248519 0.0331365 0.0383574 0.00777085]
[0.002247 0.0367646 0.0001932 0.03324015 0.00627815]
[0.0276453 0.037173 0.03463015 0.078643 0.00359125]
[0. 0.00905125 0.00627695 0.00359315 0. ]]
|-- -var2535
|-- 0.0
Could anyone please help me? I cannot find the issue.