Product of optimization variables as MIDCP

I am fairly new to cvx and optimization an I am having a bit of a hard time getting the constraints of my problem right.
I am trying to optimize the input charge and discharge power to a battery, whose product needs to be zero for physical reasons (cannot simultaneously charge and discharge).

My problem is set up as follows:

cvx_begin quiet
variables u(10,2)
expressions y_bar(10) C1(10) C2(10)
reshape_u = reshape(u',2*length(u),1);
%gets my input from 2 columns to 1 column
g_t = P_g*y_ini + Q_g*[u_ini; reshape_u];
y_bar = Yf*g_t - Gamma*(Yp*g_t - y_ini); % ny*10 x 1
norm_g = norm(g_t);
C1 = mu_p*(sqrt(diag(temp_1)) + norm(g_t)*sqrt(sigma*diag(temp_2)));
C2 = mu_p*( sqrt(diag(temp_1)) + norm_g*sqrt(sigma*diag(temp_2)));
minimize R*norm(u(:,1) + u(:,2),1) + gamma_1 * sum(pos(-upper_y_bound + y_bar + C1)) + gamma_2 * sum(pos(-y_bar + lower_y_bound + C2)) + norm(g_t)
subject to
zeros(10,2) <= u <= 65*ones(10,2);
**u(:,1).*u(:,2) == zeros(10,1);**

The problem is with the constraint in bold, which is non-convex. In fact if I run the algorithm like this I get the disciplined convex error. Is it possible to express it in a form solvable with mixed integer programming?

This is a ccmplementarity constraint, which can be linearized with a binary variable for each element.

Let M1 be the tightest upper bound for u(:,1), M2 the tightest upper bound for u(:,2). In your case, M1 and M2 can both be chosen as 65.

variable b(10) binary
u(:,1) <= M1*b
u(:,2) <= M2*(1-b)

For each row of u, this forces at least one of u(:,1) or u(:,2) to be zero.

1 Like

BTW, when you have included the new constraints i showed, the right inequality of zeros(10,2) <= u <= 65*ones(10,2) is redundant, and that double -sided inequality can be replaced by 0 <= u. (The other inequality could have been written more compactly as u <= 65, but is no longer needed.)