I just migrated to GAMS from excel solver this past weekend and am pretty novice at the syntax of GAMS. I’m attempting to write an example code which imports the plant capacity of the transport problem from an excel file. I’ve achieved the import of the excel data to gdx file but have an issue loading the parameter data for use during the execution phase of the program. it always returns error 409 after the $LOAD command.
I’ve assigned a parameter CAP for the capacity and intent to replace parameter A(I) with it in the code once I get beyond this load issue.
There has to be a little mistake hiding . Please help me. Also, is there a way I can display the content of the parameter CAP in the .lst file to see what was loaded to the parameter even if I do not use the parameter?
MS excel file is attached
The program.
SETS
I canning plants / SEATTLE, SAN-DIEGO /
J markets / NEW-YORK, CHICAGO, TOPEKA / ;
$CALL ‘GDXXRW.EXE i=C:\Users\Steven_Srivastava\Desktop\GAMS\EXCELIMPORT\data.xls O=C:\Users\Steven_Srivastava\Desktop\GAMS\EXCELIMPORT\data.gdx par=CAP rng=sheet1!A6:B7 rdim=1 set=i’;
$GDXIN ‘C:\Users\Steven_Srivastava\Desktop\GAMS\EXCELIMPORT\data.gdx’
PARAMETER
CAP(I) capacity of plant i;
$LOAD CAP
$GDXIN
PARAMETER
A(I) capacity of plant i in cases
/ SEATTLE 350
SAN-DIEGO 600 /
B(J) demand at market j in cases
/ NEW-YORK 325
CHICAGO 300
TOPEKA 275 / ;
TABLE D(I,J) distance in thousands of miles
NEW-YORK CHICAGO TOPEKA
SEATTLE 2.5 1.7 1.8
SAN-DIEGO 2.5 1.8 1.4 ;
SCALAR F freight in dollars per case per thousand miles /90/ ;
PARAMETER C(I,J) transport cost in thousands of dollars per case ;
C(I,J) = F * D(I,J) / 1000 ;
VARIABLES
X(I,J) shipment quantities in cases
Z total transportation costs in thousands of dollars ;
POSITIVE VARIABLE X ;
EQUATIONS
COST define objective function
SUPPLY(I) observe supply limit at plant i
DEMAND(J) satisfy demand at market j ;
COST … Z =E= SUM((I,J), C(I,J)*X(I,J)) ;
SUPPLY(I) … SUM(J, X(I,J)) =L= A(I) ;
DEMAND(J) … SUM(I, X(I,J)) =G= B(J) ;
MODEL TRANSPORT /ALL/ ;
SOLVE TRANSPORT USING LP MINIMIZING Z ;
The output
GAMS Rev 237 WEX-WEI 23.7.3 x86_64/MS Windows 03/25/14 09:16:06 Page 1
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
C o m p i l a t i o n
1 SETS
2 I canning plants / SEATTLE, SAN-DIEGO /
3 J markets / NEW-YORK, CHICAGO, TOPEKA / ;
4
GDXIN C:\Users\Steven_Srivastava\Desktop\GAMS\EXCELIMPORT\data.gdx
7 PARAMETER
8 CAP(I) capacity of plant i;
9 $LOAD CAP
**** $409
10 $GDXIN
11 PARAMETER
12 A(I) capacity of plant i in cases
13 / SEATTLE 350
14 SAN-DIEGO 600 /
15 B(J) demand at market j in cases
16 / NEW-YORK 325
17 CHICAGO 300
18 TOPEKA 275 / ;
19 TABLE D(I,J) distance in thousands of miles
20 NEW-YORK CHICAGO TOPEKA
21 SEATTLE 2.5 1.7 1.8
22 SAN-DIEGO 2.5 1.8 1.4 ;
23 SCALAR F freight in dollars per case per thousand miles /90/ ;
24 PARAMETER C(I,J) transport cost in thousands of dollars per case ;
25 C(I,J) = F * D(I,J) / 1000 ;
26 VARIABLES
27 X(I,J) shipment quantities in cases
28 Z total transportation costs in thousands of dollars ;
29 POSITIVE VARIABLE X ;
30 EQUATIONS
31 COST define objective function
32 SUPPLY(I) observe supply limit at plant i
33 DEMAND(J) satisfy demand at market j ;
34 COST … Z =E= SUM((I,J), C(I,J)*X(I,J)) ;
35 SUPPLY(I) … SUM(J, X(I,J)) =L= A(I) ;
36 DEMAND(J) … SUM(I, X(I,J)) =G= B(J) ;
37 MODEL TRANSPORT /ALL/ ;
38
39 SOLVE TRANSPORT USING LP MINIMIZING Z ;
**** $257
GAMS Rev 237 WEX-WEI 23.7.3 x86_64/MS Windows 03/25/14 09:16:06 Page 2
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Error Messages
257 Solve statement not checked because of previous errors
409 Unrecognizable item - skip to find a new statement
looking for a ‘;’ or a key word to get started again
**** 2 ERROR(S) 0 WARNING(S)
GAMS Rev 237 WEX-WEI 23.7.3 x86_64/MS Windows 03/25/14 09:16:06 Page 3
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Include File Summary
SEQ GLOBAL TYPE PARENT LOCAL FILENAME
1 1 INPUT 0 0 C:\Users\Steven_Srivastava\Desktop\GAM
S\EXCELIMPORT\xlimportv5.gms
2 5 CALL 1 5 GDXXRW.EXE i=C:\Users\Steven_Srivastav
a\Desktop\GAMS\EXCELIMPORT\data.xls O=
C:\Users\Steven_Srivastava\Desktop\GAM
S\EXCELIMPORT\data.gdx par=CAP rng=she
et1!A6:B7 rdim=1 set=i
3 6 GDXIN 1 6 C:\Users\Steven_Srivastava\Desktop\GAM
S\EXCELIMPORT\data.gdx
COMPILATION TIME = 0.499 SECONDS 3 Mb WEX237-237 Aug 23, 2011
USER: GAMS Development Corporation, Washington, DC G871201/0000CA-ANY
Free Demo, 202-342-0180, sales@gams.com, www.gams.com DC0000
**** FILE SUMMARY
Input C:\Users\Steven_Srivastava\Desktop\GAMS\EXCELIMPORT\xlimportv5.gms
Output C:\Users\Steven_Srivastava\Documents\gamsdir\projdir\xlimportv5.lst
**** USER ERROR(S) ENCOUNTERED
Thanks in advance
–
data.xls (25 KB)