Percent (%) usage

Hi all,

Quick question - what does the percent sign mean/enable in code. It seems like it may be some form of a macro, but I’m not quite sure. An example would be in the McCarl GAMS User Guide for “$call”

$call Gdxxrw “%XLS%” @xllink.txt log=xllink.log

  • If filtered import, read from GDX
    $if %more% == ‘’ $goto unfiltered
    $GDXin xllink.gdx
    $load %sym%
    $GDXin
    $goto term

$label unfiltered
$onempty
$if ParType %sym% parameter %sym% /
$if SetType %sym% set %sym% /
$call GDXdump xllink.gdx symb=%sym% noheader > xllink.in
$include xllink.in

-Brian


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/groups/opt_out.

Hi Brian



The %…% is a placeholder. For example, if you have two data sets for your model, you can use the following code to read in your choice of data:


\

  • Choose model data

$setglobal city Chicago


\

  • Extract datsa from xlsx-spreadheet

$call ‘gdxxrw .\data%city%\DataTransport%city%.xlsx sq = N o=.\temp%city%hh.gdx index=twohh trace=3 CheckDate’



If you run this code, it will read the data from DataTransportChicago.xlsx in the directory .\data\Chicago.

If my other data is for Zurich, I only have to change the setglobal to Zurich.

You can also use this technique to save your results in different gdx or excel files, or set values of parameters (which is particularly nice if you want to run a batch file for different scenarios).



Note that you now can run your model also from the command line (or with options in the Gamside):



Gams mymodel --city=Chicago



And then run your model for Zurich



Gams mymodel –-city= Zurich



Hope this helps.

Cheers



Renger


Modelworks

Gewerbestrasse 15

3600 Thun – Switzerland

+41 79 818 53 73

Info@modelworks.ch

blog.modelworks.ch









From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Brian
Sent: Mittwoch, 23. Oktober 2013 19:38
To: gamsworld@googlegroups.com
Subject: Percent (%) usage



Hi all,



Quick question - what does the percent sign mean/enable in code. It seems like it may be some form of a macro, but I’m not quite sure. An example would be in the McCarl GAMS User Guide for “$call”



$call Gdxxrw “%XLS%” @xllink.txt log=xllink.log

  • If filtered import, read from GDX
    $if %more% == ‘’ $goto unfiltered
    $GDXin xllink.gdx
    $load %sym%
    $GDXin
    $goto term

$label unfiltered
$onempty
$if ParType %sym% parameter %sym% /
$if SetType %sym% set %sym% /
$call GDXdump xllink.gdx symb=%sym% noheader > xllink.in
$include xllink.in



-Brian


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/groups/opt_out.


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/groups/opt_out.

Hi Renger,

Thank you, this is quite useful.

Would I be able to use this technique to run a loop over a parameter that has a mis-ordered set? Basically, I’d like to read data in the order 1,2,3,…11,12 but the set becomes ordered as 1,10,11,12,2,3,…8,9. Running a loop itself would not work, since the set is out of order. For example, running the following would run whatever was in the loop out of the order I wanted:

SETS a
b
c
d1 /t1 t10 t11 t12 t2 t3 t4 t5 t6 t7 t8 t9/
PARAMETER para1(a,b,c,d1);
PARAMETER e

LOOP (d1,
e = para1(a,b,c,d1) + e;
);

But if instead my loop looked like the following:

$setglobal d2 t1

LOOP (d1,
e = para1(a,b,c,%d2%) + e;
);

The issue is that it throws the error “Domain violation for set”. Basically, is there any way to call an observation within a multi-dimensional parameter within a loop that does not loop over a set defined as part of the parameter in question?

Thanks,
Brian

On Wednesday, October 23, 2013 10:37:52 AM UTC-7, Brian wrote:

Hi all,

Quick question - what does the percent sign mean/enable in code. It seems like it may be some form of a macro, but I’m not quite sure. An example would be in the McCarl GAMS User Guide for “$call”

$call Gdxxrw “%XLS%” @xllink.txt log=xllink.log

  • If filtered import, read from GDX
    $if %more% == ‘’ $goto unfiltered
    $GDXin xllink.gdx
    $load %sym%
    $GDXin
    $goto term

$label unfiltered
$onempty
$if ParType %sym% parameter %sym% /
$if SetType %sym% set %sym% /
$call GDXdump xllink.gdx symb=%sym% noheader > xllink.in
$include xllink.in

-Brian


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/groups/opt_out.

Hi Brian

If you use a specific set element it should be in “ “ (e.g. a,b,c,”%d2%”)

Cheers

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Brian
Sent: Donnerstag, 24. Oktober 2013 19:37
To: gamsworld@googlegroups.com
Subject: Re: Percent (%) usage



Hi Renger,



Thank you, this is quite useful.



Would I be able to use this technique to run a loop over a parameter that has a mis-ordered set? Basically, I’d like to read data in the order 1,2,3,…11,12 but the set becomes ordered as 1,10,11,12,2,3,…8,9. Running a loop itself would not work, since the set is out of order. For example, running the following would run whatever was in the loop out of the order I wanted:



SETS a

b

c

d1 /t1 t10 t11 t12 t2 t3 t4 t5 t6 t7 t8 t9/

PARAMETER para1(a,b,c,d1);

PARAMETER e



LOOP (d1,

e = para1(a,b,c,d1) + e;

);



But if instead my loop looked like the following:



$setglobal d2 t1



LOOP (d1,

e = para1(a,b,c,%d2%) + e;

);



The issue is that it throws the error “Domain violation for set”. Basically, is there any way to call an observation within a multi-dimensional parameter within a loop that does not loop over a set defined as part of the parameter in question?



Thanks,

Brian


On Wednesday, October 23, 2013 10:37:52 AM UTC-7, Brian wrote:

Hi all,



Quick question - what does the percent sign mean/enable in code. It seems like it may be some form of a macro, but I’m not quite sure. An example would be in the McCarl GAMS User Guide for “$call”



$call Gdxxrw “%XLS%” @xllink.txt log=xllink.log

  • If filtered import, read from GDX
    $if %more% == ‘’ $goto unfiltered
    $GDXin xllink.gdx
    $load %sym%
    $GDXin
    $goto term

$label unfiltered
$onempty
$if ParType %sym% parameter %sym% /
$if SetType %sym% set %sym% /
$call GDXdump xllink.gdx symb=%sym% noheader > xllink.in
$include xllink.in



-Brian


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/groups/opt_out.


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/groups/opt_out.