
| Line: 1 to 1 | |||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||
| Changed: | |||||||||||||||||||||||
| < < |
DescriptionParameters hold "hard" values in AMPL. The values of parameters can be defined and changed in AMPL, but once a solver will not change them while looking for an optimal solution. Declaring a ParameterAMPL parameters are created in a similar way to AMPL variables, using the {\tt param} keyword followed by a label. \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} | Parameters in AMPL | |||||||||||||||||||||
| Deleted: | |||||||||||||||||||||||
| < < | -- MichaelOSullivan - 02 Mar 2008 | ||||||||||||||||||||||
| \ No newline at end of file | |||||||||||||||||||||||
| Added: | |||||||||||||||||||||||
| > > |
DescriptionParameters hold "hard" values in AMPL. The values of parameters can be defined and changed in AMPL, but a solver will not change them while looking for an optimal solution. Return to topDeclaring a ParameterAMPL parameters are created in a similar way to AMPL variables, using theparam keyword followed by a label.
param <paramname>; Exampleparam MinProtein;Like variables parameters are often defined over a set and may have several attributes:
param <paramname> [{<indexname>}] [<attributes>];
Example
param ProteinPercent {INGREDIENTS} >= 0 <= 100;
Return to top
Parameter Types??? Up to here ??? Parameters have the same possible types asParameter BoundsAs well as using parameter types to check the validity of data, real and integer parameters can also have bounds set during their declaration. These bounds will be checked by AMPL any time the value of the parameter changes and, if they are violated, and error will be generated.Example\begin{verbatim} param counter integer >= 0; let counter := -1; # This generates an error as counter is < 0 \end{verbatim}
Default ValuesDefault parameter values can be used to quickly set a large number of parameter values automatically. If a parameter is used without being explicitly assigned a value the default value is used for that parameter. AMPL uses a default value of 0 if no default value is given.Example\begin{verbatim} set DIGITS := 1..5; param isok {DIGITS} binary default 1; let isok[3] := 0; display {i in DIGITS} isok[i]; # Result #==
# isok[i] [*] :=
# 1 1
# 2 1
# 3 0
# 4 1
# 5 1
# ;
\end{verbatim}The AMPL macros {\tt Infinity} and {\tt -Infinity} are useful as defaults for parameters that act as bounds ({\tt Infinity} as a default upper bound, 0 or {\tt -Infinity} as a default lower bound). Defining a ParameterOnce a parameter has been declared it is usually defined in a data file. This is done simply for a single value using the assignment operator {\tt :=}:\begin{verbatim} param MinProtein := 8.0 ; \end{verbatim} For parameters declared over a 1-dimensional set this can be done using default values and a list for those parameters that don't take default values: \begin{verbatim} model; param Min {REQUIREMENTS} default -Infinity; data; param Min := PROTEIN 8.0 FAT 6.0 ; \end{verbatim}In a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional sets.
Defining Multiple ParametersUsing the {\tt :} operator, multiple parameters may be defined at once. Simply state the names of the parameters and the {\tt :=} operator. Then list the set elements and values on the following rows.\begin{verbatim}
param:
If a parameter is not defined or the default value is sufficient, use the {\tt .} operator.
\begin{verbatim}
model;
This approach also works for 2-dimensional parameters and lists, for the American Steel problem this allows us to "cut-and-paste" the list of arc properties
\begin{verbatim}
From node To node Cost Minimum Maximum
Youngstown Albany 500 - 1000
Youngstown Cincinnati 350 - 3000
Youngstown Kansas City 450 1000 5000
Youngstown Chicago 375 - 5000
etc
\end{verbatim}
becomes
\begin{verbatim}
param: Cost Min Max:=
Youngstown Cincinnati 350 0 3000
Youngstown 'Kansas City' 450 1000 5000
...
Chicago Gary 120 0 4000
;
\end{verbatim}
\begin{verbatim}
# Objective: minimise the cost per (100g) can
minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Percentage[i];
\begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} \begin{verbatim} | ||||||||||||||||||||||