Require a linear function Topic is solved

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

Require a linear function

Post by parag_patil » 2 weeks ago

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: 176
Joined: 8 months ago

Re: Require a linear function

Post by abhosekar » 2 weeks ago

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: 17
Joined: 2 months ago
Location: Ahmedabad
Contact:

Re: Require a linear function

Post by parag_patil » 2 weeks ago

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