bianry variables remain unchanged using implies

52 views
Skip to first unread message

Jane Zheng

unread,
Aug 27, 2014, 10:09:07 AM8/27/14
to yal...@googlegroups.com
Hi, Johan,

I have a conditionnal constraint which poses different relations to two of 9 states: if x(8)<=const1., x(4) - x(3) == const.2; if x(8) >= const.1, x(4) - x(3) == const.3. I use function implies to code this condition as (in MPC framework):

b_switch = binvar(1, Np);
for i=...Np
constraints = [constraints, ...
            implies(b_switch(i),[x(8,i+1) <= const1., x(3,i+1) == x(4,i+1) - const2.]),...
            implies(~b_switch(i), [x(8,i+1) >= const1., x(3,i+1) == x(4,i+1) - const3.])];
(constraints bounding all the variables)
end
Is there a problem writing so? why am I getting b_switch =ones(1, Np) all the time? and the stored data for x(8) are stuck at const.1. I just cannot figure out why it doesn't work. Thank you!

Best,
Huarong

Johan Löfberg

unread,
Aug 27, 2014, 11:39:03 AM8/27/14
to yal...@googlegroups.com
Looks OK, based on the minimal code displayed.

Do you have strong reasons to believe that it is not optimal? If so, simply add some constraint that one of the switches is zero as you think it should be, and then you will see that

1. The objective is lower: Then there is a bug. That should not be possible
2. The objective is the same. OK, simply means that the solution is non-unique, but all ones is just as good
3. The objective is higher. All ones is indeed optimal and a must

Jane Zheng

unread,
Sep 2, 2014, 4:27:29 AM9/2/14
to yal...@googlegroups.com
Hi Johan,

Thanks for replying.
I tried to fix the final binary variable to 0 when x(8,i+1) approaches const1 as you suggested. But then I got infeasible solutions.
What I didn't mention in the first post is that x(3,i+1) is one of terms I minimized in the cost function. x(3,i+1) == x(4,i+1) - const2/const3 in which x(4,i+1) is continuous. So the switch from const2 to const3 will result in big x(3,i+1) which is not what the minimization cost function wants. Does this explain why the binary vector b_switch remains unchanged in the optimization problem? I am not sure if implies only works for the switches in the model or it also works for the switches in the cost function. Hope to hear your suggestions on this problem.
Thank you.

Best,
Huarong

Johan Löfberg

unread,
Sep 2, 2014, 4:55:02 AM9/2/14
to yal...@googlegroups.com
The validity of implies is not affected by how the variables are used in other parts of the model.

If the switch leads to some costly behavior, then it will of course be optimal to not switch, if that is feasible. Not sure if that is what you are asking though

Johan Löfberg

unread,
Sep 2, 2014, 5:02:39 AM9/2/14
to yal...@googlegroups.com
If the code is reasonably compact, feel free to post it for sanity check (or send it to me privately if you wish)

Jane Zheng

unread,
Sep 2, 2014, 5:03:08 AM9/2/14
to yal...@googlegroups.com
Yes. I guess it is because the switch leads to some costly behavior in x(3,i+1). I will try by assigning higher weighting matrix to other terms in the cost function to see if I can then observe switch in the binary variables.
Thank you.

Best,
Huarong 

Jane Zheng

unread,
Sep 4, 2014, 3:47:28 PM9/4/14
to yal...@googlegroups.com
Hi Johan,

I have made the switch work. The first switch is successful, but during the second switch, I got the values for binvar b_switch something like 3.8417e-006, and the cplex solver still shows me "successfully solved" flag. Does this mean I need to adjust the cplex.mip.tolerances? I don't really understand how these tolerances affect the optimality/feasibility of the programming. What do you think might be the problem causing not exact {0,1} solutions of binvar b_switch ?
Thank you.

Best,
Huarong

Johan Löfberg

unread,
Sep 4, 2014, 3:54:55 PM9/4/14
to yal...@googlegroups.com

3.8417e-006 is probably considered to be zero in the default tolerances
Reply all
Reply to author
Forward
0 new messages