variable with changing number of arguments

13 views
Skip to first unread message

mar_ir

unread,
Aug 25, 2016, 5:23:10 PM8/25/16
to AMPL Modeling Language
Hi,

I need to define variables that depend on a variable number k of arguments. For example, I would like to do the following for a generic k

set Y = 1 .. 3;

var P {y1 in Y, y2 in Y, ....., yk in Y};

k ranges from 8 to 200 approx depending on the particular application, so I want to write a model where I just have to set the value of k at the very beginning as a parameter (so I don't have to enter the names of arguments y1, y2,.... yk manually for each application). In addition, I would like to use the "number" associated with an argument to define the objetive function and/or restrictions; for example with k=3


maximize Function: sum {k in Y} sum {y1 in Y, y2 in Y, y3 in Y: yk == k}   P[y1,y2,y3]


What is the most efficient way of doing this?


Thanks

Robert Fourer

unread,
Aug 26, 2016, 2:01:43 PM8/26/16
to am...@googlegroups.com
The dimension of an AMPL entity -- the number of indexes or "subscripts" -- must be fixed; it cannot depend on a data parameter, such as k in your example. This restriction in necessitated by the syntax in which the subscripts are given explicitly separately by commas (as in P[y1,y2,y3]); a significant revision to the AMPL syntax would be needed to allow a number of subscripts that can be different depending on the data.

Also note that if k = 200 then you would have 3^200 variables in your problem, which would not be practical. For reasonable values of k you may need a different AMPL model for each k value.

Bob Fourer
am...@googlegroups.com

=======

mar_ir

unread,
Aug 26, 2016, 4:09:18 PM8/26/16
to AMPL Modeling Language, 4...@ampl.com
Thanks Robert, I was almost convinced that a different model for each k is needed but wanted to be 100% sure about that
Reply all
Reply to author
Forward
0 new messages