Require a linear function Topic is solved

Problems with syntax of GAMS
Post Reply
parag_patil
User
User
Posts: 30
Joined: 2 years ago
Location: Ahmedabad
Contact:

Require a linear function

Post 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
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Require a linear function

Post 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
parag_patil
User
User
Posts: 30
Joined: 2 years ago
Location: Ahmedabad
Contact:

Re: Require a linear function

Post 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
Post Reply