Difference: ParametersInAMPL (9 vs. 10)

Revision 102018-07-29 - MichaelOSullivan

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

Defining 2-Dimensional Parameters

In a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional parameters.

Changed:
<
<
  1. Using a List For any parameter values that don't take the default value, you list the set element and value for that parameter.
    model; param Min {ARCS} integer, default 0; data; param Min := Youngstown 'Kansas City' 1000 Pittsburgh 'Kansas City' 2000 Cincinnati Albany 1000 
  2. Using a Table To define parameter data in a table format you use the param keyword and the parameter's name followed by the : operator, a list of the second index set elements followed by the := operator, then rows of the table with an element of the first index set followed by the values corresponding to the second index set's element in that column.
    param : ... := ... ... ... ; 
    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 ; 
    You can also define parameter data in a transposed table using almost the same syntax, but with the (tr) keyword and reversing the indexing sets
    param (tr) : ... := ... ... ... ; 
  3. Using an Array You define a list of column indices and values for each row index.
    param Cost := [Youngstown, *] Cincinnati 350 'Kansas City' 450 ... ... [Chicago, *] ... Gary 120 ; 
    Note The row indices have [=} and =] around them (as opposed to ( and ) for sets).
>
>
  1. Using a List For any parameter values that don't take the default value, you list the set element and value for that parameter.
model;
param Min {ARCS} integer, default 0;
data;
param Min :=
Youngstown 'Kansas City' 1000
Pittsburgh 'Kansas City' 2000
Cincinnati Albany 1000
  1. Using a Table To define parameter data in a table format you use the param keyword and the parameter's name followed by the : operator, a list of the second index set elements followed by the := operator, then rows of the table with an element of the first index set followed by the values corresponding to the second index set's element in that column.
param : ... := ... ... ... ;
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 ;
You can also define parameter data in a transposed table using almost the same syntax, but with the (tr) keyword and reversing the indexing sets
param (tr) : ... := ... ... ... ;
  1. Using an Array You define a list of column indices and values for each row index.
param Cost :=
[Youngstown, *] Cincinnati 350 'Kansas City' 450 ... ...
[Chicago, *] ... Gary 120 ;
Note The row indices have [=} and =] around them (as opposed to ( and ) for sets).
 

Defining Multi-Dimensional Parameters

Since 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:
<
<
  1. Using a List
    param Cost := Youngstown April Albany April 0.5 # = 500 / 1000 Youngstown April Youngstown May 0.015 # = 15 / 1000 ... ; 
  2. Using a Table
    param Cost := [*, May, *, May] Cincinnati 'Kansas City' Albany ... := Youngstown 0.35 0.45 0.5 ... Pittsburgh 0.35 0.45 . ... ... ; 
    Notice the [ ] around *, May, *, May as opposed to the ( ) for sets!
>
>
  1. Using a List
    param Cost :=
    Youngstown April Albany April 0.5 # = 500 / 1000
    Youngstown April Youngstown May 0.015 # = 15 / 1000 ... ;
    
  2. Using a Table
    param Cost :=
    [*, May, *, May] Cincinnati 'Kansas City' Albany ... :=
    Youngstown 0.35 0.45 0.5 ...
    Pittsburgh 0.35 0.45 . ... ... ;
Notice the [ ] around *, May, *, May as opposed to the ( ) for sets!
 
  1. Using an Array
    set TIME_ARCS := (*, May, *, May) (Youngstown, Cincinnati) 0.35 ... ; 
    or
    set TIME_ARCS := (Youngstown, May, *, May) Cincinnati 0.35 'Kansas City' 0.45 ... ... ; 

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:             ... :    ...    ...  ; 
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
 
From node To node Cost Minimum Maximum
Youngstown Albany 500 - 1000
Line: 119 to 177
 
etc

becomes

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
Line: 128 to 192
 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
 
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