# NAG CL Interfacee04rjc (handle_​set_​linconstr)

## 1Purpose

e04rjc is a part of the NAG optimization modelling suite and defines the block of linear constraints of the problem.

## 2Specification

 #include
 void e04rjc (void *handle, Integer nclin, const double bl[], const double bu[], Integer nnzb, const Integer irowb[], const Integer icolb[], const double b[], Integer *idlc, NagError *fail)
The function may be called by the names: e04rjc or nag_opt_handle_set_linconstr.

## 3Description

After the initialization function e04rac has been called, e04rjc may be used to define the linear constraints ${l}_{B}\le Bx\le {u}_{B}$ of the problem unless the linear constraints have already been defined. This will typically be used for problems, such as linear programming (LP)
 $minimize x∈ℝn cTx (a) subject to lB≤Bx≤uB, (b) lx≤x≤ux , (c)$ (1)
 $minimize x∈ℝn 12 xTHx + cTx (a) subject to lB≤Bx≤uB, (b) lx≤x≤ux , (c)$ (2)
nonlinear programming (NLP)
 $minimize x∈ℝn fx (a) subject to lg≤gx≤ug, (b) lB≤Bx≤uB, (c) lx≤x≤ux, (d)$ (3)
or linear semidefinite programming (SDP)
 $minimize x∈ℝn cTx (a) subject to ∑ i=1 n xi Aik - A0k ⪰ 0 , k=1,…,mA , (b) lB≤Bx≤uB, (c) lx≤x≤ux, (d)$ (4)
where $n$ is the number of decision variables, $B$ is a general ${m}_{B}×n$ rectangular matrix and ${l}_{B}$ and ${u}_{B}$ are ${m}_{B}$-dimensional vectors. Note that upper and lower bounds are specified for all the constraints. This form allows full generality in specifying various types of constraint. In particular, the $j$th constraint may be defined as an equality by setting ${l}_{j}={u}_{j}$. If certain bounds are not present, the associated elements of ${l}_{B}$ or ${u}_{B}$ may be set to special values that are treated as $-\infty$ or $+\infty$. See the description of the optional parameter ${\mathbf{Infinite Bound Size}}$ which is common among all solvers in the suite. Its value is denoted as $\mathit{bigbnd}$ further in this text. Note that the bounds are interpreted based on its value at the time of calling this function and any later alterations to ${\mathbf{Infinite Bound Size}}$ will not affect these constraints.
See Section 4.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.

None.

## 5Arguments

1: $\mathbf{handle}$void * Input
On entry: the handle to the problem. It needs to be initialized by e04rac and must not be changed between calls to the NAG optimization modelling suite.
2: $\mathbf{nclin}$Integer Input
On entry: ${m}_{B}$, the number of linear constraints (number of rows of the matrix $B$).
If ${\mathbf{nclin}}=0$, no linear constraints will be defined and bl, bu, nnzb, irowb, icolb and b will not be referenced and may be NULL.
Constraint: ${\mathbf{nclin}}\ge 0$.
3: $\mathbf{bl}\left[{\mathbf{nclin}}\right]$const double Input
4: $\mathbf{bu}\left[{\mathbf{nclin}}\right]$const double Input
On entry: bl and bu define lower and upper bounds of the linear constraints, ${l}_{B}$ and ${u}_{B}$, respectively. To define the $j$th constraint as equality, set ${\mathbf{bl}}\left[j-1\right]={\mathbf{bu}}\left[j-1\right]=\beta$, where $\left|\beta \right|<\mathit{bigbnd}$. To specify a nonexistent lower bound (i.e., ${l}_{j}=-\infty$), set ${\mathbf{bl}}\left[j-1\right]\le -\mathit{bigbnd}$; to specify a nonexistent upper bound, set ${\mathbf{bu}}\left[j-1\right]\ge \mathit{bigbnd}$.
Constraints:
• ${\mathbf{bl}}\left[\mathit{j}-1\right]\le {\mathbf{bu}}\left[\mathit{j}-1\right]$, for $\mathit{j}=1,2,\dots ,{\mathbf{nclin}}$;
• ${\mathbf{bl}}\left[\mathit{j}-1\right]<\mathit{bigbnd}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nclin}}$;
• ${\mathbf{bu}}\left[\mathit{j}-1\right]>-\mathit{bigbnd}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nclin}}$;
• if ${\mathbf{bl}}\left[\mathit{j}-1\right]={\mathbf{bu}}\left[\mathit{j}-1\right]$, $\left|{\mathbf{bl}}\left[\mathit{j}-1\right]\right|<\mathit{bigbnd}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nclin}}$.
5: $\mathbf{nnzb}$Integer Input
On entry: nnzb gives the number of nonzeros in matrix $B$.
Constraint: if ${\mathbf{nclin}}>0$, ${\mathbf{nnzb}}>0$.
6: $\mathbf{irowb}\left[{\mathbf{nnzb}}\right]$const Integer Input
7: $\mathbf{icolb}\left[{\mathbf{nnzb}}\right]$const Integer Input
8: $\mathbf{b}\left[{\mathbf{nnzb}}\right]$const double Input
On entry: arrays irowb, icolb and b store nnzb nonzeros of the sparse matrix $B$ in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). The matrix $B$ has dimensions ${m}_{B}×n$, where $n$, the number of variables in the problem, was set in nvar during the initialization of the handle by e04rac. irowb specifies one-based row indices, icolb specifies one-based column indices and b specifies the values of the nonzero elements in such a way that ${b}_{ij}={\mathbf{b}}\left[l-1\right]$ where $i={\mathbf{irowb}}\left[l-1\right]$ and $j={\mathbf{icolb}}\left[\mathit{l}-1\right]$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzb}}$. No particular order of elements is expected, but elements should not repeat.
Constraint: $1\le {\mathbf{irowb}}\left[\mathit{l}-1\right]\le {\mathbf{nclin}}$, $1\le {\mathbf{icolb}}\left[\mathit{l}-1\right]\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzb}}$.
9: $\mathbf{idlc}$Integer * Input/Output
Note: idlc is reserved for future releases of the NAG Library.
On entry: if ${\mathbf{idlc}}=0$, new linear constraints are added to the problem definition. This is the only value allowed at the moment.
Constraint: ${\mathbf{idlc}}=0$.
On exit: the number of the last linear constraint added, thus nclin.
10: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
A set of linear constraints has already been defined.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_BOUND
On entry, $j=〈\mathit{\text{value}}〉$, ${\mathbf{bl}}\left[j-1\right]=〈\mathit{\text{value}}〉$, $\mathit{bigbnd}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{bl}}\left[j-1\right]<\mathit{bigbnd}$.
On entry, $j=〈\mathit{\text{value}}〉$, ${\mathbf{bl}}\left[j-1\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{bu}}\left[j-1\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{bl}}\left[j-1\right]\le {\mathbf{bu}}\left[j-1\right]$.
On entry, $j=〈\mathit{\text{value}}〉$, ${\mathbf{bu}}\left[j-1\right]=〈\mathit{\text{value}}〉$, $\mathit{bigbnd}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{bu}}\left[j-1\right]>-\mathit{bigbnd}$.
NE_HANDLE
The supplied handle does not define a valid handle to the data structure for the NAG optimization modelling suite. It has not been initialized by e04rac or it has been corrupted.
NE_INT
On entry, ${\mathbf{nclin}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nclin}}\ge 0$.
On entry, ${\mathbf{nnzb}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnzb}}>0$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_INVALID_CS
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{icolb}}\left[\mathit{i}-1\right]=〈\mathit{\text{value}}〉$ and $n=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{icolb}}\left[\mathit{i}-1\right]\le n$.
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{irowb}}\left[\mathit{i}-1\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{nclin}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{irowb}}\left[\mathit{i}-1\right]\le {\mathbf{nclin}}$.
On entry, more than one element of b has row index $〈\mathit{\text{value}}〉$ and column index $〈\mathit{\text{value}}〉$.
Constraint: each element of b must have a unique row and column index.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_PHASE
The problem cannot be modified in this phase any more, the solver has already been called.
NE_REF_MATCH
On entry, ${\mathbf{idlc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{idlc}}=0$.

Not applicable.

## 8Parallelism and Performance

e04rjc is not threaded in any implementation.

None.

## 10Example

This example demonstrates how to use the MPS file reader e04mxc and this suite of functions to define and solve a QP problem. e04mxc uses a different output format to the one required by e04rjc, in particular, it uses the compressed column storage (CCS) (see Section 2.1.3 in the F11 Chapter Introduction) instead of the coordinate storage and the linear objective vector is included in the system matrix. Therefore a simple transformation is needed before calling e04rjc as demonstrated in the example program.
The data file stores the following problem:
 $minimize cT x + 12 xT H x subject to lB ≤Bx ≤uB, -2 ≤Ax ≤2,$
where
 $c= -4.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.1 -0.3 , H= 2 1 1 1 1 0 0 0 0 1 2 1 1 1 0 0 0 0 1 1 2 1 1 0 0 0 0 1 1 1 2 1 0 0 0 0 1 1 1 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ,$
 $B= 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 4.0 1.0 2.0 3.0 4.0 -2.0 1.0 1.0 1.0 1.0 1.0 -1.0 1.0 -1.0 1.0 1.0 1.0 1.0 1.0 ,$
 $lB= -2.0 -2.0 -2.0 and uB= 1.5 1.5 4.0 .$
The optimal solution (to five figures) is
 $x*=2.0,-0.23333,-0.26667,-0.3,-0.1,2.0,2.0,-1.7777,-0.45555T.$