In the OPTMODEL modeling language, parameters are named locations that hold constant values. Parameter declarations specify
the parameter type followed by a list of parameter names to declare. For example, the following statement declares numeric
parameters named a
and b
:
number a, b;
Similarly, the following statements declare a set s
of strings, a set n
of numbers, and a set sn
of tuples:
set<string> s; set<number> n; set<string, number> sn;
You can assign values to parameters in various ways. A parameter can be assigned a value with an assignment statement. For
example, the following statements assign values to the parameter s
, n
, and sn
in the preceding declaration:
s = {'a', 'b', 'c'}; n = {1, 2, 3}; sn = {<'a',1>, <'b',2>, <'c',3>};
Parameter values can also be assigned using a READ DATA statement (see the section READ DATA Statement).
A parameter declaration can provide an explicit value. To specify the value, follow the parameter name with an equal sign (=) and an expression. The value expression can be written in terms of other parameters. The declared parameter takes on a new value each time a parameter that is used in the expression changes. This automatic value update is shown in the following example:
proc optmodel; number pi=4*atan(1); number r; number circum=2*pi*r; r=1; put circum; /* prints 6.2831853072 */ r=2; put circum; /* prints 12.566370614 */
The automatic update of parameter values makes it easy to perform "what if" analysis since, after the solver finds a solution, you can change parameters and reinvoke the solver. You can easily examine the effects of the changes on the optimal values.
If you declare a set parameter that has only the SET type specifier, then the element type is determined from the initialization
expression. If the initialization expression is omitted or if the expression is an empty set, then the set type defaults to
SET<NUMBER>. For example, the following statement implicitly declares s1
as a set of numbers:
set s1;
The following statement declares s2
as a set of strings:
set s2 = {'A'};
You can declare an array parameter by following the parameter name with an index set specification (see the section Index Sets). For example, declare an array of 10 numbers as follows:
number c{1..10};
Individual locations of a parameter array can be referred to with an indexing expression. For example, you can refer to the
third location of parameter c
as c[3]
. Array index sets cannot be specified using a function such as RAND that returns a different value each time it is called.
Parameter names must be declared before they are used. Nonarray names become available at the end of the parameter declaration item. Array names become available after the index set specification. The latter case permits some forms of recursion in the optional initialization expression that can be supplied for a parameter.
You do not need to assign values to parameters before they are referenced. Most information in PROC OPTMODEL is stored symbolically and resolved when necessary. Values are resolved in certain statements. For example, PROC OPTMODEL resolves a parameter used in the objective during the execution of a SOLVE statement. If no value is available during resolution, then an error is diagnosed.