Extract 1 from variables {-1, 0, 1}

Problems with modeling
Post Reply
leewing159
User
User
Posts: 2
Joined: 1 week ago

Extract 1 from variables {-1, 0, 1}

Post by leewing159 » 1 week ago

Hi, this is my first question on Gams Forum.

I'm now modelling with gams, and having a trouble.

I have a variable name as A.
A(machine, time) only has value of -1, 0, 1 as its value.
Actually, 1 means 'turning on a machine', -1 means 'turning off machine' in my model.

I would like to extract only '1' and '-1' value from A.
I tried introducing new variables such as A_positive and A_negative.
Adding two more equations in my model.

A_positive(machine, time) = max(A(machine, time), 0);
A_negative(machine, time) = min(A(machine, time), 0);

But, it does not work with error message below.
"Endogenous function argument(s) not allowed in linear models"

Is there any other way that I can do this?

Thanks in advance.

User avatar
dirkse
Moderator
Moderator
Posts: 84
Joined: 3 years ago
Location: Fairfax, VA

Re: Extract 1 from variables {-1, 0, 1}

Post by dirkse » 1 week ago

You could do some thing like this:

binary variables
switchOn 'turning machine on'
switchOff 'turning machine off'
;
equation switchCon;
switchCon .. switchOn + switchOff =L= 1;

With this, you have the option to do nothing or to switch on or switch off, but not switch on and off.

-Steve

leewing159
User
User
Posts: 2
Joined: 1 week ago

Re: Extract 1 from variables {-1, 0, 1}

Post by leewing159 » 1 week ago

Thanks for your reply.

For me, I solve this trouble with this.

Binary variable switch_on
Binary variable switch_off

with two constraints
A = switch_on - switch_off;
switch_on + switch_off =L= 1;

then when A = 1, switch on always have value of 1 and value of 0 for switch_off.
Also, when A = 0, both value are 0.
When A=-1, switch_on 0, switch off 1.

Post Reply