(Sub) sets defined by elements in a parameter statement

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

(Sub) sets defined by elements in a parameter statement

Post by Archiver »



Hello All,

Please forgive the potentially horribly naive question, but I don't
use GAMS too much. I've been struggling with this for a little while
now... Imagine as a simple use case that a user (namely me) wants to
have upper or lower bounds imposed on only a subset of the variables
in his problem.

Ideally, I would like to simply declare one set (the set of variables
for which bounds are to be imposed) to be a subset of another set,
and have the elements in the subset be taken directly from the
parameter statement.

Is this possible? If not, then why not -- it seems very natural to
me.
Here is a small example:


set
A "Set A"
ix(A) " subset of A"
;

parameters
c(A) " something indexed over A"
u(ix) " indexed over a subset of A"
;

set A /
Steve,
Dirkse,
Is,
Cool /
;

parameter c(A)
/ Steve 42.0
Dirkse 666.0
Is 42.0
Cool 666.0 /
;

parameter u(ix)
/ Steve -1.0
Cool 0.0 /
;

display c;
display u;

This doesn't work, as it tells me that the values for the domain of ix
are unknown.

25 parameter u(ix)
26 / Steve -1.0 /
**** $361


GAMS Rev 147 x86/
Linux
05/07/07 15:46:11 Page 2
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Error Messages

361 Values for domain 1 are unknown - no checking possible

--------------------


This is part of a larger model, and I would rather not have to
explicity write out *all* of the data necessary to define *all* of the
subsets for *all* of the constraints that I want to hold given the
input data.

Thanks for any help you can provide.

Cheers,
-Jeff


--~--~---------~--~----~------------~-------~--~----~
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: (Sub) sets defined by elements in a parameter statement

Post by Archiver »



Jeff,

GAMS needs to know which set elements belong to ix (at compile time)
in order to do domain checking of parameter u. So you either declare
the members of set ix explicitely like:

set ix(A) / Steve, cool /;

or you define parameter u over set A:

set u(A) / Steve -1.0, Cool 0.0 /;

and use the u(A)0 as membership indicator for subset ix (which can't
be used as a domain in variable, parameter, whatever declarations):

ix(A) = u(A);

You can use ix from there in execution time statements like

x.lo(ix) = u(ix);

Since membership is check with u(A)0 we won't get Cool as member of
ix. You can either have a numerical 0 but a logical non-zero by
specifying

set u(A) / Steve -1.0, Cool eps /;

In case you have plenty 0.0 in u and you want the 0.0 as logical non-
zeros, you could do

$oneps
set u(A) / Steve -1.0, Cool 0.0 /;
$offeps

which treads all explicit 0.0 as eps. Be careful with your
comparisons: ix(A) = u(A); will make Cool par of ix, ix(A) = u(A)0
will not (since eps is a numerical 0).


Hope this is not too confusing and it helps,
Michael

On May 7, 4:05 pm, j...@lehigh.edu wrote:
> > Hello All,
> >
> > Please forgive the potentially horribly naive question, but I don't
> > use GAMS too much. I've been struggling with this for a little while
> > now... Imagine as a simple use case that a user (namely me) wants to
> > have upper or lower bounds imposed on only a subset of the variables
> > in his problem.
> >
> > Ideally, I would like to simply declare one set (the set of variables
> > for which bounds are to be imposed) to be a subset of another set,
> > and have the elements in the subset be taken directly from the
> > parameter statement.
> >
> > Is this possible? If not, then why not -- it seems very natural to
> > me.
> > Here is a small example:
> >
> > set
> > A "Set A"
> > ix(A) " subset of A"
> > ;
> >
> > parameters
> > c(A) " something indexed over A"
> > u(ix) " indexed over a subset of A"
> > ;
> >
> > set A /
> > Steve,
> > Dirkse,
> > Is,
> > Cool /
> > ;
> >
> > parameter c(A)
> > / Steve 42.0
> > Dirkse 666.0
> > Is 42.0
> > Cool 666.0 /
> > ;
> >
> > parameter u(ix)
> > / Steve -1.0
> > Cool 0.0 /
> > ;
> >
> > display c;
> > display u;
> >
> > This doesn't work, as it tells me that the values for the domain of ix
> > are unknown.
> >
> > 25 parameter u(ix)
> > 26 / Steve -1.0 /
> > **** $361
> >
> > GAMS Rev 147 x86/
> > Linux
> > 05/07/07 15:46:11 Page 2
> > G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
> > Error Messages
> >
> > 361 Values for domain 1 are unknown - no checking possible
> >
> > --------------------
> >
> > This is part of a larger model, and I would rather not have to
> > explicity write out *all* of the data necessary to define *all* of the
> > subsets for *all* of the constraints that I want to hold given the
> > input data.
> >
> > Thanks for any help you can provide.
> >
> > Cheers,
> > -Jeff


--~--~---------~--~----~------------~-------~--~----~
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: (Sub) sets defined by elements in a parameter statement

Post by Archiver »



Hi Michael,

Thanks very much for your extremely timely and useful response.
18 minutes. Wow!

As an aside, I don't think you know very much about practical Customer
Service. My wife does customer support for a small software company,
and she has found that it is better to make all customers wait at least
20 minutes before answering their email, since if you respond too
quickly, they start to get upset if ever you happen to take *more* than
a half an hour. :-)

> > GAMS needs to know which set elements belong to ix (at compile time)
> > in order to do domain checking of parameter u.

I guess I was hoping that GAMS would not be so strict -- as long as ix
was known to be a subset of A and the elements were valid elements for
A, I was hoping it would work...


> > and use the u(A)0 as membership indicator for subset ix (which can't
> > be used as a domain in variable, parameter, whatever declarations):

I had been doing the u(A) 0 check before, but got burned a couples
times when I actually *wanted* a zero for the constraint. However...


> >
> > Since membership is check with u(A)0 we won't get Cool as member of
> > ix. You can either have a numerical 0 but a logical non-zero by
> > specifying
> >
> > set u(A) / Steve -1.0, Cool eps /;
> >

This is exactly what I need -- thanks!

As usual, I owe you one. Please add it to my tab...

Cheers,
-Jeff

> > -~----------~----~----~----~------~----~------~--~---

Post Reply