# NAG FL Interfacee04rjf (handle_​set_​linconstr)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

e04rjf is a part of the NAG optimization modelling suite and adds a new block of linear constraints to the problem or modifies an individual linear constraint.

## 2Specification

Fortran Interface
 Subroutine e04rjf ( bl, bu, nnzb, b, idlc,
 Integer, Intent (In) :: nclin, nnzb, irowb(nnzb), icolb(nnzb) Integer, Intent (Inout) :: idlc, ifail Real (Kind=nag_wp), Intent (In) :: bl(nclin), bu(nclin), b(nnzb) Type (c_ptr), Intent (In) :: handle
#include <nag.h>
 void e04rjf_ (void **handle, const Integer *nclin, const double bl[], const double bu[], const Integer *nnzb, const Integer irowb[], const Integer icolb[], const double b[], Integer *idlc, Integer *ifail)
The routine may be called by the names e04rjf or nagf_opt_handle_set_linconstr.

## 3Description

After the handle has been initialized (e.g., e04raf has been called), e04rjf may be used to add to the problem a new block of ${m}_{B}$ linear constraints
 $lB≤Bx≤uB$
where $B$ is a general ${m}_{B}×n$ rectangular matrix, $n$ is the current number of decision variables in the model and ${l}_{B}$ and ${u}_{B}$ are ${m}_{B}$-dimensional vectors defining the lower and upper bounds, respectively. The call can be repeated to add multiple blocks to the model.
Note that the bounds are specified for all the constraints of this block. 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 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 routine and any later alterations to Infinite Bound Size will not affect these constraints.
The linear constraints can be edited. To identify the individual constraints, they are numbered starting with $1$, see idlc. A single constraint (i.e., a single row of the matrix $B$) can be modified (replaced) by e04rjf by referring to its idlc. An individual coefficient ${b}_{\mathrm{ij}}$ of the matrix $B$ can be set or modified by e04tjf and bounds of a single constraint can be set or modified by e04tdf. Note that it is also possible to temporarily disable and enable individual constraints in the model by e04tcf and e04tbf, respectively.
Linear constraints may be present in many different types of problems, for simplicity of the notation, only one block of linear constraints is presented. For example,
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)
 $minimize x∈ℝn 12 xTHx + cTx (a) subject to 12 xTQkx + rkTx + sk≤0 , k=1,…,mQ , (b) lB≤Bx≤uB, (c) lx≤x≤ux , (d)$ (3)
Nonlinear Programming (NLP)
 $minimize x∈ℝn f(x) (a) subject to lg≤g(x)≤ug, (b) 12 xTQkx + rkTx + sk≤0 , k=1,…,mQ , (c) lB≤Bx≤uB, (d) lx≤x≤ux, (e)$ (4)
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)$ (5)
See Section 3.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.

None.

## 5Arguments

1: $\mathbf{handle}$Type (c_ptr) Input
On entry: the handle to the problem. It needs to be initialized (e.g., by e04raf) 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$) in this block.
If ${\mathbf{nclin}}=0$, no linear constraints will be added and bl, bu, nnzb, irowb, icolb and b will not be referenced.
Constraints:
• ${\mathbf{nclin}}\ge 0$;
• if ${\mathbf{idlc}}>0$, ${\mathbf{nclin}}=1$.
3: $\mathbf{bl}\left({\mathbf{nclin}}\right)$Real (Kind=nag_wp) array Input
4: $\mathbf{bu}\left({\mathbf{nclin}}\right)$Real (Kind=nag_wp) array 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\right)={\mathbf{bu}}\left(j\right)=\beta$, where $|\beta |<\mathit{bigbnd}$. To specify a nonexistent lower bound (i.e., ${l}_{j}=-\infty$), set ${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$; to specify a nonexistent upper bound, set ${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$.
Constraints:
• ${\mathbf{bl}}\left(\mathit{j}\right)\le {\mathbf{bu}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,{\mathbf{nclin}}$;
• ${\mathbf{bl}}\left(\mathit{j}\right)<\mathit{bigbnd}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nclin}}$;
• ${\mathbf{bu}}\left(\mathit{j}\right)>-\mathit{bigbnd}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nclin}}$;
• if ${\mathbf{bl}}\left(\mathit{j}\right)={\mathbf{bu}}\left(\mathit{j}\right)$, $|{\mathbf{bl}}\left(\mathit{j}\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: ${\mathbf{nnzb}}\ge 0$.
6: $\mathbf{irowb}\left({\mathbf{nnzb}}\right)$Integer array Input
7: $\mathbf{icolb}\left({\mathbf{nnzb}}\right)$Integer array Input
8: $\mathbf{b}\left({\mathbf{nnzb}}\right)$Real (Kind=nag_wp) array 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$ is the current number of decision variables in the model. 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\right)$ where $i={\mathbf{irowb}}\left(l\right)$ and $j={\mathbf{icolb}}\left(\mathit{l}\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}\right)\le {\mathbf{nclin}}$, $1\le {\mathbf{icolb}}\left(\mathit{l}\right)\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzb}}$.
9: $\mathbf{idlc}$Integer Input/Output
On entry: if ${\mathbf{idlc}}=0$, a new block of linear constraints is added to the model; otherwise, ${\mathbf{idlc}}>0$ refers to the number of an existing linear constraint which will be replaced and nclin must be set to one.
Constraint: ${\mathbf{idlc}}\ge 0$.
On exit: if ${\mathbf{idlc}}=0$, the number of the last linear constraint added. By definition, it is the number of linear constraints already defined plus nclin. Otherwise, ${\mathbf{idlc}}>0$ stays unchanged.
10: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $-1$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
The supplied handle does not define a valid handle to the data structure for the NAG optimization modelling suite. It has not been properly initialized or it has been corrupted.
${\mathbf{ifail}}=2$
The problem cannot be modified right now, the solver is running.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{idlc}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{idlc}}\ge 0$.
On entry, ${\mathbf{idlc}}=⟨\mathit{\text{value}}⟩$.
The given idlc does not match with any existing linear constraint.
The maximum idlc is $⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{idlc}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{nclin}}=⟨\mathit{\text{value}}⟩$.
Constraint: If ${\mathbf{idlc}}>0$, ${\mathbf{nclin}}=1$.
On entry, ${\mathbf{nclin}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nclin}}\ge 0$.
On entry, ${\mathbf{nnzb}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nnzb}}\ge 0$.
${\mathbf{ifail}}=8$
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{icolb}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$ and $n=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{icolb}}\left(\mathit{i}\right)\le n$.
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{irowb}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{nclin}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{irowb}}\left(\mathit{i}\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.
${\mathbf{ifail}}=10$
On entry, $j=⟨\mathit{\text{value}}⟩$, ${\mathbf{bl}}\left(j\right)=⟨\mathit{\text{value}}⟩$, $\mathit{bigbnd}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{bl}}\left(j\right)<\mathit{bigbnd}$.
On entry, $j=⟨\mathit{\text{value}}⟩$, ${\mathbf{bl}}\left(j\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{bu}}\left(j\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{bl}}\left(j\right)\le {\mathbf{bu}}\left(j\right)$.
On entry, $j=⟨\mathit{\text{value}}⟩$, ${\mathbf{bu}}\left(j\right)=⟨\mathit{\text{value}}⟩$, $\mathit{bigbnd}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{bu}}\left(j\right)>-\mathit{bigbnd}$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

e04rjf is not threaded in any implementation.

### 9.1Internal Changes

Internal changes have been made to this routine as follows:
• At Mark 27.1: Previously, it was not possible to define more than one block of the linear constraints, modify the constraints or to edit the model once a solver had been called. These limitations have been removed and the associated error codes were removed. ${\mathbf{ifail}}={\mathbf{4}}$ and ${\mathbf{ifail}}={\mathbf{6}}$ have been extended to reflect the new use of idlc.
For details of all known issues which have been reported for the NAG Library please refer to the Known Issues.

## 10Example

This example demonstrates how to use the MPS file reader e04mxf and this suite of routines to define and solve a QP problem. e04mxf uses a different output format to the one required by e04rjf, 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 e04rjf 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.45555)T.$