Using implies command

108 views
Skip to first unread message

MY

unread,
May 31, 2018, 11:58:47 AM5/31/18
to YALMIP
Hi,

I would like to do the following logic calculations with implies command but not sure how to do it.
My original if statement is as follows:

if t>1  % t is time
    tm = num2str( t-1 );
    eval(['Rtm = R_kl' tm ';'])  % R_kl=binvar(n,1)
    eval(['Rt = R_kl' tt ';'])
if Rtm==Rt
Obj(t) = Obj(t)
else
 Obj(t) = Obj(t)+1000;
end

This is how I do it by implies:

if t>1
    tm = num2str( t-1 );
    eval(['Rtm = R_kl' tm ';'])
    eval(['Rt = R_kl' tt ';'])
implies(Rtm==Rt,Obj(t)==Obj(t))
else 
    Obj(t) = Obj(t)+1000;
end

Johan Löfberg

unread,
May 31, 2018, 1:05:08 PM5/31/18
to YALMIP

the constraint obj(t) == obj(t) makes no sense (as it always is true), and obj(t) = obj(t)+100 is not well defined (what is obj(t) from the beginning?)

and the code you start with is not correct as there is a missing end, so it is very unclear how the logic is supposed to be

MY

unread,
May 31, 2018, 1:20:02 PM5/31/18
to YALMIP
Let me try to make it more clear.

for t=1:T  % t is time
 tt
= num2str( t );
eval([' X' tt ' = sdpvar(n,n)'])
eval([ 'R_kl' tt ' = binvar(9,1)']);
eval([' Obj(t)= trace(A(t)*X' tt ')']) % A is defined matrix

if t>1  
    tm
= num2str( t-1 );
   
eval(['Rtm = R_kl' tm ';'])
   
eval(['Rt = R_kl' tt ';'])
if Rtm~=Rt
 
Obj(t) = Obj(t)+1000;

end
else
end
end


How I can do this y using implies?

Thanks,

Johan Löfberg

unread,
May 31, 2018, 1:34:25 PM5/31/18
to YALMIP
looks like you want to do

for t=1:T  % t is
time
    X
{t} = sdpvar(n,n);
    R
{t} = binvar(9,1);
       
   
if t>1
        sdpvar z
        cases
= binvar(2,1);
       
Model = [Model, implies(cases(1), [R{t}==R{t-1}, z == trace(A(t)*X{t})])
                        implies
(cases(2), [sum(abs(R{t}-R{t-1}))>= 1/2, z == trace(A(t)*X{t})+100])                        
                        sum
(cases) == 1];
     
Obj = [Obj z];
   
else
     
Obj = trace(A(t)*X{t});
   
end
end

although expression A(t)*X{t} looks dubious. One would express this is supposed to be the inner product of two matrices, but A(t) is a scalar...

it also looks strangely unconstrained in X, i.e. constraints missing

MY

unread,
May 31, 2018, 2:29:24 PM5/31/18
to YALMIP
I tried your suggestion, but not able to get feasible solution.

I'm wondering if it is possible for me to send my code to your personal email, so you may have a look at it?

Thanks,

Johan Löfberg

unread,
May 31, 2018, 2:37:34 PM5/31/18
to YALMIP
sure
Message has been deleted
Message has been deleted

Evgeny Schnittmann

unread,
Jun 8, 2018, 7:24:20 AM6/8/18
to YALMIP
Hello Mr. Löfberg,

at the Moment im trying to restrict certain cases in my yalmip-optimization. Im trying to do it with the implies function. My question is, if it is possible to formulate a Logical "&" in that context.

How can I for example translate the following Code into an implies-constraint?

if a && b
    c=1;
end

My solution for now is:

if a
   Constraints = [Constraints, implies(b,c)]
end

Is there a better alternative?

Thank you in advance!


Johan Löfberg

unread,
Jun 8, 2018, 7:34:59 AM6/8/18
to YALMIP
So a is constant? Then that is the most natural model yes

Evgeny Schnittmann

unread,
Jun 8, 2018, 7:38:26 AM6/8/18
to YALMIP
Yes a is from 1 to horizon (unit commitment) and b is of the type sdpvar. Anyway, thank you very much!

Johan Löfberg

unread,
Jun 8, 2018, 7:46:30 AM6/8/18
to YALMIP
and c is binary too? Otherwise you must write implies(b,c==1)

and of course, if both b and c are binary, you are simply saying c>=b

Johan Löfberg

unread,
Jun 8, 2018, 8:04:46 AM6/8/18
to YALMIP
...assuming b binary too of course

Evgeny Schnittmann

unread,
Jun 8, 2018, 8:05:54 AM6/8/18
to YALMIP
You are right, i forgot the second "=" (not in my Code though). no, c and b are both continuous.

Johan Löfberg

unread,
Jun 8, 2018, 8:10:14 AM6/8/18
to YALMIP
if b and c are continuous, then b implies c does not make any numerical sense. So if b = 10^-40, you want to avoid c=0 but you are ok with c = 10^-32
Reply all
Reply to author
Forward
0 new messages