headers with the csvdisplay command

224 views
Skip to first unread message

Op

unread,
Dec 17, 2009, 4:49:27 PM12/17/09
to AMPL Modeling Language
I would like to include meaningful headers in the output files that I
create with the csvdisplay command instead of the generic "Index_1"
and "Expr_1" labels. I found a workaround:

option csvdisplay_header 0;
print "Location,Product,Amount" > output.csv;
csvdisplay {(l,p) in LOCPROD}Amount[l,p]>output.csv;
close output.csv;


It seems like there would be a way to assign "Index_1" to be
"Location", but I can't figure out the syntax. Any suggestions?
Thanks.

Robert Fourer

unread,
Dec 19, 2009, 11:06:16 AM12/19/09
to am...@googlegroups.com, Op

Your use of "print" together with "csvdisplay" is probably the best solution
here. The "csvdisplay" command was devised as a way of writing data in a
generic form that could be processed by other programs, and so it doesn't
have much of anything in the way of options for producing more meaningful
output like column headings.

If you can work with tab-separated fields then one alternative is to use
AMPL "table" command which produces much the same output but with complete
flexibility in generating column headings. For example in a model that has

set LINKS within {ORIG,DEST};
var Trans {LINKS} >= 0;

one can use the commands

table transtab OUT "transfile.tab":
{(i,j) in LINKS} -> [origin,destination], Trans[i,j] ~ shipped;
write table transtab;

to get a file transfile.tab that begins

ampl.tab 2 1
origin destination shipped
GARY DET 0
GARY LAN 0
GARY STL 800
GARY LAF 600
CLEV FRA 0
...

There are numerous options to regulate what appears in the table, as
described in chapter 10 of the AMPL book.

Bob Fourer
4...@ampl.com

Reply all
Reply to author
Forward
0 new messages