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 (103 KB)
.
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 KB)
NP1 - New.gms (4.44 KB)
input.xlsx (103 KB)
Terminate your statements with a ‘;’ then you are on the safe side. There are plenty more errors…
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,
;
Yes, you are right.
Thank you very much for your help.
I will check the model and try to solve the other errors.
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.
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
Model- GAMS.pdf (325 KB)
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.
Just make 5 models and solve them in sequence. Check the model/solve status if you have a feasible solution:
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
Thank you very much for your great help.
I have defined all the functions in sequence.
But, I have two problems:
- Although I have defined all of the variables, GAMS gives me Error 66 (The symbol shown has not been defined or assigned).
- 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.5 KB)
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/Telog((WTe/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 KB)
Thank you very much for your complete response.
We actually celebrate Nowrouz, which is the first day of Spring.
Anyway, Happy Christmas!
I wish you the bests.
Dear Dr. Bussieck,
The model works well, but I have one problem.
In equation
1/Telog((WTe/D)+1) =L= M-N
the models considers the left hand side up to 2 digits and it causes some numerical examples get the wrong answer.
I have attached the Excel File, including four numerical examples. In the second and fourth ones, GAMS considers the rounded value of the above mentioned equation’s left hand side up to 2 digits.
I would highly appreciate it if you help me solve this issue.
Best regards.
input - Copy.xlsx (19.2 KB)
Zohreh,
GAMS does its calculations in double-precision arithmetic - there is no calculating “up to 2 digits” or anything like that. However, the listing file displays values in rounded form. Also, solvers do their calculations with tolerances, so an equation like LHS <= RHS is not satisfied exactly, but only within a tolerance (e.g. 1e-5 or similar). These facts, or perhaps others, may be relevant to tracking down any inconsistencies between your results and your expectations, but it’s not likely to be any rounded calculations in GAMS itself.
I could perhaps say more if you could be more explicit about the problem. For example, what result in GAMS do you see that you don’t expect? What do you expect to see instead? Why?
-Steve
Dear Dr. Dirkse,
I have 2 cases: Tw<=(M-N) and Tw>=(M-N).
If Tw<(M-N), the result would be the minimum of m1, m2, and m3 (m4, m5, m6, m7, and m8 are definitely infeasible).
If Tw>(M-N), the result would be the minimum of m4, m5, m6, m7, and m8 (m1, m2, and m3 are definitely infeasible).
If Tw=(M-N), the result would be the minimum of m1 to m8 (of course the ones which are feasible).
In the Excel file, for Sc1 and Sc2, Tw=0.059991 and M-N= 0.07, since Tw<(M-N), I expected the result be the minimum of m1, m2, and m3. But, GAMS finds feasible solutions for m1, m2, m3, and m5 (it considers Tw=(M-N)).
Thank you very much for your attention.
input - Copy.xlsx (9.18 KB)
Hi GAMS forum Friends
I have got similar challenges like Zohreh while running my model. I have received “an error-2 Identifier expected” on several lines of the attached GAMS Code. I would appreciate it if someone can help me to remove these errors.
Gams New.gms (9.87 KB)
Hi,
You are mixing GAMS and MPSGE syntax. The MPSGE syntax is inside a $onText/$offText area and ignored by the GAMS compiler. Check out the MPSGE introduction at: https://www.gams.com/latest/docs/UG_MPSGE_Intro.html.
-Michael
Hi Michael
Thank you very much for your prompt response, as you suggested me, I have inserted the MPSGE syntax in $onand$offtext in section (ii) but still, nothing has improved. Please, can you check and correct it for me. I have attached the entire model syntax and excel sheet.
With Kind regards
Ekalo
CGE Water.gms (26.3 KB)
CGE Water.gms (26.3 KB)
NB.xlsx (28.3 KB)
There are many compilation error. Get rid of them. The compiler error message will help you with this. For example, then first one:
201 chksam(i) = sum(j,sam(i,j)-sam(j,i));
**** $171,148 $171,148
**** 148 Dimension different - The symbol is referenced with more/less
**** indices as declared
**** 171 Domain violation for set
Your parameter sam is declared as “Table SAM(r,i,j) initial SAM ;”. What happened to the “r” index in your chksam assignment? Please study the GAMS material to fix the errors on after the other yourself.
Good luck,
-Michael
Hi Michael
Thank you very much again, okay I got the balance check part, please can you help me with section II which is MPSGE model syntax and I will deal with the rest part. Please, please, just help me with section II of my GAMS code and it was attached with my previous message. God may bless you, sir.
With regards
Ekalo
Sorry, I can’t help with MPSGE syntax. Never learned that. I guess someone suggested to you using MPSGE, I would go to that person to get help. -Michael