specifying values of several one-dimensional parameters

41 views
Skip to first unread message

Ellen

unread,
Nov 12, 2012, 2:05:59 PM11/12/12
to AMPL Modeling Language
In the AMPL book (section 9.2, page 151 of second edition), the values
of the one-dimensional parameters rate, profit and market are
specified over the set PROD whose elements are BANDS, COILS and PLATE,
as follows:

param : rate profit
market :=
BANDS 200 25 6000
COILS 140 30 4000
PLATE 160 29
3500 ;

Can such a specification of values be made with the orientation of the
parameters and set elements reversed? I.e., all of the set elements
listed first followed by each parameter's respective values.

I want to do this because I have a small number of parameters all
indexed over one very long set and I'd like to minimize the rows in
the Excel sheet from which my AMPL data file is created. (I don't care
how many columns it has.)

Robert Fourer

unread,
Nov 14, 2012, 4:23:11 PM11/14/12
to am...@googlegroups.com
The AMPL data-file format does not have an option to read the transpose of a
table of this kind, with parameter names (rate, profit, market) on the left
and index names (BANDS, COILS, PLATE, ...) on the top. To read something
like the transpose, you would have to define a 2-dimensional parameter that
contains all the data, then copy it to the 1-dimensional parameters. For
example:

set PROD;
set parname = {"rate","profit","market"};

param rpm {parname,PROD};
param rate {p in PROD} = rpm["rate",p];
param profit {p in PROD} = rpm["profit",p];
param market {p in PROD} = rpm["market",p];

Then the data could be written like this:

set PROD := BANDS COILS PLATE ;

param rpm: BANDS COILS PLATE :=
rate 200 140 120
profit 25 30 29
market 6000 4000 3500 ;

If instead you are using "table" statements to read directly from a
spreadsheet (rather than dumping the spreadsheet's contents to a text file),
then the arrangement of data in the sheet has to consist of one or more key
(index) columns followed by one or more data (parameter) columns, so again
the transpose of this arrangement is not recognized. You could try reading
the spreadsheet data into a parameter like rpm above, however, following the
instructions for "Indexed collections of data columns" on page 196 of
chapter 10 in the AMPL book (www.ampl.com/BOOK/download.html).

Of course Excel has a way of copying any table to its transpose, but
presumably the idea here is to avoid that.

Bob Fourer
4...@ampl.com
Reply all
Reply to author
Forward
0 new messages