meet a problem when I set binary variable with big M problem

85 views
Skip to first unread message

Yimiao,G

unread,
May 14, 2013, 12:24:19 PM5/14/13
to yal...@googlegroups.com
Dear Johan,

I met a problem below: (binary +big M)

objective: 
Objective_COST=Objective_COST+plus_term

constraint G, A is an auxiliary decision variable, W is a value, M is a big value, Y is a binary
G=[A<=W+M(1-Y)];
G=[G,(-200)*(W-A)-M(1-Y)<=plus_term<=(-200)*(W-A)+M(1-Y)];
G=[G,200*(A-W)-M*Y<=plus_term<=200*(A-W)+M*Y];

in other words, it needs to get:
(1)when A<=W, Objective_COST=Objective_COST+(-200)*(W-A)
(2)when A>=W,  Objective_COST=Objective_COST+(200)*(A-W)

However, I coded and ran, with error in yalmip shown that below:

"??? Undefined function or variable 'plus_term'."

I don't know how to debug now.

Would you mind helping me to solve this problem? many thanks in advance, Johan:)

regards,
Yimiao



Johan Löfberg

unread,
May 14, 2013, 12:34:49 PM5/14/13
to yal...@googlegroups.com
Well, obviously you are using a variable (or function) called plus_term in the definition of your objective, but you haven't defined this value/function. It is not a YALMIP, but basic MATLAB coding mistake.

Johan Löfberg

unread,
May 14, 2013, 1:07:17 PM5/14/13
to yal...@googlegroups.com
You have forgotten to declare plus_term as an sdpvar.

BTW, when you say M is a large number, I hope you know it should be a "small but sufficiently large" carefully derived number., i.e., just using a massively large number will lead to a lousy model.

Yimiao,G

unread,
May 15, 2013, 1:34:42 AM5/15/13
to yal...@googlegroups.com
Dear Johan,

Thanks for your explanations.
(1) for the declare "plus_term" as sdpvar problem:

I try to code as below:  

plus_term=sdpvar(1,1,'full'); % add

objective: 
Objective_COST=Objective_COST+plus_term

constraint G, A is an auxiliary decision variable, W is a value, M is a big value, Y is a binary
G=[A<=W+M(1-Y)];
G=[G,(-200)*(W-A)-M(1-Y)<=plus_term<=(-200)*(W-A)+M(1-Y)];
G=[G,200*(A-W)-M*Y<=plus_term<=200*(A-W)+M*Y];

There is another error: 
??? Error using ==> subsindex
Function 'subsindex' is not defined for values of class 'sdpvar'.
Error in ==>
G=[A<=W+M(1-Y)]; 


I think it may be the problem with A. A in my model is a combination expression, e.g. A=a1*X1+a2*X2+......, X1,X2 are variables.
But I don't know the detailed reason. Am I right?

(2) about the big M's value, do you mean that M cannot be too large,just using a smart large value is enough?

Thanks for your hardworking, Johan:)


Yimiao





Johan Löfberg

unread,
May 15, 2013, 2:00:08 AM5/15/13
to yal...@googlegroups.com
1.You have several places where you write M(1-Y). You mean M*(1-Y)

2. Using a huge number leads to poor models, bad relaxations and lousy numerics.

Example on a small-but-sufficiently-large big-M constant:

We have a model where the variable x is the length of a car which we are designing optimally. The binary variable b models if the car is a budget version. If the car is a budget version, the length of the car may not be more than 4 meters. A big-M model is

x <= 4+M*b

A crappy choice of M is, e.g., 10^7

x <= 4+10^7*b

What we are saying here is, if the car is not a budget car, the length constraint should be inactive so it can be up to 10000000 meters long. Will lead to crappy numerics, and the big-M constant is just unnecessarily large. How long can an optimal car realistically be? In Sweden, no vehicle is allowed to be longer than 24 meters on the roads anyway. So, why not use that information and simply use

x <= 4+20*b

Hence, a small but sufficiently large value and the length is not effectively limited by this constraint. It will never be active in an optimal design anyway. You can most often derive these bounds from model insight, and sometimes by solving small optimization problems on sub-parts of the model (remove some constraints until the model is easy, and then maximize x, and there you have an upper bound)

Yimiao,G

unread,
May 15, 2013, 3:53:21 AM5/15/13
to yal...@googlegroups.com
Dear Johan,

Many thanks to you :)
(1)The first problem is solved already. 
(2) About the big M value, your explanation is very cute and easy to understand. 

You are a dedicated person. 

Thanks again. 

Yimiao

Yimiao,G

unread,
May 15, 2013, 3:59:10 AM5/15/13
to yal...@googlegroups.com
Dear Johan,

BTW, how can I change this question's status to "Answered"?

Yimiao

Johan Löfberg

unread,
May 15, 2013, 4:00:53 AM5/15/13
to yal...@googlegroups.com
You already have
Reply all
Reply to author
Forward
0 new messages