Thanks Steve, that’s very helpful.
Dave Martell
On Monday, November 4, 2013 4:13:09 AM UTC-5, Steven Dirkse wrote:
Dave,
You raise an interesting question about using subsets to declare variables and equations, and you have some good company in doing so: this was something that Rick Rosenthal was a strong advocate for, and Bruce McCarl has this near the top of his wish list also.
A related question is on creating aliases. Currently one cannot create an alias for a multi-dimensional set. This is something we are thinking about adding.
The way to approach this is to declare variables and equations over the full domains, e.g. f(i,j), x(i,j). But declarations only say how big something could possibly be, now what it actually is. Define equations over the desired tuples, so that only the model rows you want are produced from the equations. It may be that this is enough to restrict the variable usage to the desired tuple set. If not, you need to adjust the algebra to use only those tuples that you want included in the model.
It’s worth emphasizing here that in GAMS, model rows (e.g. f(‘i2’,‘j3’)) exist when they are part of the defined equation, not the declared equation. Model columns (e.g. x(‘i2’,‘j3’)) exist if they are used in the rows that make up the model. So if you use only those variables from your tuple set, your model will not contain any extra variables. Of course, that does require you to use the tuple set to control variable usage, or at least consider if this is necessary, each time you use a variable.
Changing the current scheme wouldn’t change things much for equations declarations. You only define an equation once, so you can easily use the tuple maps then. But to use only variables in a tuple map, you have to use the tuple (potentially) each time you use the variable. This is additional work but more importantly it’s easy to get wrong., and if you get it wrong there is no automatic check that this has happened. So usually we talk about “allowing variables declared over tuples” when this topic comes up.
Here’s a model with some comments on how this works:
sets
i / i1 * i2 /
j / j1 * j3 /
ij(i,j) / i1.j1,i2.j3/
;
- declarations must be over singleton sets, two lines below do not work
- positive variable x(ij);
- equation f(ij);
positive variable x(i,j), y(i,j), z(i,j);
equation f1(i,j), f2(i,j), f3(i,j);
- but equation definitions and variable usage can use tuples,
- the three below are equivalent
f1(ij) … x(ij) =g= 2;
f2(ij(i,j)) … y(i,j) =g= 2;
f3(i,j)$ij(i,j) … z(i,j) =g= 2;
model m / f1.x, f2.y, f3.z /;
solve m using mcp;
- above we used equations defined over ij.
- we can also do sums over ij, like this:
- obj =e= sum{ij, x(ij)} + sum{ij(i,j), x(i,j)**c(j)}
HTH,
-Steve
On Sun, Nov 3, 2013 at 10:27 PM, wrote:
Hello,
I have some questions concerning the use of sparse tuples to reduce the size of mathematical programming models.
The following set of un-commented instructions should run under GAMS
\
- I am developing a model with:
sets i /1*5/
j /A,B,C/;
\
- I define a tuple with the statement:
set tuple (i,j) /1.A,2.A,5.B,5.C/;
\
- It appears that I can sum over tuples as in:
parameter sum1,vol(i,j);
vol(i,j)=1;
sum1=sum((i,j), vol(i,j));
\
-
and I can define a variable x over the sets i and j with:
variable x(i,j);
\
-
but I cannot define the variable x over the tuple with:
-
variable x(tuple);
\
-
or
-
variable x(tuple(i,j));
display i,j,tuple,vol,sum1;
\
-
That means my model will have decision variables x that don’t really exist
-
and must be zero and my model will therefore be larger than it needs to be.
\
-
Also, despite the fact that GAMS views a tuple as “a set defined over other sets”
-
I cannot use it in the same way as I use a simple set, to create equations
-
The following code works:
variable y(i);
alias (i,k);
set tuple2 (i,k) /1.2,2.3,5.1,5.2/;
display tuple2;
equation adjacency(i,k);
adjacency (tuple2 (i,k))… y(i) + y(k) =L=1;
display tuple2;
\
-
but the following code does not work:
\
-
adjacency (tuple2)… y(i) + y(k) =L=1;
\
-
that suggests the name of the tuple is “tuple2 (i,k)” but GAMS
-
displays it at “tuple2” which suggests that is not the case.
\
-
Does GAMS compel me to use sets, tuples and equations in these ways
-
or am I missing something?
\
-
Thanks
-
Dave Martell
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/groups/opt_out.