Conditional Equations with Variable in GAMS

Problems with syntax of GAMS
Post Reply
Lilson
User
User
Posts: 1
Joined: 10 months ago

Conditional Equations with Variable in GAMS

Post by Lilson »

I'm trying to implement conditional statements in the equations part of GAMS non-linear optimisation. I know that $ statements or for loops are not allowed. I also tried big M method but also failed. What I need is something like this:

Code: Select all

Energy_Exported(t) = PV_Generation(t) -Demand(t);

Energy_Exported(t)$[Energy_Exported(t)<0] = 0; 
That would work if implemented on both parameters. But Demand(t) is an optimised positive variable.

I tried enforcing Demand(t) to be positive variable and then

Code: Select all

Energy_Imported(t) =g= Demand(t) - PV_Generation(t);
but that also doesn't work - I got unbounded solution.

The problem is that in some cases the outcome of PV_Generation(t) -Demand(t) may be positive or negative. If it's negative I want to set the variable to 0.

Many thanks for your help!
GabrielYin
User
User
Posts: 72
Joined: 6 years ago
Location: Dallas, TX, USA
Contact:

Re: Conditional Equations with Variable in GAMS

Post by GabrielYin »

This is a modeling question rather than a GAMS syntax question.

If your problem is a minimization problem over Energy_Exported, simply put:

Energy_Exported >= PV_Generation - Demand
Energy_Exported >= 0

If your problem is a maximization problem over Energy_Exported, then you have to use a binary indicator A:

Energy_Exported <= (PV_Generation - Demand) * A
PV_Generation - Demand <= M * A
PV_Generation - Demand >= -M * (1 - A)
Energy_Exported <= M * A
Energy_Exported >= 0

M is a big value. The first equation is bilinear, so you will need to use linearization techniques such as McCormick Envelope.

Best,
Gabriel
ekt
User
User
Posts: 3
Joined: 9 months ago

Re: Conditional Equations with Variable in GAMS

Post by ekt »

Lilson, can i reach you any social media for some asking about modeling in GAMS?
Post Reply