# NAG CPP Interfacenagcpp::opt::handle_set_group (e04rb)

## 1Purpose

handle_set_group is a part of the NAG optimization modelling suite and modifies a model by either adding a new, or replacing or deleting an existing, quadratic or rotated quadratic cone constraint.

## 2Specification

#include "e04/nagcpp_e04rb.hpp"
#include "e04/nagcpp_class_CommE04RA.hpp"
template <typename COMM, typename GROUP>

void function handle_set_group(COMM &comm, const string gtype, const GROUP &group, types::f77_integer &idgroup, OptionalE04RB opt)
template <typename COMM, typename GROUP>

void function handle_set_group(COMM &comm, const string gtype, const GROUP &group, types::f77_integer &idgroup)

## 3Description

After the initialization function handle_​init has been called, handle_set_group may be used to edit a model by adding, replacing, or deleting a cone constraint $i$ of dimension ${m}_{i}$. The supported cones are quadratic cone and rotated quadratic cone, also known as second-order cones, which are defined as follows:
 $K q mi ≔ {z=(z1,z2,…,zmi)∈ℝmi : z12≥ ∑ j=2 mi zj2, z1≥0} .$ (1)
 $K r mi ≔ {z=(z1,z2,…,zmi)∈ℝmi : 2z1z2≥ ∑ j=3 mi zj2, z1≥0, z2≥0} .$ (2)
The cone constraint is defined by its type and a subset (group) of variables. Let index set ${G}^{i}\subseteq \left\{1,2,\dots ,n\right\}$ denote variable indices, then ${x}_{{G}^{i}}$ will denote the subvector of variables $x\in {ℝ}^{n}$.
For example, if ${m}_{i}=3$ and ${G}^{i}=\left\{4,1,2\right\}$, then a quadratic cone constraint
 $xGi = (x4,x1,x2) ∈ Kq3$
implies the inequality constraints
 $x42 ≥ x12 + x22 , x4 ≥ 0 .$
Typically, this function will be used to build second-order cone programming (SOCP) problems which might be formulated in the following way:
 $minimize x∈ℝn cTx (a) subject to lB≤Bx≤uB, (b) lx≤x≤ux , (c) xGi∈Kmi, i=1,…,r, (d)$ (3)
where ${\mathcal{K}}^{{m}_{i}}$ is either quadratic cone or rotated quadratic cone of dimension ${m}_{i}$.
handle_set_group can be called repeatedly to add, replace or delete one cone constraint at a time. See Section 3.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.

None.

## 5Arguments

1: $\mathbf{comm}$CommE04RA Input/Output
Communication structure. An object of either the derived class CommE04RA or its base class NoneCopyableComm can be supplied. It is recommended that the derived class is used. If the base class is supplied it must first be initialized via a call to opt::handle_init (e04ra).
2: $\mathbf{gtype}$string Input
On entry: the type of the cone constraint, case insensitive.
${\mathbf{gtype}}=\text{'QUAD'}$ or $\text{'Q'}$
The group defines a quadratic cone.
${\mathbf{gtype}}=\text{'RQUAD'}$ or $\text{'R'}$
The group defines a rotated quadratic cone.
Constraint: ${\mathbf{gtype}}=\text{'QUAD'}$, $\text{'Q'}$, $\text{'RQUAD'}$ or $\text{'R'}$.
3: $\mathbf{group}\left({\mathbf{lgroup}}\right)$types::f77_integer array Input
On entry: ${G}^{i}$, the indices of the variables in the constraint. If ${\mathbf{lgroup}}=0$, group is not referenced.
Constraint: $1\le {\mathbf{group}}\left(\mathit{k}\right)\le n$, for $\mathit{k}=0,1,\dots ,{\mathbf{lgroup}}$, where $n$ is the number of decision variables in the problem. The elements must not repeat and each variable can appear in one cone at most, see Section 9.
4: $\mathbf{idgroup}$types::f77_integer Input/Output
On entry:
${\mathbf{idgroup}}=0$
A new cone constraint is created.
${\mathbf{idgroup}}>0$
$i$, the ID number of the existing constraint to be deleted or replaced.
Constraint: ${\mathbf{idgroup}}\ge 0$.
On exit: if ${\mathbf{idgroup}}=0$ on entry, the ID number of the new cone constraint is returned. By definition, this is the number of the cone constraints already defined plus one. Otherwise, idgroup stays unchanged.
5: $\mathbf{opt}$OptionalE04RB Input/Output
Optional parameter container, derived from Optional.

1: $\mathbf{lgroup}$
${m}_{i}$, the number of the variables in the group.

## 6Exceptions and Warnings

Errors or warnings detected by the function:
All errors and warnings have an associated numeric error code field, errorid, stored either as a member of the thrown exception object (see errorid), or as a member of opt.ifail, depending on how errors and warnings are being handled (see Error Handling for more details).
Raises: ErrorException
$\mathbf{errorid}=1$
comm::handle has not been initialized.
$\mathbf{errorid}=1$
comm::handle does not belong to the NAG optimization modelling suite,
has not been initialized properly or is corrupted.
$\mathbf{errorid}=1$
comm::handle has not been initialized properly or is corrupted.
$\mathbf{errorid}=2$
The problem cannot be modified in this phase any more, the solver
$\mathbf{errorid}=3$
On entry, variable with index $i=⟨\mathit{value}⟩$ has been defined
in a cone in a previous call to this function.
Constraint: each variable may be defined in one cone constraint at most.
$\mathbf{errorid}=4$
On entry, ${\mathbf{idgroup}}=⟨\mathit{value}⟩$.
The given idgroup does not match with any cone constraint already defined.
$\mathbf{errorid}=5$
On entry, ${\mathbf{lgroup}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{lgroup}}\ge 0$.
$\mathbf{errorid}=5$
On entry, ${\mathbf{gtype}}=⟨\mathit{value}⟩$ and ${\mathbf{lgroup}}=⟨\mathit{value}⟩$.
Constraint: if ${\mathbf{gtype}}=\text{"QUAD"}\text{​ or ​}\text{"Q"}$, ${\mathbf{lgroup}}=0$ or ${\mathbf{lgroup}}\ge 2$.
$\mathbf{errorid}=5$
On entry, ${\mathbf{gtype}}=⟨\mathit{value}⟩$ and ${\mathbf{lgroup}}=⟨\mathit{value}⟩$.
Constraint: if ${\mathbf{gtype}}=\text{"RQUAD"}\text{​ or ​}\text{"R"}$, ${\mathbf{lgroup}}=0$ or ${\mathbf{lgroup}}\ge 3$.
$\mathbf{errorid}=6$
On entry, ${\mathbf{gtype}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{gtype}}=\text{"QUAD"},\text{"Q"},\text{"RQUAD"}\text{​ or ​}\text{"R"}$.
$\mathbf{errorid}=7$
On entry, ${\mathbf{idgroup}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{idgroup}}\ge 0$.
$\mathbf{errorid}=8$
On entry, $k=⟨\mathit{value}⟩$, ${\mathbf{group}}\left[k-1\right]=⟨\mathit{value}⟩$ and
$n=⟨\mathit{value}⟩$.
Constraint: $1\le {\mathbf{group}}\left[k-1\right]\le n$.
$\mathbf{errorid}=9$
On entry, ${\mathbf{group}}\left[i-1\right]={\mathbf{group}}\left[j-1\right]=⟨\mathit{value}⟩$
for $i=⟨\mathit{value}⟩$ and $j=⟨\mathit{value}⟩$.
Constraint: elements in group cannot repeat.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument has $⟨\mathit{\text{value}}⟩$ dimensions.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument was a vector of size $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
The size for the supplied array could not be ascertained.
$\mathbf{errorid}=10602$
On entry, the raw data component of $⟨\mathit{\text{value}}⟩$ is null.
$\mathbf{errorid}=10603$
On entry, unable to ascertain a value for $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10605$
On entry, the communication class $⟨\mathit{\text{value}}⟩$ has not been initialized correctly.
$\mathbf{errorid}=-99$
An unexpected error has been triggered by this routine.
$\mathbf{errorid}=-399$
Your licence key may have expired or may not have been installed correctly.
$\mathbf{errorid}=-999$
Dynamic memory allocation failed.

Not applicable.

## 8Parallelism and Performance

Please see the description for the underlying computational routine in this section of the FL Interface documentation.

Overlapping of cones is not supported, which means each variable may be defined in one cone at most. However by adding auxiliary variables, you can achieve the same effect. For example, if ${x}_{a}\in {\mathcal{K}}^{{m}_{1}}$ and ${x}_{a}\in {\mathcal{K}}^{{m}_{2}}$, you can add one more variable ${x}_{b}={x}_{a}$ and set ${x}_{a}\in {\mathcal{K}}^{{m}_{1}}$, ${x}_{b}\in {\mathcal{K}}^{{m}_{2}}$.

## 10Example

This example solves the following SOCP problem
 $minimize⁡ 10.0x1 + 20.0x2 + x3$
subject to the bounds
 $-2.0 ≤ x1 ≤ 2.0 -2.0 ≤ x2 ≤ 2.0$
the general linear constraints
 $-0.1x1 - 0.1x2 + x3 ≤ 1.5 1.0 ≤ -0.06x1 + x2 + x3$
and the cone constraint
 $(x3,x1,x2) ∈ K q 3 .$
The optimal solution (to five significant figures) is
 $x*=(-1.2682,-4.0843,1.3323)T,$
and the objective function value is $-19.518$.
 Source File Data Results ex_e04rb.cpp None ex_e04rb.r