Looping over file names

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

Looping over file names

Post by Archiver »



Hi,

I've written a GAMS program using the xls2gms function to upload data
and the execute_unload function to save the final result. However, I
need to run the same GAMS code for 50 different countries, which means
I have 50 different xls input files.

Is there a way to loop over file names so that I can change the input
file and the output file each time (e.g. Input_file_CountryX.xls,
Results_CountryX.gdx) ?

A simplified version of my code is below.

Thanks for your help-
Alison

-----------------------
*Read data from external spreadsheet
$call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc

set i /
$include industries.set
/;
set o /
$include occupations.set
/;
**************
*Define B from external spreadsheet
Table B(o,i) degree of belief
$include matrixB.inc
;
Parameter avg(i) average by industry/
$include Average.inc
/;
**************

Equations, Objective Function, etc.

**************
*Run the model to get results
Model WAGES /objective/;
Solve WAGES using dnlp minimizing find_min;
Display w.l, w.m;
**************
*Export results to Excel by creating a .gdx file
execute_unload "Results_Country1.gdx" w.L w.M
execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--~--~---------~--~----~------------~-------~--~----~
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: Looping over file names

Post by Archiver »



Alison,

you could use GAMS as a platform independent scripting language. For
example you could change your program to parametrize the file names:

Change the following lines:

$call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i...
...
execute_unload "Results_Country1.gdx" w.L w.M
execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

to

$call =xls2gms i=Input_file_%instance%.xls r1=Sets!set_i...
...
execute_unload "Results_%instance%.gdx" w.L w.M
execute 'gdxxrw.exe Results_%instance%.gdx var=w.L'

Now, when you call your GAMS program you supply the instance name by
adding '--instance=Country1' to the GAMS call. Create a second GAMS
model e.g. run.gms that contains the following information:

$call gams mymodel.gms --instance=Country1
$if errorlevel 1 $abort 'problems with instance Country1'
$call gams mymodel.gms --instance=Country2
$if errorlevel 1 $abort 'problems with instance Country2'
...
$call gams mymodel.gms --instance=Country50
$if errorlevel 1 $abort 'problems with instance Country50'

If you want to keep the log and lst file from the individual runs, use
GAMS parameters lo, o and lf:

$call gams mymodel.gms --instance=Country1 lo=2 o=Country1.lst
lf=Country1.log
$if errorlevel 1 $abort 'problems with instance Country1'
...

Moreover, you could use GAMS to create the model run.gms: Create
another GAMS model makerun.gms:

set i instances /1*50/;

file frun / run.gms /; put frun '* Run file to run ' card(i):0 '
instances of mymodel';
loop(i,
put / '$call gams mymodel.gms --instance=Country' i.tl:0 ' lo=2
o=Country' i.tl:0 '.lst lf=Country' i.tl:0 '.log'
/ "$if errorlevel 1 $abort 'problems with instance Country"
i.tl:0 "'";
);

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator


On Feb 24, 3:23 pm, Alison wrote:
> > Hi,
> >
> > I've written a GAMS program using the xls2gms function to upload data
> > and the execute_unload function to save the final result. However, I
> > need to run the same GAMS code for 50 different countries, which means
> > I have 50 different xls input files.
> >
> > Is there a way to loop over file names so that I can change the input
> > file and the output file each time (e.g. Input_file_CountryX.xls,
> > Results_CountryX.gdx) ?
> >
> > A simplified version of my code is below.
> >
> > Thanks for your help-
> > Alison
> >
> > -----------------------
> > *Read data from external spreadsheet
> > $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> > o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> > o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
> >
> > set i /
> > $include industries.set
> > /;
> > set o /
> > $include occupations.set
> > /;
> > **************
> > *Define B from external spreadsheet
> > Table B(o,i) degree of belief
> > $include matrixB.inc
> > ;
> > Parameter avg(i) average by industry/
> > $include Average.inc
> > /;
> > **************
> >
> > Equations, Objective Function, etc.
> >
> > **************
> > *Run the model to get results
> > Model WAGES /objective/;
> > Solve WAGES using dnlp minimizing find_min;
> > Display w.l, w.m;
> > **************
> > *Export results to Excel by creating a .gdx file
> > execute_unload "Results_Country1.gdx" w.L w.M
> > execute 'gdxxrw.exe Results_Country1.gdx var=w.L'
--~--~---------~--~----~------------~-------~--~----~
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: Looping over file names

Post by Archiver »


i Alison
You could use the put utility and run a loop over your set of countries:.

LOOP(countries,

* Generate an include file (countries.inc) with the code for the specific country with the PUT utility and using
* "countries.tl"

* include the generated file with the code to import the country specific data

* Solve the model

* Generate an inlcude file (results.inc) with the code for the specific country with the PUT utility

* include the generated file

);

Hope this helps

Renger

On Tue, Feb 24, 2009 at 9:23 PM, Alison wrote:


Hi,

I've written a GAMS program using the xls2gms function to upload data
and the execute_unload function to save the final result. However, I
need to run the same GAMS code for 50 different countries, which means
I have 50 different xls input files.

Is there a way to loop over file names so that I can change the input
file and the output file each time (e.g. Input_file_CountryX.xls,
Results_CountryX.gdx) ?

A simplified version of my code is below.

Thanks for your help-
Alison

-----------------------
*Read data from external spreadsheet
$call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc

set i /
$include industries.set
/;
set o /
$include occupations.set
/;
**************
*Define B from external spreadsheet
Table B(o,i) degree of belief
$include matrixB.inc
;
Parameter avg(i) average by industry/
$include Average.inc
/;
**************

Equations, Objective Function, etc.

**************
*Run the model to get results
Model WAGES /objective/;
Solve WAGES using dnlp minimizing find_min;
Display w.l, w.m;
**************
*Export results to Excel by creating a .gdx file
execute_unload "Results_Country1.gdx" w.L w.M
execute 'gdxxrw.exe Results_Country1.gdx var=w.L'





--
Renger van Nieuwkoop

--~--~---------~--~----~------------~-------~--~----~
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: Looping over file names

Post by Archiver »


is I try this - I got the message: "Starting execution - empty program"

When I start the model without the extra file and the line "$call gams MasterarbeitModel_instance.gms --instance=3" it is working.

What is wrong? The GDX-Input is working and refreshed but the model is not solved.


Am Donnerstag, 26. Februar 2009 13:42:05 UTC+1 schrieb Michael Bussieck:

Alison,

you could use GAMS as a platform independent scripting language. For
example you could change your program to parametrize the file names:

Change the following lines:

$call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i...
...
execute_unload "Results_Country1.gdx" w.L w.M
execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

to

$call =xls2gms i=Input_file_%instance%.xls r1=Sets!set_i...
...
execute_unload "Results_%instance%.gdx" w.L w.M
execute 'gdxxrw.exe Results_%instance%.gdx var=w.L'

Now, when you call your GAMS program you supply the instance name by
adding '--instance=Country1' to the GAMS call. Create a second GAMS
model e.g. run.gms that contains the following information:

$call gams mymodel.gms --instance=Country1
$if errorlevel 1 $abort 'problems with instance Country1'
$call gams mymodel.gms --instance=Country2
$if errorlevel 1 $abort 'problems with instance Country2'
...
$call gams mymodel.gms --instance=Country50
$if errorlevel 1 $abort 'problems with instance Country50'

If you want to keep the log and lst file from the individual runs, use
GAMS parameters lo, o and lf:

$call gams mymodel.gms --instance=Country1 lo=2 o=Country1.lst
lf=Country1.log
$if errorlevel 1 $abort 'problems with instance Country1'
...

Moreover, you could use GAMS to create the model run.gms: Create
another GAMS model makerun.gms:

set i instances /1*50/;

file frun / run.gms /; put frun '* Run file to run ' card(i):0 '
instances of mymodel';
loop(i,
put / '$call gams mymodel.gms --instance=Country' i.tl:0 ' lo=2
o=Country' i.tl:0 '.lst lf=Country' i.tl:0 '.log'
/ "$if errorlevel 1 $abort 'problems with instance Country"
i.tl:0 "'";
);

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator


On Feb 24, 3:23 pm, Alison wrote:
> Hi,
>
> I've written a GAMS program using the xls2gms function to upload data
> and the execute_unload function to save the final result. However, I
> need to run the same GAMS code for 50 different countries, which means
> I have 50 different xls input files.
>
> Is there a way to loop over file names so that I can change the input
> file and the output file each time (e.g. Input_file_CountryX.xls,
> Results_CountryX.gdx) ?
>
> A simplified version of my code is below.
>
> Thanks for your help-
> Alison
>
> -----------------------
> *Read data from external spreadsheet
> $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
>
> set i /
> $include industries.set
> /;
> set o /
> $include occupations.set
> /;
> **************
> *Define B from external spreadsheet
> Table B(o,i) degree of belief
> $include matrixB.inc
> ;
> Parameter avg(i) average by industry/
> $include Average.inc
> /;
> **************
>
> Equations, Objective Function, etc.
>
> **************
> *Run the model to get results
> Model WAGES /objective/;
> Solve WAGES using dnlp minimizing find_min;
> Display w.l, w.m;
> **************
> *Export results to Excel by creating a .gdx file
> execute_unload "Results_Country1.gdx" w.L w.M
> execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Looping over file names

Post by Archiver »


I really need help here.

It's just not working and I don't know why. Is this loop "trick" just working with "=xls2gms" and NOT with gdxxrw?

Am Donnerstag, 30. April 2015 08:01:14 UTC+2 schrieb Alexander Strenge:

is I try this - I got the message: "Starting execution - empty program"

When I start the model without the extra file and the line "$call gams MasterarbeitModel_instance.gms --instance=3" it is working.

What is wrong? The GDX-Input is working and refreshed but the model is not solved.


Am Donnerstag, 26. Februar 2009 13:42:05 UTC+1 schrieb Michael Bussieck:

Alison,

you could use GAMS as a platform independent scripting language. For
example you could change your program to parametrize the file names:

Change the following lines:

$call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i...
...
execute_unload "Results_Country1.gdx" w.L w.M
execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

to

$call =xls2gms i=Input_file_%instance%.xls r1=Sets!set_i...
...
execute_unload "Results_%instance%.gdx" w.L w.M
execute 'gdxxrw.exe Results_%instance%.gdx var=w.L'

Now, when you call your GAMS program you supply the instance name by
adding '--instance=Country1' to the GAMS call. Create a second GAMS
model e.g. run.gms that contains the following information:

$call gams mymodel.gms --instance=Country1
$if errorlevel 1 $abort 'problems with instance Country1'
$call gams mymodel.gms --instance=Country2
$if errorlevel 1 $abort 'problems with instance Country2'
...
$call gams mymodel.gms --instance=Country50
$if errorlevel 1 $abort 'problems with instance Country50'

If you want to keep the log and lst file from the individual runs, use
GAMS parameters lo, o and lf:

$call gams mymodel.gms --instance=Country1 lo=2 o=Country1.lst
lf=Country1.log
$if errorlevel 1 $abort 'problems with instance Country1'
...

Moreover, you could use GAMS to create the model run.gms: Create
another GAMS model makerun.gms:

set i instances /1*50/;

file frun / run.gms /; put frun '* Run file to run ' card(i):0 '
instances of mymodel';
loop(i,
put / '$call gams mymodel.gms --instance=Country' i.tl:0 ' lo=2
o=Country' i.tl:0 '.lst lf=Country' i.tl:0 '.log'
/ "$if errorlevel 1 $abort 'problems with instance Country"
i.tl:0 "'";
);

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator


On Feb 24, 3:23 pm, Alison wrote:
> Hi,
>
> I've written a GAMS program using the xls2gms function to upload data
> and the execute_unload function to save the final result. However, I
> need to run the same GAMS code for 50 different countries, which means
> I have 50 different xls input files.
>
> Is there a way to loop over file names so that I can change the input
> file and the output file each time (e.g. Input_file_CountryX.xls,
> Results_CountryX.gdx) ?
>
> A simplified version of my code is below.
>
> Thanks for your help-
> Alison
>
> -----------------------
> *Read data from external spreadsheet
> $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
>
> set i /
> $include industries.set
> /;
> set o /
> $include occupations.set
> /;
> **************
> *Define B from external spreadsheet
> Table B(o,i) degree of belief
> $include matrixB.inc
> ;
> Parameter avg(i) average by industry/
> $include Average.inc
> /;
> **************
>
> Equations, Objective Function, etc.
>
> **************
> *Run the model to get results
> Model WAGES /objective/;
> Solve WAGES using dnlp minimizing find_min;
> Display w.l, w.m;
> **************
> *Export results to Excel by creating a .gdx file
> execute_unload "Results_Country1.gdx" w.L w.M
> execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Looping over file names

Post by Archiver »


Hi Alexander
Hard to say without your code.
Renger

On Tuesday, May 5, 2015 at 8:26:26 AM UTC+2, Alexander Strenge wrote:

I really need help here.

It's just not working and I don't know why. Is this loop "trick" just working with "=xls2gms" and NOT with gdxxrw?

Am Donnerstag, 30. April 2015 08:01:14 UTC+2 schrieb Alexander Strenge:

is I try this - I got the message: "Starting execution - empty program"

When I start the model without the extra file and the line "$call gams MasterarbeitModel_instance.gms --instance=3" it is working.

What is wrong? The GDX-Input is working and refreshed but the model is not solved.


Am Donnerstag, 26. Februar 2009 13:42:05 UTC+1 schrieb Michael Bussieck:

Alison,

you could use GAMS as a platform independent scripting language. For
example you could change your program to parametrize the file names:

Change the following lines:

$call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i...
...
execute_unload "Results_Country1.gdx" w.L w.M
execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

to

$call =xls2gms i=Input_file_%instance%.xls r1=Sets!set_i...
...
execute_unload "Results_%instance%.gdx" w.L w.M
execute 'gdxxrw.exe Results_%instance%.gdx var=w.L'

Now, when you call your GAMS program you supply the instance name by
adding '--instance=Country1' to the GAMS call. Create a second GAMS
model e.g. run.gms that contains the following information:

$call gams mymodel.gms --instance=Country1
$if errorlevel 1 $abort 'problems with instance Country1'
$call gams mymodel.gms --instance=Country2
$if errorlevel 1 $abort 'problems with instance Country2'
...
$call gams mymodel.gms --instance=Country50
$if errorlevel 1 $abort 'problems with instance Country50'

If you want to keep the log and lst file from the individual runs, use
GAMS parameters lo, o and lf:

$call gams mymodel.gms --instance=Country1 lo=2 o=Country1.lst
lf=Country1.log
$if errorlevel 1 $abort 'problems with instance Country1'
...

Moreover, you could use GAMS to create the model run.gms: Create
another GAMS model makerun.gms:

set i instances /1*50/;

file frun / run.gms /; put frun '* Run file to run ' card(i):0 '
instances of mymodel';
loop(i,
put / '$call gams mymodel.gms --instance=Country' i.tl:0 ' lo=2
o=Country' i.tl:0 '.lst lf=Country' i.tl:0 '.log'
/ "$if errorlevel 1 $abort 'problems with instance Country"
i.tl:0 "'";
);

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator


On Feb 24, 3:23 pm, Alison wrote:
> Hi,
>
> I've written a GAMS program using the xls2gms function to upload data
> and the execute_unload function to save the final result. However, I
> need to run the same GAMS code for 50 different countries, which means
> I have 50 different xls input files.
>
> Is there a way to loop over file names so that I can change the input
> file and the output file each time (e.g. Input_file_CountryX.xls,
> Results_CountryX.gdx) ?
>
> A simplified version of my code is below.
>
> Thanks for your help-
> Alison
>
> -----------------------
> *Read data from external spreadsheet
> $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
>
> set i /
> $include industries.set
> /;
> set o /
> $include occupations.set
> /;
> **************
> *Define B from external spreadsheet
> Table B(o,i) degree of belief
> $include matrixB.inc
> ;
> Parameter avg(i) average by industry/
> $include Average.inc
> /;
> **************
>
> Equations, Objective Function, etc.
>
> **************
> *Run the model to get results
> Model WAGES /objective/;
> Solve WAGES using dnlp minimizing find_min;
> Display w.l, w.m;
> **************
> *Export results to Excel by creating a .gdx file
> execute_unload "Results_Country1.gdx" w.L w.M
> execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Looping over file names

Post by Archiver »


Hi Renger,

attached you will find my code.
I want to run this model with several input files and create several output files.

The input is described in EXCEL and should be read from one sheet: line 10 for instance = 1 and from line 20 for instance = 2 and so on.

The same should happen for the Output. It should be written to one sheet: line 10 for instance = 1 and to line 20 for instance = 2 and so on.


I want to work with "run.gms" and "makerun.gms" files like described here.


Model in GAMS:

*LCC MODEL

sets
i work-brakedown structure
subi1(i) all R&D processes
subi2(i) all manufacturin processes
subi3(i) all usage processes
subi4(i) all EOL processes
;
alias (i,j);

parameters
* Parameters
balance(i) balance for an activity i if alternative o is chosen
capacity(i,j) max amount of products or pieces for activity j if alternative o is chosen
************************** PHASE: Research & Development *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_RD_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
******* FIX COST TYPES ******************************************************************************************************
c_RD_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
************************** PHASE: MANUFACTURING *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_M_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
******* FIX COST TYPES ******************************************************************************************************
c_M_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
************************** PHASE: USAGE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_U_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Usage"
******* FIX COST TYPES ******************************************************************************************************
c_U_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Usage"

************************** PHASE: END-OF-LIFE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_E_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
******* FIX COST TYPES ******************************************************************************************************
c_E_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
;
********************************************************************************
********************************************************************************
********************************************************************************
scalar
lotsize
;
lotsize = 200;

*Loading data from Excel'
$Call 'gdxxrw.exe i=RunTest_01.XLS cmerge=1 se=0 o=LCCModel_%instance%.gdx UpdLinks=3 index=GamsInput!B%instance%0'
$gdxin LCCModel_%instance%.gdx
$load i
$loadM i wrote:
> Hi,
>
> I've written a GAMS program using the xls2gms function to upload data
> and the execute_unload function to save the final result. However, I
> need to run the same GAMS code for 50 different countries, which means
> I have 50 different xls input files.
>
> Is there a way to loop over file names so that I can change the input
> file and the output file each time (e.g. Input_file_CountryX.xls,
> Results_CountryX.gdx) ?
>
> A simplified version of my code is below.
>
> Thanks for your help-
> Alison
>
> -----------------------
> *Read data from external spreadsheet
> $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
>
> set i /
> $include industries.set
> /;
> set o /
> $include occupations.set
> /;
> **************
> *Define B from external spreadsheet
> Table B(o,i) degree of belief
> $include matrixB.inc
> ;
> Parameter avg(i) average by industry/
> $include Average.inc
> /;
> **************
>
> Equations, Objective Function, etc.
>
> **************
> *Run the model to get results
> Model WAGES /objective/;
> Solve WAGES using dnlp minimizing find_min;
> Display w.l, w.m;
> **************
> *Export results to Excel by creating a .gdx file
> execute_unload "Results_Country1.gdx" w.L w.M
> execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

RE: Looping over file names

Post by Archiver »


Can you also send the excel file (either here or to my personal email address)

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Alexander Strenge
Sent: Dienstag, 5. Mai 2015 17:26
To: gamsworld@googlegroups.com
Subject: Re: Looping over file names



Hi Renger,



attached you will find my code.

I want to run this model with several input files and create several output files.



The input is described in EXCEL and should be read from one sheet: line 10 for instance = 1 and from line 20 for instance = 2 and so on.



The same should happen for the Output. It should be written to one sheet: line 10 for instance = 1 and to line 20 for instance = 2 and so on.





I want to work with "run.gms" and "makerun.gms" files like described here.





Model in GAMS:



*LCC MODEL

sets
i work-brakedown structure
subi1(i) all R&D processes
subi2(i) all manufacturin processes
subi3(i) all usage processes
subi4(i) all EOL processes
;
alias (i,j);

parameters
* Parameters
balance(i) balance for an activity i if alternative o is chosen
capacity(i,j) max amount of products or pieces for activity j if alternative o is chosen
************************** PHASE: Research & Development *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_RD_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
******* FIX COST TYPES ******************************************************************************************************
c_RD_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
************************** PHASE: MANUFACTURING *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_M_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
******* FIX COST TYPES ******************************************************************************************************
c_M_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
************************** PHASE: USAGE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_U_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Usage"
******* FIX COST TYPES ******************************************************************************************************
c_U_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Usage"

************************** PHASE: END-OF-LIFE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_E_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
******* FIX COST TYPES ******************************************************************************************************
c_E_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
;
********************************************************************************
********************************************************************************
********************************************************************************
scalar
lotsize
;
lotsize = 200;

*Loading data from Excel'
$Call 'gdxxrw.exe i=RunTest_01.XLS cmerge=1 se=0 o=LCCModel_%instance%.gdx UpdLinks=3 index=GamsInput!B%instance%0'
$gdxin LCCModel_%instance%.gdx
$load i
$loadM i wrote:
> Hi,
>
> I've written a GAMS program using the xls2gms function to upload data
> and the execute_unload function to save the final result. However, I
> need to run the same GAMS code for 50 different countries, which means
> I have 50 different xls input files.
>
> Is there a way to loop over file names so that I can change the input
> file and the output file each time (e.g. Input_file_CountryX.xls,
> Results_CountryX.gdx) ?
>
> A simplified version of my code is below.
>
> Thanks for your help-
> Alison
>
> -----------------------
> *Read data from external spreadsheet
> $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
>
> set i /
> $include industries.set
> /;
> set o /
> $include occupations.set
> /;
> **************
> *Define B from external spreadsheet
> Table B(o,i) degree of belief
> $include matrixB.inc
> ;
> Parameter avg(i) average by industry/
> $include Average.inc
> /;
> **************
>
> Equations, Objective Function, etc.
>
> **************
> *Run the model to get results
> Model WAGES /objective/;
> Solve WAGES using dnlp minimizing find_min;
> Display w.l, w.m;
> **************
> *Export results to Excel by creating a .gdx file
> execute_unload "Results_Country1.gdx" w.L w.M
> execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

RE: Looping over file names

Post by Archiver »


Or better: send me a zip-file with all your stuff so I can check what is going on.

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Alexander Strenge
Sent: Dienstag, 5. Mai 2015 17:26
To: gamsworld@googlegroups.com
Subject: Re: Looping over file names



Hi Renger,



attached you will find my code.

I want to run this model with several input files and create several output files.



The input is described in EXCEL and should be read from one sheet: line 10 for instance = 1 and from line 20 for instance = 2 and so on.



The same should happen for the Output. It should be written to one sheet: line 10 for instance = 1 and to line 20 for instance = 2 and so on.





I want to work with "run.gms" and "makerun.gms" files like described here.





Model in GAMS:



*LCC MODEL

sets
i work-brakedown structure
subi1(i) all R&D processes
subi2(i) all manufacturin processes
subi3(i) all usage processes
subi4(i) all EOL processes
;
alias (i,j);

parameters
* Parameters
balance(i) balance for an activity i if alternative o is chosen
capacity(i,j) max amount of products or pieces for activity j if alternative o is chosen
************************** PHASE: Research & Development *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_RD_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
******* FIX COST TYPES ******************************************************************************************************
c_RD_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
************************** PHASE: MANUFACTURING *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_M_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
******* FIX COST TYPES ******************************************************************************************************
c_M_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
************************** PHASE: USAGE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_U_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Usage"
******* FIX COST TYPES ******************************************************************************************************
c_U_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Usage"

************************** PHASE: END-OF-LIFE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_E_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
******* FIX COST TYPES ******************************************************************************************************
c_E_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
;
********************************************************************************
********************************************************************************
********************************************************************************
scalar
lotsize
;
lotsize = 200;

*Loading data from Excel'
$Call 'gdxxrw.exe i=RunTest_01.XLS cmerge=1 se=0 o=LCCModel_%instance%.gdx UpdLinks=3 index=GamsInput!B%instance%0'
$gdxin LCCModel_%instance%.gdx
$load i
$loadM i wrote:
> Hi,
>
> I've written a GAMS program using the xls2gms function to upload data
> and the execute_unload function to save the final result. However, I
> need to run the same GAMS code for 50 different countries, which means
> I have 50 different xls input files.
>
> Is there a way to loop over file names so that I can change the input
> file and the output file each time (e.g. Input_file_CountryX.xls,
> Results_CountryX.gdx) ?
>
> A simplified version of my code is below.
>
> Thanks for your help-
> Alison
>
> -----------------------
> *Read data from external spreadsheet
> $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
>
> set i /
> $include industries.set
> /;
> set o /
> $include occupations.set
> /;
> **************
> *Define B from external spreadsheet
> Table B(o,i) degree of belief
> $include matrixB.inc
> ;
> Parameter avg(i) average by industry/
> $include Average.inc
> /;
> **************
>
> Equations, Objective Function, etc.
>
> **************
> *Run the model to get results
> Model WAGES /objective/;
> Solve WAGES using dnlp minimizing find_min;
> Display w.l, w.m;
> **************
> *Export results to Excel by creating a .gdx file
> execute_unload "Results_Country1.gdx" w.L w.M
> execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

RE: Looping over file names

Post by Archiver »


Or better: send me a zip-file with all your stuff so I can check what is going on.

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Alexander Strenge
Sent: Dienstag, 5. Mai 2015 17:26
To: gamsworld@googlegroups.com
Subject: Re: Looping over file names



Hi Renger,



attached you will find my code.

I want to run this model with several input files and create several output files.



The input is described in EXCEL and should be read from one sheet: line 10 for instance = 1 and from line 20 for instance = 2 and so on.



The same should happen for the Output. It should be written to one sheet: line 10 for instance = 1 and to line 20 for instance = 2 and so on.





I want to work with "run.gms" and "makerun.gms" files like described here.





Model in GAMS:



*LCC MODEL

sets
i work-brakedown structure
subi1(i) all R&D processes
subi2(i) all manufacturin processes
subi3(i) all usage processes
subi4(i) all EOL processes
;
alias (i,j);

parameters
* Parameters
balance(i) balance for an activity i if alternative o is chosen
capacity(i,j) max amount of products or pieces for activity j if alternative o is chosen
************************** PHASE: Research & Development *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_RD_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
******* FIX COST TYPES ******************************************************************************************************
c_RD_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Research & Development"
c_RD_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Research & Development"
************************** PHASE: MANUFACTURING *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_M_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
******* FIX COST TYPES ******************************************************************************************************
c_M_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Manufacturing"
c_M_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Manufacturing"
************************** PHASE: USAGE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_U_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "Usage"
******* FIX COST TYPES ******************************************************************************************************
c_U_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "Usage"
c_U_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "Usage"
c_U_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "Usage"
c_U_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "Usage"
c_U_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "Usage"
c_U_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "Usage"

************************** PHASE: END-OF-LIFE *********************************************************************
******* VARIABLE COST TYPES **************************************************************************************************
c_E_v1(j) variable cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v2(j) variable cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v3(j) variable cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v4(j) variable cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v5(j) variable cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_v6(j) variable cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
******* FIX COST TYPES ******************************************************************************************************
c_E_f1(j) fix cost type 1 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f2(j) fix cost type 2 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f3(j) fix cost type 3 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f4(j) fix cost type 4 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f5(j) fix cost type 5 for activity j if alternative o is chosen in phase "End-of-Life"
c_E_f6(j) fix cost type 6 for activity j if alternative o is chosen in phase "End-of-Life"
;
********************************************************************************
********************************************************************************
********************************************************************************
scalar
lotsize
;
lotsize = 200;

*Loading data from Excel'
$Call 'gdxxrw.exe i=RunTest_01.XLS cmerge=1 se=0 o=LCCModel_%instance%.gdx UpdLinks=3 index=GamsInput!B%instance%0'
$gdxin LCCModel_%instance%.gdx
$load i
$loadM i wrote:
> Hi,
>
> I've written a GAMS program using the xls2gms function to upload data
> and the execute_unload function to save the final result. However, I
> need to run the same GAMS code for 50 different countries, which means
> I have 50 different xls input files.
>
> Is there a way to loop over file names so that I can change the input
> file and the output file each time (e.g. Input_file_CountryX.xls,
> Results_CountryX.gdx) ?
>
> A simplified version of my code is below.
>
> Thanks for your help-
> Alison
>
> -----------------------
> *Read data from external spreadsheet
> $call =xls2gms i=Input_file_Country1.xls r1=Sets!set_i
> o1=industries.set r2=Sets!set_o o2=occupations.set r3=Wages!matrixB
> o3=matrixB.inc r4=Sets!MatrixA o4=Average.inc
>
> set i /
> $include industries.set
> /;
> set o /
> $include occupations.set
> /;
> **************
> *Define B from external spreadsheet
> Table B(o,i) degree of belief
> $include matrixB.inc
> ;
> Parameter avg(i) average by industry/
> $include Average.inc
> /;
> **************
>
> Equations, Objective Function, etc.
>
> **************
> *Run the model to get results
> Model WAGES /objective/;
> Solve WAGES using dnlp minimizing find_min;
> Display w.l, w.m;
> **************
> *Export results to Excel by creating a .gdx file
> execute_unload "Results_Country1.gdx" w.L w.M
> execute 'gdxxrw.exe Results_Country1.gdx var=w.L'

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Post Reply