Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Parameters in AMPL | ||||||||
Line: 40 to 40 | ||||||||
Parameter Types | ||||||||
Changed: | ||||||||
< < | ??? Up to here ???
Parameters have the same possible types as > > | Parameters have the same possible types as variables. However, since parameter values are defined (not searched for), declaring a parameter type means that AMPL will ensure that the parameter is only ever assigned that type of data. For example, you cannot assign an integer parameter the value 1.5. This behaviour is very useful for automatically checking the validity of data files.
Return to top
Parameter Bounds | ||||||
Deleted: | ||||||||
< < | Parameter Bounds | |||||||
As 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. | ||||||||
Changed: | ||||||||
< < | Example\begin{verbatim} param counter integer >= 0; | |||||||
> > |
Exampleparam counter integer >= 0; | |||||||
let counter := -1; # This generates an error as counter is < 0 | ||||||||
Changed: | ||||||||
< < | \end{verbatim} | |||||||
> > | ||||||||
Changed: | ||||||||
< < | Default Values | |||||||
> > | Return to top
Default Values | |||||||
Default 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. | ||||||||
Changed: | ||||||||
< < | Example\begin{verbatim} | |||||||
> > |
Example | |||||||
set DIGITS := 1..5; param isok {DIGITS} binary default 1; | ||||||||
Line: 72 to 78 | ||||||||
# 4 1 # 5 1 # ; | ||||||||
Changed: | ||||||||
< < | \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). | |||||||
> > |
The AMPL macros Infinity and -Infinity are useful as defaults for parameters that act as bounds (Infinity as a default upper bound, 0 or -Infinity as a default lower bound).
Return to top | |||||||
Changed: | ||||||||
< < | Defining a Parameter | |||||||
> > | Defining a Parameter | |||||||
Once a parameter has been declared it is usually defined in a data file. This is done simply for a single value | ||||||||
Changed: | ||||||||
< < | using the assignment operator {\tt :=}:
\begin{verbatim} | |||||||
> > | using the assignment operator := :
| |||||||
param MinProtein := 8.0 ; | ||||||||
Changed: | ||||||||
< < | \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: | ||||||||
Changed: | ||||||||
< < | \begin{verbatim} | |||||||
> > | ||||||||
model; param Min {REQUIREMENTS} default -Infinity; | ||||||||
Line: 93 to 103 | ||||||||
PROTEIN 8.0 FAT 6.0 ; | ||||||||
Changed: | ||||||||
< < | \end{verbatim} In a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional sets.
| |||||||
> > |
Defining 2-Dimensional ParametersIn a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional sets.
| |||||||
model; param Min {ARCS} integer, default 0; | ||||||||
Line: 108 to 119 | ||||||||
Youngstown 'Kansas City' 1000 Pittsburgh 'Kansas City' 2000 Cincinnati Albany 1000 | ||||||||
Changed: | ||||||||
< < | \end{verbatim}
\begin{verbatim}
param | |||||||
> > |
| |||||||
... | ||||||||
Changed: | ||||||||
< < | ||||||||
> > | <im> <value(im, j1)> <value(im, j2)> ... <value(im, jn)> | |||||||
; | ||||||||
Changed: | ||||||||
< < | \end{verbatim} If the element does not exist or the default value is correct then place a {\tt .} in the table. Otherwise, put the parameter value. \begin{verbatim} | |||||||
> > | If the element does not exist or the default value is correct then place a . in the table. Otherwise, put the parameter value. | |||||||
param Cost: Cincinnati 'Kansas City' Chicago Albany Houston Tempe Gary := Youngstown 350 450 375 500 . . . Pittsburgh 350 450 400 . . . 450 Cincinnati . . . 350 550 . . 'Kansas City' . . . . 375 650 . Chicago . . . . . 600 120 ; | ||||||||
Changed: | ||||||||
< < | \end{verbatim} You can also define parameter data in a transposed table using almost the same syntax, but with the {\tt (tr)} keyword and reversing the indexing sets \begin{verbatim}
param | |||||||
> > | You can also define parameter data in a transposed table using almost the same syntax, but with the (tr) keyword and reversing the indexing setsparam <paramname> (tr) : <i1> <i2> ... <im> := <j1> <value(i1, j1)> <value(i2, j1)> ... <value(im, j1)> | |||||||
... | ||||||||
Changed: | ||||||||
< < | ||||||||
> > | <jn> <value(i1, jn)> <value(i2, jn)> ... <value(im, jn)> | |||||||
; | ||||||||
Changed: | ||||||||
< < | \end{verbatim}
\begin{verbatim} | |||||||
> > |
| |||||||
param Cost := | ||||||||
Changed: | ||||||||
< < | [Youngstown, *] Cincinnati 350 'Kansas City' 450 ... | |||||||
> > | [Youngstown, *] Cincinnati 350 'Kansas City' 450 ... | |||||||
... | ||||||||
Changed: | ||||||||
< < | [Chicago, *] ... Gary 120 ;
\end{verbatim} *Note* The row indices have {\tt [} and {\tt ]} around them (as opposed to {\tt (} and {\tt )} for sets). | |||||||
> > | [Chicago, *] ... Gary 120 ;
Note The row indices have [=} and =] around them (as opposed to ( and ) for sets).
Defining Multi-Dimensional ParametersSince we have multi-dimensional sets, we might need multi-dimensional parameters, e.g.,Cost {TIME_ARCS} has four dimensions. We can define these parameters in a similar way to multi-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. | ||||||||
Line: 207 to 233 | ||||||||
Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Percentage[i] <= Max[r]; \end{verbatim} | ||||||||
Deleted: | ||||||||
< < |
Under Construction Below HereMulti-dimensional ParametersSince we have been using multi-dimensional sets, we might need multi-dimensional parameters, e.g., {\tt Cost {TIME_ARCS}}. We can define these parameters in a similar way toView topic | History: r10 < r9 < r8 < r7 | More topic actions... ![]() ![]() Ideas, requests, problems regarding TWiki? Send feedback |