Hi Everyone,
I’m trying to run a GAMS profit max model using the Python API. The .gms file from command line works, but I’m trying to load and run the model all within Python using the get_model_text() function and setting up and using a database.
The main problem I’m noticing is that I get the #353 error when including a data table item as D(FM, “COL_NAME”) within my Equations, where D is a data table (2-d Parameter as in Python API), FM is a set, and “COL_NAME” is a column name in my data table. This also occurs with my Variable when I have XV(“COL_NAME”).
ERROR 353 The domain for this index position is unknown and the element
cannot be checked at this point. Missing data statement.
The only major difference between my Python implementation and the straight GAMS command line implementation is that I do not include a $INCLUDE dat file with the data table in the Python implementation.
So, my question is, Can you tell me why I am not able to call D(FM, “COL_NAME”) or XV(“COL_NAME”) in the Python API representation? Any pointers on setting the Python API correctly?
Thanks in advance!
Brad
My .lst file is attached showing the error. Also, my Python code specifically related to populating the database is as follows (and attached; I populated a lot of these variables in the .py code using the ref_dat.csv):
#Initialize Workspace
ws = GamsWorkspace(debug=2) #1,2,3
#Set up database
db = ws.add_database()
##Add in appropriate Sets and Parameters
FM = db.add_set(“FM”, 1, “farms”)
for m in range(0,87):
FM.add_record(FMdata[m])
ONEDATA = db.add_set_dc(“ONEDATA”, [FM], “farms”)
for m in range(0,87):
ONEDATA.add_record(FMdata[m])
R = db.add_set(“R”, 1, “R list of names”)
for m in Rdata:
R.add_record(m)
FIXED_INPUTS = db.add_set_dc(“FIXED_INPUTS”, [R], “R list of names”)
for m in FIXED_INPUTSdata:
FIXED_INPUTS.add_record(m)
OUTPUTS = db.add_set_dc(“OUTPUTS”, [R], “R list of names”)
for m in OUTPUTSdata:
OUTPUTS.add_record(m)
INPUTS = db.add_set_dc(“INPUTS”, [R], “R list of names”)
for m in INPUTSdata:
INPUTS.add_record(m)
FSS = db.add_set_dc(“FSS”, [ONEDATA], “R list of names”)
#for m in range(0,87):
FSS.add_record(FMdata[m])
##Add table, which can be treted as a parameter with dim=2.
D = GamsParameter(db, “D”, 2, “distance in thousands of miles”)
for k, v in Ddata.iteritems():
D.add_record(k).value = v
print k, v
#SNIPPET OF D PARAMETER TABLE TAKEN FROM A PYTHON DICTIONARY I CREATED.
#(‘FM20’, ‘TOTALFUEL’) 286.337127463
#(‘FM67’, ‘TOTALFUEL’) 57968.0865303
#(‘FM47’, ‘FERTILIZER’) 60703.2489191
#(‘FM66’, ‘SEED’) 78969.5099126
#(‘FM79’, ‘MAINTENANCE’) 97355
#(‘FM18’, ‘CROP_SALES’) 3269.50205695
(‘FM44’, ‘TAX’) 75691.4106682
#(‘FM72’, ‘ZIPC’) 284527.501893
#(‘FM13’, ‘TAX’) 50624.2413051
#(‘FM8’, ‘CROP_SALES’) 40005.6856242
#(‘FM10’, ‘UTILITIES’) 143682.975168
#(‘FM7’, ‘TAX’) 1704.99069405
#(‘FM25’, ‘FERTILIZER’) 17407.1955689
t2 = ws.add_job_from_string(get_model_text())
#Run Model
t2.run(databases=db)
\
gamsError.lst (4.55 KB)
ref_dat.csv (16.4 KB)
rungams.py (8.08 KB)