.inc files Topic is solved

Problems with syntax of GAMS
ferrib
User
User
Posts: 10
Joined: 2 months ago

.inc files

Post by ferrib » 2 months ago

Hi there,

I am having trouble importing data using ".inc" files.

I am able to import data my parameters from an excel sheet. But it takes such a long time to process, and I have an old example where parameters were imported using .inc files so I decided to give it a try (this seemed faster for the parameters i was able to import, but correct me if not!).

For parameters which only contain one value or an array i managed to read the .inc file. But when I have columns I can't. I suppose this has to do with how data is formatted (i copied a table from excel and pasted it on the notepad file) - i get errors 170 (domain violation - dimension different) and 334 (i guess because of 170). I have also tried .csv files, but i did not manage to do it: anyway, would it be faster than from the excel file?

example of the data i need to input (couldn't attach, "invalid format"):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
d1 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480
d2 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490
d3 34 54 74 94 114 134 154 174 194 214 234 254 274 294 314 334 354 374 394 414 434 454 474 494
d4 38 58 78 98 118 138 158 178 198 218 238 258 278 298 318 338 358 378 398 418 438 458 478 498

Many thanks in advance.
F

User avatar
bussieck
Moderator
Moderator
Posts: 198
Joined: 2 years ago

Re: .inc files

Post by bussieck » 2 months ago

The following works for me. Since you did not align the data (required for normal Table statement), you need to read under $ondelim. For this you need to add the 'd' in the header row:

Code: Select all

set i / 1*24 /, d / d1*d4 /;
$onecho > data.inc
d 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
d1 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480
d2 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490
d3 34 54 74 94 114 134 154 174 194 214 234 254 274 294 314 334 354 374 394 414 434 454 474 494
d4 38 58 78 98 118 138 158 178 198 218 238 258 278 298 318 338 358 378 398 418 438 458 478 498
$offecho
table data(d,i)
$ondelim
$include data.inc
$offdelim
;
-Michael

ferrib
User
User
Posts: 10
Joined: 2 months ago

Re: .inc files

Post by ferrib » 2 months ago

Michael,

Thanks so much for your quick feedback.

Understood the $ondelim and $offdelim, also the first "d". Additionally, I was only declaring the table as "parameter" (and not "table") - and that was working for importing data from the excel.

User avatar
bussieck
Moderator
Moderator
Posts: 198
Joined: 2 years ago

Re: .inc files

Post by bussieck » 2 months ago

Not sure how you read data from Excel, but with gdxxrw (the best supported way) you get a GDX file and then it does not matter if you declare as parameter or table.

-Michael

mahmoudabadi
User
User
Posts: 1
Joined: 2 months ago

Re: .inc files

Post by mahmoudabadi » 2 months ago

Dear Ferrib
I agree with bussieck. If your data is in Excel sheet file, the best way is to use GDXXRW which is a very powerful command to read and write data from and on Excel sheet files.
I had many problems to use .inc files, but I am using the above command without any problem.
Regards, Abbas Mahmoudabadi

ferrib
User
User
Posts: 10
Joined: 2 months ago

Re: .inc files

Post by ferrib » 2 months ago

Hi there,

I tried GDXXRW but .inc is way faster. I was losing 1 minute to input the data via GDXXRW, but with .inc files it takes literally nothing.

Best regards

User avatar
Renger
Posts: 201
Joined: 2 years ago

Re: .inc files

Post by Renger » 2 months ago

Hi
GDXXRW has the option "CheckDate": it checks before importing the data from an excel sheet if the sheet has been changed in the meantime. If not, it will skip the import and use the already available gdx file from the most recent import.
Cheers
Renger

ferrib
User
User
Posts: 10
Joined: 2 months ago

Re: .inc files

Post by ferrib » 2 weeks ago

Hi again,

Just ressurrecting this topic to see if any of you can provide an example with the CheckDate option. I can't make it work. Let's say my example for loading data is as follows, where should i place my "checkdate"?

Set d;
$call gdxxrw.exe i=input.xlsx set=d rng=Sheet1!c2 rdim=1 cdim=0
$gdxin input.gdx
$load d
$gdxin
display d;

Thanks in advance

User avatar
Renger
Posts: 201
Joined: 2 years ago

Re: .inc files

Post by Renger » 2 weeks ago

Hi
It should be written at the end of the line and correctly spelled: not "checkdate" but CheckDate.
If this doesn't work, please send an excel sheet and the code that doesn't work.
Cheers
Renger

ferrib
User
User
Posts: 10
Joined: 2 months ago

Re: .inc files

Post by ferrib » 2 weeks ago

Hi Renger,

Thanks for your help.

Attached the .xlsx file and the gams code.
Attachments
Untitled_16.gms
(121 Bytes) Downloaded 3 times
input.xlsx
(7.99 KiB) Downloaded 4 times

Post Reply