[AMPL 16098] subsets

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 16098] subsets

Juan Reyes
Hello,

So far in my AMPL experience, I haven't had the need to use subsets and index over them, I read the documentation on https://ampl.com/BOOK/CHAPTERS/09-sets2.pdf and tried to search for examples but I'm not near a good understanding on how to do it properly.

I need just two subsets of a subset f 5 elements, the first two are going to be the members of the first subset and the last 3 the members of the second, I came up with this formulation but when I tried to run the model is giving me this errors:
efes2.mod, line 18 (offset 570):
POTBREWERIES needs to be subscripted.
context:  param  >>> BrewCost{POTBREWERIES} <<< ;

efes2.mod, line 20 (offset 647):
POTBREWERIES needs to be subscripted.
context:  param  >>> ExpandCost{POTBREWERIES} <<< ;

efes2.mod, line 39 (offset 1432):
POTBREWERIES needs to be subscripted.
context:  var  >>> openB{POTBREWERIES, <<< TIME} binary;

efes2.mod, line 41 (offset 1519):
POTBREWERIES needs to be subscripted.
context:  var  >>> expandB{POTBREWERIES, <<< TIME} binary;

This is the snippet of the code where I create the set and subsets

#declaring sets used in the model
set MALTERIES; #index will be m
set BREWERIES; #index will be b
set CURBREWERIES {1..2} within BREWERIES; #index will be c
set POTBREWERIES {3..5} within BREWERIES; #index will be p
set DCs; #index will be d
set TIME; #index will be t

Any insight in how to do it properly and/or examples that do a similar thing so I can learn from it would be greatly appreciated.

Thanks,

Juan


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 16104] subsets

AMPL mailing list
My understanding is that you have a set of 5 elements and you need to create two subsets out of that. The first subset will have first three elements and the second subset has last two elements of the set.

Based on your description, you can create subsets as follows:

set BREWERIES; #index will be b
set CURBREWERIES {1..2} within BREWERIES; #index will be c
set POTBREWERIES {1..3} within BREWERIES; #index will be p

data;
set BREWERIES = a b c d e ;
set CURBREWERIES[1] = a;
set CURBREWERIES[2] = b;
set POTBREWERIES[1] = c;
set POTBREWERIES[2] = d;
set POTBREWERIES[3] = e;

--
Paras Tiwari
[hidden email]
{#HS:555689707-4591#}
On Fri, Apr 6, 2018 at 12:44 AM UTC, <[hidden email]> wrote:
Hello,

So far in my AMPL experience, I haven't had the need to use subsets and index over them, I read the documentation on https://ampl.com/BOOK/CHAPTERS/09-sets2.pdf and tried to search for examples but I'm not near a good understanding on how to do it properly.

I need just two subsets of a subset f 5 elements, the first two are going to be the members of the first subset and the last 3 the members of the second, I came up with this formulation but when I tried to run the model is giving me this errors:
efes2.mod, line 18 (offset 570):
POTBREWERIES needs to be subscripted.
context: param >>> BrewCost{POTBREWERIES} <<< ;

efes2.mod, line 20 (offset 647):
POTBREWERIES needs to be subscripted.
context: param >>> ExpandCost{POTBREWERIES} <<< ;

efes2.mod, line 39 (offset 1432):
POTBREWERIES needs to be subscripted.
context: var >>> openB{POTBREWERIES, <<< TIME} binary;

efes2.mod, line 41 (offset 1519):
POTBREWERIES needs to be subscripted.
context: var >>> expandB{POTBREWERIES, <<< TIME} binary;

This is the snippet of the code where I create the set and subsets

#declaring sets used in the model
set MALTERIES; #index will be m
set BREWERIES; #index will be b
set CURBREWERIES {1..2} within BREWERIES; #index will be c
set POTBREWERIES {3..5} within BREWERIES; #index will be p
set DCs; #index will be d
set TIME; #index will be t

Any insight in how to do it properly and/or examples that do a similar thing so I can learn from it would be greatly appreciated.

Thanks,

Juan


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.