Change labels in a set

Hi all!:

I am trying to put together a nice automatic model structure for a problem, but I’m facing a challenge that seems minor:

1- I have a GDX file containing a 2-dim parameter (e in the example), which I use to populate two different sets (ii and jj in the example).

$gdxin H_GDX
$load ii<e.dim1 jj<e.dim2
$gdxin

2- I need to have a set (in order to project some equations and variables and don’t re-write code) that is the union of a prior set (d) with one of this two “populated” sets (jj), but I need the new set (z) to have TWO elements per each in the original (jj).

Using:

set z /set.d, set.jj/

Brings me close, but I would need a way to beforehand “duplicate” jj modifying each label in a subtle way, so that I can then join all three sets, i.e.:

set z/set.d, set.jj1, set.jj2/

Which is what I’m trying to accomplish.

Any ideas ? Forgive me if I’m not being quite clear, it’s a really simple matter but it’s a bit hard to explain.

Best regards and thanks in advance
Claudio

\

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.

Claudio,

When I’m doing similar things with sets I often reach a point where I just start up a sub-job, do the dirty work of set creation and label-munging there, export the set to a new GDX, and read that GDX in the top-level GAMS job. Typically the stake-holders in the project like having the dirty bits handled separately, and there is often a long list of data hacks that accumulate, so it’s good to collect them as a subtask.

For example, you could do:

$gdxin H_GDX
$load ii wrote:

Hi all!:

I am trying to put together a nice automatic model structure for a problem, but I’m facing a challenge that seems minor:

1- I have a GDX file containing a 2-dim parameter (e in the example), which I use to populate two different sets (ii and jj in the example).

$gdxin H_GDX
$load ii<e.dim1 jj<e.dim2
$gdxin

2- I need to have a set (in order to project some equations and variables and don’t re-write code) that is the union of a prior set (d) with one of this two “populated” sets (jj), but I need the new set (z) to have TWO elements per each in the original (jj).

Using:

set z /set.d, set.jj/

Brings me close, but I would need a way to beforehand “duplicate” jj modifying each label in a subtle way, so that I can then join all three sets, i.e.:

set z/set.d, set.jj1, set.jj2/

Which is what I’m trying to accomplish.

Any ideas ? Forgive me if I’m not being quite clear, it’s a really simple matter but it’s a bit hard to explain.

Best regards and thanks in advance
Claudio

\

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.



\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com

Steven,

First of all thanks for your help. I agree with you, I do that all the time, in use several .gms files in this one.

The question I had refers as to how to do the, using your words, “label-munging” in GAMS.

For instance, in the example you sent, what would be the commands I should use in zMaker.gms to create a duplicate jj with automatically edited labels ? Or am I stuck with calling external programs: awk or the like ?

Thanks again and regards
Claudio


On Thu, Mar 5, 2015 at 12:29 PM, Steven Dirkse wrote:

Claudio,

When I’m doing similar things with sets I often reach a point where I just start up a sub-job, do the dirty work of set creation and label-munging there, export the set to a new GDX, and read that GDX in the top-level GAMS job. Typically the stake-holders in the project like having the dirty bits handled separately, and there is often a long list of data hacks that accumulate, so it’s good to collect them as a subtask.

For example, you could do:

$gdxin H_GDX
$load ii wrote:

Hi all!:

I am trying to put together a nice automatic model structure for a problem, but I’m facing a challenge that seems minor:

1- I have a GDX file containing a 2-dim parameter (e in the example), which I use to populate two different sets (ii and jj in the example).

$gdxin H_GDX
$load ii<e.dim1 jj<e.dim2
$gdxin

2- I need to have a set (in order to project some equations and variables and don’t re-write code) that is the union of a prior set (d) with one of this two “populated” sets (jj), but I need the new set (z) to have TWO elements per each in the original (jj).

Using:

set z /set.d, set.jj/

Brings me close, but I would need a way to beforehand “duplicate” jj modifying each label in a subtle way, so that I can then join all three sets, i.e.:

set z/set.d, set.jj1, set.jj2/

Which is what I’m trying to accomplish.

Any ideas ? Forgive me if I’m not being quite clear, it’s a really simple matter but it’s a bit hard to explain.

Best regards and thanks in advance
Claudio

\

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.



\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com


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.

Claudio,

Attached is an example where the label creation (concatenation only) happens in GAMS. If you want to do more complicated stuff (e.g. change all occurrences of “one” with “uno”) awk would be better, but the structure isn’t so different.

-Steve



On Thu, Mar 5, 2015 at 11:53 AM, Claudio Delpino wrote:

Steven,

First of all thanks for your help. I agree with you, I do that all the time, in use several .gms files in this one.

The question I had refers as to how to do the, using your words, “label-munging” in GAMS.

For instance, in the example you sent, what would be the commands I should use in zMaker.gms to create a duplicate jj with automatically edited labels ? Or am I stuck with calling external programs: awk or the like ?

Thanks again and regards
Claudio


On Thu, Mar 5, 2015 at 12:29 PM, Steven Dirkse wrote:

Claudio,

When I’m doing similar things with sets I often reach a point where I just start up a sub-job, do the dirty work of set creation and label-munging there, export the set to a new GDX, and read that GDX in the top-level GAMS job. Typically the stake-holders in the project like having the dirty bits handled separately, and there is often a long list of data hacks that accumulate, so it’s good to collect them as a subtask.

For example, you could do:

$gdxin H_GDX
$load ii wrote:

Hi all!:

I am trying to put together a nice automatic model structure for a problem, but I’m facing a challenge that seems minor:

1- I have a GDX file containing a 2-dim parameter (e in the example), which I use to populate two different sets (ii and jj in the example).

$gdxin H_GDX
$load ii<e.dim1 jj<e.dim2
$gdxin

2- I need to have a set (in order to project some equations and variables and don’t re-write code) that is the union of a prior set (d) with one of this two “populated” sets (jj), but I need the new set (z) to have TWO elements per each in the original (jj).

Using:

set z /set.d, set.jj/

Brings me close, but I would need a way to beforehand “duplicate” jj modifying each label in a subtle way, so that I can then join all three sets, i.e.:

set z/set.d, set.jj1, set.jj2/

Which is what I’m trying to accomplish.

Any ideas ? Forgive me if I’m not being quite clear, it’s a really simple matter but it’s a bit hard to explain.

Best regards and thanks in advance
Claudio

\

main.gms (274 Bytes)
zMaker.gms (272 Bytes)