Dynamic Set Range equivalent to AIMMS' Element Parameter

Hello,

I’m wondering if it’s possible to have sets with ranges according to other sets, just like the Element Parameter object in AIMMS (http://www.aimms.com/aimms/download/manuals/aimms3lr_setelementstringexpressions.pdf).

For example, I’d like to do something like this (it doesn’t compile, but that’s the idea):

SETS
I /1*3/
P /a,b,c/
IP(I,P)
;


IP(‘2’,‘b’) = ‘a’;

Note that the range of set IP is the set P. In AIMMS, I’d create an Element Parameter object called IP with the range of set P. Ultimately, I’d like to do the following (an example):

sum(I, prod(P, z(I,IP(I,P))))

where z is a variable whose domain is (I,P), but notice that I indexed the second element using the “element parameter”, which returns an element of the set P.

Can this be done in GAMS?

Thank you.


Bruno


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.

Bruno,

This kind of thing is done in GAMS with what I’d call a tuple map. I believe the small example below illustrates what I mean and how to use a tuple map effectively in your case.

BTW, if you’re not in the habit of using GDX, this example might change your mind. For example, save the source to a file “xx.gms”, run “gams xx gdx=out” or the equivalent in the IDE, and then browse the file out.gdx that results or dump it to a terminal with “gdxdump out.gdx”.

-Steve

$ontext
Illustrate a “set-valued mapping” or “index map”
using a power set enumeration as an example
$offtext

sets
b ‘binary digits’ / b0, b1 /
p / a, b, c /
i / i0 * i7 /
pwr(i,p,b) / system.powerSetLeft /
ip(i,p) ‘power set of p, indexed by i’
;
parameters
v(p)
s(i) ‘simple sum to show it works’
;
ip(i,p) = pwr(i,p,‘b1’);
v(p) = power(10,ord(p)-1);

  • this sum treats subsets of p as a function of i
    s(i) = sum {ip(i,p), v(p)};

scalar bruno;
parameter w(i,p) /
i0.(a,b,c) 10
i1.(a,b,c) 10
i3.(a,b,c) 2
i6.(a,b,c) .5
i7.(a,b,c) .5
/;
bruno = sum {i, prod{ip(i,p), w(i,p)}};

display ip, s, bruno;



On Fri, Jul 10, 2015 at 12:54 AM, Bruno Abreu Calfa wrote:

Hello,

I’m wondering if it’s possible to have sets with ranges according to other sets, just like the Element Parameter object in AIMMS (http://www.aimms.com/aimms/download/manuals/aimms3lr_setelementstringexpressions.pdf).

For example, I’d like to do something like this (it doesn’t compile, but that’s the idea):

SETS
I /1*3/
P /a,b,c/
IP(I,P)
;


IP(‘2’,‘b’) = ‘a’;

Note that the range of set IP is the set P. In AIMMS, I’d create an Element Parameter object called IP with the range of set P. Ultimately, I’d like to do the following (an example):

sum(I, prod(P, z(I,IP(I,P))))

where z is a variable whose domain is (I,P), but notice that I indexed the second element using the “element parameter”, which returns an element of the set P.

Can this be done in GAMS?

Thank you.


Bruno


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

Hi, Steve,

Thank you very much for your example and explanation. However, I think my problem seems to be a but more involved. I actually want to evaluate something like the following:

sum(i, prod(p, 1 - z(ip(i,p),p)*(1 - lambda(p,j))))

where z is a variable, lambda is a parameter, and ip is that mapping set that we discussed earlier. Note that it should only be applied to z. In other words, the expression above only includes the variables z for all p elements and for only the i elements that belongs to the mapping ip(i,p). I’m not sure how to do it. Don’t worry about the index j, it’s not the problem here.

Best,

Bruno

\

Bruno,

This gamsworld list is great, but since we’re both at ISMP in Pittsburgh listening to great speakers talk about the latest in optimization, maybe we can talk there. I’ll keep an eye open for you.

-Steve

On Sun, Jul 12, 2015 at 3:48 PM, Bruno Abreu Calfa wrote:

Hi, Steve,

Thank you very much for your example and explanation. However, I think my problem seems to be a but more involved. I actually want to evaluate something like the following:

sum(i, prod(p, 1 - z(ip(i,p),p)*(1 - lambda(p,j))))

where z is a variable, lambda is a parameter, and ip is that mapping set that we discussed earlier. Note that it should only be applied to z. In other words, the expression above only includes the variables z for all p elements and for only the i elements that belongs to the mapping ip(i,p). I’m not sure how to do it. Don’t worry about the index j, it’s not the problem here.

Best,

Bruno


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

Steve,

I just wanted to let you know that I figured it out after our discussion. I’d like to share it here in case it’ll be useful to others.

The “trick” to obtain a mapping from a set to an element of a set is to use a tuple. In this example, given a pair (I,P), I’d like to retrieve the “right” element I (according to some criterion in my problem). Steve suggested declaring a set IPunique(II,P,I), properly initialize it, and then sum over it with sum(IPunique(II,P,I), …). For me, it worked better to define IPunique(II,P,I) as a parameter and initialize it to 1 or 0 accordingly. So the constraint becomes:

sum(I, prod(P, 1 - sum((II) $ IPunique(II,P,I), z(II,P))*(1 - lambda(P,J))))

Note the extra summation surrounding only the z variable, whose index I is now its alias II. If properly initialized, the summation over II makes sure that only one z term will be present given a pair (I,P).

Thank you very much for your help, Steve!

Best,


Bruno


On Monday, July 13, 2015 at 8:09:18 AM UTC-5, Steven Dirkse wrote:

Bruno,

This gamsworld list is great, but since we’re both at ISMP in Pittsburgh listening to great speakers talk about the latest in optimization, maybe we can talk there. I’ll keep an eye open for you.

-Steve

On Sun, Jul 12, 2015 at 3:48 PM, Bruno Abreu Calfa wrote:

Hi, Steve,

Thank you very much for your example and explanation. However, I think my problem seems to be a but more involved. I actually want to evaluate something like the following:

sum(i, prod(p, 1 - z(ip(i,p),p)*(1 - lambda(p,j))))

where z is a variable, lambda is a parameter, and ip is that mapping set that we discussed earlier. Note that it should only be applied to z. In other words, the expression above only includes the variables z for all p elements and for only the i elements that belongs to the mapping ip(i,p). I’m not sure how to do it. Don’t worry about the index j, it’s not the problem here.

Best,

Bruno


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/d/optout.



\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdi...@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.