How to import excel file in GAMS?

6,095 views
Skip to first unread message

sara sohail

unread,
Feb 13, 2012, 3:35:33 AM2/13/12
to gams...@googlegroups.com
Dear GAMS Friends,

I am a beginner in GAMS so i need help how to import excel file in to GAMS software. 

Can any of you help me so that i can understand it and complete my work?

Kind Regards,

Sara


deepti singhal

unread,
Feb 13, 2012, 4:01:26 AM2/13/12
to gams...@googlegroups.com
Dear Sara

Pl follow this link 
U need to convert an excel file in GDX format and then u can read it in gams

All the best

Cheers
Deepti

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.



--
Deepti Chadha (Singhal)

sara sohail

unread,
Feb 13, 2012, 4:33:29 AM2/13/12
to gams...@googlegroups.com
Thax Deepti,

I shall try it then come to you again.

Wishes,
Sara

sara sohail

unread,
Feb 13, 2012, 4:58:57 AM2/13/12
to gams...@googlegroups.com
Hi All!

i did not understand it can anyone explain how to do this. because i did not get a hint about GDX file? Or how to get Excel file in GAMS. Please help me. The things on line are not so easy to understand.

Wishes,

Sara

sara sohail

unread,
Feb 13, 2012, 5:03:39 AM2/13/12
to gams...@googlegroups.com
http://www.pep-net.org/fileadmin/medias/pdf/Weighted_Tariff_1.pdf 
is this link fine to understand GDX and excel conversion?

Sara

ali

unread,
Feb 13, 2012, 5:40:58 AM2/13/12
to gams...@googlegroups.com
Hi Sara
If you want send me(7arbaha...@gmail.com) an E-mail so i give you
a small project that may help you to learn how it works.

Lena

unread,
Feb 13, 2012, 10:19:10 AM2/13/12
to gams...@googlegroups.com
Sara,
 
You can import excel file in to gams as the following:
 
$call =xls2gms @"C:\directory your file has been saved\xls2gms_data.txt"
 
*then you define for example "a" as Stores and write;
 
a   stores/
$include C:\directory your file has been saved \files name.inc
 
Hope this helps,
Lena

Savitsky Andre

unread,
Feb 13, 2012, 10:34:41 AM2/13/12
to gams...@googlegroups.com
 

$onecho > task.txt
set= M rng= nodes!u6 rdim=1
set= province rng= nodes!X12 rdim=1
set= Season rng= nodes!V2 rdim=1
par= Distribution rng= nodes!X11 rdim=1 cdim=1
par= Distribution_surplus rng= nodes!X19 rdim=1 cdim=1
set= SeasonToMonth rng= nodes!U6 rdim=2
set= N rng= nodes!b6 rdim=1
set= River rng= nodes!m6 rdim=1
set= Lake rng= nodes!m37 rdim=1
set= Canal rng= nodes!q7 rdim=1
set= Out rng= nodes!m32 rdim=1
set= NN rng= nodes!e6 rdim=2
set= N_Canal rng= nodes!p7 rdim=2
set= Canal_prov rng= nodes!q7 rdim=2
par= Inflow rng= water_data!c147 rdim=1 cdim=1
par= Correction rng= nodes!e6 rdim=2
par= Observation rng= water_data!c66 rdim=2 cdim=1
par= Demand rng= water_data!c5 rdim=1 cdim=1
par= canal_capacity rng= water_data!r6 rdim=1
par= Start_Vol rng= water_data!c137 rdim=1
set= Coeff rng= water_data!h136 cdim=1
Par= Coeff_Lake rng= water_data!g136 rdim=1 cdim=1
par= Up_Rule rng= water_data!c114 rdim=1 cdim=1
par= Lo_Rule rng= water_data!c128 rdim=1 cdim=1
par= Side_INFLOW rng= water_data!c165 rdim=1 cdim=1
par= Timestep rng= nodes!Y6 dim=0
par= conversion rng= nodes!y3 dim=0
par= TimeLag rng= nodes!i6 rdim=2
$offecho

*
* OUTTASK0 file for output organization
*

$onecho > outtask0.txt
text="Table of Content" rng=TOC!a1
var= intake rng=water_output!c6 rdim=1 cdim=1 textid=intake rng=toc!a12 linkid=intake
text=back rng=water_output!c4 link=toc!a12 textid=intake rng=water_output!d4
par= demand rng=water_output!c70 rdim=1 cdim=1 textid=demand rng=toc!a13 linkid=demand
text=back rng=water_output!c68 link=toc!a13 textid=demand rng=water_output!d68
par= demand_total rng=water_output1!c70 rdim=1 cdim=1 textid=demand_total rng=toc!a13 linkid=demand_total
text=back rng=water_output1!c68 link=toc!a13 textid=demand_total rng=water_output1!d68
par= province_demand rng=water_output!c130 rdim=1 cdim=1 textid=water_output_info rng=toc!a13 linkid=province_demand
text=back rng=water_output!c128 link=toc!a13 textid=province_demand rng=water_output!d128
par= province_demand_surplus rng=water_output!c140 rdim=1 cdim=1 textid=water_output_info rng=toc!a13 linkid=province_demand_surplus
text=back rng=water_output!c138 link=toc!a13 textid=province_demand_surplus rng=water_output!d138
par= province_intakes rng=water_output!c150 rdim=1 cdim=1 textid=water_output_info rng=toc!a13 linkid=province_intakes
text=back rng=water_output!c148 link=toc!a13 textid=province_intakes rng=water_output!d148
par= province_intakes_surplus rng=water_output!c160 rdim=1 cdim=1 textid=water_output_info rng=toc!a13 linkid=province_intakes_surplus
text=back rng=water_output!c158 link=toc!a13 textid=province_intakes_surplus rng=water_output!d158
var= power_Generation rng=water_output!c170 rdim=1 cdim=1 textid=water_output_info rng=toc!a13 linkid=province_intakes
text=back rng=water_output!c168 link=toc!a13 textid=power_Generation rng=water_output!d168
par= LevelInLakesAboveTurbine rng=water_output!c190 rdim=1 cdim=1 textid=water_output_info rng=toc!a13 linkid=province_intakes
text=back rng=water_output!c188 link=toc!a13 textid=LevelInLakesAboveTurbine rng=water_output!d188
par= Observed rng=balance_checking!c8 rdim=2 cdim=1 textid=Balance_checking rng=toc!a14 linkid=Observed
text=back rng=balance_checking!c6 link=toc!a14 textid=Observed rng=balance_checking!d6
par= Computed rng=balance_checking!c30 rdim=2 cdim=1 textid=Balance_checking rng=toc!a14 linkid=Observed
text=back rng=balance_checking!c28 link=toc!a14 textid=Computed rng=balance_checking!d28
var= Volume rng=balance_checking!c50 rdim=1 cdim=1 textid=Balance_checking rng=toc!a14 linkid=Observed
text=back rng=balance_checking!c48 link=toc!a14 textid=Volume rng=balance_checking!d48
par= Start_Vol rng=balance_checking!b51 rdim=1 textid=Balance_checking rng=toc!a14 linkid=Observed
text=Start_Vol rng=balance_checking!c50
var= flow rng=balance_checking!c70 rdim=2 cdim=1 textid=Balance_checking rng=toc!a14 linkid=Observed
text=back rng=balance_checking!c68 link=toc!a14 textid=Flow rng=balance_checking!d68
var= ArtWater rng=art_water!c8 rdim=1 cdim=1 textid=Artwater rng=toc!a15 linkid=ArtWater
text=back rng=art_water!c6 link=toc!a14 textid=ArtWater rng=art_water!d6
var= OBJ rng=TOC!e3 text=object_func rng=TOC!d3
$offecho


$call gdxxrw.exe c:\water_only\indus_water_balance_month.xls se=0 o=test1.gdx @task.txt trace=3
$gdxin test1.gdx
*-------------------------------------------------------------------------------
SET m timestep ;
$loaddc m
****
****
****
****
****
****
****
****
****
****
****
****
/;
solve indus_water_only using NLP minimazing obj;
***
***
***


******************************************
* output organization
* not forget to create new project in working folder
* file water_output.xls will be organize automatically
 
 
 
 
 
execute_unload 'alex.gdx';
* close xls if open
execute 'xlstalk -s c:/water_only/indus_water_balance_month.xls';
execute 'gdxxrw.exe alex.gdx o=c:/water_only/indus_water_balance_month.xls @outtask0.txt trace=3';
* open xls and show
execute 'xlstalk -O c:/water_only/indus_water_balance_month.xls';

 
 
 
13.02.2012, 19:19, "Lena" <lenl...@gmail.com>:
--
With kindly regards!
Andre Savitsky
E-mail:andre...@yandex.ru
andre...@yahoo.com

ELCIN KABELOGLU

unread,
Feb 14, 2012, 5:25:11 AM2/14/12
to gams...@googlegroups.com
Hi,
Here there is a mini example to show how to import data from excel to gams.
Firstly you have to have new excel file in gamsdir folder. In the example it is deneme.xlsx
Your data should be inside this file. Then you can copy the the codes below. Hope it works

Elcin,


set
positions/1*73/
make/model1,model2,model3/
color/color1,color2,color3,color4,color5/;

 // sets are defined

parameter firstposassignn(positions,make,color);
*data
$call "gdxxrw dene.xlsx par=firstposassignn rng=sayfa1!a2:c5 rdim=3"
$gdxin dene.gdx
$load firstposassignn

display firstposassignn



2012/2/13 sara sohail <sara...@gmail.com>

sara sohail

unread,
Feb 14, 2012, 5:39:48 AM2/14/12
to gams...@googlegroups.com, eekab...@gmail.com
Dear Elcin rather dearest at the moment,

Your email looks a bit easy i shall work accordingly and may i ask if somewhere i got stuck?because i just started GAMS..new born in GAMS..

kind wishes,

Sara

Savitsky Andre

unread,
May 16, 2013, 5:17:12 PM5/16/13
to gams...@googlegroups.com
 Dear Friend!
You wrote that data located on ap.xls file
Will be better if You wrote full path
 
You say rng =a1:e5
 
But how it located here?
What the spreadsheet?
 
use this  rng = spreadsheet_name!a1  rdim=1 cdim =1
 
locate data
            i1  i2   i3  i4
 j1         1   2   3  4 
 j2        54  5   6  7
 
 
16.05.2013, 19:52, "nadia" <n.mosh...@gmail.com>:

Dear Friend,

I import data from excel to gams using below code.

$CALL GDXXRW.EXE ap.xls par=cf rng=A1:E5
Parameter cf(*,*);
$GDXIN ap.gdx
$LOAD cf
$GDXIN
display cf;

the model run truelyy, It produce gdx files and  show the solutions. "cf" parametesr mentioned above are the coefficients of the objective functions. the gams ignores these coefficients.my objective function is :

one  .. z =e= sum((i,k,l,j), cf(i,k,l,j)*x(i,k,l,j));
but in the output gams does not show the coefficients of X.
let's help me.
thank you.
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.

To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

nadia moshahedi

unread,
May 17, 2013, 3:20:47 PM5/17/13
to gams...@googlegroups.com
thank you. but I still have some problem. I figure out that inorder to import data from excell to gams, I should install gdxxrw file. I Am I right or I did not get the point? I look for it every where in the internet, but I could not find any thing. All the links were unavailable.
did you install this on your pc? do you have it?I wonder if it is necessary to install this software?

thanks for your help my friend
Nadia


--
You received this message because you are subscribed to a topic in the Google Groups "gamsworld" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gamsworld/EoZOdpjQERI/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to gamsworld+...@googlegroups.com.

A.R. Bahari

unread,
May 17, 2013, 5:50:31 PM5/17/13
to gams...@googlegroups.com
Hi
Try this by the attachments:
First of all locate the *.xls* file in the following path:
E:\Data\MatrixInputs.XLS
Have a look at the sheet named "index" and  in rows, 5,6,7 and 17 of my cod to discover how importing data from excel is performed.
The 5 last rows export data to Excel
Close the excel file  when GAMS is runing.
MatrixInputs.xls
Optimize.gms

nadia moshahedi

unread,
May 18, 2013, 1:18:01 PM5/18/13
to gams...@googlegroups.com
Dear friend,

thank youuuuuuuuu... It seems you are expert in gams. it works :D

Best Regards,
Nadia

Savitsky Andre

unread,
May 17, 2013, 8:00:02 PM5/17/13
to gams...@googlegroups.com
Nadia!
 
1) gdxxrw is part of GAMSIDE and You have it in You computer
May be You have old, Download new version of GAMS IDE 
somewhere copy from this installation gdxxrw.exe 
 
and overwrite instead your. But I am almost sure You have working gdxxrw in You computer.
 
 
This GAMS model
__________
$onecho > task.txt
***********************************************************************************
set= i rng= Node!b1 cdim=1
set= j rng= Node!A2 rdim=1
par= nn rng= Node!a1 rdim=1 cdim=1
***********************************************************************************
$offecho

$call gdxxrw.exe "nadii.xls" se=0 o="nadii.gdx" @task.txt trace=3
$gdxin nadii.gdx

SETS i ;
$loaddc i
SETS j ;
$loaddc j
Parameter nn(j,i) ;
$loaddc nn
______________
 
In attachment excel file
 
I made one spreadsheet "node"
 
I make small table
inside
 
___   i1 i2 i3
 
j1          5
 
j2      4 
 
j3          55
 
or something like this
 
 
All the best! 
 
This work I check
 
please, not forgot to locate this in one folder and create GAMS project in the same folder
 
 
 
 
 
 
 
 
 
 
 
 
 
17.05.2013, 23:23, "nadia moshahedi" <n.mosh...@gmail.com>:
nadii.xls
for_nadii.gms

John Ryan

unread,
May 20, 2013, 1:28:11 PM5/20/13
to gams...@googlegroups.com

Possibly this may be helpful and I should mention there is no software to load to make the gdxxrw functionality work. Simply the commands and process noted below.

 

Here is an example of loading items from excel using the gdxxrw capability. In this example I set a global model name which is also the name of the excel spreadsheet. You could ignore that and simply write your excel model name in the area $call “gdxxrw excelmodel.xlsx.

 

In order to load the date you need to define the sets or parameters first and then you identify each element and point it to where the data is located. In this example the first item read is SlsPosition, given the list I am reading from has duplicates, therefore I have used the “dset” command vs. just “set” as the dset will eliminate duplicates. You then define the set “SlsPosition”, where it is at “Rng=worksheet name and range and then the row and column dimensions. There are defaults here so I only specified the row dimension, however depending on your structure you may need to specify both (see McCarl’s guide for further details). The single quotation  “ at the beginning and end are critical and all of the entire string must be kept on one line in the gams model, you cannot do a return half way through the line. If there are so many elements it is to long you need to duplicate the $call command and $gdxin and $load for the new line. This is not desirable if it is a big excel file because it will have to open and close the spreadsheet twice and if it is a big file this can add a fair bit of time to the process of reading the data.

 

Next is the “$gdxin excelmodel.gdx” line and last you have to load the data by set or parameter with the “$Load” command.

 

If the data is a parameter, instead of “dset” or “set” use “par” as shown below.

 

Once you get one file to work this process is easy to duplicate. You will also find over time that excel really is not a preferred way because it is pretty weak if you have a lot of data. When you get there the use of “include” text files is a far superior and easier way to get data into the model as they work with a one line simple command such as “$include SlsData.inc” and all the information below would be imported. You define the sets and parameters in the include file but you do not have to bother with all the load or other commands.

 

Hope this was of some use,

 

 

GAMS model example from an optimal estimate of Sales Headcount model

------------------------------------------------------------

$Setglobal ModelName   SalesHeadcountModel

 

set              SlsPosition,SlsLevel,FileNum,Name,JobTitle,JobNum,DeptName,DeptNum,SlsZip;

parameter        SlsCompCalc(FileNum,SlsFactors);

 

$call "gdxxrw %modelname%.xlsx dset SlsPosition Rng=ModelInput!AC2:AC100 rdim=1 dset SlsLevel Rng=ModelInput!AD2:AD100 rdim=1 dset=FileNum Rng=ModelInput!A2:A100 rdim=1 dset=Name Rng=ModelInput!B2:B100 rdim=1 dset=JobTitle Rng=ModelInput!AB2:AB100 rdim=1 dset=JobNum Rng=ModelInput!H2:H100 rdim=1 dset=DeptName Rng=ModelInput!AF2:AF100 rdim=1 dset=DeptNum Rng=ModelInput!AE2:AE100 rdim=1 set=DeptNum2DeptName Rng=ModelInput!AE2:AF100 rdim=2  dset=SlsZip Rng=ModelInput!Q2:Q100 rdim=1 par=SlsCompCalc Rng=ModelInput!S1:V100 rdim=1 cdim=1”

 

$gdxin  %modelname%.gdx

 

$load SlsPosition

$load SlsLevel

$load FileNum

$load Name

$load JobTitle

$load JobNum

$load DeptName

$load DeptNum

$load SlsZip

$load SlsCompCalc

-------------------------------------------------------------------------

Regards,

 

John

Ines TR

unread,
Jul 6, 2013, 9:50:08 AM7/6/13
to gams...@googlegroups.com
Hello Alireza!

I found your answer to this post.
I am having the same problem as Annoisa regarding being a beginner and unable to import into GAMS from Excel.
I´ve tried a few things and nothing works. I wonder if you can have a look at the following code and identify what might be wrong with it.
The error message I get is : Unable to open gdx file for $GDXIN. It seems to me that the gdx file is not being generated.

SET
i
r ;
alias(i,j);

$CALL GDXXRW.EXE I=InputGAMS.xlsx  O=InputGAMS.gdx skipempty=0 trace=2 index=Index!A1'
$GDXIN InputGAMS.gdx
$LOAD i r

PARAMETERS
         d(i)    annual demand of product i
         c(j)    capacity at supplier j
         B(j,r)  busines vol interval
         k(j,r)  upper limit r for j dsct sched
         P(i,j)  price data
         Q(i,j)  quality data
         L(i,j)  lateness data
         S(i,j)  sustainability data

$GDXIN InputGAMS.gdx
$load d c b k p q l s
$gdxin


Thanks so much!
Ines

--
You received this message because you are subscribed to a topic in the Google Groups "gamsworld" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gamsworld/EoZOdpjQERI/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to gamsworld+...@googlegroups.com.

To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

saosan

unread,
Jul 6, 2013, 2:08:07 PM7/6/13
to gams...@googlegroups.com
Hi,

i would like to ask if it is necessary in excel to write like 1.23 or i can 1,23

thanks a lot

John Ryan

unread,
Jul 9, 2013, 12:09:03 PM7/9/13
to gams...@googlegroups.com

If you want to load data from an excel spreadsheet, please find attached one method that works. This is from an actual model that reads the data from columns in the spreadsheet. The key structure is first to define the set and parameter names that the model will be reading from the excel file, then to identify the location of the data through the $call command, then create the gdx file where the data will be stored through the $gdxin command and lastly import the variable and parameter data into the model via the $load command.

 

Define the sets and parameters to be read from excel

$call "gdxxrw %modelname%.xlsx

$gdxin  %modelname%.gdx

$load

 

First step, identify the set and parameters you will be using in your model and reading from the file. Next, you will note in the string attached there is %modelname% as in the model I defined the model name so I would not have to rewrite it. You should insert the name of your spreadsheet here so it would read $call “gdxxrw mymodelname.xlsx “. You then need to define the data to be read, is it a set or parameter, in this case my first data to be read was SlsPosition, and I used dset because there was a risk of duplicates in the data and the dset command removes duplicates, otherwise you should simply use set or parameter as the designation. Next is the name of the data that you will be using in your model, then where is it in the excel file, in my case the Rng= identifies in spreadsheet mymodelname.xlsx, tab in the spreadhsheet named ModelInput!, in column AC2:AC100 is all the data to be imported as set SlsPosition while removing any duplicates. Lastly you need to define the dimensions of the data, both row and columns,  and in this case the data is 1 dimensional so I set rdim=1. You should review McCarl’s on this as it will provide you guidance on the defaults and how to specifiy the rdim and cdim values. This last area can give you an unable to read error if you get the dimensions wrong. In fact any error on range or dimensions etc.. will give you that error command.

 

The last word of advice is if your data set is large and it takes a while to open the spreadsheet you need to write these commands all on one line, you may not hit enter and continue writing on the next line. This is cumbersome as I have provided only a portion of the data read in this example and it makes the model a little hard to read but then you only open the file once and you can speed up the import process.

 

 

Set       SlsPosition,SlsLevel,FileNum,Name,JobTitle,JobNum,DeptName,DeptNum,SlsZip;

Parameter  SlsCompCalc(FileNum,SlsFactors);

 

$call "gdxxrw %modelname%.xlsx dset SlsPosition Rng=ModelInput!AC2:AC100 rdim=1 dset SlsLevel Rng=ModelInput!AD2:AD100 rdim=1 dset=FileNum Rng=ModelInput!A2:A100 rdim=1 dset=Name Rng=ModelInput!B2:B100 rdim=1 dset=JobTitle Rng=ModelInput!AB2:AB100 rdim=1 dset=JobNum Rng=ModelInput!H2:H100 rdim=1 dset=DeptName Rng=ModelInput!AF2:AF100 rdim=1 dset=DeptNum Rng=ModelInput!AE2:AE100 rdim=1 set=DeptNum2DeptName Rng=ModelInput!AE2:AF100 rdim=2  dset=SlsZip Rng=ModelInput!Q2:Q100 rdim=1 par=SlsCompCalc Rng=ModelInput!S1:V100 rdim=1 cdim=1"

$gdxin  %modelname%.gdx

 

$load SlsPosition

$load SlsLevel

$load FileNum

$load Name

$load JobTitle

$load JobNum

$load DeptName

$load DeptNum

$load SlsZip

$load SlsCompCalc

 

With all that being said, reading from excel works pretty good but truthfully is quite cumbersome and is pretty poor if you have a large excel file. In our models we tend to read everything in via include files using the $include command, where you all you do is $ include filename and in the .inc file itself you specify the set or parameter and the data associated with it. Below is an example of the include file as you will see it is exactly as you would have the data if you wrote it into the model and in this approach there is no need to define the set or parameter in the model as it is defined in the include file. It is also wise to use quotation marks around data types that have spaces or other characters in them to ensure the data is read and the spaces ignored, otherwise they could create a reading issue. This method reads much faster than an excel spreadsheet, almost instantly, and it avoids any excel limitation on rows or columns as excel is capped at around 1 million rows and something like 20000 columns. Our models almost always use this approach as it is far more efficient than excel.

 

Include File example of data in the file

 

set SalesID/

118509

117856

119324

119332

/;

 

set ID2EmpName(SalesID,EmpName)/

118509       .       "Joe Blow"

117856       .       "John Smith"

119324       .       "Jerry White"

119332       .       "Rod Stewart"

 

set EmpZip(ZipCodes)/

33027

36064

70810

/;

 

set Emp2Zip(SalesID,EmpZip)/

118509  .       33027

117856  .       36064

119324  .       70810

119332  .       70810

/;

 

parameter SalesQuota(SalesID)/

118509       603119

117856       867162

119324       346750

119332       880844

/;

 

Regards,

 

John A. Ryan            john...@orm-tech.com

 

From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Ines TR


Sent: Saturday, July 06, 2013 8:50 AM
To: gams...@googlegroups.com

saosan

unread,
Jul 13, 2013, 6:16:13 AM7/13/13
to gams...@googlegroups.com
I would like to ask if there is difference between exel and gams in real numbers for example 1,156. In excel i write this like 1,156 but in gams 1.156. Can i import this data from excel to gams without changing the point?

thanks a lot

Paul Van der Eijk

unread,
Jul 15, 2013, 9:15:34 AM7/15/13
to gams...@googlegroups.com
A tool like GDXXRW uses a binary interface to the Excel data; so
decimal comma or period is not an issue. When you write text files
you will need to adjust the output because GAMS only recognizes
the period in a number .

--Paul


On Sat, Jul 13, 2013 at 6:16 AM, saosan <apopetr...@gmail.com> wrote:
I would like to ask if there is difference between exel and gams in real numbers for example 1,156. In excel i write this like 1,156 but in gams 1.156. Can i import this data from excel to gams without changing the point?

thanks a lot

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Paul van der Eijk
GAMS Development Corporation
Tel  : (202) 342-0180  Fax  : (202) 342-0181
Email: pvand...@gams.com  
Web : http://www.gams.com

saosan

unread,
Jul 15, 2013, 1:25:46 PM7/15/13
to gams...@googlegroups.com
Thanks for your answer. I would like to ask more if i want to import from Excel to Gams 3-4 data values from the same excel sheet i write for example:

PARAMETER Load(T,Pe)
$CALL GDXXRW data1.xls par=Load rng=LData!A27:I51 Cdim=1 Rdim=1
$GDXIN data1.gdx
$LOAD Load
$GDXIN
Display Load;


PARAMETER Wind(T,P)
$CALL GDXXRW data1.xls par=Wind rng=WData!A30:B54 Cdim=1 Rdim=1
$GDXIN data1.gdx
$LOAD Wind
$GDXIN
Display Wind;

Using the same name.gdx is that true? 

saosan

unread,
Jul 16, 2013, 6:34:46 AM7/16/13
to gams...@googlegroups.com
What is more i would like to ask in which file i must have my excel so gams to read the data. Thanks again

Renger van Nieuwkoop

unread,
Jul 16, 2013, 7:15:37 AM7/16/13
to <gamsworld@googlegroups.com>
Hi Saosan
No, You can add the path to the file name.
Cheers

Renger

sent from my iPad

Am 16.07.2013 um 12:35 schrieb "saosan" <apopetr...@gmail.com>:

What is more i would like to ask in which file i must have my excel so gams to read the data. Thanks again

--

saosan

unread,
Jul 16, 2013, 11:59:39 AM7/16/13
to gams...@googlegroups.com
Thanks a lot. I put my xls to gams file and everything is ok. Moreover, i would like to ask again if there is any problem to use the same name.gdx two or three times as I read data from the same excel. How i can see the data which I read If i want to test it?

Finally, if i have data like

i1  100
i2  200
i3 2500

i put only cdim=1?

Thanks a lot

Renger van Nieuwkoop

unread,
Jul 16, 2013, 12:05:43 PM7/16/13
to <gamsworld@googlegroups.com>
Just try out and learn from that, especially look at the documentation (gdxutils). It contains about 20 examples
Cheers
Renger

Sent from my iPhone
--

saosan

unread,
Jul 16, 2013, 2:04:58 PM7/16/13
to gams...@googlegroups.com
You are right but i ask something specific.

Paul Van der Eijk

unread,
Jul 16, 2013, 3:32:25 PM7/16/13
to gams...@googlegroups.com
You can do this in one call to GDXXRW and one $LOAD
something along these lines:

(Better not to make the command lines too long)

$Onecho > task.txt

par=Load rng=LData!A27:I51 Cdim=1 Rdim=1
par=Wind rng=WData!A30:B54 Cdim=1 Rdim=1
$offecho

$CALL GDXXRW data1.xls @task.txt
$GDXIN data1.gdx
$LOAD Load Wind
$GDXIN
display Load, Window;



--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Renger van Nieuwkoop

unread,
Jul 16, 2013, 4:22:13 PM7/16/13
to <gamsworld@googlegroups.com>
Rdim is the number of sets you have in the columns (See Examples in the gdxutils...), cdim the number of sets you have in the rows. So, you use rdim=1
Cheers 
Renger

sent from my iPad

Am 16.07.2013 um 21:07 schrieb "saosan" <apopetr...@gmail.com>:

You are right but i ask something specific.

--

saosan

unread,
Jul 17, 2013, 12:38:29 PM7/17/13
to gams...@googlegroups.com
Thanks a lot both of you. So if i do not undestand the compact way i can make this what I post it. Am I right?

saosan

unread,
Jul 17, 2013, 2:03:51 PM7/17/13
to gams...@googlegroups.com
Ok i manage to read my data, but how i can change the accuracy? For instance imports only three digit after comma

Owais Nooruddin

unread,
Jul 18, 2013, 5:03:11 AM7/18/13
to gams...@googlegroups.com

option decimals=6;








On Wed, Jul 17, 2013 at 9:03 PM, saosan <apopetr...@gmail.com> wrote:
Ok i manage to read my data, but how i can change the accuracy? For instance imports only three digit after comma

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Regards,
Owais Nooruddin

+358465700556

saosan

unread,
Jul 21, 2013, 12:08:57 PM7/21/13
to gams...@googlegroups.com
it works. thank you

Mario González Sauri

unread,
Sep 12, 2013, 8:19:41 PM9/12/13
to gams...@googlegroups.com

Dear Members;

I'm a newbie on gams. I'm modeling a classic assignment problem. I have the data on a excel sheet and I'm working on importing it to gams. I have read your posts; however I can't find my mistake. The log file says something like this

Output gdx file deleted
Total time = 2511 Ms
--- ASSIGMENT01.gms(20) 3 Mb
*** GDXIN failed C:\Users\Wario84\Documents\gamsdir\projdir\INPUT.gdx
*** Msg: No such file or directory 

My code is this:

SETS
I TASKS /TASK1*TASK10/
J PROCESSORS /PROCESSOR1*PROCESSOR60/;

PARAMETERS
PROFIT(I,J)
RESOURCE(I,J)
CAPACITY(I);

$CALL GDXXRW I=C:\Users\Wario84\Documents\gamsdir\projdir\ASSIGMENT01\INPUT.xls par=PROFIT rng=Entrada!A1:BH10 par=RESOURCE rng=Entrada!A12:BH21 par=CAPACITY rng=Entrada!A23:J23
$gdxin INPUT.gdx

$load
PROFIT
RESOURCE
CAPACITY
$GDXIN

display
PROFIT
RESOURCE
CAPACITY;



BINARY VARIABLE
X(I,J);

VARIABLE
Z;

EQUATIONS
OBJ
CAPACITYCONS(I);
OBJ.. Z =E= SUM ( (I,J),PROFIT(I,J)*X(I,J) );
CAPACITYCONS(I).. SUM ( I,RESOURCE(I,J)*X(I,J) ) =L= CAPACITY(I);

MODEL ASSIGMENT01 /ALL/;
SOLVE ASSIGMENT01 USING MIP MAXIMIZING Z;


Hope you can help me!

Regards.

Mario

Michael Bussieck

unread,
Sep 13, 2013, 2:41:44 AM9/13/13
to gams...@googlegroups.com
Mario,

I think the log says is very clearly:

Output file: C:\Users\Wario84\Documents\gamsdir\projdir\INPUT.gdx
**** There were 11 duplicate entries for symbol PROFIT
 1: 18,18
...

Output gdx file deleted Total time = 2511 Ms --- ASSIGMENT01.gms(20) 3 Mb *** GDXIN failed C:\Users\Wario84\Documents\gamsdir\projdir\INPUT.gdx
So the tool gdxxrw has difficulties reading your Excel input and to make sure that you don't pick up some trash, it deletes the partically created INPUT.GDX. When I call an external program from within GAMS I always check its return code afterwards:

...
$call gdxxrw ....
$if errorlevel 1 $abort gdxxrw failed!
$gdxin input
...

Now to why gdxxrw failed. In your spreadsheet you only had numbers. GAMS data is not positional but relational, meaning that we always need the keys that go with the data. I suggest you look again at part V of the gdxutils.pdf document (http://gams.com/dd/docs/tools/gdxutils.pdf). I corrected this part of your program. You find the XLS file and the GAMS file here:

http://www.gams.com/upload/files/201309130237__2Mario.zip

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator
Reply all
Reply to author
Forward
0 new messages