Difference: ParametersInAMPL (1 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

Revision 92014-10-01 - MichaelOSullivan

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

Declaring a Parameter

AMPL parameters are created in a similar way to AMPL variables, using the param keyword followed by a label.

Changed:
<
<
param ; 
>
>
param <my param name>; 
 

Example

Changed:
<
<
param MinProtein; 
Like variables parameters are often defined over a set and may have several attributes:
param  [{}] []; 
>
>
param MinProtein; 

Like variables parameters are often defined over a set and may have several attributes:

param  <my param name>[{<(optional) indexing set>}] [<(optional) bounds, default values>]; 
 

Example

Changed:
<
<
param ProteinPercent {INGREDIENTS} >= 0 <= 100; 
>
>
param ProteinPercent {INGREDIENTS} >= 0 <= 100; 
  Return to top
Line: 41 to 45
 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: 49 to 56
  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 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 
  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).
 

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!
  3. 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 ... ... ; 
>
>
  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!
  3. 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: 85 to 119
 
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: 94 to 128
 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

Revision 82009-09-07 - CameronWalker

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

Declaring a Parameter

AMPL parameters are created in a similar way to AMPL variables, using the param keyword followed by a label.

Changed:
<
<
param ; 
>
>
param ; 
 

Example

Changed:
<
<
param MinProtein; 
Like variables parameters are often defined over a set and may have several attributes:
param  [{}] []; 
>
>
param MinProtein; 
Like variables parameters are often defined over a set and may have several attributes:
param  [{}] []; 
 

Example

param ProteinPercent {INGREDIENTS} >= 0 <= 100; 
Line: 49 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).
Line: 63 to 63
 

Defining 2-Dimensional Parameters

Changed:
<
<
In a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional sets.
>
>
In a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional parameters.
 
  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 
Changed:
<
<
  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 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

Line: 75 to 75
 
  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

Revision 72009-07-22 - CameronWalker

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

Declaring a Parameter

AMPL parameters are created in a similar way to AMPL variables, using the param 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 Parameters

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

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 <paramname> :
          <j1>            <j2>            ... <jn> :=
    <i1>  <value(i1, j1)> <value(i1, j2)> ... <value(i1, jn)>
    ...
    <im>  <value(im, j1)> <value(im, j2)> ... <value(im, jn)>
     ;
    
    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 <paramname> (tr) :
          <i1>            <i2>            ... <im> :=
    <j1>  <value(i1, j1)> <value(i2, j1)> ... <value(im, j1)>
    ...
    <jn>  <value(i1, jn)> <value(i2, jn)> ... <value(im, jn)>
     ;
    
  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 
  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).
 

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!
  3. 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 ...
    ... ;
    
>
>
  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!
  3. 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:     <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
 
From node To node Cost Minimum Maximum
Youngstown Albany 500 - 1000
Line: 210 to 85
 
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

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

Revision 62008-04-02 - MichaelOSullivan

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

Revision 52008-03-02 - MichaelOSullivan

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

Parameters in AMPL

  1. Description

Revision 42008-03-02 - MichaelOSullivan

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

Parameters in AMPL

Line: 8 to 8
 
  1. Parameter Bounds
  2. Default Values
  3. Defining a Parameter
Changed:
<
<
  1. Accessing a Parameter
>
>
  1. Accessing a Parameter
 

Description

Parameters 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.
Line: 174 to 174
 ... ;
Changed:
<
<
??? Up to here ???

Defining Multiple Parameters

Using 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: ... : <value1,1> <value1,2> ... <value2,1> <value2,2> ... ; \end{verbatim}

If a parameter is not defined or the default value is sufficient, use the {\tt .} operator.

\begin{verbatim}

>
>

Defining Multiple Parameters

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

Line: 199 to 197
 FIBRE . 2.0 SALT . 0.4 ;
Changed:
<
<
\end{verbatim}

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}

>
>
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
Youngstown Cincinnati 350 - 3000
Youngstown Kansas City 450 1000 5000
Youngstown Chicago 375 - 5000
etc
 becomes
Changed:
<
<

\begin{verbatim}

>
>

 param: Cost Min Max:= Youngstown Cincinnati 350 0 3000 Youngstown 'Kansas City' 450 1000 5000 ... Chicago Gary 120 0 4000 ;
Changed:
<
<
\end{verbatim}

>
>
 
Changed:
<
<

Accessing a Parameter

Parameter values are accessed by specifying the indices of the parameter you want to access within {\tt [} and {\tt ]}.

Examples

See {\tt Cost} and {\tt Contributes} below.

\begin{verbatim}

>
>
Return to top

Accessing a Parameter

Parameter values are accessed by specifying the indices of the parameter you want to access within [ and ].

Examples

See Cost and Contributes below.

 # Objective: minimise the cost per (100g) can
Changed:
<
<
minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Percentage[i];
>
>
minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Amount[i];
  # Constraints: Meet the nutritional requirements

subject to MeetRequirement {r in REQUIREMENTS}:

Changed:
<
<
Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Percentage[i] <= Max[r]; \end{verbatim}

>
>
Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Amount[i] <= Max[r];

Return to top

-- MichaelOSullivan - 02 Mar 2008

Revision 32008-03-02 - MichaelOSullivan

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

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;

>
>

Example

param 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.

  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.

    \begin{verbatim}

>
>

Defining 2-Dimensional Parameters

In a similar way to 2-dimensional sets, there are three different ways to define 2-dimensional 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;

Line: 108 to 119
 Youngstown 'Kansas City' 1000 Pittsburgh 'Kansas City' 2000 Cincinnati Albany 1000
Changed:
<
<
\end{verbatim}

  • **Using a Table** To define parameter data in a table format you use the {\tt param} keyword and the parameter’s name followed by the {\tt :} operator, a list of the second index set elements followed by the {\tt := } 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.

    \begin{verbatim} param : ... := <value(i1, j1)> <value(i1, j2)> ... <value(i1, jn)>

  • >
    >
    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 <paramname> :
            <j1>            <j2>            ... <jn> :=
      <i1>  <value(i1, j1)> <value(i1, j2)> ... <value(i1, jn)>
      
      
     ...
    Changed:
    <
    <
    <value(im, j1)> <value(im, j2)> ... <value(im, jn)>
    >
    >
    <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 (tr) : ... := <value(i1, j1)> <value(i2, j1)> ... <value(im, j1)>

    >
    >
    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 <paramname> (tr) :
          <i1>            <i2>            ... <im> :=
    <j1>  <value(i1, j1)> <value(i2, j1)> ... <value(im, j1)>
    
    
     ...
    Changed:
    <
    <
    <value(i1, jn)> <value(i2, jn)> ... <value(im, jn)>
    >
    >
    <jn> <value(i1, jn)> <value(i2, jn)> ... <value(im, jn)>
      ;
    Changed:
    <
    <
    \end{verbatim}

  • **Using an Array** You define a list of column indices and values for each row index.

    \begin{verbatim}

  • >
    >
    1. Using an Array You define a list of column indices and values for each row index.
      
      
     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 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:
    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!
    3. 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 ...
      ... ;
      

    ??? Up to here ???

     

    Defining Multiple Parameters

    Using 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 Here

    Multi-dimensional Parameters

    Since 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 to

    Revision 22008-03-02 - MichaelOSullivan

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

    1. Description
    2. Declaring a Parameter
    3. Parameter Types
    4. Parameter Bounds
    5. Default Values
    6. Defining a Parameter
    7. Accessing a Parameter


    Description


    Parameters 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 Parameter


    AMPL parameters are created in a similar way to AMPL variables, using the {\tt param} keyword followed by a label.

    \begin{verbatim}
    param ;
    \end{verbatim}


    Example


    \begin{verbatim}
    param MinProtein;
    \end{verbatim}


    Like variables parameters are often defined over a set and may have several attributes:

    \begin{verbatim}
    param [{}] [];
    \end{verbatim}


    Example


    \begin{verbatim}
    param ProteinPercent {INGREDIENTS} >= 0 <= 100;
    \end{verbatim}



    Parameter Types


    Parameters have the same possible types as

    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.

    Example


    \begin{verbatim}
    param counter integer >= 0;

    let counter := -1; # This generates an error as counter is < 0
    \end{verbatim}



    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.

    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 Parameter


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


    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.

      \begin{verbatim}
      model;

      param Min {ARCS} integer, default 0;

      data;

      param Min :=
      Youngstown 'Kansas City' 1000
      Pittsburgh 'Kansas City' 2000
      Cincinnati Albany 1000
      \end{verbatim}




    2. **Using a Table** To define parameter data in a table format you use the {\tt param} keyword and the parameter’s name followed by the {\tt :} operator, a list of the second index set elements followed by the {\tt := } 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.

      \begin{verbatim}
      param :
      ... :=
      <value(i1, j1)> <value(i1, j2)> ... <value(i1, jn)>
      ...
      <value(im, j1)> <value(im, j2)> ... <value(im, jn)>
      ;
      \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}
      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 ;
      \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 (tr) :
      ... :=
      <value(i1, j1)> <value(i2, j1)> ... <value(im, j1)>
      ...
      <value(i1, jn)> <value(i2, jn)> ... <value(im, jn)>
      ;
      \end{verbatim}



    3. **Using an Array** You define a list of column indices and values for each row index.

      \begin{verbatim}
      param Cost :=
      [Youngstown, ] Cincinnati 350 'Kansas City' 450 ...
      ...
      [Chicago, *] ... Gary 120 ;
      \end{verbatim}


      **Note*
      The row indices have {\tt [} and {\tt ]} around them (as opposed to {\tt (} and {\tt )} for sets).



    Defining Multiple Parameters


    Using 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: ... :
    <value1,1> <value1,2> ...
    <value2,1> <value2,2> ...
    ;
    \end{verbatim}


    If a parameter is not defined or the default value is sufficient, use the {\tt .} operator.

    \begin{verbatim}
    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
    ;
    \end{verbatim}


    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}



    Accessing a Parameter


    Parameter values are accessed by specifying the indices of the parameter you want to access within {\tt [} and {\tt ]}.

    Examples


    See {\tt Cost} and {\tt Contributes} below.

    \begin{verbatim}
    # Objective: minimise the cost per (100g) can
    minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Percentage[i];

    # Constraints: Meet the nutritional requirements

    subject to MeetRequirement {r in REQUIREMENTS}:
    Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Percentage[i]
    <= Max[r];
    \end{verbatim}



    Under Construction Below Here


    Multi-dimensional Parameters


    Since 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 to >
    >

    Parameters in AMPL

     
    Deleted:
    <
    <
    -- MichaelOSullivan - 02 Mar 2008
     \ No newline at end of file
    Added:
    >
    >
    1. Description
    2. Declaring a Parameter
    3. Parameter Types
    4. Parameter Bounds
    5. Default Values
    6. Defining a Parameter
    7. Accessing a Parameter

    Description

    Parameters 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 top

    Declaring a Parameter

    AMPL parameters are created in a similar way to AMPL variables, using the param keyword followed by a label.

    param <paramname>;
    

    Example

    param 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 as

    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.

    Example

    \begin{verbatim} param counter integer >= 0;

    let counter := -1; # This generates an error as counter is < 0 \end{verbatim}

    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.

    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 Parameter

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

    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.

      \begin{verbatim} model;

      param Min {ARCS} integer, default 0;

      data;

      param Min := Youngstown 'Kansas City' 1000 Pittsburgh 'Kansas City' 2000 Cincinnati Albany 1000 \end{verbatim}

    2. **Using a Table** To define parameter data in a table format you use the {\tt param} keyword and the parameter’s name followed by the {\tt :} operator, a list of the second index set elements followed by the {\tt := } 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.

      \begin{verbatim} param : ... := <value(i1, j1)> <value(i1, j2)> ... <value(i1, jn)> ... <value(im, j1)> <value(im, j2)> ... <value(im, jn)> ; \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} 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 ; \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 (tr) : ... := <value(i1, j1)> <value(i2, j1)> ... <value(im, j1)> ... <value(i1, jn)> <value(i2, jn)> ... <value(im, jn)> ; \end{verbatim}

    3. **Using an Array** You define a list of column indices and values for each row index.

      \begin{verbatim} param Cost := [Youngstown, *] Cincinnati 350 'Kansas City' 450 ... ... [Chicago, *] ... Gary 120 ; \end{verbatim}

      *Note* The row indices have {\tt [} and {\tt ]} around them (as opposed to {\tt (} and {\tt )} for sets).

    Defining Multiple Parameters

    Using 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: ... : <value1,1> <value1,2> ... <value2,1> <value2,2> ... ; \end{verbatim}

    If a parameter is not defined or the default value is sufficient, use the {\tt .} operator.

    \begin{verbatim} 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 ; \end{verbatim}

    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}

    Accessing a Parameter

    Parameter values are accessed by specifying the indices of the parameter you want to access within {\tt [} and {\tt ]}.

    Examples

    See {\tt Cost} and {\tt Contributes} below.

    \begin{verbatim} # Objective: minimise the cost per (100g) can minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Percentage[i];

    # Constraints: Meet the nutritional requirements

    subject to MeetRequirement {r in REQUIREMENTS}: Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Percentage[i] <= Max[r]; \end{verbatim}

    Under Construction Below Here

    Multi-dimensional Parameters

    Since 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 to

    Revision 12008-03-02 - MichaelOSullivan

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

    1. Description
    2. Declaring a Parameter
    3. Parameter Types
    4. Parameter Bounds
    5. Default Values
    6. Defining a Parameter
    7. Accessing a Parameter


    Description


    Parameters 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 Parameter


    AMPL parameters are created in a similar way to AMPL variables, using the {\tt param} keyword followed by a label.

    \begin{verbatim}
    param ;
    \end{verbatim}


    Example


    \begin{verbatim}
    param MinProtein;
    \end{verbatim}


    Like variables parameters are often defined over a set and may have several attributes:

    \begin{verbatim}
    param [{}] [];
    \end{verbatim}


    Example


    \begin{verbatim}
    param ProteinPercent {INGREDIENTS} >= 0 <= 100;
    \end{verbatim}



    Parameter Types


    Parameters have the same possible types as

    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.

    Example


    \begin{verbatim}
    param counter integer >= 0;

    let counter := -1; # This generates an error as counter is < 0
    \end{verbatim}



    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.

    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 Parameter


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


    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.

      \begin{verbatim}
      model;

      param Min {ARCS} integer, default 0;

      data;

      param Min :=
      Youngstown 'Kansas City' 1000
      Pittsburgh 'Kansas City' 2000
      Cincinnati Albany 1000
      \end{verbatim}




    2. **Using a Table** To define parameter data in a table format you use the {\tt param} keyword and the parameter’s name followed by the {\tt :} operator, a list of the second index set elements followed by the {\tt := } 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.

      \begin{verbatim}
      param :
      ... :=
      <value(i1, j1)> <value(i1, j2)> ... <value(i1, jn)>
      ...
      <value(im, j1)> <value(im, j2)> ... <value(im, jn)>
      ;
      \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}
      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 ;
      \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 (tr) :
      ... :=
      <value(i1, j1)> <value(i2, j1)> ... <value(im, j1)>
      ...
      <value(i1, jn)> <value(i2, jn)> ... <value(im, jn)>
      ;
      \end{verbatim}



    3. **Using an Array** You define a list of column indices and values for each row index.

      \begin{verbatim}
      param Cost :=
      [Youngstown, ] Cincinnati 350 'Kansas City' 450 ...
      ...
      [Chicago, *] ... Gary 120 ;
      \end{verbatim}


      **Note*
      The row indices have {\tt [} and {\tt ]} around them (as opposed to {\tt (} and {\tt )} for sets).



    Defining Multiple Parameters


    Using 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: ... :
    <value1,1> <value1,2> ...
    <value2,1> <value2,2> ...
    ;
    \end{verbatim}


    If a parameter is not defined or the default value is sufficient, use the {\tt .} operator.

    \begin{verbatim}
    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
    ;
    \end{verbatim}


    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}



    Accessing a Parameter


    Parameter values are accessed by specifying the indices of the parameter you want to access within {\tt [} and {\tt ]}.

    Examples


    See {\tt Cost} and {\tt Contributes} below.

    \begin{verbatim}
    # Objective: minimise the cost per (100g) can
    minimize TotalCost: sum {i in INGREDIENTS} Cost[i] * Percentage[i];

    # Constraints: Meet the nutritional requirements

    subject to MeetRequirement {r in REQUIREMENTS}:
    Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Percentage[i]
    <= Max[r];
    \end{verbatim}



    Under Construction Below Here


    Multi-dimensional Parameters


    Since 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 to 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