display_precision
option. For example, if your inputs are specified to 4 significant digits, e.g., 0.013
, you can use
option display_precision 4;to get your solution values to the same number of significant digits. src="four_dp.jpg" Note that AMPL still keeps its numbers at full precision, so you need to be careful with your objective function values. src="five_dp.jpg" When we change the
display_precision
to 5 significant digits, the displayed TotalCost
and the cost calculated by using the displayed Amount
values differ. If you are using rounded solution values, make sure to check the objective value before quoting your solution.
??? Up to here ???
Often when we display something (like variable values) many of the resulting numbers are 0 and we are only interested in the non-zero numbers. To stop any rows of zeros being displayed you can set the {\tt omit_zero_rows} option:
\begin{verbatim} option omit_zero_rows 1; \end{verbatim}
To stop any columns of zeros being displayed you can set the {\tt omit_zero_cols} option:
\begin{verbatim} option omit_zero_cols 1; \end{verbatim}
You can also force {\tt display} to use either tables or a single column by using the {\tt display_1col} option. This option will use one column if the number of values to display is less than {\tt display_1col}. The initial value of {\tt display_1col} is 20, so any {\tt display} command that shows less than 20 values will be displayed as a column. Setting {\tt display_1col} to 0 forces {\tt display} to use tables whenever possible.
The {\tt print} command only writes strings to the output.
The {\tt printf} command allows you to print text and values together in a format you can control. It uses the same {\tt printf} format as C and Matlab.
You can print over sets or set expressions as well
\begin{verbatim} # brewery.run reset;
model transportation.mod; data brewery.dat; option solver cplex; solve; print 'TRANSPORTATION SOLUTION -- Non-zero shipments' > brewery.out; display TotalCost >> brewery.out; printf {s in SUPPLY_NODES, d in DEMAND_NODES : Flow[s, d] > 0} 'Ship %d crates of beer from warehouse %s to pub %s\n', Flow[s, d], s, d >> brewery.out; close brewery.out; \end{verbatim}Running {\tt brewery.run} in AMPL creates a file {\tt brewery.out}.
\begin{verbatim} TRANSPORTATION SOLUTION -- Non-zero shipments TotalCost = 8600
Ship 300 crates of beer from warehouse A to pub 1 Ship 700 crates of beer from warehouse A to pub 5 Ship 200 crates of beer from warehouse B to pub 1 Ship 900 crates of beer from warehouse B to pub 2 Ship 1800 crates of beer from warehouse B to pub 3 Ship 200 crates of beer from warehouse B to pub 4 \end{verbatim}-- MichaelOSullivan - 02 Mar 2008