Line: 1 to 1 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
<-- Ready to Review --> | |||||||||||
Line: 20 to 20 | |||||||||||
Declaring a ParameterAMPL parameters are created in a similar way to AMPL variables, using theparam keyword followed by a label. | |||||||||||
Changed: | |||||||||||
< < | param <paramname>; | ||||||||||
> > | param | ||||||||||
Example | |||||||||||
Changed: | |||||||||||
< < | param MinProtein;Like variables parameters are often defined over a set and may have several attributes: param <paramname> [{<indexname>}] [<attributes>]; | ||||||||||
> > | param MinProtein;Like variables parameters are often defined over a set and may have several attributes: param | ||||||||||
Example | |||||||||||
Changed: | |||||||||||
< < | param ProteinPercent {INGREDIENTS} >= 0 <= 100; | ||||||||||
> > | param ProteinPercent {INGREDIENTS} >= 0 <= 100; | ||||||||||
Return to top | |||||||||||
Line: 48 to 38 | |||||||||||
Parameter Bounds | |||||||||||
Changed: | |||||||||||
< < | 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. | ||||||||||
> > | 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, an error will be generated. | ||||||||||
Example | |||||||||||
Changed: | |||||||||||
< < | param counter integer >= 0; let counter := -1; # This generates an error as counter is < 0 | ||||||||||
> > | param counter integer >= 0; let counter := -1; # This generates an error as counter is < 0 | ||||||||||
Return to top | |||||||||||
Line: 63 to 49 | |||||||||||
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.
Example | |||||||||||
Changed: | |||||||||||
< < | 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 # ; | ||||||||||
> > | 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 # ; | ||||||||||
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
Defining a Parameter | |||||||||||
Changed: | |||||||||||
< < | Once 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 := :
param MinProtein := 8.0 ; | ||||||||||
> > | Once 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 := : param MinProtein := 8.0 ; | ||||||||||
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: | |||||||||||
< < | model; param Min {REQUIREMENTS} default -Infinity; data; param Min := PROTEIN 8.0 FAT 6.0 ; | ||||||||||
> > | model; param Min {REQUIREMENTS} default -Infinity; data; param Min := PROTEIN 8.0 FAT 6.0 ; | ||||||||||
Defining 2-Dimensional ParametersIn a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional sets. | |||||||||||
Changed: | |||||||||||
< < |
| ||||||||||
> > |
| ||||||||||
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: | |||||||||||
Changed: | |||||||||||
< < |
| ||||||||||
> > |
| ||||||||||
Defining Multiple Parameters | |||||||||||
Changed: | |||||||||||
< < | Using the : operator, multiple parameters may be defined at once. Simply state the names of the parameters and the := operator. Then list the set elements and values on the following rows.
param: <name1> <name2> ... : <element1> <value1,1> <value1,2> ... <element2> <value2,1> <value2,2> ... ;If a parameter is not defined or the default value is sufficient, use the . operator.
model; # The lower and upper bounds on the requirements param Min {REQUIREMENTS} default -Infinity; param Max {REQUIREMENTS} default Infinity; data; param: Min Max:= PROTEIN 8.0 . FAT 6.0 . FIBRE . 2.0 SALT . 0.4 ;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 | ||||||||||
> > | Using the : operator, multiple parameters may be defined at once. Simply state the names of the parameters and the := operator. Then list the set elements and values on the following rows. param:If a parameter is not defined or the default value is sufficient, use the . operator. model; # The lower and upper bounds on the requirements param Min {REQUIREMENTS} default -Infinity; param Max {REQUIREMENTS} default Infinity; data; param: Min Max:= PROTEIN 8.0 . FAT 6.0 . FIBRE . 2.0 SALT . 0.4 ;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 | ||||||||||
| |||||||||||
Line: 210 to 85 | |||||||||||
| |||||||||||
Changed: | |||||||||||
< < | param: Cost Min Max:= Youngstown Cincinnati 350 0 3000 Youngstown 'Kansas City' 450 1000 5000 ... Chicago Gary 120 0 4000 ; | ||||||||||
> > | param: Cost Min Max:= Youngstown Cincinnati 350 0 3000 Youngstown 'Kansas City' 450 1000 5000 ... Chicago Gary 120 0 4000 ; | ||||||||||
Return to top
Accessing a Parameter | |||||||||||
Changed: | |||||||||||
< < | Parameter values are accessed by specifying the indices of the parameter you want to access within [ and ] . | ||||||||||
> > | Parameter values are accessed by specifying the indices of the parameter you want to access within [ and ] . | ||||||||||
Examples | |||||||||||
Changed: | |||||||||||
< < | See Cost and Contributes below.
# Objective: minimise the cost per (100g) can minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Amount[i]; # Constraints: Meet the nutritional requirements subject to MeetRequirement {r in REQUIREMENTS}: Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Amount[i] <= Max[r]; | ||||||||||
> > | See Cost and Contributes below. # Objective: minimise the cost per (100g) can minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Amount[i]; # Constraints: Meet the nutritional requirements subject to MeetRequirement {r in REQUIREMENTS}: Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Amount[i] <= Max[r]; | ||||||||||
Return to top |