Error 2- Identifier Expected

Problems with syntax of GAMS
Zohreh
User
User
Posts: 9
Joined: 4 years ago

Error 2- Identifier Expected

Post by Zohreh »

Dear friends,
I have a problem modeled in GAMS and I encounter some errors (the first is Identifier Expected) and I do not know how to solve them
input.xlsx
(102.5 KiB) Downloaded 406 times
.
I would highly appreciate it if someone can help me solve this issue.
The files have been attached.
Best regards.
NP1 - New.gms
(4.44 KiB) Downloaded 407 times
NP1 - New.gms
(4.44 KiB) Downloaded 407 times
input.xlsx
(102.5 KiB) Downloaded 406 times
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Error 2- Identifier Expected

Post by bussieck »

Terminate your statements with a ';' then you are on the safe side. There are plenty more errors...

Code: Select all

Parameters
    input(scenario,*)    Input for the scenarios,
    report(scenario,*)   Reporting
    Results(*,scenario)  Saving results
                      D  the annual demand rate,
                      A  the ordering cost per order,
                      W  The supplier's predefined quantity of orders, at which the full trade credit is allowed,
                      c  The unit purchasing cost,
                      p  The unit selling price,
                      h  The unit holding cost per year excluding interest charge,
                      Ie The interest earned per dollar per year,
                      Ip The interest charged per dollar in stock per year,
                      M  The retailer's credit period offered by the supplier in years,
                      N  The customer's credit period offered by the retailer in years,
                      Al The percentage of purchase amount which is granted for the trade credit by the supplier,
                      Te The deteriorating rate a fraction of the on-hand inventory
*                      Tw The time interval during which  units are depleted to 0 because of demand and deterioration,
*                      Q  The optimal order quantity of the retailer,
;
Zohreh
User
User
Posts: 9
Joined: 4 years ago

Re: Error 2- Identifier Expected

Post by Zohreh »

Yes, you are right.
Thank you very much for your help.
I will check the model and try to solve the other errors.
Zohreh
User
User
Posts: 9
Joined: 4 years ago

Re: Error 2- Identifier Expected

Post by Zohreh »

Thank you very much indeed.
I have one more problem. One of the errors is division by 0 and I must set the variable T greater than (not equal to) zero. I could not find any operator to do so.
I would highly appreciate it if you guide me how to define T>0 in GAMS, in which T is a decision variable.
Best regards.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Error 2- Identifier Expected

Post by bussieck »

Use a lower bound on T (T.lo=1e-3;) Also don't use **2 for squares. ** is the real power operator. If you have **2, use sqr which can have negative arguments, while **2 cannot.

-Michael
Zohreh
User
User
Posts: 9
Joined: 4 years ago

Re: Error 2- Identifier Expected

Post by Zohreh »

Model- GAMS.pdf
(325.45 KiB) Downloaded 367 times
Thank you very much for your great support.
I have a question.
My model consists of different models, depending on the parameters and the variable's relationships.
How can I define it in GAMS? I mean how it is possible to ask GAMS that if the first set of constraints is satisfied, then return z1, else if the second set is satisfied, return z2, ...
The model is attached.
I would highly appreciate it if you guide me.
Best regards.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Error 2- Identifier Expected

Post by bussieck »

Just make 5 models and solve them in sequence. Check the model/solve status if you have a feasible solution:

Code: Select all

e11.. 1/Te*log((W*Te/D)+1) =L= M-N;
e12.. T =G= M-N;
o1.. z1 =E= A/T+(h*D)/(sqr(Te)*T)*((exp(Te*T)-1)-(Te*T))+(c/T)*((D/Te)*(exp(Te*T)-1)-D*T)+((c*Ip*D)/T)*((sqr(T+N-M))/2)-((p*Ie*D)/T)*((sqr(M-N))/2);
model m1 /e11,e12,o1/;
solve m1 min z us nlp;
if (m1.solvestat=1 and (m1.modelstat=1 or m1.modelstat=2 or m1.modelstat=8), abort.noError 'm1 solved to feasibility');

e21.. T =L= M-N
e22.. T =G= 1/Te*log((W*Te/D)+1)
o2.. z1 =E= A/T+(h*D)/(sqr(Te)*T)*((exp(Te*T)-1)-(Te*T))+(c/T)*((D/Te)*(exp(Te*T)-1)-D*T)+((c*Ip*D)/T)*((sqr(T+N-M))/2)-((p*Ie*D)/T)*((sqr(M-N))/2);
model m2 /e21,e22,o2/;
solve m2 min z us nlp;
if (m2.solvestat=1 and (m2.modelstat=1 or m2.modelstat=2 or m2.modelstat=8), abort.noError 'm2 solved to feasibility');

*...
Obviously, you need to declare all you variable and equation symbols before.

-Michael
Zohreh
User
User
Posts: 9
Joined: 4 years ago

Re: Error 2- Identifier Expected

Post by Zohreh »

Thank you very much for your great help.
Zohreh
User
User
Posts: 9
Joined: 4 years ago

Re: Error 2- Identifier Expected

Post by Zohreh »

I have defined all the functions in sequence.
But, I have two problems:
1. Although I have defined all of the variables, GAMS gives me Error 66 (The symbol shown has not been defined or assigned).
2. Moreover, I want to ask GAMS to read data from an Excel file and display the results in another one. I am not sure whether the way I have coded the problem is OK. or not and don't know where to put the following code:
Loop(scenario,
D = input(scenario,"D");
A = input(scenario,"A");
W = input(scenario,"W");
c = input(scenario,"c");
p = input(scenario,"p");
h = input(scenario,"h");
Ie = input(scenario,"Ie");
Ip = input(scenario,"Ip");
M = input(scenario,"M");
N = input(scenario,"N");
Al = input(scenario,"Al");
Te = input(scenario,"Te");
I would highly appreciate it if you help me to solve these issues.
Best regards.
TC- Total.gms
(20.55 KiB) Downloaded 359 times
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Error 2- Identifier Expected

Post by bussieck »

If you have a scenario loop you need to move all the declarations and equation definitions before this loop. Also check your understanding of compile and execution time in GAMS. Multiple "$echo deltaterm 1 > baron.opt" have no effect because they are all done before execution starts, so the last "$echo deltaterm 1 > baron.opt" wins.

My suggested solution to stop as soon as a model has been solved to feasibility with "if (m1.solvestat=1 and (m1.modelstat=1 or m1.modelstat=2 or m1.modelstat=8), abort.noError 'm1 solved to feasibility');" makes no sense if you want to solve multiple scenarios, since it stops the entire GAMS run. You might want to just solve all models, record the model status and in case of feasibility also record the level of the decision variables at the point returned by the solver.

Moreover, your can use "$batInclude" to move code that repeats in an external file. If you actually can jump to the next scenario as soon as a model has solved to feasibility, you can use the keyword "continue" (commented the batinclude in my code) and some logic.

Some of your constraints (e.g. e11 .. 1/Te*log((W*Te/D)+1) =L= M-N;) have no decision variable in it. For some scenarios this will result in an infeasible row and GAMS does not like such infeasible constant constraint and terminates with an execution error. If you coded them correctly without decision variables, you either need to check it's feasibility by GAMS statement and in case of infeasibility not even call the solver. Another solution is to introduce a dummy variable (and have this fixed to zero) to trick GAMS.

I have attached a working version with the latter trick.

Consider this a late Christmas present (not sure if you celebrate Christmas in your part of the world).

-Michael
TC- Total - MRB.gms
(8.09 KiB) Downloaded 380 times
Post Reply