## a question about Gams modeling

Problems with modeling
lawrence
User
Posts: 2
Joined: 1 year ago

### a question about Gams modeling

I am facing a problem with Gams modeling, and will be very appreciated if someone can help me.

I define:
set t
variable x(t).

I want to express this equation as a constraint in my model:
x(t=T)>=sum(t,x(t<=T-1))
which means the variable x at time slot t should be equal or larger than the sum of x at all time slot before t.

I tried a lot of ways to express it as an equation in Gams, but all of them doesn't work. Can someone here help me dealing with this? Thanks!

Lawrence

Renger
Posts: 219
Joined: 2 years ago

### Re: a question about Gams modeling

Hi Lawrence

I assume that T is the last period in your model

Code: Select all

``````
set
t  'periods' /t1*t10/,
lastt(t) 'last period';

* Define the last period by using the total number of elements in the set t
lastt(t)\$(ord(t) eq card(t)) = yes;

display lastt;

variable x(t).

alias(t,tt);

x(lastt) =G= sum(tt\$(ord(tt) lt card(t), x(tt));

``````
Cheers
Renger

lawrence
User
Posts: 2
Joined: 1 year ago

### Re: a question about Gams modeling

Hi Renger,

Your code is very helpful and my problem is solved now. Thank you very much!

Lawrence