NAG CL Interface
e04mwc (miqp_​mps_​write)

1 Purpose

e04mwc writes data for sparse linear programming, mixed integer linear programming, quadratic programming or mixed integer quadratic programming problems to a file in MPS format.

2 Specification

#include <nag.h>
void  e04mwc (Nag_FileID fileid, Integer n, Integer m, Integer nnzc, Integer nnza, Integer ncolh, Integer nnzh, Integer lintvar, const Integer idxc[], const double c[], Integer iobj, const double a[], const Integer irowa[], const Integer iccola[], const double bl[], const double bu[], char pnames[][9], char crname[][9], const double h[], const Integer irowh[], const Integer iccolh[], Integer minmax, const Integer intvar[], NagError *fail)
The function may be called by the names: e04mwc or nag_opt_miqp_mps_write.

3 Description

e04mwc writes data for linear programming (LP) or quadratic programming (QP) problems (or their mixed integer variants) from an optimization problem to a MPS output file, see Section 3.1 in e04mxc for the format description. The problem is expected in the form
minimize x cTx+12xTHx   subject to  l x Ax u.  
Where n is the number of variables, m is the number of general linear constraints, A is the linear constraint matrix with dimension m by n, the vectors l and u are the lower and upper bounds, respectively. H is the Hessian matrix with dimension n by n, however, only leading ncolh columns might contain nonzero elements and the rest is assumed to be zero.
Note that the linear term of the objective function c might be supplied either as c or via iobj. If c is supplied then idxc contains the indices of the nonzero elements of sparse vector c, whereas if iobj is supplied (iobj>0), row iobj of matrix A is a free row storing the nonzero elements of c.
Note: that this function uses fixed MPS format, see IBM (1971).

4 References

IBM (1971) MPSX – Mathematical programming system Program Number 5734 XM4 IBM Trade Corporation, New York

5 Arguments

1: fileid Nag_FileID Input
On entry: the ID of the file to store the problem data as returned by a call to x04acc.
Constraint: fileid0.
2: n Integer Input
On entry: n, the number of variables in the problem.
Constraint: n1.
3: m Integer Input
On entry: m, the number of constraints in the problem. This is the number of rows in the linear constraint matrix A, including the free row (if any; see iobj).
Constraint: m0.
4: nnzc Integer Input
On entry: the number of nonzero elements in the sparse vector c.
If nnzc=0, the vector c is considered empty and the arrays idxc and c will not be referenced and may be NULL. In this case the linear term of the objective function, if any, might be provided via iobj.
Constraints:
  • nnzc0;
  • if nnzc>0, iobj=0.
5: nnza Integer Input
On entry: the number of nonzero elements in matrix A.
If nnza=0, matrix A is considered empty, arrays a and irowa will not be referenced and may be NULL, and iccola should be the array of 1.
Constraint: nnza0.
6: ncolh Integer Input
On entry: the number of leading nonzero columns of the Hessian matrix H.
If ncolh=0, the quadratic term H of the objective function is considered zero (e.g., LP problems), and arrays h, irowh and iccolh will not be referenced and may be NULL.
Constraint: 0ncolhn.
7: nnzh Integer Input
On entry: the number of nonzero elements of the Hessian matrix H.
Constraints:
  • if ncolh>0, nnzh>0;
  • otherwise nnzh=0.
8: lintvar Integer Input
On entry: the number of integer variables in the problem.
If lintvar=0, all variables are considered continuous and array intvar will not be referenced and may be NULL.
Constraint: lintvar0.
9: idxc[nnzc] const Integer Input
10: c[nnzc] const double Input
On entry: the nonzero elements of sparse vector c. idxc[i-1] must contain the index of c[i-1] in the vector, for i=1,2,,nnzc.
The elements are stored in ascending order.
Constraints:
  • 1idxc[i-1]n, for i=1,2,,nnzc;
  • idxc[i-1]<idxc[i], for i=1,2,,nnzc.
11: iobj Integer Input
On entry: if iobj>0, row iobj of A is a free row containing the nonzero coefficients of the linear terms of the objective function. In this case nnzc is set to 0.
If iobj=0, there is no free row in A, and the linear terms might be supplied in array c.
Constraint: if iobj>0, nnzc=0.
12: a[nnza] const double Input
13: irowa[nnza] const Integer Input
14: iccola[dim] const Integer Input
Note: the dimension, dim, of the array iccola must be at least
  • n+1 when nnza>0.
On entry: the nonzero elements of matrix A in compressed column storage (see Section 2.1.3 in the F11 Chapter Introduction). Arrays irowa and a store the row indices and the values of the nonzero elements, respectively. The elements are sorted by columns and within each column in nondecreasing order. Duplicate entries are not allowed. iccola contains the (one-based) indices to the beginning of each column in a and irowa.
If nnza=0, a and irowa are not referenced and may be NULL.
Constraints:
  • 1irowa[i-1]m, for i=1,2,,nnza;
  • iccola[0]=1;
  • iccola[i-1]iccola[i], for i=1,2,,n;
  • iccola[n]=nnza+1.
15: bl[n+m] const double Input
16: bu[n+m] const double Input
On entry: bl and bu contains the lower bounds l and the upper bounds u, respectively.
The first n elements refer to the bounds for the variables x and the rest to the bounds for the linear constraints (including the objective row iobj if present).
To specify a nonexistent lower bound (i.e., lj=-inf), set bl[j-1]-1020; to specify a nonexistent upper bound, set bu[j-1]1020.
Constraints:
  • bl[j-1]bu[j-1], for j=1,2,,n+m;
  • bl[j-1]<1020, for j=1,2,,n+m;
  • bu[j-1]>-1020, for j=1,2,,n+m;
  • if iobj>0, bl[iobj+n-1]-1020 and bu[iobj+n-1]1020.
17: pnames[5][9] char Input
On entry: a set of names associated with the MPSX form of the problem.
The names can be composed only from ‘printable’ characters (ASCII codes between 32 and 127).
If any of the names are blank, the default name is used.
pnames[0]
Contains the name of the problem.
pnames[1]
Contains the name of the objective row if the objective is provided in c instead of iobj and all names crname are given. The name must be nonempty and unique. In all other cases pnames[1] is not used.
pnames[2]
Contains the name of the RHS set.
pnames[3]
Contains the name of the RANGE.
pnames[4]
Contains the name of the BOUNDS.
18: crname[n+m][9] char Input
On entry: the names of all the variables and constraints in the problem in that order.
The names can be composed only from ‘printable’ characters and must be unique.
crname may be NULL in which case it will not be referenced and the names are automatically generated.
19: h[nnzh] const double Input
20: irowh[nnzh] const Integer Input
21: iccolh[dim] const Integer Input
Note: the dimension, dim, of the array iccolh must be at least
  • ncolh+1 when ncolh>0.
On entry: the nonzero elements of the Hessian matrix H in compressed column storage (see Section 2.1.3 in the F11 Chapter Introduction). The Hessian matrix, H, is symmetric and its elements are stored in a lower triangular matrix.
Arrays irowh and h store the row indices and the values of the nonzero elements, respectively. The elements are sorted by columns and within each column in nondecreasing order. Duplicate entries are not allowed. iccolh contains the (one-based) indices to the beginning of each column in h and irowh.
If ncolh=0, h is not referenced and may be NULL.
Constraints:
  • 1irowh[i-1]ncolh, for i=1,2,,nnzh;
  • iccolh[0]=1;
  • iccolh[i-1]iccolh[i], for i=1,2,,ncolh;
  • iccolh[ncolh]=nnzh+1.
22: minmax Integer Input
On entry: minmax defines the direction of optimization problem.
minmax=-1
Minimization.
minmax=1
Maximization.
Constraint: minmax=-1 or 1.
23: intvar[lintvar] const Integer Input
On entry: intvar contains the indices k of variables xk which are defined as integers. Duplicate indices are not allowed.
If lintvar=0, intvar is not referenced and may be NULL.
Constraint: 1intvar[j-1]n, for j=1,2,,lintvar.
24: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error 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.
NE_ARRAY_INPUT
On entry, iccola[0]=value.
Constraint: iccola[0]=1.
On entry, iccola[n]=value and nnza=value.
Constraint: iccola[n]=nnza+1.
On entry, iccolh[0]=value.
Constraint: iccolh[0]=1.
On entry, iccolh[ncolh]=value and nnzh=value.
Constraint: iccolh[ncolh]=nnzh+1.
On entry, intvar[value]=intvar[value]= value.
Constraint: all entries in intvar must be unique.
NE_BAD_PARAM
On entry, argument value had an illegal value.
On entry, minmax=value.
Constraint: minmax=-1 or 1.
NE_BOUND
On entry, j=value and bl[j-1]=value, bl[j-1] is incorrect.
Constraint: bl[j-1]<1e+20.
On entry, j=value, bl[j-1]=value and bu[j-1]=value are incorrect.
Constraint: bl[j-1]bu[j-1].
On entry, j=value, bl[j-1]=value and bu[j-1]=value, the integer variable j requires at least one bound finite.
Constraint: at least one of the following conditions must be met for integer variable j: bl[j-1]>−1e+20, bu[j-1]<1e+20.
On entry, j=value and bu[j-1]=value, bu[j-1] is incorrect.
Constraint: bu[j-1]>-1e+20.
NE_FILEID
On entry, fileid=value.
Constraint: fileid0.
NE_INT
On entry, m=value.
Constraint: m0.
On entry, n=value.
Constraint: n1.
NE_INT_2
On entry, lintvar=value.
Constraint: lintvar0.
On entry, nnza=value.
Constraint: nnza0.
On entry, nnzc=value.
Constraint: nnzc0.
NE_INT_3
On entry, ncolh=value and n=value.
Constraint: 0ncolhn.
On entry, ncolh=value and nnzh=value.
Constraint: if ncolh=0, nnzh=0.
On entry, ncolh=value and nnzh=value.
Constraint: if ncolh>0, nnzh>0.
NE_INT_4
On entry, iobj=value and m=value.
Constraint: 0iobjm.
On entry, iobj=value and nnzc=value.
Constraint: at most one of iobj or nnzc may be nonzero.
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=value, irowa[i-1]=value and m=value.
Constraint: 1irowa[i-1]m.
On entry, j=value, i=value, ncolh=value and irowh[i-1]=value
Constraint: jirowh[i-1]ncolh (within the lower triangle).
On entry, more than one element of a has row index value and column index value.
Constraint: each element of a must have a unique row and column index.
On entry, more than one element of h has row index value and column index value.
Constraint: each element of h must have a unique row and column index.
NE_MPS_ILLEGAL_NAME
On entry, crname[j-1] for j=value has been already used.
Constraint: the names in crname must be unique.
The name specified in pnames[1] is empty or has been already used among row names.
Constraint: the names in pnames[1] must be unique and nonempty if crname is provided and nnzc>0.
NE_MPS_PRINTABLE
On entry, crname[j-1] for j=value is incorrect.
Constraint: the names in crname must consist only of printable characters.
On entry, pnames[j-1] for j=value is incorrect.
Constraint: the names in pnames must consist only of printable characters.
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_NOT_INCREASING
On entry, j=value, iccola[j-1]=value and iccola[j]=value, the values of iccola must be nondecreasing.
Constraint: iccola[j-1]iccola[j].
On entry, j=value, iccolh[j-1]=value and iccolh[j]=value, the values of iccolh must be nondecreasing.
Constraint: iccolh[j-1]iccolh[j].
NE_NOT_STRICTLY_INCREASING
On entry, j=value, idxc[j-1]=value and idxc[j]=value.
Constraint: idxc[j-1]<idxc[j].
NE_OBJ_BOUND
On entry, iobj=value, bl[j-1]=value and bu[j-1]=value, if iobj>0 the bounds must be infinite.
Constraints: bl[j-1]-1e+20, bu[j-1]1e+20.
NE_STATE_VAL
On entry, j=value, idxc[j-1]=value and n=value.
Constraint: 1idxc[j-1]n.
On entry, j=value, intvar[j-1]=value and lintvar=value.
Constraint: 1intvar[j-1]lintvar.
NE_WRITE_ERROR
An error occurred when writing to file.

7 Accuracy

Not applicable.

8 Parallelism and Performance

e04mwc is not threaded in any implementation.

9 Further Comments

None.

10 Example

This example shows how to store an optimization problem to a file in MPS format after it has been solved by e04nqc. The problem is a minimization of the quadratic function fx=cTx+12xTHx, where
c=-200.0,-2000.0,-2000.0,-2000.0,-2000.0,400.0,400.0T  
H= 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 2 0 0 0 0 0 2 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 2 0 0 0 0 0 2 2  
subject to the bounds
000x10200 000x22500 400x30800 100x40700 000x51500 000x61500 000x71500  
and to the linear constraints
x1 + x2 + x3 + x4 + x5 + x6 + x7 = 2000 0.15x1 + 0.04x2 + 0.02x3 + 0.04x4 + 0.02x5 + 0.01x6 + 0.03x7 60 0.03x1 + 0.05x2 + 0.08x3 + 0.02x4 + 0.06x5 + 0.01x6 100 0.02x1 + 0.04x2 + 0.01x3 + 0.02x4 + 0.02x5 40 0.02x1 + 0.03x2 + 0.01x5 30 1500 0.70x1 + 0.75x2 + 0.80x3 + 0.75x4 + 0.80x5 + 0.97x6 250 0.02x1 + 0.06x2 + 0.08x3 + 0.12x4 + 0.02x5 + 0.01x6 + 0.97x7 300.  
The initial point, which is infeasible, is
x0=0.0,0.0,0.0,0.0,0.0,0.0,0.0T.  
The optimal solution (to five figures) is
x*=0.0,349.40,648.85,172.85,407.52,271.36,150.02T.  
The generated file is called e04mwce.mps.

10.1 Program Text

Program Text (e04mwce.c)

10.2 Program Data

Program Data (e04mwce.d)

10.3 Program Results

Program Results (e04mwce.r)