Scippy

SCIP

Solving Constraint Integer Programs

reader_mps.c File Reference

Detailed Description

(extended) MPS file reader

Author
Thorsten Koch
Tobias Achterberg
Marc Pfetsch
Stefan Heinz
Stefan Vigerske
Michael Winkler

This reader/writer handles MPS files in extended MPS format, as it is used by CPLEX. In the extended format the limits on variable name lengths and coefficients are considerably relaxed. The columns in the format are then separated by whitespaces.

Definition in file reader_mps.c.

#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "scip/reader_mps.h"
#include "scip/cons_knapsack.h"
#include "scip/cons_indicator.h"
#include "scip/cons_linear.h"
#include "scip/cons_logicor.h"
#include "scip/cons_setppc.h"
#include "scip/cons_varbound.h"
#include "scip/cons_and.h"
#include "scip/cons_sos1.h"
#include "scip/cons_sos2.h"
#include "scip/cons_quadratic.h"
#include "scip/cons_soc.h"
#include "scip/cons_bounddisjunction.h"
#include "scip/pub_misc.h"

Go to the source code of this file.

Macros

#define READER_NAME   "mpsreader"
 
#define READER_DESC   "file reader for MIQPs in IBM's Mathematical Programming System format"
 
#define READER_EXTENSION   "mps"
 
#define DEFAULT_LINEARIZE_ANDS   TRUE
 
#define DEFAULT_AGGRLINEARIZATION_ANDS   TRUE
 
#define MPS_MAX_LINELEN   1024
 
#define MPS_MAX_NAMELEN   256
 
#define MPS_MAX_VALUELEN   26
 
#define MPS_MAX_FIELDLEN   20
 
#define PATCH_CHAR   '_'
 
#define BLANK   ' '
 

Typedefs

typedef enum MpsSection MPSSECTION
 
typedef struct MpsInput MPSINPUT
 
typedef struct SparseMatrix SPARSEMATRIX
 

Enumerations

enum  MpsSection {
  MPS_NAME,
  MPS_OBJSEN,
  MPS_OBJNAME,
  MPS_ROWS,
  MPS_USERCUTS,
  MPS_LAZYCONS,
  MPS_COLUMNS,
  MPS_RHS,
  MPS_RANGES,
  MPS_BOUNDS,
  MPS_SOS,
  MPS_QUADOBJ,
  MPS_QMATRIX,
  MPS_QCMATRIX,
  MPS_INDICATORS,
  MPS_ENDATA
}
 

Functions

static SCIP_RETCODE mpsinputCreate (SCIP *scip, MPSINPUT **mpsi, SCIP_FILE *fp)
 
static void mpsinputFree (SCIP *scip, MPSINPUT **mpsi)
 
static MPSSECTION mpsinputSection (const MPSINPUT *mpsi)
 
static const char * mpsinputField0 (const MPSINPUT *mpsi)
 
static const char * mpsinputField1 (const MPSINPUT *mpsi)
 
static const char * mpsinputField2 (const MPSINPUT *mpsi)
 
static const char * mpsinputField3 (const MPSINPUT *mpsi)
 
static const char * mpsinputField4 (const MPSINPUT *mpsi)
 
static const char * mpsinputField5 (const MPSINPUT *mpsi)
 
static const char * mpsinputObjname (const MPSINPUT *mpsi)
 
static SCIP_OBJSENSE mpsinputObjsense (const MPSINPUT *mpsi)
 
static SCIP_Bool mpsinputHasError (const MPSINPUT *mpsi)
 
static SCIP_Bool mpsinputIsInteger (const MPSINPUT *mpsi)
 
static void mpsinputSetSection (MPSINPUT *mpsi, MPSSECTION section)
 
static void mpsinputSetProbname (MPSINPUT *mpsi, const char *probname)
 
static void mpsinputSetObjname (MPSINPUT *mpsi, const char *objname)
 
static void mpsinputSetObjsense (MPSINPUT *mpsi, SCIP_OBJSENSE sense)
 
static void mpsinputSyntaxerror (MPSINPUT *mpsi)
 
static void mpsinputEntryIgnored (SCIP *scip, MPSINPUT *mpsi, const char *what, const char *what_name, const char *entity, const char *entity_name, SCIP_VERBLEVEL verblevel)
 
static void clearFrom (char *buf, unsigned int pos)
 
static void patchField (char *buf, int beg, int end)
 
static SCIP_Bool mpsinputReadLine (MPSINPUT *mpsi)
 
static void mpsinputInsertField4 (MPSINPUT *mpsi, const char *str)
 
static void mpsinputInsertName (MPSINPUT *mpsi, const char *name, SCIP_Bool second)
 
static SCIP_RETCODE readName (SCIP *scip, MPSINPUT *mpsi)
 
static SCIP_RETCODE readObjsen (SCIP *scip, MPSINPUT *mpsi)
 
static SCIP_RETCODE readObjname (SCIP *scip, MPSINPUT *mpsi)
 
static SCIP_RETCODE readRows (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readCols (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readRhs (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readRanges (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readBounds (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readSOS (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readQMatrix (MPSINPUT *mpsi, SCIP_Bool isQuadObj, SCIP *scip)
 
static SCIP_RETCODE readQCMatrix (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readIndicators (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readMps (SCIP *scip, const char *filename)
 
static SCIP_DECL_HASHGETKEY (hashGetKeyVar)
 
static SCIP_DECL_HASHKEYEQ (hashKeyEqVar)
 
static SCIP_DECL_HASHKEYVAL (hashKeyValVar)
 
static unsigned int computeFieldWidth (unsigned int width)
 
static void printRecord (SCIP *scip, FILE *file, const char *col1, const char *col2, unsigned int maxnamelen)
 
static void printStart (SCIP *scip, FILE *file, const char *col1, const char *col2, int maxnamelen)
 
static void printEntry (SCIP *scip, FILE *file, const char *varname, const char *consname, SCIP_Real value, int *recordcnt, unsigned int maxnamelen)
 
static void printRowType (SCIP *scip, FILE *file, SCIP_Real lhs, SCIP_Real rhs, const char *name)
 
static SCIP_RETCODE initializeMatrix (SCIP *scip, SPARSEMATRIX **matrix, int slots)
 
static SCIP_RETCODE checkSparseMatrixCapacity (SCIP *scip, SPARSEMATRIX *matrix, int capacity)
 
static void freeMatrix (SCIP *scip, SPARSEMATRIX *matrix)
 
static SCIP_RETCODE getLinearCoeffs (SCIP *scip, const char *consname, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Bool transformed, SPARSEMATRIX *matrix, SCIP_Real *rhs)
 
static SCIP_RETCODE collectAggregatedVars (SCIP *scip, SCIP_VAR **vars, int nvars, SCIP_VAR ***aggvars, int *naggvars, int *saggvars, SCIP_HASHTABLE *varAggregated)
 
static SCIP_RETCODE checkVarnames (SCIP *scip, SCIP_VAR **vars, int nvars, unsigned int *maxnamelen, const char ***varnames, SCIP_HASHMAP **varnameHashmap)
 
static SCIP_RETCODE checkConsnames (SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_Bool transformed, unsigned int *maxnamelen, const char ***consnames, SCIP_Bool *error)
 
static void printColumnSection (SCIP *scip, FILE *file, SPARSEMATRIX *matrix, SCIP_HASHMAP *varnameHashmap, SCIP_HASHTABLE *indicatorSlackHash, unsigned int maxnamelen)
 
static void printRhsSection (SCIP *scip, FILE *file, int nconss, const char **consnames, SCIP_Real *rhss, unsigned int maxnamelen)
 
static void printRangeSection (SCIP *scip, FILE *file, SCIP_CONS **conss, int nconss, const char **consnames, SCIP_Bool transformed, unsigned int maxnamelen)
 
static void printBoundSectionName (SCIP *scip, FILE *file)
 
static void printBoundSection (SCIP *scip, FILE *file, SCIP_VAR **vars, int nvars, SCIP_VAR **aggvars, int naggvars, SCIP_VAR **fixvars, int nfixvars, SCIP_Bool transformed, const char **varnames, SCIP_HASHTABLE *indicatorSlackHash, unsigned int maxnamelen)
 
static SCIP_DECL_READERCOPY (readerCopyMps)
 
static SCIP_DECL_READERFREE (readerFreeMps)
 
static SCIP_DECL_READERREAD (readerReadMps)
 
static SCIP_DECL_READERWRITE (readerWriteMps)
 
SCIP_RETCODE SCIPincludeReaderMps (SCIP *scip)
 

Macro Definition Documentation

#define READER_NAME   "mpsreader"
#define READER_DESC   "file reader for MIQPs in IBM's Mathematical Programming System format"

Definition at line 55 of file reader_mps.c.

Referenced by SCIPincludeReaderMps().

#define READER_EXTENSION   "mps"

Definition at line 56 of file reader_mps.c.

Referenced by SCIPincludeReaderMps().

#define DEFAULT_LINEARIZE_ANDS   TRUE

should possible "and" constraint be linearized when writing the mps file?

Definition at line 58 of file reader_mps.c.

Referenced by SCIPincludeReaderMps().

#define DEFAULT_AGGRLINEARIZATION_ANDS   TRUE

should an aggregated linearization for and constraints be used?

Definition at line 61 of file reader_mps.c.

Referenced by SCIPincludeReaderMps().

#define MPS_MAX_LINELEN   1024

Definition at line 67 of file reader_mps.c.

Referenced by mpsinputReadLine().

#define MPS_MAX_VALUELEN   26

Definition at line 69 of file reader_mps.c.

Referenced by printBoundSection(), printEntry(), printRecord(), and SCIP_DECL_READERWRITE().

#define MPS_MAX_FIELDLEN   20

Definition at line 70 of file reader_mps.c.

Referenced by computeFieldWidth().

#define PATCH_CHAR   '_'

Definition at line 72 of file reader_mps.c.

Referenced by patchField().

#define BLANK   ' '

Definition at line 73 of file reader_mps.c.

Referenced by clearFrom(), mpsinputReadLine(), and patchField().

Typedef Documentation

typedef enum MpsSection MPSSECTION

Definition at line 102 of file reader_mps.c.

typedef struct MpsInput MPSINPUT

Definition at line 128 of file reader_mps.c.

typedef struct SparseMatrix SPARSEMATRIX

Definition at line 139 of file reader_mps.c.

Enumeration Type Documentation

enum MpsSection

enum containing all mps sections

Enumerator
MPS_NAME 
MPS_OBJSEN 
MPS_OBJNAME 
MPS_ROWS 
MPS_USERCUTS 
MPS_LAZYCONS 
MPS_COLUMNS 
MPS_RHS 
MPS_RANGES 
MPS_BOUNDS 
MPS_SOS 
MPS_QUADOBJ 
MPS_QMATRIX 
MPS_QCMATRIX 
MPS_INDICATORS 
MPS_ENDATA 

Definition at line 83 of file reader_mps.c.

Function Documentation

static SCIP_RETCODE mpsinputCreate ( SCIP scip,
MPSINPUT **  mpsi,
SCIP_FILE fp 
)
static

creates the mps input structure

Parameters
scipSCIP data structure
mpsimps input structure
fpfile object for the input file

Definition at line 143 of file reader_mps.c.

References FALSE, MPS_NAME, mpsinputFree(), NULL, SCIP_CALL, SCIP_OBJSENSE_MINIMIZE, SCIP_OKAY, SCIPallocMemory, and SCIPgetBoolParam().

Referenced by readMps().

static void mpsinputFree ( SCIP scip,
MPSINPUT **  mpsi 
)
static

free the mps input structure

Parameters
scipSCIP data structure
mpsimps input structure

Definition at line 181 of file reader_mps.c.

References mpsinputSection(), and SCIPfreeMemory.

Referenced by mpsinputCreate(), and readMps().

static MPSSECTION mpsinputSection ( const MPSINPUT mpsi)
static

returns the current section

Parameters
mpsimps input structure

Definition at line 191 of file reader_mps.c.

References mpsinputField0(), and NULL.

Referenced by mpsinputFree(), readMps(), and readRows().

static const char* mpsinputField0 ( const MPSINPUT mpsi)
static

return the current value of field 0

Parameters
mpsimps input structure

Definition at line 202 of file reader_mps.c.

References mpsinputField1(), and NULL.

Referenced by mpsinputSection(), readBounds(), readCols(), readIndicators(), readName(), readObjname(), readObjsen(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRows(), and readSOS().

static const char* mpsinputField1 ( const MPSINPUT mpsi)
static

return the current value of field 1

Parameters
mpsimps input structure

Definition at line 213 of file reader_mps.c.

References mpsinputField2(), and NULL.

Referenced by mpsinputField0(), readBounds(), readCols(), readIndicators(), readName(), readObjname(), readObjsen(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRows(), and readSOS().

static const char* mpsinputField2 ( const MPSINPUT mpsi)
static

return the current value of field 2

Parameters
mpsimps input structure

Definition at line 224 of file reader_mps.c.

References mpsinputField3(), and NULL.

Referenced by mpsinputField1(), readBounds(), readCols(), readIndicators(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRows(), and readSOS().

static const char* mpsinputField3 ( const MPSINPUT mpsi)
static

return the current value of field 3

Parameters
mpsimps input structure

Definition at line 235 of file reader_mps.c.

References mpsinputField4(), and NULL.

Referenced by mpsinputField2(), readBounds(), readCols(), readIndicators(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), and readSOS().

static const char* mpsinputField4 ( const MPSINPUT mpsi)
static

return the current value of field 4

Parameters
mpsimps input structure

Definition at line 246 of file reader_mps.c.

References mpsinputField5(), and NULL.

Referenced by mpsinputField3(), readBounds(), readCols(), readIndicators(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), and readSOS().

static const char* mpsinputField5 ( const MPSINPUT mpsi)
static

return the current value of field 5

Parameters
mpsimps input structure

Definition at line 257 of file reader_mps.c.

References mpsinputObjname(), and NULL.

Referenced by mpsinputField4(), readCols(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), and readSOS().

static const char* mpsinputObjname ( const MPSINPUT mpsi)
static

returns the objective name

Parameters
mpsimps input structure

Definition at line 281 of file reader_mps.c.

References mpsinputObjsense(), and NULL.

Referenced by mpsinputField5(), readCols(), readRhs(), and readRows().

static SCIP_OBJSENSE mpsinputObjsense ( const MPSINPUT mpsi)
static

returns the objective sense

Parameters
mpsimps input structure

Definition at line 292 of file reader_mps.c.

References mpsinputHasError(), NULL, and SCIP_Bool.

Referenced by mpsinputObjname(), readMps(), and readQMatrix().

static SCIP_Bool mpsinputHasError ( const MPSINPUT mpsi)
static

returns if an error was detected

Parameters
mpsimps input structure

Definition at line 303 of file reader_mps.c.

References mpsinputIsInteger(), NULL, and SCIP_Bool.

Referenced by mpsinputObjsense(), and readMps().

static SCIP_Bool mpsinputIsInteger ( const MPSINPUT mpsi)
static

returns the value of the Bool "is integer" in the mps input

Parameters
mpsimps input structure

Definition at line 314 of file reader_mps.c.

References mpsinputSetSection(), and NULL.

Referenced by mpsinputHasError(), and readCols().

static void mpsinputSetSection ( MPSINPUT mpsi,
MPSSECTION  section 
)
static

set the section in the mps input structure to given section

Parameters
mpsimps input structure
sectionsection that is set

Definition at line 325 of file reader_mps.c.

References mpsinputSetProbname(), and NULL.

Referenced by mpsinputIsInteger(), readBounds(), readCols(), readIndicators(), readName(), readObjname(), readObjsen(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRows(), and readSOS().

static void mpsinputSetProbname ( MPSINPUT mpsi,
const char *  probname 
)
static

set the problem name in the mps input structure to given problem name

Parameters
mpsimps input structure
probnamename of the problem to set

Definition at line 337 of file reader_mps.c.

References MPS_MAX_NAMELEN, mpsinputSetObjname(), NULL, and SCIPmemccpy().

Referenced by mpsinputSetSection(), and readName().

static void mpsinputSetObjname ( MPSINPUT mpsi,
const char *  objname 
)
static

set the objective name in the mps input structure to given objective name

Parameters
mpsimps input structure
objnamename of the objective function to set

Definition at line 351 of file reader_mps.c.

References MPS_MAX_NAMELEN, mpsinputSetObjsense(), NULL, and SCIPmemccpy().

Referenced by mpsinputSetProbname(), readObjname(), and readRows().

static void mpsinputSetObjsense ( MPSINPUT mpsi,
SCIP_OBJSENSE  sense 
)
static

set the objective sense in the mps input structure to given objective sense

Parameters
mpsimps input structure
sensesense of the objective function

Definition at line 365 of file reader_mps.c.

References mpsinputSyntaxerror(), and NULL.

Referenced by mpsinputSetObjname(), and readObjsen().

static void mpsinputSyntaxerror ( MPSINPUT mpsi)
static
static void mpsinputEntryIgnored ( SCIP scip,
MPSINPUT mpsi,
const char *  what,
const char *  what_name,
const char *  entity,
const char *  entity_name,
SCIP_VERBLEVEL  verblevel 
)
static

method post a ignore message

Parameters
scipSCIP data structure
mpsimps input structure
whatwhat get ignored
what_namename of that object
entityentity
entity_nameentity name
verblevelSCIP verblevel for this message

Definition at line 389 of file reader_mps.c.

References clearFrom(), NULL, and SCIPverbMessage().

Referenced by mpsinputSyntaxerror(), readBounds(), readCols(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRows(), and readSOS().

static void clearFrom ( char *  buf,
unsigned int  pos 
)
static

fill the line from pos up to column 80 with blanks.

Parameters
bufbuffer to clear
posposition to start the clearing process

Definition at line 411 of file reader_mps.c.

References BLANK, and patchField().

Referenced by mpsinputEntryIgnored(), and mpsinputReadLine().

static void patchField ( char *  buf,
int  beg,
int  end 
)
static

change all blanks inside a field to PATCH_CHAR.

Parameters
bufbuffer to patch
begposition to begin
endposition to end

Definition at line 425 of file reader_mps.c.

References BLANK, mpsinputReadLine(), PATCH_CHAR, and SCIP_Bool.

Referenced by clearFrom(), and mpsinputReadLine().

static SCIP_Bool mpsinputReadLine ( MPSINPUT mpsi)
static
static void mpsinputInsertField4 ( MPSINPUT mpsi,
const char *  str 
)
static

Insert str as field 4 and shift all other fields up.

Parameters
mpsimps input structure
strstr to insert

Definition at line 622 of file reader_mps.c.

References mpsinputInsertName(), and NULL.

Referenced by mpsinputReadLine(), and readBounds().

static void mpsinputInsertName ( MPSINPUT mpsi,
const char *  name,
SCIP_Bool  second 
)
static

Insert name as field 1 or 2 and shift all other fields up.

Parameters
mpsimps input structure
namename to insert
secondinsert as second field?

Definition at line 636 of file reader_mps.c.

References NULL, and readName().

Referenced by mpsinputInsertField4(), readBounds(), readRanges(), and readRhs().

static SCIP_RETCODE readName ( SCIP scip,
MPSINPUT mpsi 
)
static

Process NAME section.

Parameters
scipSCIP data structure
mpsimps input structure

Definition at line 660 of file reader_mps.c.

References MPS_LAZYCONS, MPS_OBJNAME, MPS_OBJSEN, MPS_ROWS, MPS_USERCUTS, mpsinputField0(), mpsinputField1(), mpsinputReadLine(), mpsinputSetProbname(), mpsinputSetSection(), mpsinputSyntaxerror(), NULL, readObjsen(), SCIP_OKAY, and SCIPdebugMessage.

Referenced by mpsinputInsertName(), and readMps().

static SCIP_RETCODE readObjsen ( SCIP scip,
MPSINPUT mpsi 
)
static

Process OBJSEN section. This Section is a CPLEX extension.

Parameters
scipSCIP data structure
mpsimps input structure

Definition at line 707 of file reader_mps.c.

References MPS_LAZYCONS, MPS_OBJNAME, MPS_ROWS, MPS_USERCUTS, mpsinputField0(), mpsinputField1(), mpsinputReadLine(), mpsinputSetObjsense(), mpsinputSetSection(), mpsinputSyntaxerror(), NULL, readObjname(), SCIP_OBJSENSE_MAXIMIZE, SCIP_OBJSENSE_MINIMIZE, SCIP_OKAY, and SCIPdebugMessage.

Referenced by readMps(), and readName().

static SCIP_RETCODE readObjname ( SCIP scip,
MPSINPUT mpsi 
)
static

Process OBJNAME section. This Section is a CPLEX extension.

Parameters
scipSCIP data structure
mpsimps input structure

Definition at line 759 of file reader_mps.c.

References MPS_LAZYCONS, MPS_ROWS, MPS_USERCUTS, mpsinputField0(), mpsinputField1(), mpsinputReadLine(), mpsinputSetObjname(), mpsinputSetSection(), mpsinputSyntaxerror(), NULL, readRows(), SCIP_OKAY, and SCIPdebugMessage.

Referenced by readMps(), and readObjsen().

static SCIP_RETCODE readSOS ( MPSINPUT mpsi,
SCIP scip 
)
static
static SCIP_RETCODE readQMatrix ( MPSINPUT mpsi,
SCIP_Bool  isQuadObj,
SCIP scip 
)
static

Process QMATRIX or QUADOBJ section.

  • We read the QMATRIX or QUADOBJ section, which is a nonstandard section introduced by CPLEX.
  • We create a quadratic constraint for this matrix and add a variable to the objective to represent the value of the QMATRIX.
  • For a QMATRIX, we expect that both lower and upper diagonal elements are given and every coefficient has to be divided by 2.0.
  • For a QUADOBJ, we expect that only the upper diagonal elements are given and thus only coefficients on the diagonal have to be divided by 2.0.
Parameters
mpsimps input structure
isQuadObjwhether we actually read a QUADOBJ section
scipSCIP data structure

Definition at line 1846 of file reader_mps.c.

References FALSE, MPS_ENDATA, MPS_INDICATORS, MPS_QCMATRIX, mpsinputEntryIgnored(), mpsinputField0(), mpsinputField1(), mpsinputField2(), mpsinputField3(), mpsinputField4(), mpsinputField5(), mpsinputObjsense(), mpsinputReadLine(), mpsinputSetSection(), mpsinputSyntaxerror(), NULL, readQCMatrix(), SCIP_Bool, SCIP_CALL, SCIP_OBJSENSE_MINIMIZE, SCIP_OKAY, SCIP_Real, SCIP_VARTYPE_CONTINUOUS, SCIP_VERBLEVEL_NORMAL, SCIPaddCons(), SCIPaddVar(), SCIPallocBufferArray, SCIPcalcMemGrowSize(), SCIPconsGetName(), SCIPcreateConsQuadratic(), SCIPcreateVar(), SCIPdebugMessage, SCIPdebugPrintCons, SCIPerrorMessage, SCIPfindVar(), SCIPfreeBufferArray, SCIPinfinity(), SCIPreallocBufferArray, SCIPreleaseCons(), SCIPreleaseVar(), SCIPvarGetName(), SCIPwarningMessage(), and TRUE.

Referenced by readMps(), and readSOS().

static SCIP_RETCODE readIndicators ( MPSINPUT mpsi,
SCIP scip 
)
static
static SCIP_RETCODE readMps ( SCIP scip,
const char *  filename 
)
static

Read LP in "MPS File Format".

A specification of the MPS format can be found at

http://plato.asu.edu/ftp/mps_format.txt, ftp://ftp.caam.rice.edu/pub/people/bixby/miplib/mps_format,

and in the

CPLEX Reference Manual

This routine should read all valid MPS format files. What it will not do, is to find all cases where a file is ill formed. If this happens it may complain and read nothing or read "something".

Parameters
scipSCIP data structure
filenamename of the input file

Definition at line 2459 of file reader_mps.c.

References FALSE, MPS_BOUNDS, MPS_COLUMNS, MPS_ENDATA, MPS_INDICATORS, MPS_LAZYCONS, MPS_OBJNAME, MPS_OBJSEN, MPS_QCMATRIX, MPS_QMATRIX, MPS_QUADOBJ, MPS_RANGES, MPS_RHS, MPS_ROWS, MPS_SOS, MPS_USERCUTS, mpsinputCreate(), mpsinputFree(), mpsinputHasError(), mpsinputObjsense(), mpsinputSection(), mpsinputSyntaxerror(), NULL, readBounds(), readCols(), readIndicators(), readName(), readObjname(), readObjsen(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRows(), readSOS(), SCIP_Bool, SCIP_CALL, SCIP_CALL_TERMINATE, SCIP_DECL_HASHGETKEY(), SCIP_NOFILE, SCIP_OKAY, SCIP_READERROR, SCIPcreateProb(), SCIPerrorMessage, SCIPfclose(), SCIPfopen(), SCIPprintSysError(), SCIPsetObjsense(), and TRUE.

Referenced by readIndicators(), and SCIP_DECL_READERREAD().

static SCIP_DECL_HASHGETKEY ( hashGetKeyVar  )
static

hash key retrieval function for variables

Definition at line 2567 of file reader_mps.c.

References SCIP_DECL_HASHKEYEQ().

Referenced by readMps().

static SCIP_DECL_HASHKEYEQ ( hashKeyEqVar  )
static

returns TRUE iff the indices of both variables are equal

Definition at line 2574 of file reader_mps.c.

References FALSE, SCIP_DECL_HASHKEYVAL(), and TRUE.

Referenced by SCIP_DECL_HASHGETKEY().

static SCIP_DECL_HASHKEYVAL ( hashKeyValVar  )
static

returns the hash value of the key

Definition at line 2583 of file reader_mps.c.

References computeFieldWidth(), and SCIPvarGetIndex().

Referenced by SCIP_DECL_HASHKEYEQ().

static unsigned int computeFieldWidth ( unsigned int  width)
static

computes the field width such that the output file is nicely arranged

Parameters
widthrequired width

Definition at line 2592 of file reader_mps.c.

References MAX, MIN, MPS_MAX_FIELDLEN, and printRecord().

Referenced by printRecord(), printStart(), and SCIP_DECL_HASHKEYVAL().

static void printRecord ( SCIP scip,
FILE *  file,
const char *  col1,
const char *  col2,
unsigned int  maxnamelen 
)
static

output two strings in columns 1 and 2 with computed widths

Parameters
scipSCIP data structure
fileoutput file (or NULL for standard output)
col1column 1
col2column 2
maxnamelenmaximum name length

Definition at line 2603 of file reader_mps.c.

References computeFieldWidth(), MPS_MAX_NAMELEN, MPS_MAX_VALUELEN, NULL, printStart(), SCIPinfoMessage(), and SCIPsnprintf().

Referenced by computeFieldWidth(), printBoundSection(), printColumnSection(), printEntry(), and SCIP_DECL_READERWRITE().

static void printStart ( SCIP scip,
FILE *  file,
const char *  col1,
const char *  col2,
int  maxnamelen 
)
static

output two strings in columns 1 (width 2) and 2 (width 8)

Parameters
scipSCIP data structure
fileoutput file (or NULL for standard output)
col1column 1
col2column 2
maxnamelenmaximum name length (-1 if irrelevant)

Definition at line 2629 of file reader_mps.c.

References computeFieldWidth(), MPS_MAX_NAMELEN, NULL, printEntry(), SCIPinfoMessage(), and SCIPsnprintf().

Referenced by printBoundSection(), printColumnSection(), printEntry(), printRecord(), printRowType(), and SCIP_DECL_READERWRITE().

static void printEntry ( SCIP scip,
FILE *  file,
const char *  varname,
const char *  consname,
SCIP_Real  value,
int *  recordcnt,
unsigned int  maxnamelen 
)
static

prints the given data as column entry

Parameters
scipSCIP data structure
fileoutput file (or NULL for standard output)
varnamevariable name
consnameconstraint name
valuevalue to display
recordcntpointer to store the number of records per line
maxnamelenmaximum name length

Definition at line 2663 of file reader_mps.c.

References MPS_MAX_VALUELEN, NULL, printRecord(), printRowType(), printStart(), SCIPinfoMessage(), and SCIPsnprintf().

Referenced by printColumnSection(), printRangeSection(), printRhsSection(), and printStart().

static void printRowType ( SCIP scip,
FILE *  file,
SCIP_Real  lhs,
SCIP_Real  rhs,
const char *  name 
)
static

prints the constraint type to file stream

Parameters
scipSCIP data structure
fileoutput file (or NULL for standard output)
lhsleft hand side
rhsright hand side
nameconstraint name

Definition at line 2701 of file reader_mps.c.

References initializeMatrix(), NULL, printStart(), SCIPinfoMessage(), SCIPisEQ(), SCIPisGT(), SCIPisInfinity(), and SCIPsnprintf().

Referenced by printEntry(), and SCIP_DECL_READERWRITE().

static SCIP_RETCODE initializeMatrix ( SCIP scip,
SPARSEMATRIX **  matrix,
int  slots 
)
static

initializes the sparse matrix

Parameters
scipSCIP data structure
matrixpointer to sparse matrix containing the entries
slotsnumber of slots

Definition at line 2740 of file reader_mps.c.

References checkSparseMatrixCapacity(), SCIP_CALL, SCIP_OKAY, SCIPallocBuffer, and SCIPallocBufferArray.

Referenced by printRowType(), and SCIP_DECL_READERWRITE().

static SCIP_RETCODE checkSparseMatrixCapacity ( SCIP scip,
SPARSEMATRIX matrix,
int  capacity 
)
static

this method takes care that the required capacity is available in the sparse matrix

Parameters
scipSCIP data structure
matrixsparse matrix for storing the coefficient
capacityneeded capacity

Definition at line 2758 of file reader_mps.c.

References freeMatrix(), SCIP_CALL, SCIP_OKAY, and SCIPreallocBufferArray.

Referenced by getLinearCoeffs(), initializeMatrix(), and SCIP_DECL_READERWRITE().

static void freeMatrix ( SCIP scip,
SPARSEMATRIX matrix 
)
static

frees the sparse matrix

Parameters
scipSCIP data structure
matrixsparse matrix to free

Definition at line 2776 of file reader_mps.c.

References getLinearCoeffs(), SCIPfreeBuffer, and SCIPfreeBufferArray.

Referenced by checkSparseMatrixCapacity(), and SCIP_DECL_READERWRITE().

static SCIP_RETCODE getLinearCoeffs ( SCIP scip,
const char *  consname,
SCIP_VAR **  vars,
SCIP_Real vals,
int  nvars,
SCIP_Bool  transformed,
SPARSEMATRIX matrix,
SCIP_Real rhs 
)
static

computes the coefficient for the given variables and linear constraint information

Parameters
scipSCIP data structure
consnamename of the constraint
varsarray of variables
valsarray of coefficients values (or NULL if all coefficient values are 1)
nvarsnumber of variables
transformedtransformed constraint?
matrixsparse matrix for storing the coefficient
rhspointer to right hand side

Definition at line 2791 of file reader_mps.c.

References checkSparseMatrixCapacity(), collectAggregatedVars(), NULL, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPallocBufferArray, SCIPduplicateBufferArray, SCIPfreeBufferArray, SCIPgetProbvarLinearSum(), SCIPisInfinity(), SCIPreallocBufferArray, SCIPvarGetOrigvarSum(), and TRUE.

Referenced by freeMatrix(), and SCIP_DECL_READERWRITE().

static SCIP_RETCODE collectAggregatedVars ( SCIP scip,
SCIP_VAR **  vars,
int  nvars,
SCIP_VAR ***  aggvars,
int *  naggvars,
int *  saggvars,
SCIP_HASHTABLE varAggregated 
)
static

check whether given variables are aggregated and put them into an array without duplication

Parameters
scipSCIP data structure
varsvariable array
nvarsnumber of active variables in the problem
aggvarspointer to array storing the aggregated variables on output
naggvarspointer to number of aggregated variables on output
saggvarspointer to number of slots in aggvars array
varAggregatedhashtable for checking duplicates

Definition at line 2884 of file reader_mps.c.

References checkVarnames(), NULL, SCIP_CALL, SCIP_OKAY, SCIP_VARSTATUS_AGGREGATED, SCIP_VARSTATUS_MULTAGGR, SCIP_VARSTATUS_NEGATED, SCIPcalcMemGrowSize(), SCIPhashtableExists(), SCIPhashtableInsert(), SCIPreallocBlockMemoryArray, and SCIPvarGetStatus().

Referenced by getLinearCoeffs(), and SCIP_DECL_READERWRITE().

static SCIP_RETCODE checkVarnames ( SCIP scip,
SCIP_VAR **  vars,
int  nvars,
unsigned int *  maxnamelen,
const char ***  varnames,
SCIP_HASHMAP **  varnameHashmap 
)
static

method check if the variable names are not longer than MPS_MAX_NAMELEN - 1

Parameters
scipSCIP data structure
varsarray of variables
nvarsnumber of variables
maxnamelenpointer to store the maximum name length
varnamespointer to array of variable names
varnameHashmappointer to hash map storing variable, variable name mapping

Definition at line 2941 of file reader_mps.c.

References checkConsnames(), MAX, MPS_MAX_NAMELEN, NULL, SCIP_CALL, SCIP_OKAY, SCIPallocBufferArray, SCIPblkmem(), SCIPcalcHashtableSize(), SCIPhashmapCreate(), SCIPhashmapExists(), SCIPhashmapInsert(), SCIPsnprintf(), SCIPvarGetName(), and SCIPwarningMessage().

Referenced by collectAggregatedVars(), and SCIP_DECL_READERWRITE().

static SCIP_RETCODE checkConsnames ( SCIP scip,
SCIP_CONS **  conss,
int  nconss,
SCIP_Bool  transformed,
unsigned int *  maxnamelen,
const char ***  consnames,
SCIP_Bool error 
)
static

method check if the constraint names are not longer than MPS_MAX_NAMELEN - 1

Parameters
scipSCIP data structure
conssarray of all constraints
nconssnumber of all constraints
transformedTRUE iff problem is the transformed problem
maxnamelenpointer to store the maximum name length
consnamespointer to array of constraint names
errorpointer to store whether all constraint names exist

Definition at line 3005 of file reader_mps.c.

References FALSE, MAX, MPS_MAX_NAMELEN, NULL, printColumnSection(), SCIP_CALL, SCIP_OKAY, SCIPallocBufferArray, SCIPconsGetName(), SCIPconsIsEnabled(), SCIPfreeBufferArray, SCIPsnprintf(), SCIPwarningMessage(), and TRUE.

Referenced by checkVarnames(), and SCIP_DECL_READERWRITE().

static void printColumnSection ( SCIP scip,
FILE *  file,
SPARSEMATRIX matrix,
SCIP_HASHMAP varnameHashmap,
SCIP_HASHTABLE indicatorSlackHash,
unsigned int  maxnamelen 
)
static

outputs the COLUMNS section of the MPS format

Parameters
scipSCIP data structure
fileoutput file, or NULL if standard output should be used
matrixsparse matrix containing the entries
varnameHashmapmap from SCIP_VAR* to variable name
indicatorSlackHashhashtable containing slack variables from indicators (or NULL)
maxnamelenmaximum name length

Definition at line 3083 of file reader_mps.c.

References FALSE, NULL, printEntry(), printRecord(), printRhsSection(), printStart(), SCIP_Bool, SCIP_Real, SCIP_VARTYPE_CONTINUOUS, SCIPdebugMessage, SCIPhashmapExists(), SCIPhashmapGetImage(), SCIPhashtableExists(), SCIPinfoMessage(), SCIPsortPtrPtrReal(), SCIPvarGetName(), SCIPvarGetType(), and TRUE.

Referenced by checkConsnames(), and SCIP_DECL_READERWRITE().

static void printRhsSection ( SCIP scip,
FILE *  file,
int  nconss,
const char **  consnames,
SCIP_Real rhss,
unsigned int  maxnamelen 
)
static

outputs the right hand side section

Parameters
scipSCIP data structure
fileoutput file, or NULL if standard output should be used
nconssnumber of constraints
consnamesconstraint names
rhssright hand side array
maxnamelenmaximum name length

Definition at line 3175 of file reader_mps.c.

References NULL, printEntry(), printRangeSection(), SCIPdebugMessage, SCIPinfoMessage(), and SCIPisInfinity().

Referenced by printColumnSection(), and SCIP_DECL_READERWRITE().

static void printRangeSection ( SCIP scip,
FILE *  file,
SCIP_CONS **  conss,
int  nconss,
const char **  consnames,
SCIP_Bool  transformed,
unsigned int  maxnamelen 
)
static

outputs the range section

Parameters
scipSCIP data structure
fileoutput file, or NULL if standard output should be used
conssconstraint array
nconssnumber of constraints
consnamesconstraint names
transformedTRUE iff problem is the transformed problem
maxnamelenmaximum name length

Definition at line 3213 of file reader_mps.c.

References NULL, printBoundSectionName(), printEntry(), SCIP_Real, SCIPconsGetHdlr(), SCIPconshdlrGetName(), SCIPconsIsEnabled(), SCIPdebugMessage, SCIPgetLhsLinear(), SCIPgetLhsVarbound(), SCIPgetRhsLinear(), SCIPgetRhsVarbound(), SCIPinfoMessage(), SCIPisEQ(), SCIPisGT(), and SCIPisInfinity().

Referenced by printRhsSection(), and SCIP_DECL_READERWRITE().

static void printBoundSectionName ( SCIP scip,
FILE *  file 
)
static

print bound section name

Parameters
scipSCIP data structure
fileoutput file, or NULL if standard output should be used

Definition at line 3281 of file reader_mps.c.

References printBoundSection(), SCIPdebugMessage, and SCIPinfoMessage().

Referenced by printBoundSection(), and printRangeSection().

static void printBoundSection ( SCIP scip,
FILE *  file,
SCIP_VAR **  vars,
int  nvars,
SCIP_VAR **  aggvars,
int  naggvars,
SCIP_VAR **  fixvars,
int  nfixvars,
SCIP_Bool  transformed,
const char **  varnames,
SCIP_HASHTABLE indicatorSlackHash,
unsigned int  maxnamelen 
)
static

output bound section

Parameters
scipSCIP data structure
fileoutput file, or NULL if standard output should be used
varsactive variables
nvarsnumber of active variables
aggvarsneeded aggregated variables
naggvarsnumber of aggregated variables
fixvarsall fixed variables
nfixvarsnumber of fixed variables
transformedTRUE iff problem is the transformed problem
varnamesarray with variable names
indicatorSlackHashhashtable containing slack variables from indicators (or NULL)
maxnamelenmaximum name length

Definition at line 3292 of file reader_mps.c.

References FALSE, MPS_MAX_VALUELEN, NULL, printBoundSectionName(), printRecord(), printStart(), SCIP_Bool, SCIP_DECL_READERCOPY(), SCIP_Real, SCIP_VARSTATUS_FIXED, SCIP_VARTYPE_BINARY, SCIPhashtableExists(), SCIPinfoMessage(), SCIPisEQ(), SCIPisFeasEQ(), SCIPisFeasZero(), SCIPisInfinity(), SCIPisZero(), SCIPsnprintf(), SCIPvarGetLbLocal(), SCIPvarGetLbOriginal(), SCIPvarGetName(), SCIPvarGetStatus(), SCIPvarGetType(), SCIPvarGetUbLocal(), SCIPvarGetUbOriginal(), and TRUE.

Referenced by printBoundSectionName(), and SCIP_DECL_READERWRITE().

static SCIP_DECL_READERCOPY ( readerCopyMps  )
static

copy method for reader plugins (called when SCIP copies plugins)

Definition at line 3551 of file reader_mps.c.

References NULL, READER_NAME, SCIP_CALL, SCIP_DECL_READERFREE(), SCIP_OKAY, SCIPincludeReaderMps(), and SCIPreaderGetName().

Referenced by printBoundSection().

static SCIP_DECL_READERFREE ( readerFreeMps  )
static

destructor of reader to free user data (called when SCIP is exiting)

Definition at line 3565 of file reader_mps.c.

References NULL, READER_NAME, SCIP_DECL_READERREAD(), SCIP_OKAY, SCIPfreeMemory, SCIPreaderGetData(), and SCIPreaderGetName().

Referenced by SCIP_DECL_READERCOPY().

static SCIP_DECL_READERREAD ( readerReadMps  )
static
static SCIP_DECL_READERWRITE ( readerWriteMps  )
static

problem writing method of reader

Definition at line 3606 of file reader_mps.c.

References checkConsnames(), checkSparseMatrixCapacity(), checkVarnames(), collectAggregatedVars(), FALSE, freeMatrix(), getLinearCoeffs(), initializeMatrix(), SCIP_QuadVarTerm::lincoef, MAX, MPS_MAX_NAMELEN, MPS_MAX_VALUELEN, NULL, printBoundSection(), printColumnSection(), printRangeSection(), printRecord(), printRhsSection(), printRowType(), printStart(), READER_NAME, SCIP_Bool, SCIP_CALL, SCIP_Longint, SCIP_OBJSENSE_MAXIMIZE, SCIP_OKAY, SCIP_Real, SCIP_SETPPCTYPE_COVERING, SCIP_SETPPCTYPE_PACKING, SCIP_SETPPCTYPE_PARTITIONING, SCIP_SUCCESS, SCIP_VARSTATUS_AGGREGATED, SCIP_VARSTATUS_FIXED, SCIP_VARTYPE_IMPLINT, SCIPallocBlockMemoryArray, SCIPallocBufferArray, SCIPblkmem(), SCIPconsGetHdlr(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPconsIsEnabled(), SCIPdebugMessage, SCIPfindConshdlr(), SCIPfreeBlockMemoryArray, SCIPfreeBufferArray, SCIPgetBilinTermsQuadratic(), SCIPgetBinaryVarIndicator(), SCIPgetCapacityKnapsack(), SCIPgetCoefsLinearVarsQuadratic(), SCIPgetLhsCoefsSOC(), SCIPgetLhsConstantSOC(), SCIPgetLhsLinear(), SCIPgetLhsOffsetsSOC(), SCIPgetLhsQuadratic(), SCIPgetLhsVarbound(), SCIPgetLhsVarsSOC(), SCIPgetLinearConsIndicator(), SCIPgetLinearVarsQuadratic(), SCIPgetNBilinTermsQuadratic(), SCIPgetNLhsVarsSOC(), SCIPgetNLinearVarsQuadratic(), SCIPgetNQuadVarTermsQuadratic(), SCIPgetNVarsAnd(), SCIPgetNVarsKnapsack(), SCIPgetNVarsLinear(), SCIPgetNVarsLogicor(), SCIPgetNVarsSetppc(), SCIPgetNVarsSOS1(), SCIPgetNVarsSOS2(), SCIPgetQuadVarTermsQuadratic(), SCIPgetResultantAnd(), SCIPgetRhsCoefSOC(), SCIPgetRhsLinear(), SCIPgetRhsOffsetSOC(), SCIPgetRhsQuadratic(), SCIPgetRhsVarbound(), SCIPgetRhsVarSOC(), SCIPgetSlackVarIndicator(), SCIPgetTypeSetppc(), SCIPgetValsLinear(), SCIPgetVarsAnd(), SCIPgetVarsKnapsack(), SCIPgetVarsLinear(), SCIPgetVarsLogicor(), SCIPgetVarsSetppc(), SCIPgetVarsSOS1(), SCIPgetVarsSOS2(), SCIPgetVarVarbound(), SCIPgetVbdcoefVarbound(), SCIPgetVbdvarVarbound(), SCIPgetWeightsKnapsack(), SCIPgetWeightsSOS1(), SCIPgetWeightsSOS2(), SCIPhashmapExists(), SCIPhashmapFree(), SCIPhashmapGetImage(), SCIPhashmapInsert(), SCIPhashtableCreate(), SCIPhashtableExists(), SCIPhashtableFree(), SCIPhashtableInsert(), SCIPincludeReaderMps(), SCIPinfinity(), SCIPinfoMessage(), SCIPisEQ(), SCIPisInfinity(), SCIPisZero(), SCIPprintOrigProblem(), SCIPprintTransProblem(), SCIPreaderGetData(), SCIPreaderGetName(), SCIPreallocBufferArray, SCIPsnprintf(), SCIPvarGetName(), SCIPvarGetNegatedVar(), SCIPvarGetNLocksDown(), SCIPvarGetNLocksUp(), SCIPvarGetObj(), SCIPvarGetStatus(), SCIPvarGetType(), SCIPvarIsNegated(), SCIPwarningMessage(), TRUE, and SCIP_QuadVarTerm::var.

Referenced by SCIP_DECL_READERREAD().