Scippy

SCIP

Solving Constraint Integer Programs

ReaderMOP.cpp File Reference

Detailed Description

Class implementing .mop file reader.

Author
Sebastian Schenker
Timo Strunk

Adaption of SCIP MPS reader towards MOP format with multiple objectives. The input file has to follow some simple conventions

  • It has to contain a problem in MPS format
  • The file extension must be .mop
  • Every row marked N is treated as an objective

Definition in file ReaderMOP.cpp.

#include "ReaderMOP.h"
#include <iostream>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "objscip/objscip.h"
#include "prob_data_objectives.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_sos1.h"
#include "scip/cons_sos2.h"
#include "scip/cons_nonlinear.h"
#include "scip/cons_bounddisjunction.h"
#include "scip/pub_misc.h"

Go to the source code of this file.

Macros

#define MPS_MAX_LINELEN   1024
 global define More...
 
#define MPS_MAX_NAMELEN   256
 global define More...
 
#define MPS_MAX_VALUELEN   26
 global define More...
 
#define MPS_MAX_FIELDLEN   20
 global define More...
 
#define PATCH_CHAR   '_'
 global define More...
 
#define BLANK   ' '
 global define More...
 

Typedefs

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

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,
  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 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 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 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 readRowsMop (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readColsMop (MPSINPUT *mpsi, SCIP *scip)
 
static SCIP_RETCODE readMOP (SCIP *scip, const char *filename)
 
 SCIP_DECL_READERFREE (ReaderMOP::scip_free)
 
 SCIP_DECL_READERREAD (ReaderMOP::scip_read)
 

Macro Definition Documentation

◆ MPS_MAX_LINELEN

#define MPS_MAX_LINELEN   1024

global define

Definition at line 50 of file ReaderMOP.cpp.

Referenced by mpsinputReadLine().

◆ MPS_MAX_NAMELEN

#define MPS_MAX_NAMELEN   256

◆ MPS_MAX_VALUELEN

#define MPS_MAX_VALUELEN   26

global define

Definition at line 52 of file ReaderMOP.cpp.

◆ MPS_MAX_FIELDLEN

#define MPS_MAX_FIELDLEN   20

global define

Definition at line 53 of file ReaderMOP.cpp.

◆ PATCH_CHAR

#define PATCH_CHAR   '_'

global define

Definition at line 55 of file ReaderMOP.cpp.

Referenced by patchField().

◆ BLANK

#define BLANK   ' '

global define

Definition at line 56 of file ReaderMOP.cpp.

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

Typedef Documentation

◆ MPSSECTION

typedef enum MpsSection MPSSECTION

typedef

Definition at line 78 of file ReaderMOP.cpp.

◆ MPSINPUT

typedef struct MpsInput MPSINPUT

typedef

Definition at line 100 of file ReaderMOP.cpp.

◆ SPARSEMATRIX

typedef struct SparseMatrix SPARSEMATRIX

typedef

Definition at line 111 of file ReaderMOP.cpp.

Enumeration Type Documentation

◆ MpsSection

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 
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 59 of file ReaderMOP.cpp.

Function Documentation

◆ mpsinputCreate()

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 115 of file ReaderMOP.cpp.

References FALSE, MPS_NAME, NULL, SCIP_CALL, SCIP_OBJSENSE_MINIMIZE, SCIP_OKAY, and SCIPallocBlockMemory().

Referenced by readMOP().

◆ mpsinputFree()

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

free the mps input structure

Parameters
scipSCIP data structure
mpsimps input structure

Definition at line 148 of file ReaderMOP.cpp.

References SCIPfreeBlockMemory.

Referenced by readMOP().

◆ mpsinputSection()

static MPSSECTION mpsinputSection ( const MPSINPUT mpsi)
static

returns the current section

Parameters
mpsimps input structure

Definition at line 158 of file ReaderMOP.cpp.

References NULL.

Referenced by readMOP(), and readRowsMop().

◆ mpsinputField0()

static const char* mpsinputField0 ( const MPSINPUT mpsi)
static

return the current value of field 0

Parameters
mpsimps input structure

Definition at line 169 of file ReaderMOP.cpp.

References NULL.

Referenced by readBounds(), readColsMop(), readIndicators(), readName(), readObjname(), readObjsen(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRowsMop(), and readSOS().

◆ mpsinputField1()

static const char* mpsinputField1 ( const MPSINPUT mpsi)
static

return the current value of field 1

Parameters
mpsimps input structure

Definition at line 180 of file ReaderMOP.cpp.

References NULL.

Referenced by readBounds(), readColsMop(), readIndicators(), readName(), readObjname(), readObjsen(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRowsMop(), and readSOS().

◆ mpsinputField2()

static const char* mpsinputField2 ( const MPSINPUT mpsi)
static

return the current value of field 2

Parameters
mpsimps input structure

Definition at line 191 of file ReaderMOP.cpp.

References NULL.

Referenced by readBounds(), readColsMop(), readIndicators(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRowsMop(), and readSOS().

◆ mpsinputField3()

static const char* mpsinputField3 ( const MPSINPUT mpsi)
static

return the current value of field 3

Parameters
mpsimps input structure

Definition at line 202 of file ReaderMOP.cpp.

References NULL.

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

◆ mpsinputField4()

static const char* mpsinputField4 ( const MPSINPUT mpsi)
static

return the current value of field 4

Parameters
mpsimps input structure

Definition at line 213 of file ReaderMOP.cpp.

References NULL.

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

◆ mpsinputField5()

static const char* mpsinputField5 ( const MPSINPUT mpsi)
static

return the current value of field 5

Parameters
mpsimps input structure

Definition at line 224 of file ReaderMOP.cpp.

References NULL.

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

◆ mpsinputObjsense()

static SCIP_OBJSENSE mpsinputObjsense ( const MPSINPUT mpsi)
static

returns the objective sense

Parameters
mpsimps input structure

Definition at line 235 of file ReaderMOP.cpp.

References NULL.

Referenced by readMOP(), and readQMatrix().

◆ mpsinputHasError()

static SCIP_Bool mpsinputHasError ( const MPSINPUT mpsi)
static

returns if an error was detected

Parameters
mpsimps input structure

Definition at line 246 of file ReaderMOP.cpp.

References NULL.

Referenced by readMOP().

◆ mpsinputIsInteger()

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 257 of file ReaderMOP.cpp.

References NULL.

Referenced by readColsMop().

◆ mpsinputSetSection()

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 268 of file ReaderMOP.cpp.

References NULL.

Referenced by readBounds(), readColsMop(), readIndicators(), readName(), readObjname(), readObjsen(), readQCMatrix(), readQMatrix(), readRanges(), readRhs(), readRowsMop(), and readSOS().

◆ mpsinputSetProbname()

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 280 of file ReaderMOP.cpp.

References MPS_MAX_NAMELEN, NULL, and SCIPmemccpy().

Referenced by readName().

◆ mpsinputSetObjname()

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 294 of file ReaderMOP.cpp.

References MPS_MAX_NAMELEN, NULL, and SCIPmemccpy().

Referenced by readObjname().

◆ mpsinputSetObjsense()

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 308 of file ReaderMOP.cpp.

References NULL.

Referenced by readObjsen().

◆ mpsinputSyntaxerror()

static void mpsinputSyntaxerror ( MPSINPUT mpsi)
static

◆ mpsinputEntryIgnored()

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 332 of file ReaderMOP.cpp.

References NULL, and SCIPverbMessage().

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

◆ clearFrom()

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 354 of file ReaderMOP.cpp.

References BLANK.

Referenced by mpsinputReadLine().

◆ patchField()

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 368 of file ReaderMOP.cpp.

References BLANK, and PATCH_CHAR.

Referenced by mpsinputReadLine().

◆ mpsinputReadLine()

static SCIP_Bool mpsinputReadLine ( MPSINPUT mpsi)
static

◆ mpsinputInsertName()

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 565 of file ReaderMOP.cpp.

References NULL.

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

◆ readName()

static SCIP_RETCODE readName ( SCIP scip,
MPSINPUT mpsi 
)
static

Process NAME section.

Parameters
scipSCIP data structure
mpsimps input structure

Definition at line 589 of file ReaderMOP.cpp.

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

Referenced by readMOP().

◆ readObjsen()

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 636 of file ReaderMOP.cpp.

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

Referenced by readMOP().

◆ readObjname()

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 688 of file ReaderMOP.cpp.

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

Referenced by readMOP().

◆ readRhs()

◆ readRanges()

◆ readBounds()

◆ readSOS()

static SCIP_RETCODE readSOS ( MPSINPUT mpsi,
SCIP scip 
)
static

◆ readQMatrix()

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 1449 of file ReaderMOP.cpp.

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

Referenced by readMOP().

◆ readQCMatrix()

◆ readIndicators()

◆ readRowsMop()

◆ readColsMop()

◆ readMOP()

◆ SCIP_DECL_READERFREE()

SCIP_DECL_READERFREE ( ReaderMOP::scip_free  )

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

Definition at line 2309 of file ReaderMOP.cpp.

References SCIP_OKAY.

◆ SCIP_DECL_READERREAD()

SCIP_DECL_READERREAD ( ReaderMOP::scip_read  )

problem reading method of reader

Definition at line 2314 of file ReaderMOP.cpp.

References NULL, readMOP(), SCIP_CALL, SCIP_NOFILE, SCIP_OKAY, SCIP_READERROR, and SCIP_SUCCESS.