Hello, I am a new user in GAMS.
I have a question about the given number which is also the variable.
There is my question.
Max x(1)+x(2)+… +x(100)
x(i)<=x(i+1) +2x(i+2)
x(99)=1000
x(100)=1200
all variables are non-negative.
Here is what I typed. However, the variable showed it redefined.
How could I define x(i=99)=1000 in GAMS?
By the way, my “parameters” did not work sometimes. It did not blue so I could not build parameters.
Is there any way to fix it?
The way you should declare the set and parameter is:
set i /i1*i100/;
parameters
x(i)
/i99 1000,
i100 1200/;
But you can’t have the same name for two different elements! If you want to have fixed values for the last two xariables you must use the following instead of the parameter:
x.fx('i99') = 1000;
x.fx('i100') = 1200;
Then, in con1, when set i reaches its last two elements (i99 and i100) will produce x(‘i101’) and x(‘i102’) which are not “valid”, so you will need do replace with the following:
con1(i)$(ord(i) le card(i)-2).. x(i)=l=x(i+1)+2*x(i+2);
Expect input the fixed value I also wandering how could I input the initial value of the variable.
For example, I would like to calculate MP(t) (mfg. production, t is the period from 1~3), and I know the initial production(t=1) is 300.
I am wondering which one is correct. Also I am confused on the difference between scalar and parameter.
equation:
MP(t)…MP.l(t)=E=300;
or
scalar:
MP1 ‘initial production at mfg.’ / 300 /
or
the other ways I search from library:
tb(t) ‘base period’
tt(t) ‘terminal period’;
tb(t) = yes$(ord(t) = 1);
tt(t) = yes$(ord(t) = card(t));
If the last one is correct, I still have the question about this.
I input the code as below.
However, it shows that Error 198
“Set used in ‘ord’ or lag is not ordered.
Hint: Some of the elements of the set were used before this
was initialized and the order was different from the order used
in this set. Try to initialize the set earlier.
$offOrder allows lag operations on dynamic sets, reset with
$onOrder”
If I delete i parts /1,2/, it worked. I have no idea about this.
I am appreciate for replying me.
I would strongly advise you to take a look at the introduction into Gams in the manual.
You define a parameter over 100 elements and then assign 4 values to the parameter, which is impossible and furthermore the definition of this parameter is not following Gams rules.
This parameter x(i) then it becomes a variable: x(i) can only be a parameter or a variable.