### 4.4 Constraint statement

  subject to name alias domain : expression , = expression ;  subject to name alias domain : expression , <= expression ;  subject to name alias domain : expression , >= expression ;  subject to name alias domain : expression , <= expression , <= expression ;  subject to name alias domain : expression , >= expression , >= expression ;
Where:

name is the symbolic name of the constraint;

alias is an optional string literal which specifies the alias of the constraint;

domain is an optional indexing expression which specifies the subscript domain of the constraint;

expressions are linear expressions for computing components of the constraint. (Commae following expressions may be omitted.)

Note:

The keyword subject to may be reduced to subj to, or to s.t., or be omitted at all.

Examples

s.t. r: x + y + z, >= 0, <= 1;
limit{t in 1..T}: sum{j in prd} make[j,t] <= max_prd;
subject to balance{i in raw, t in 1..T}:
store[i,t+1] - store[i,t] - sum{j in prd} units[i,j] * make[j,t];
subject to rlim 'regular-time limit' {t in time}:
sum{p in prd} pt[p] * rprd[p,t] <= 1.3 * dpp[t] * crews[t];


The constraint statement declares a constraint. If the subscript domain is not specified, the constraint is a simple (scalar) constraint, otherwise it is a n-dimensional array of elemental constraints.

Elemental constraint(s) associated with the model constraint (if it is a simple constraint) or its members (if it is an array) correspond to the linear constraints in the LP/MIP problem formulation (see Section “Linear programming problem”).

If the constraint has the form of equality or single inequality, i.e. includes two expressions, one of which follows the colon and other follows the relation sign =, <=, or >=, both expressions in the statement can be linear expressions. If the constraint has the form of double inequality, i.e. includes three expressions, the middle expression can be a linear expression while the leftmost and rightmost ones can be only numeric expressions.

Generating the model is, generally speaking, generating its constraints, which are always evaluated for the entire subscript domain. Evaluating constraints leads, in turn, to evaluating other model objects such as sets, parameters, and variables.

Constructing the actual linear constraint included in the problem instantce, which (constraint) corresponds to a particular elemental constraint, is performed as follows.

If the constraint has the form of equality or single inequality, evaluation of both linear expressions gives two resultant linear forms: $$\matrix{ f=a_1x_1+a_2x_2+\dots+a_nx_n+a_0,\cr g=b_1x_1+b_2x_2+\dots+b_nx_n+b_0,\cr }$$ where $x_1, x_2, \dots, x_n$ are elemental variables, $a_1, a_2, \dots, a_n, b_1, b_2$, $\dots, b_n$ are numeric coefficients, $a_0$ and $b_0$ are constant terms. Then all linear terms of f and g are carried to the left-hand side, and the constant terms are carried to the right-hand side that gives the final elemental constraint in the standard form: $$(a_1-b_1)x_1+(a_2-b_2)x_2+\dots+(a_n-b_n)x_n \left\{ \matrix{=\cr\leq\cr\geq\cr}\right\}b_0-a_0.$$

If the constraint has the form of double inequality, evaluation of the middle linear expression gives the resultant linear form: $$f=a_1x_1+a_2x_2+\dots+a_nx_n+a_0,$$ and evaluation of the leftmost and rightmost numeric expressions gives two numeric values l and u. Then the constant term of the linear form is carried to both left-hand and right-hand sides that gives the final elemental constraint in the standard form: $$l-a_0\leq a_1x_1+a_2x_2+\dots+a_nx_n\leq u-a_0.$$