The usage of MAX: whats the difference between this two expressions?

16 views
Skip to first unread message

Weiwei Yao

unread,
Feb 27, 2020, 1:51:21 AM2/27/20
to YALMIP
Dear Prof. Lofberg,

Thank you very much for your previous helps. YALMIP is so great for us!

Now I have a question: what's the difference between the two expressions below? Why do I get different results with the two expressions ? Could you help me please : )
-----------------------------------------------------------------
x = sdpvar(1,24);
y = sdpvar(1,24);
z = max(max(x),max(y));     %expression A
z = max(x+y);                      %expression B
-----------------------------------------------------------------




Full m-code as follows:
%**********************************************************************
close all;clear;clc;
X = sdpvar(1,24);
Y = sdpvar(1,24);
onoffX = binvar(1,24);
onoffY = binvar(1,24);
F = [onoffX+onoffY<=1,
0<=X<=1e5.*onoffX,
0<=Y<=1e5.*onoffY];


%**********************************************************************
% Is the two expressions the same? Why do I get different results?
% expression A:
                max_XY = max(max(X),max(Y));
% expression B:
                max_XY = max(X+Y);
%**********************************************************************


f = sum(X)+max_XY;
ops = sdpsettings('verbose',0,'debug',1,'solver','gurobi');
result = optimize(F,-f,ops);
f = value(f)
% The result with expression A is 4.3e5, and another is 2.5e6.


Johan Löfberg

unread,
Feb 27, 2020, 2:05:47 AM2/27/20
to YALMIP
of course you get different answers

max(max([1 2 3]),max([1 2 3])) = 3

max([1 2 3]+[1 2 3]) = 6


...and using big-M modelling with coefficients in the order 10^5 is a recipe for numerical problems and strange results.
Message has been deleted

Weiwei Yao

unread,
Feb 27, 2020, 2:31:52 AM2/27/20
to YALMIP
Because of the binvar onoffX + onoffY <=1, so X and Y are  mutually exclusive.

max(max([1 0 3]),max([0 2 0])) = 3

max([1 0 3]+[0 2 0]) = 3

Why is that? Maybe the most likely cause is the order 10^5 ?

Best regards

Johan Löfberg

unread,
Feb 27, 2020, 2:34:09 AM2/27/20
to YALMIP
Are you asking why max([1 0 3]+[0 2 0]) is equal to 3??

Weiwei Yao

unread,
Feb 27, 2020, 2:37:41 AM2/27/20
to YALMIP
I mean X and Y are  mutually exclusive.  So the example you give is inappropriate.

[1 0 3] and [0 2 0] is appropriate, not [1 2 3] and [1 2 3].

Thank you so much!

Weiwei Yao

unread,
Feb 27, 2020, 2:39:12 AM2/27/20
to YALMIP
X.*Y always equal zero in my model.  so X=[1 2 3] and Y=[1 2 3]  is  inappropriate.

Johan Löfberg

unread,
Feb 27, 2020, 2:43:21 AM2/27/20
to yal...@googlegroups.com
So I guess your question this is, should the two objectives

sum(X)  + max(X+Y)

and

sum(X)  + max(max(X,max(Y))

lead to the same maximizing argument (Y=0, X at upper bound)?

Yes they should, but with this horrible big-M scaling you don't get that. You cannot expect things to work with the bounds go above 10^4 or so, since that is an internal assumption in the big-M modelling that you don't have any bounds on variables involved in big-m models larger than that.

Weiwei Yao

unread,
Feb 27, 2020, 2:51:33 AM2/27/20
to YALMIP
Now I find that, when I reduce the coefficients from 1e5 to 1e3, all the confused results disappear. That's great! 

But what's the principle with using big-M modelling? Where's the bound? Maybe the best feasible way is to lower the coefficients. 1e5 is too much larger.

Thank you Prof Lofberg! 

Johan Löfberg

unread,
Feb 27, 2020, 3:01:03 AM2/27/20
to YALMIP
YALMIP uses bounds 10^4 on some internal big-M constructs which are required to implement your nonconvex use of the max-operator.
Reply all
Reply to author
Forward
0 new messages