How to write this constraint

Problems with syntax of GAMS
Post Reply
romyn
User
User
Posts: 3
Joined: 7 months ago

How to write this constraint

Post by romyn » 7 months ago

Hello

I am finding difficulty in modeling this constrain, your help would be much appreciated:

s(j+n) >= c(i,j) for every i where n= 1,2,3,4,5...N-j

s(j) is a defined parameter
c(i,j) is a defined variable
i and j are defined sets
N is equal to last component of set j

how can I index j+n and how to create n= 1 to N-j (dynamically changing with j)

User avatar
achristensen
User
User
Posts: 14
Joined: 7 months ago

Re: How to write this constraint

Post by achristensen » 7 months ago

hi there... i think we might need a bit of clarifying information here to help out. Do you have a superset that includes all elements j+n? Or are you trying to do some sort of circular lead/lag operation? If so, check out the documentation here: https://www.gams.com/latest/docs/UG_OrderedSets.html (you would need to use the ++ or -- syntax). Circular set operations are handy, but if you can avoid them I would try to do that... they can get tricky to debug.

also... when writing a new constraint you should first ask yourself what set do I want to write my constraint over... remember that you can control the creation of the constraint with the definition statement first (the part before the ".."). i.e.,

d(i,j)$c(i).. x(i,j) =E= a(i) + b(j);

(you can also do something similar during equation declaration)

let me know, and I'll try and help out more.

best,
adam

romyn
User
User
Posts: 3
Joined: 7 months ago

Re: How to write this constraint

Post by romyn » 7 months ago

Essentially I am trying to achieve this:

s(j+1) >= c(i,j)
s(j+n) >= c(i,j)
s(j+n) >= c(i,j)

romyn
User
User
Posts: 3
Joined: 7 months ago

Re: How to write this constraint

Post by romyn » 7 months ago

Essentially what im trying to achieve is this:

s(j+1) =g= c(i,j)
fyp.gms
(2.8 KiB) Downloaded 22 times
s(j+2) =g= c(i,j)
s(j+3) =g= c(i,j)
s(j+4) =g= c(i,j)
.
.
.
until we reach the end of set j

I tried s(j+1) and s(j++1) but no matter how you define it, gams is not allowing me to input n as a set or scaler (in the form of a loop, for, while functions), but rather requires a primary real number. I cannot seem to get past this error as I do not want to input these numbers manually (I have a huge number of variables). How can I define it before the equations?

(sorry for the previous reply I submitted it by mistake)

Kindly view the file attached, my problem concerns constraint dep(i,j), Thank you for your help!

User avatar
achristensen
User
User
Posts: 14
Joined: 7 months ago

Re: How to write this constraint

Post by achristensen » 7 months ago

you cannot use a loop statement within an equation definition... you need to somehow structure your equation definition so that the looping behavior you are hoping for is taken care of entirely with set operations. This might also necessitate an alias set. While doing this you might also need to rethink your choice of decision variables... It might be helpful to post this question in the "Modeling" section of the forum rather than "Syntax".

sorry I couldn't be of more help at the moment.

best,
adam

Post Reply