Conditional variables

Problems with modeling
Post Reply
Rofice
User
User
Posts: 28
Joined: 6 years ago

Conditional variables

Post by Rofice »

Dear all,

I want to model if b(y)<0, then c(y)=b(y), otherwise c(y)=0. Likewise if b(y)>0, then d(y)=b(y), otherwise d(y)=0. Where b,c,d are variables.

Attached is the model which is MINLP. I will really appreciate if someone can help me to formulate MILP formulation. Thanks in advance!

Kind regards,
Rofice
conditional.gms
(687 Bytes) Downloaded 245 times
Fred
Posts: 373
Joined: 7 years ago

Re: Conditional variables

Post by Fred »

Hi,

you could use a big M formulation and change your model as follows:

Code: Select all

$eolcom //
 set y year /0*10/

 parameter a(y) /
 1        -5.5
 2        -16.5
 3        -20.5
 4*10      30.5 /

 display a;

 scalar bigM /100/;

 free variable
 b
 obj fake objective;

 negative variable c ;

 positive variable d ;

 binary variable   e ;

 equation
 eq1
 eq2
 eq3   Non-linear constraint that should be linearized
 eq4   Non-linear constraint that should be linearized
 eq11 ;

 eq1(y)..
         b(y) =e= a(y);

 eq2(y)..
         c(y)+d(y) =e= b(y);
 
 eq3(y)..
         c(y) =g= -bigM*(1-e(y));         

 eq4(y)..
         d(y) =l= bigM*e(y);

 eq11.. obj =e= 2;

 model m /all/

 option optcr = 0, minlp = baron;

 solve m maximizing obj using minlp;
Note that you should make sure to choose bigM sufficiently large but as small as possible.

I hope this helps!

Fred
Rofice
User
User
Posts: 28
Joined: 6 years ago

Re: Conditional variables

Post by Rofice »

Hi,

Thank you very much for the codes! One more thing, you said bound for big M should be large enough but as small as possible. I am just wondering what will happen if a very very big value for big M is used?

Regards,
Rofice
Fred
Posts: 373
Joined: 7 years ago

Re: Conditional variables

Post by Fred »

For example, the solver might run into numerical difficulties.

Best,
Fred
zar
User
User
Posts: 17
Joined: 4 years ago

Re: Conditional variables

Post by zar »

Hi Fred,

Can you help me with formulating the following function:
image.png
image.png (6.03 KiB) Viewed 3073 times
where, a(n) and a(n+1) are parameters, x and lambda(n) are variables.

Appreciate your help.

Thanks,
zar
Post Reply