Difference: PrintingInAMPL (1 vs. 8)

Revision 82009-10-09 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
<-- Ready to Review -->
Line: 12 to 12
 

How many decimal places?

When solving mathematical programming problems, the accuracy of your solutions should never be more than the

Changed:
<
<
accuracy of your data. You can set the precision that AMPL displays values via the display_precision option. For example, if your inputs are specified to 4 significant digits, e.g., 0.013, you can use
>
>
accuracy of your data. You can set the precision for displaying values in AMPL via the 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;
Line: 28 to 28
 

Displaying Information

Changed:
<
<
You have already seen how to display a variable using the display command. We can also display AMPL expressions the same way, e.g., we might want to see how supply we are using in a transportation problem.
>
>
You have already seen how to display a variable using the display command. We can also display AMPL expressions the same way, e.g., we might want to see how much supply we are using in a transportation problem.
  display.jpg

Revision 72008-04-08 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
<-- Ready to Review -->
Line: 71 to 71
 reset;

model transportation.mod;

Added:
>
>
. . .
 data brewery.dat;
Added:
>
>
. . .
 option solver cplex;

solve;

Line: 82 to 91
 display TotalCost >> brewery.out;

printf {s in SUPPLY_NODES, d in DEMAND_NODES : Flow[s, d] > 0}

Changed:
<
<
'Ship %d crates of beer from warehouse %s to pub %s\n', Flow[s, d], s, d >> brewery.out;
>
>
'Ship %d crates of beer from warehouse %s to pub %s\n', Flow[s, d], s, d >> brewery.out;
  close brewery.out;

Revision 62008-03-04 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
Changed:
<
<
<-- Under Construction -->
>
>
<-- Ready to Review -->
 

Displaying and Printing in AMPL

Line: 26 to 26
  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.
Deleted:
<
<
??? Up to here ???
 

Displaying Information

You have already seen how to display a variable using the display command. We can also display AMPL expressions the same way, e.g., we might want to see how supply we are using in a transportation problem.

Changed:
<
<
src="display.jpg"
>
>
display.jpg
  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 omit_zero_rows option:

Line: 43 to 41
 option omit_zero_cols 1;
Changed:
<
<
src="omit.jpg"
>
>
omit.jpg
  You can also force display to use either tables or a single column by using the display_1col option. This option will use one column if the number of values to display is less than display_1col. The initial value of display_1col is 20, so any display command that shows less than 20 values will be displayed as a column. Setting display_1col to 0 forces display to use tables whenever possible.
Changed:
<
<
src="display_1col.jpg"
>
>
display_1col.jpg
 

Printing Information

By playing with the display options we can get the display command to format output in a nice way. However, we can also decide exactly what is displayed by using print and printf.

Changed:
<
<
src="print.jpg"
>
>
print.jpg
  The print command only writes strings to the output.

The printf command allows you to print text and values together in a format you can control. It uses the same printf format as C and Matlab.

Changed:
<
<
src="printf.jpg"
>
>
printf.jpg
  You can print over sets or set expressions as well
Changed:
<
<
src="printf_set.jpg"
>
>
printf_set.jpg
 

Printing to a File

Changed:
<
<
All the output commands can be directed to a file. Adding > <filename&gt to the end of an output command creates the file with the given name and writes to it. Subsequent output commands append output to the file by adding >> <filename> to the commands. You should close your file when done so you can open it with another program. This is very useful for saving your solutions (in a useful format with printf), for example
>
>
All the output commands can be directed to a file. Adding > <filename> to the end of an output command creates the file with the given name and writes to it. Subsequent output commands append output to the file by adding >> <filename> to the commands. You should close your file when done so you can open it with another program. This is very useful for saving your solutions (in a useful format with printf), for example
 
# brewery.run
reset;

Line: 83 to 81
  display TotalCost >> brewery.out;
Changed:
<
<
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;
>
>
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;
Changed:
<
<
Running brewery.run in AMPL creates a file brewery.out.

-- MichaelOSullivan - 02 Mar 2008

  • display.jpg:
    display.jpg

  • omit.jpg:
    omit.jpg

  • display_1col.jpg:
    display_1col.jpg

  • print.jpg:
    print.jpg

  • printf.jpg:
    printf.jpg
>
>
Running brewery.run in AMPL creates a file brewery.out:
TRANSPORTATION SOLUTION -- Non-zero shipments
TotalCost = 8600

 
Changed:
<
<
  • printf_set.jpg:
    printf_set.jpg
>
>
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
 
Changed:
<
<
>
>
-- MichaelOSullivan - 02 Mar 2008
 
META FILEATTACHMENT attachment="four_dp.jpg" attr="h" comment="" date="1204604433" name="four_dp.jpg" path="four_dp.jpg" size="35091" stream="four_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="five_dp.jpg" attr="h" comment="" date="1204604447" name="five_dp.jpg" path="five_dp.jpg" size="36558" stream="five_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"

Revision 52008-03-04 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
<-- Under Construction -->
Line: 28 to 28
  ??? Up to here ???
Changed:
<
<

Displaying Information

You have already seen how to display a variable using the {\tt display} command. We can also display {a href="Expressioins in AMPL">AMPL expressions the same way, e.g., we might want to see how supply we are using in a transportation problem.

>
>

Displaying Information

 
Changed:
<
<
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}

>
>
You have already seen how to display a variable using the display command. We can also display AMPL expressions the same way, e.g., we might want to see how supply we are using in a transportation problem.

src="display.jpg"

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 omit_zero_rows option:


 option omit_zero_rows 1;
Changed:
<
<
\end{verbatim}

To stop any columns of zeros being displayed you can set the {\tt omit_zero_cols} option:

\begin{verbatim}

>
>
To stop any columns of zeros being displayed you can set the omit_zero_cols option:

 option omit_zero_cols 1;
Changed:
<
<
\end{verbatim}

>
>

src="omit.jpg"

You can also force display to use either tables or a single column by using the display_1col option. This option will use one column if the number of values to display is less than display_1col. The initial value of display_1col is 20, so any display command that shows less than 20 values will be displayed as a column. Setting display_1col to 0 forces display to use tables whenever possible.

src="display_1col.jpg"

Printing Information

By playing with the display options we can get the display command to format output in a nice way. However, we can also decide exactly what is displayed by using print and printf.

 
Changed:
<
<
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.

>
>
src="print.jpg"
 
Changed:
<
<

Printing Information

>
>
The print command only writes strings to the output.
 
Changed:
<
<
By playing with the {\tt display} options we can get the {\tt display} command to format output in a nice way. However, we can also decide exactly what is displayed by using {\tt print} and {\tt printf}. <p

The {\tt print} command only writes strings to the output.

>
>
The printf command allows you to print text and values together in a format you can control. It uses the same printf format as C and Matlab.
 
Changed:
<
<
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.

>
>
src="printf.jpg"
 
Changed:
<
<
You can print over sets or set expressions as well

>
>
You can print over sets or set expressions as well
 
Changed:
<
<

Printing to a File

>
>
src="printf_set.jpg"
 
Changed:
<
<
All the output commands can be directed to a file. Adding {\tt > <filename>} to the end of an output command creates the file with the given name and writes to it. Subsequent output commands append output to the file by adding {\tt >> <filename>} to the commands. You should close your file when done so you can open it with another program. This is very useful for saving your solutions (in a useful format with {\tt printf}), for example

brewery.run

\begin{verbatim}

>
>

Printing to a File

All the output commands can be directed to a file. Adding > <filename&gt to the end of an output command creates the file with the given name and writes to it. Subsequent output commands append output to the file by adding >> <filename> to the commands. You should close your file when done so you can open it with another program. This is very useful for saving your solutions (in a useful format with printf), for example


 # brewery.run reset;
Line: 72 to 79
  solve;
Changed:
<
<
print 'TRANSPORTATION SOLUTION -- Non-zero shipments' > brewery.out;
>
>
print 'TRANSPORTATION SOLUTION -- Non-zero shipments' > brewery.out;
  display TotalCost >> brewery.out;
Line: 82 to 88
  Flow[s, d], s, d >> brewery.out;

close brewery.out;

Changed:
<
<
\end{verbatim}

>
>
 
Changed:
<
<
Running {\tt brewery.run} in AMPL creates a file brewery.out.
>
>
Running brewery.run in AMPL creates a file brewery.out.
  -- MichaelOSullivan - 02 Mar 2008
Added:
>
>
  • display.jpg:
    display.jpg

  • omit.jpg:
    omit.jpg

  • display_1col.jpg:
    display_1col.jpg

  • print.jpg:
    print.jpg

  • printf.jpg:
    printf.jpg

  • printf_set.jpg:
    printf_set.jpg

 
META FILEATTACHMENT attachment="four_dp.jpg" attr="h" comment="" date="1204604433" name="four_dp.jpg" path="four_dp.jpg" size="35091" stream="four_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="five_dp.jpg" attr="h" comment="" date="1204604447" name="five_dp.jpg" path="five_dp.jpg" size="36558" stream="five_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="brewery.out" attr="" comment="" date="1204604566" name="brewery.out" path="brewery.out" size="374" stream="brewery.out" tmpFilename="" user="MichaelOSullivan" version="1"
>
>
META FILEATTACHMENT attachment="display.jpg" attr="h" comment="" date="1204605023" name="display.jpg" path="display.jpg" size="43546" stream="display.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="omit.jpg" attr="h" comment="" date="1204605041" name="omit.jpg" path="omit.jpg" size="20893" stream="omit.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="display_1col.jpg" attr="h" comment="" date="1204605073" name="display_1col.jpg" path="display_1col.jpg" size="23462" stream="display_1col.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="print.jpg" attr="h" comment="" date="1204605128" name="print.jpg" path="print.jpg" size="19738" stream="print.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="printf.jpg" attr="h" comment="" date="1204605145" name="printf.jpg" path="printf.jpg" size="49225" stream="printf.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="printf_set.jpg" attr="h" comment="" date="1204605157" name="printf_set.jpg" path="printf_set.jpg" size="54976" stream="printf_set.jpg" tmpFilename="" user="MichaelOSullivan" version="1"

Revision 42008-03-04 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
<-- Under Construction -->
Line: 17 to 17
 option display_precision 4; to get your solution values to the same number of significant digits.
Changed:
<
<
src="four_dp.jpg"
>
>
four_dp.jpg
  Note that AMPL still keeps its numbers at full precision, so you need to be careful with your objective function values.
Changed:
<
<
src="five_dp.jpg"
>
>
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.
Line: 82 to 84
 close brewery.out; \end{verbatim}

Changed:
<
<
Running {\tt brewery.run} in AMPL creates a file {\tt brewery.out}.

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}

>
>
Running {\tt brewery.run} in AMPL creates a file brewery.out.
  -- MichaelOSullivan - 02 Mar 2008
Deleted:
<
<
  • four_dp.jpg:
    four_dp.jpg

  • five_dp.jpg:
    five_dp.jpg
 
META FILEATTACHMENT attachment="four_dp.jpg" attr="h" comment="" date="1204604433" name="four_dp.jpg" path="four_dp.jpg" size="35091" stream="four_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="five_dp.jpg" attr="h" comment="" date="1204604447" name="five_dp.jpg" path="five_dp.jpg" size="36558" stream="five_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
Added:
>
>
META FILEATTACHMENT attachment="brewery.out" attr="" comment="" date="1204604566" name="brewery.out" path="brewery.out" size="374" stream="brewery.out" tmpFilename="" user="MichaelOSullivan" version="1"

Revision 32008-03-04 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
<-- Under Construction -->
Line: 9 to 9
 
  1. Printing Information
  2. Printing to a File
Changed:
<
<
How many decimal places?
>
>

How many decimal places?

 
Changed:
<
<
??? Up to here ??? When solving mathematical programming problems, the accuracy of your solutions should *never* be more than the accuracy of your data. You can set the precision that AMPL displays values via the {\tt display_precision} option. For example, if your inputs are specified to 4 significant digits, e.g., {\tt 0.013}, you can use

\begin{verbatim}

>
>
When solving mathematical programming problems, the accuracy of your solutions should never be more than the accuracy of your data. You can set the precision that AMPL displays values via the 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;
Changed:
<
<
\end{verbatim}

>
>
 to get your solution values to the same number of significant digits.
Changed:
<
<

>
>
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.
Changed:
<
<

>
>
src="five_dp.jpg"
 
Changed:
<
<
When we change the {\tt display_precision} to 5 significant digits, the displayed {\tt TotalCost} and the cost calculated by using the displayed {\tt Amount} values differ. If you are using rounded solution values, make sure to *check* the *objective value* before quoting your solution.
>
>
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 ???

 

Displaying Information

You have already seen how to display a variable using the {\tt display} command. We can also display {a href="Expressioins in AMPL">AMPL expressions the same way, e.g., we might want to see how supply we are using in a transportation problem.
Line: 97 to 97
 \end{verbatim}

-- MichaelOSullivan - 02 Mar 2008 \ No newline at end of file

Added:
>
>
  • four_dp.jpg:
    four_dp.jpg

  • five_dp.jpg:
    five_dp.jpg

META FILEATTACHMENT attachment="four_dp.jpg" attr="h" comment="" date="1204604433" name="four_dp.jpg" path="four_dp.jpg" size="35091" stream="four_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"
META FILEATTACHMENT attachment="five_dp.jpg" attr="h" comment="" date="1204604447" name="five_dp.jpg" path="five_dp.jpg" size="36558" stream="five_dp.jpg" tmpFilename="" user="MichaelOSullivan" version="1"

Revision 22008-03-02 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
Changed:
<
<

Displaying and Printing in AMPL

>
>
<-- Under Construction -->

Displaying and Printing in AMPL

  1. How many decimal places?
  2. Displaying Information
  3. Printing Information
  4. Printing to a File

How many decimal places?

??? Up to here ??? When solving mathematical programming problems, the accuracy of your solutions should *never* be more than the accuracy of your data. You can set the precision that AMPL displays values via the {\tt display_precision} option. For example, if your inputs are specified to 4 significant digits, e.g., {\tt 0.013}, you can use

\begin{verbatim} option display_precision 4; \end{verbatim}

to get your solution values to the same number of significant digits.

Note that AMPL still keeps its numbers at full precision, so you need to be careful with your objective function values.

When we change the {\tt display_precision} to 5 significant digits, the displayed {\tt TotalCost} and the cost calculated by using the displayed {\tt Amount} values differ. If you are using rounded solution values, make sure to *check* the *objective value* before quoting your solution.

Displaying Information

You have already seen how to display a variable using the {\tt display} command. We can also display {a href="Expressioins in AMPL">AMPL expressions the same way, e.g., we might want to see how supply we are using in a transportation problem.

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.

Printing Information

By playing with the {\tt display} options we can get the {\tt display} command to format output in a nice way. However, we can also decide exactly what is displayed by using {\tt print} and {\tt printf}. <p

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

Printing to a File

All the output commands can be directed to a file. Adding {\tt > <filename>} to the end of an output command creates the file with the given name and writes to it. Subsequent output commands append output to the file by adding {\tt >> <filename>} to the commands. You should close your file when done so you can open it with another program. This is very useful for saving your solutions (in a useful format with {\tt printf}), for example

brewery.run

\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}.

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 \ No newline at end of file

Revision 12008-03-02 - MichaelOSullivan

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="AMPLSyntax"

Displaying and Printing in AMPL

-- MichaelOSullivan - 02 Mar 2008

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback