gams loop...............very imp.

Archive of Gamsworld Google Group
Post Reply
Archiver
User
User
Posts: 7876
Joined: 7 years ago

gams loop...............very imp.

Post by Archiver »



Hi,
First of all, sorry for asking too many questions, but i really need
your help.I have tried the simple approach and i was not able to open
the GAMS file from DOS.Although i wrote the correct syntax it always
gives me error messages such as "unable to open input file, no such
file or directory,terminated due to parameter errors, job model stop."
So could you please explain the other method:

set i /1*100/;
file fx /runme.gms/;
loop(i, put fx '$call gams mymodel --xlsinput=datag' i.tl:0 ' --
xlsoutput=data' i.tl:0 /); putclose fx;
execute 'gams runme.gms';

where should i put this code in the GAMS syntax.Also, where should i
put my parameters,sets ,equations , model and
solve statements(as GAMS does not accept any
parameter ,set,........definitions inside a loop)?In otherwords, i
want to know how can i organize my program exactly ..............I
really need your help
A.A.A








On Jun 6, 11:06 am, Gamsworld Admin wrote:
> > Hi,
> >
> > Why don't you try the simple approach first, running your
> > parameterized model in a cmd script?
> >
> > Michael
> >
> > On Jun 5, 12:07 pm, "A.A.A" wrote:
> >
> >
> >
>> > > Hi Michael,
> >
>> > > Unfortunately the code did not work,i do not know why.i want to know
>> > > where should i put this part in my Gams syntax:
> >
>> > > set i /1*100/;
>> > > file fx /runme.gms/;
>> > > loop(i, put fx '$call gams mymodel --xlsinput=datag' i.tl:0 ' --
>> > > xlsoutput=data' i.tl:0 /); putclose fx;
>> > > execute 'gams runme.gms';
> >
>> > > Also, where should i put my parameters,sets ,equations , model and
>> > > solve statements(as GAMS does not accept any
>> > > parameter ,set,........definitions inside a loop)?In otherwords, i
>> > > want to know how can i organize my programm exactly
> >
>> > > Thanks
>> > > A.A.A
> >
>> > > On Jun 4, 7:23 pm, "A.A.A" wrote:
> >
>>> > > > Hi Michael,
>>> > > > Thank you Michael.I will try this code.
> >
>>> > > > On Jun 4, 6:16 pm, Gamsworld Admin wrote:
> >
>>>> > > > > Hi,
> >
>>>> > > > > You can parameterize your model and then have a script calling your
>>>> > > > > model with the different parameters:
> >
>>>> > > > > 1) Replace the name of the input and output Excel file with a string
>>>> > > > > macro. For example:
> >
>>>> > > > > $call =xls2gms "i=E:\simuldata1\%xlsinput%.xls" o=E:\work\dataif1.inc
>>>> > > > > R=%xlsinput%!a2:a12
>>>> > > > > $include E:\work\dataif1.inc
> >
>>>> > > > > Execute 'GDXXRW.EXE data2.gdx sq=0 o=E:\simuldata\%xlsoutput%.xls var=
>>>> > > > > V1 rng=sheet2!e2 rdim=1';
> >
>>>> > > > > 2) Now you call GAMS with specifying xlsinput and xlsoutput:
> >
>>>> > > > > gams mymodel --xlsinput=datag1 --xlsoutput=data1
> >
>>>> > > > > 3) Put this in a scrupt (cmd or whatever you like):
> >
>>>> > > > > gams mymodel --xlsinput=datag1 --xlsoutput=data1
>>>> > > > > gams mymodel --xlsinput=datag2 --xlsoutput=data2
>>>> > > > > gams mymodel --xlsinput=datag3 --xlsoutput=data3
>>>> > > > > ...
> >
>>>> > > > > Instead of a cmd script you can use GAMS as a scripting language:
> >
>>>> > > > > set i /1*100/;
>>>> > > > > file fx /runme.gms/;
>>>> > > > > loop(i, put fx '$call gams mymodel --xlsinput=datag' i.tl:0 ' --
>>>> > > > > xlsoutput=data' i.tl:0 /); putclose fx;
>>>> > > > > execute 'gams runme.gms';
> >
>>>> > > > > Hope this helps
>>>> > > > > Michael
> >
>>>> > > > > On Jun 3, 8:17 am, "A.A.A" wrote:
> >
>>>>> > > > > > Hi,
> >
>>>>> > > > > > I have a problem with writing a GAMS syntax which should be applied on
>>>>> > > > > > 100 datasets (IN AN EXCEL FORMAT) and this syntax include:
> >
>>>>> > > > > > 1-Parameter and sets definitions based on calling certain data:
> >
>>>>> > > > > > Sets
>>>>> > > > > > S1 /
>>>>> > > > > > $call =xls2gms "i=E:\simuldata1\datag1.xls" o=E:\work\dataif1.inc
>>>>> > > > > > R=datag1!a2:a12
>>>>> > > > > > $include E:\work\dataif1.inc/;
> >
>>>>> > > > > > Parameters
>>>>> > > > > > (S1) p /
>>>>> > > > > > $$call =xls2gms "i=E:\simuldata1\datag1.xls" o=E:\work\data21.inc
>>>>> > > > > > R=datag1!j2:k12
>>>>> > > > > > $include E:\work\data2l.inc/;
> >
>>>>> > > > > > 2-Other variables (which should result as an output of solving a
>>>>> > > > > > certain model) and equations:
> >
>>>>> > > > > > Variables
>>>>> > > > > > V1(i)
> >
>>>>> > > > > > Equations
>>>>> > > > > > F1 .. =E=SUM(S1,p(S1) );
>>>>> > > > > > constr1(S1) .. P=E=SUM(i,,x(S1,i));
>>>>> > > > > > z1 ..
> >
>>>>> > > > > > Model1 /F1,constr1/;
> >
>>>>> > > > > > Solve Model1 using nlp minimizing z1;
> >
>>>>> > > > > > ****3-Writting the output to excel file
> >
>>>>> > > > > > Execute_Unload "data2.gdx" V1
>>>>> > > > > > Execute 'GDXXRW.EXE data2.gdx sq=0 o=E:\simuldata\data1.xls var= V1
>>>>> > > > > > rng=sheet2!e2 rdim=1';
> >
>>>>> > > > > > And this syntax should be applied to the 100 excel datasets
>>>>> > > > > > (datag1……….datag100) and saved on 100 excel files (data1…………………
>>>>> > > > > > data100).I also have 100 sets S1……………..S100 each set based on calling
>>>>> > > > > > one data of the 100 and the same thing applies to all
>>>>> > > > > > parameters ,variables and equations.
> >
>>>>> > > > > > How could I put this syntax in a loop to produce the required output?
> >
>>>>> > > > > > Thanks in advance- Hide quoted text -
> >
>>>> > > > > - Show quoted text -- Hide quoted text -
> >
>>> > > > - Show quoted text -- Hide quoted text -
> >
>> > > - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to gamsworld@googlegroups.com
To unsubscribe from this group, send email to gamsworld-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en
-~----------~----~----~----~------~----~------~--~---


Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: gams loop...............very imp.

Post by Archiver »



Hi,

If you use the MSDOS icon (all the way to the right in the GAMS IDE)
to open a command shell you should be located in the directory where
all your GAMS files reside, this is also called the project directory.
If you don't, just use "cd \my\dir\to\go" to change the current
directory and just run

gams modelname

If you open the command shell from within the IDE the path to the gams
executable is already set, so you don't need to prefix the executable.

Hope this helps,
Michael

On Jun 8, 12:21 pm, "A.A.A" wrote:
> > Hi,
> > First of all, sorry for asking too many questions, but i really need
> > your help.I have tried the simple approach and i was not able to open
> > the GAMS file from DOS.Although i wrote the correct syntax it always
> > gives me error messages such as "unable to open input file, no such
> > file or directory,terminated due to parameter errors, job model stop."
> > So could you please explain the other method:
> >
> > set i /1*100/;
> > file fx /runme.gms/;
> > loop(i, put fx '$call gams mymodel --xlsinput=datag' i.tl:0 ' --
> > xlsoutput=data' i.tl:0 /); putclose fx;
> > execute 'gams runme.gms';
> >
> > where should i put this code in the GAMS syntax.Also, where should i
> > put my parameters,sets ,equations , model and
> > solve statements(as GAMS does not accept any
> > parameter ,set,........definitions inside a loop)?In otherwords, i
> > want to know how can i organize my program exactly ..............I
> > really need your help
> > A.A.A
> >
> > On Jun 6, 11:06 am, Gamsworld Admin wrote:
> >
> >
> >
>> > > Hi,
> >
>> > > Why don't you try the simple approach first, running your
>> > > parameterized model in a cmd script?
> >
>> > > Michael
> >
>> > > On Jun 5, 12:07 pm, "A.A.A" wrote:
> >
>>> > > > Hi Michael,
> >
>>> > > > Unfortunately the code did not work,i do not know why.i want to know
>>> > > > where should i put this part in my Gams syntax:
> >
>>> > > > set i /1*100/;
>>> > > > file fx /runme.gms/;
>>> > > > loop(i, put fx '$call gams mymodel --xlsinput=datag' i.tl:0 ' --
>>> > > > xlsoutput=data' i.tl:0 /); putclose fx;
>>> > > > execute 'gams runme.gms';
> >
>>> > > > Also, where should i put my parameters,sets ,equations , model and
>>> > > > solve statements(as GAMS does not accept any
>>> > > > parameter ,set,........definitions inside a loop)?In otherwords, i
>>> > > > want to know how can i organize my programm exactly
> >
>>> > > > Thanks
>>> > > > A.A.A
> >
>>> > > > On Jun 4, 7:23 pm, "A.A.A" wrote:
> >
>>>> > > > > Hi Michael,
>>>> > > > > Thank you Michael.I will try this code.
> >
>>>> > > > > On Jun 4, 6:16 pm, Gamsworld Admin wrote:
> >
>>>>> > > > > > Hi,
> >
>>>>> > > > > > You can parameterize your model and then have a script calling your
>>>>> > > > > > model with the different parameters:
> >
>>>>> > > > > > 1) Replace the name of the input and output Excel file with a string
>>>>> > > > > > macro. For example:
> >
>>>>> > > > > > $call =xls2gms "i=E:\simuldata1\%xlsinput%.xls" o=E:\work\dataif1.inc
>>>>> > > > > > R=%xlsinput%!a2:a12
>>>>> > > > > > $include E:\work\dataif1.inc
> >
>>>>> > > > > > Execute 'GDXXRW.EXE data2.gdx sq=0 o=E:\simuldata\%xlsoutput%.xls var=
>>>>> > > > > > V1 rng=sheet2!e2 rdim=1';
> >
>>>>> > > > > > 2) Now you call GAMS with specifying xlsinput and xlsoutput:
> >
>>>>> > > > > > gams mymodel --xlsinput=datag1 --xlsoutput=data1
> >
>>>>> > > > > > 3) Put this in a scrupt (cmd or whatever you like):
> >
>>>>> > > > > > gams mymodel --xlsinput=datag1 --xlsoutput=data1
>>>>> > > > > > gams mymodel --xlsinput=datag2 --xlsoutput=data2
>>>>> > > > > > gams mymodel --xlsinput=datag3 --xlsoutput=data3
>>>>> > > > > > ...
> >
>>>>> > > > > > Instead of a cmd script you can use GAMS as a scripting language:
> >
>>>>> > > > > > set i /1*100/;
>>>>> > > > > > file fx /runme.gms/;
>>>>> > > > > > loop(i, put fx '$call gams mymodel --xlsinput=datag' i.tl:0 ' --
>>>>> > > > > > xlsoutput=data' i.tl:0 /); putclose fx;
>>>>> > > > > > execute 'gams runme.gms';
> >
>>>>> > > > > > Hope this helps
>>>>> > > > > > Michael
> >
>>>>> > > > > > On Jun 3, 8:17 am, "A.A.A" wrote:
> >
>>>>>> > > > > > > Hi,
> >
>>>>>> > > > > > > I have a problem with writing a GAMS syntax which should be applied on
>>>>>> > > > > > > 100 datasets (IN AN EXCEL FORMAT) and this syntax include:
> >
>>>>>> > > > > > > 1-Parameter and sets definitions based on calling certain data:
> >
>>>>>> > > > > > > Sets
>>>>>> > > > > > > S1 /
>>>>>> > > > > > > $call =xls2gms "i=E:\simuldata1\datag1.xls" o=E:\work\dataif1.inc
>>>>>> > > > > > > R=datag1!a2:a12
>>>>>> > > > > > > $include E:\work\dataif1.inc/;
> >
>>>>>> > > > > > > Parameters
>>>>>> > > > > > > (S1) p /
>>>>>> > > > > > > $$call =xls2gms "i=E:\simuldata1\datag1.xls" o=E:\work\data21.inc
>>>>>> > > > > > > R=datag1!j2:k12
>>>>>> > > > > > > $include E:\work\data2l.inc/;
> >
>>>>>> > > > > > > 2-Other variables (which should result as an output of solving a
>>>>>> > > > > > > certain model) and equations:
> >
>>>>>> > > > > > > Variables
>>>>>> > > > > > > V1(i)
> >
>>>>>> > > > > > > Equations
>>>>>> > > > > > > F1 .. =E=SUM(S1,p(S1) );
>>>>>> > > > > > > constr1(S1) .. P=E=SUM(i,,x(S1,i));
>>>>>> > > > > > > z1 ..
> >
>>>>>> > > > > > > Model1 /F1,constr1/;
> >
>>>>>> > > > > > > Solve Model1 using nlp minimizing z1;
> >
>>>>>> > > > > > > ****3-Writting the output to excel file
> >
>>>>>> > > > > > > Execute_Unload "data2.gdx" V1
>>>>>> > > > > > > Execute 'GDXXRW.EXE data2.gdx sq=0 o=E:\simuldata\data1.xls var= V1
>>>>>> > > > > > > rng=sheet2!e2 rdim=1';
> >
>>>>>> > > > > > > And this syntax should be applied to the 100 excel datasets
>>>>>> > > > > > > (datag1……….datag100) and saved on 100 excel files (data1…………………
>>>>>> > > > > > > data100).I also have 100 sets S1……………..S100 each set based on calling
>>>>>> > > > > > > one data of the 100 and the same thing applies to all
>>>>>> > > > > > > parameters ,variables and equations.
> >
>>>>>> > > > > > > How could I put this syntax in a loop to produce the required output?
> >
>>>>>> > > > > > > Thanks in advance- Hide quoted text -
> >
>>>>> > > > > > - Show quoted text -- Hide quoted text -
> >
>>>> > > > > - Show quoted text -- Hide quoted text -
> >
>>> > > > - Show quoted text -- Hide quoted text -
> >
>> > > - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to gamsworld@googlegroups.com
To unsubscribe from this group, send email to gamsworld-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en
-~----------~----~----~----~------~----~------~--~---


Post Reply