Page 1 of 1

Require a linear function

Posted: Wed Jun 02, 2021 3:19 pm
by parag_patil
Dear all ,

I want to have a linear function ,

Code: Select all

y = f(x,y1,y2,y3)
The above function should give the following answers :

Code: Select all

y = y1 , if x = x1 

Code: Select all

y = y2 , if x = x2 

Code: Select all

y = y2 , if x = x3 
The variable, x is an integer variable, which will only take values, x1, x2 and x3.

I can do it when x is binary (0,1) as follows:

Code: Select all

y = x*y1 + (1-x)*y2
this gives,

Code: Select all

y = y1 , if x = 1
y = y2 , if x = 0
But I want to do it for x , taking three / four values.

Please help me in this.

Thanks

Re: Require a linear function

Posted: Wed Jun 02, 2021 5:44 pm
by abhosekar
First of all, you can model your integer variable as binary variables.

Code: Select all

set
i/1*3/
x = sum(i, i*xb(i));
sum(i, xb(i)) =e= 1;
The idea is that since x can take values 1,2,3, you can declare 3 binary variables xb('1'),xb('2'), and xb('3').

If x is 1, xb('1') is 1 and the rest are zero and so on.

You can then use xb(i) to impose conditions that you want (you know how to do that).

- Atharv

Re: Require a linear function

Posted: Wed Jun 02, 2021 6:01 pm
by parag_patil
Thank you for your answer. Yes. I did the same.

It seems that linearization is more of an art and less of a science. :D