Page 1 of 1

How to write this constraint

Posted: Fri Nov 15, 2019 7:41 pm
by romyn
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)

Re: How to write this constraint

Posted: Tue Nov 19, 2019 4:12 pm
by achristensen
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

Re: How to write this constraint

Posted: Tue Nov 19, 2019 8:54 pm
by romyn
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)

Re: How to write this constraint

Posted: Tue Nov 19, 2019 9:01 pm
by romyn
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!

Re: How to write this constraint

Posted: Tue Nov 19, 2019 10:49 pm
by achristensen
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