Gurobi says no solution but I find a solution

47 views
Skip to first unread message

Guanghui Zhu

unread,
May 25, 2025, 3:59:43 AMMay 25
to YALMIP
Dear Johan Löfberg,

%===================script start===================
t_u_number = 1;
m=5;
K=1000;
M_curr = [1,0,3,1,2]';
Cu = [0,0,-1,0,1]';
pm = [1,0,0]';
A=[1,0,0,0,0; 0,1,0,0,0; 0,0,0,1,0];

F = [];
sigma_u = intvar(t_u_number,1,'full');
F = [F,sigma_u >= 0];
t_O = intvar(m,1,'full');
F = [F, t_O >= 0];
t_I = intvar(m,1,'full');
F = [F, t_I >= 0];
b = binvar(m,1,'full');
F = [F,M_curr+Cu*sigma_u +(t_O-t_I)  >= 0];
F = [F,A*(M_curr + Cu*sigma_u + (t_O-t_I)) == pm];
for j=1:t_u_number
F = [F, A*(sigma_u(j)*Cu(:,j)) == 0];
end
F = [F,ones(1,m)*t_I >= 1];
F = [F, t_I - K*b <= 0];
F = [F, t_O - K*(ones(m,1)-b) <= 0];
obj =  ones(1,m)*(t_I + t_O);
options = sdpsettings('solver','gurobi');
output = optimize(F, obj,options); %"Either infeasible or unbounded (GRUROBI)"
%===================script end===================

I solve the above the programming model and get the information "Either infeasible or unbounded (GRUROBI)".

However, I find the following solution by hand:

sigma_u = [0]';
t_O = [0,0,0,0,0]';
t_I=[0,0,0,1,0]';
b = [0,0,0,1,0]';

Could you tell me where I went wrong?

Thand you very much!

Johan Löfberg

unread,
May 25, 2025, 4:03:38 AMMay 25
to YALMIP
In the develop branch, you will get a direct hint at what your bug is


>> F = [F,M_curr+Cu*sigma_u +(t_O-t_I)  >= 0];
Most likely you meant to write a + b, but you wrote a +b
This can easily lead to bugs, as [a +b] is a vector with two elements
If you really want to use unitary plus, you will have to edit sdpvar/uplus
and delete this message

Guanghui Zhu

unread,
May 25, 2025, 4:20:49 AMMay 25
to YALMIP
Dear  Johan Löfberg,
Thanks for you quick reply.

Do you mean I can use another symbol or function instead of ‘+’ to eliminate this bug?

Sorry, I'm a novice in this area.
Thanks.

Guanghui Zhu

unread,
May 25, 2025, 4:38:16 AMMay 25
to YALMIP
Dear  Johan Löfberg,

Thanks very much for you help.
I consult ChatGPT by taking our session as input. And I have solved the problem by using the following code:

F = [F,M_curr + Cu*sigma_u + (t_O - t_I)  >= 0];

F = [F,A*(M_curr + Cu*sigma_u + (t_O-t_I)) == pm];

I will be looking at more examples of using YALMIP to get more familiar with it.

Thanks again.

Johan Löfberg

unread,
May 25, 2025, 5:15:27 AMMay 25
to YALMIP
>> [1+1]

ans =

     2

>> [1 + 1]

ans =

     2

>> [1 +1]

ans =

     1     1

Guanghui Zhu

unread,
May 25, 2025, 5:19:58 AMMay 25
to YALMIP
Thanks.
I have completely understood the unitary plus in Matlab and YALMIP.
Reply all
Reply to author
Forward
0 new messages