NAG FL Interface
e04mwf (miqp_​mps_​write)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

e04mwf 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

Fortran Interface
Subroutine e04mwf ( outfile, n, m, nnzc, nnza, ncolh, nnzh, lintvar, idxc, c, iobj, a, irowa, iccola, bl, bu, pnames, nname, crname, h, irowh, iccolh, minmax, intvar, ifail)
Integer, Intent (In) :: outfile, n, m, nnzc, nnza, ncolh, nnzh, lintvar, idxc(nnzc), iobj, irowa(nnza), iccola(*), nname, irowh(nnzh), iccolh(*), minmax, intvar(lintvar)
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: c(nnzc), a(nnza), bl(n+m), bu(n+m), h(nnzh)
Character (8), Intent (In) :: pnames(5), crname(nname)
C Header Interface
#include <nag.h>
void  e04mwf_ (const Integer *outfile, const Integer *n, const Integer *m, const Integer *nnzc, const Integer *nnza, const Integer *ncolh, const Integer *nnzh, const Integer *lintvar, const Integer idxc[], const double c[], const Integer *iobj, const double a[], const Integer irowa[], const Integer iccola[], const double bl[], const double bu[], const char pnames[], const Integer *nname, const char crname[], const double h[], const Integer irowh[], const Integer iccolh[], const Integer *minmax, const Integer intvar[], Integer *ifail, const Charlen length_pnames, const Charlen length_crname)
The routine may be called by the names e04mwf or nagf_opt_miqp_mps_write.

3 Description

e04mwf 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 e04mxf 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×n, the vectors l and u are the lower and upper bounds, respectively. H is the Hessian matrix with dimension n×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 routine 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: outfile Integer Input
On entry: the ID of the file to store the problem data as associated by a call to x04acf.
Constraint: outfile0.
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. In this case the linear term of the objective function, if any, may 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 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.
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.
Constraint: lintvar0.
9: idxc(nnzc) Integer array Input
10: c(nnzc) Real (Kind=nag_wp) array Input
On entry: the nonzero elements of sparse vector c. idxc(i) must contain the index of c(i) in the vector, for i=1,2,,nnzc.
The elements are stored in ascending order.
Constraints:
  • 1idxc(i)n, for i=1,2,,nnzc;
  • idxc(i)<idxc(i+1), 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) Real (Kind=nag_wp) array Input
13: irowa(nnza) Integer array Input
14: iccola(*) Integer array Input
Note: the dimension of the array iccola must be at least n+1 if 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.
Constraints:
  • 1irowa(i)m, for i=1,2,,nnza;
  • iccola(1)=1;
  • iccola(i)iccola(i+1), for i=1,2,,n;
  • iccola(n+1)=nnza+1.
15: bl(n+m) Real (Kind=nag_wp) array Input
16: bu(n+m) Real (Kind=nag_wp) array 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)−1020; to specify a nonexistent upper bound, set bu(j)1020.
Constraints:
  • bl(j)bu(j), for j=1,2,,n+m;
  • bl(j)<1020, for j=1,2,,n+m;
  • bu(j)>-1020, for j=1,2,,n+m;
  • if iobj>0, bl(iobj+n)-1020 and bu(iobj+n)1020.
17: pnames(5) Character(8) array 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 126).
If any of the names are blank, the default name is used.
pnames(1)
Contains the name of the problem.
pnames(2)
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(2) is not used.
pnames(3)
Contains the name of the RHS set.
pnames(4)
Contains the name of the RANGE.
pnames(5)
Contains the name of the BOUNDS.
18: nname Integer Input
On entry: the number of column (i.e., variable) and row names supplied in the array crname.
If nname=0, the names are automatically generated and the array crname is not referenced.
Constraint: nname=0 or n+m.
19: crname(nname) Character(8) array 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.
20: h(nnzh) Real (Kind=nag_wp) array Input
21: irowh(nnzh) Integer array Input
22: iccolh(*) Integer array Input
Note: the dimension of the array iccolh must be at least ncolh+1 if 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.
Constraints:
  • 1irowh(i)ncolh, for i=1,2,,nnzh;
  • iccolh(1)=1;
  • iccolh(i)iccolh(i+1), for i=1,2,,ncolh;
  • iccolh(ncolh+1)=nnzh+1.
23: minmax Integer Input
On entry: minmax defines the direction of optimization problem.
minmax=−1
Minimization.
minmax=1
Maximization.
Constraint: minmax=−1 or 1.
24: intvar(lintvar) Integer array 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.
Constraint: 1intvar(j)n, for j=1,2,,lintvar.
25: 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 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
ifail=1
On entry, outfile=value.
Constraint: outfile0.
ifail=2
On entry, m=value.
Constraint: m0.
On entry, n=value.
Constraint: n1.
ifail=3
On entry, lintvar=value.
Constraint: lintvar0.
On entry, nname=value, n=value and m=value.
Constraint: nname=0 or n+m.
On entry, nnza=value.
Constraint: nnza0.
On entry, nnzc=value.
Constraint: nnzc0.
ifail=4
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.
ifail=5
On entry, j=value, idxc(j)=value and idxc(j+1)=value.
Constraint: idxc(j)<idxc(j+1).
On entry, j=value, idxc(j)=value and n=value.
Constraint: 1idxc(j)n.
ifail=6
On entry, minmax=value.
Constraint: minmax=−1 or 1.
ifail=7
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.
ifail=8
On entry, iobj=value, bl(j)=value and bu(j)=value, if iobj>0 the bounds must be infinite.
Constraints: bl(j)-1E+20, bu(j)1E+20.
On entry, j=value, bl(j)=value and bu(j)=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)>−1E+20, bu(j)<1E+20.
On entry, j=value, bl(j)=value and bu(j)=value are incorrect.
Constraint: bl(j)bu(j).
On entry, j=value and bl(j)=value, bl(j) is incorrect.
Constraint: bl(j)<1E+20.
On entry, j=value and bu(j)=value, bu(j) is incorrect.
Constraint: bu(j)>-1E+20.
ifail=9
On entry, crname(j) for j=value has been already used.
Constraint: the names in crname must be unique.
On entry, crname(j) for j=value is incorrect.
Constraint: the names in crname must consist only of printable characters.
On entry, pnames(j) for j=value is incorrect.
Constraint: the names in pnames must consist only of printable characters.
The name specified in pnames(2) is empty or has been already used among row names.
Constraint: the names in pnames(2) must be unique and nonempty if crname is provided and nnzc>0.
ifail=10
On entry, intvar(value)=intvar(value)= value.
Constraint: all entries in intvar must be unique.
On entry, j=value, intvar(j)=value and lintvar=value.
Constraint: 1intvar(j)lintvar.
ifail=11
On entry, i=value, irowa(i)=value and m=value.
Constraint: 1irowa(i)m.
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.
ifail=12
On entry, iccola(1)=value.
Constraint: iccola(1)=1.
On entry, iccola(n+1)=value and nnza=value.
Constraint: iccola(n+1)=nnza+1.
On entry, j=value, iccola(j)=value and iccola(j+1)=value, the values of iccola must be nondecreasing.
Constraint: iccola(j)iccola(j+1).
ifail=13
On entry, j=value, i=value, ncolh=value and irowh(i)=value
Constraint: jirowh(i)ncolh (within the lower triangle).
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.
ifail=14
On entry, iccolh(1)=value.
Constraint: iccolh(1)=1.
On entry, iccolh(ncolh+1)=value and nnzh=value.
Constraint: iccolh(ncolh+1)=nnzh+1.
On entry, j=value, iccolh(j)=value and iccolh(j+1)=value, the values of iccolh must be nondecreasing.
Constraint: iccolh(j)iccolh(j+1).
ifail=15
An error occurred when writing to file.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
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.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e04mwf 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 e04nqf. The problem is a minimization of the quadratic function f(x)=cTx+12xTHx, where
c=(-200.0,-2000.0,-2000.0,-2000.0,-2000.0,400.0,400.0)T  
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.0)T.  
The optimal solution (to five figures) is
x*=(0.0,349.40,648.85,172.85,407.52,271.36,150.02)T.  
The generated file is called e04mwfe.mps.

10.1 Program Text

Program Text (e04mwfe.f90)

10.2 Program Data

Program Data (e04mwfe.d)

10.3 Program Results

Program Results (e04mwfe.r)