Dear GAMS folks,
a quick question regarding reading data into GAMS.
To get things really clean, I would like to take a dataset that I get from somewhere else in Excel format without touching it before reading it into GAMS.
The data structure is straight forward:
Say, what I would like to automatically read-in from that table is the following things:
Sets
product
productType
typemap(product, productType)
;
Parameters
price(product)
size(product)
;
I can easily read in price and size as follows, but I have problems with the typemap(product, productType) mapping set.
So, I would go ahead and define an “Index” sheet in my Excel file that looks like this:
And would then read that in like this:
\
Sets
product
productType
typemap(product, productType)
;
Parameters
price(product)
size(product)
;
\
- Additional parameters for data upload (not needed in model)
Set attribute;
Parameter productData(product,attribute);
$onUNDF
$call gdxxrw “test.xlsx” o=data.gdx Index=Index!A1
$GDXIN data.gdx
$load attribute product productType
$load productData
$gdxin
$offUNDF
price(product) = productData(product,“price”);
size(product) = productData(product,“size”);
Execute_unload ‘mydata.gdx’;
This way, price and size are correctly filled. Now: How would I go about also reading in typemap(product, productType) automatically (without modifying the original input data), so it has e.g.
typemap(“prod1”, “fruit”) = YES;
?
Thanks in advance for any helpful responses!
Cheers
Ingmar
\