reader_blk.cpp File Reference
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include "reader_blk.h"
#include "relax_gcg.h"
#include "pub_gcgvar.h"
#include "pub_decomp.h"
#include "cons_decomp.h"
#include "scip_misc.h"

Go to the source code of this file.

Macros

#define READER_NAME   "blkreader"
 
#define READER_DESC   "file reader for structures in blk format"
 
#define READER_EXTENSION   "blk"
 
#define BLK_MAX_LINELEN   65536
 
#define BLK_MAX_PUSHEDTOKENS   2
 

Typedefs

typedef enum BlkSection BLKSECTION
 
typedef enum BlkExpType BLKEXPTYPE
 
typedef struct BlkInput BLKINPUT
 

Enumerations

enum  BlkSection {
  BLK_START, BLK_PRESOLVED, BLK_NBLOCKS, BLK_BLOCK,
  BLK_MASTERCONSS, BLK_END
}
 
enum  BlkExpType { BLK_EXP_NONE, BLK_EXP_UNSIGNED, BLK_EXP_SIGNED }
 

Functions

static void syntaxError (SCIP *scip, BLKINPUT *blkinput, const char *msg)
 
static SCIP_Bool hasError (BLKINPUT *blkinput)
 
static SCIP_Bool isDelimChar (char c)
 
static SCIP_Bool isTokenChar (char c)
 
static SCIP_Bool isValueChar (char c, char nextc, SCIP_Bool firstchar, SCIP_Bool *hasdot, BLKEXPTYPE *exptype)
 
static SCIP_Bool getNextLine (BLKINPUT *blkinput)
 
static void swapPointers (char **pointer1, char **pointer2)
 
static SCIP_Bool getNextToken (BLKINPUT *blkinput)
 
static void pushToken (BLKINPUT *blkinput)
 
static void swapTokenBuffer (BLKINPUT *blkinput)
 
static SCIP_Bool isInt (SCIP *scip, BLKINPUT *blkinput, int *value)
 
static SCIP_Bool isNewSection (SCIP *scip, BLKINPUT *blkinput)
 
static SCIP_RETCODE readStart (SCIP *scip, BLKINPUT *blkinput)
 
static SCIP_RETCODE readPresolved (SCIP *scip, BLKINPUT *blkinput)
 
static SCIP_RETCODE readNBlocks (SCIP *scip, BLKINPUT *blkinput)
 
static SCIP_RETCODE readBlock (SCIP *scip, BLKINPUT *blkinput, SCIP_READERDATA *readerdata)
 
static SCIP_RETCODE readMasterconss (SCIP *scip, BLKINPUT *blkinput, SCIP_READERDATA *readerdata)
 
static SCIP_RETCODE fillDecompStruct (SCIP *scip, BLKINPUT *blkinput, DEC_DECOMP *decomp, SCIP_READERDATA *readerdata)
 
static SCIP_RETCODE readBLKFile (SCIP *scip, SCIP_READER *reader, BLKINPUT *blkinput, const char *filename)
 
static SCIP_DECL_READERFREE (readerFreeBlk)
 
static SCIP_DECL_READERREAD (readerReadBlk)
 
static SCIP_DECL_READERWRITE (readerWriteBlk)
 
SCIP_RETCODE SCIPincludeReaderBlk (SCIP *scip)
 
SCIP_RETCODE SCIPreadBlk (SCIP *scip, const char *filename, SCIP_RESULT *result)
 

Variables

static const int NOVALUE = -1
 
static const int LINKINGVALUE = -2
 
static const char delimchars [] = " \f\n\r\t\v"
 
static const char tokenchars [] = "-+:<>="
 
static const char commentchars [] = "\\"
 

Macro Definition Documentation

#define BLK_MAX_LINELEN   65536

Definition at line 73 of file reader_blk.cpp.

Referenced by getNextLine(), getNextToken(), and SCIPreadBlk().

#define BLK_MAX_PUSHEDTOKENS   2

Definition at line 74 of file reader_blk.cpp.

Referenced by pushToken(), and SCIPreadBlk().

#define READER_DESC   "file reader for structures in blk format"

Definition at line 67 of file reader_blk.cpp.

Referenced by SCIPincludeReaderBlk().

#define READER_EXTENSION   "blk"

Definition at line 68 of file reader_blk.cpp.

Referenced by SCIPincludeReaderBlk().

#define READER_NAME   "blkreader"

Definition at line 66 of file reader_blk.cpp.

Referenced by SCIPincludeReaderBlk(), and SCIPreadBlk().

Typedef Documentation

typedef enum BlkExpType BLKEXPTYPE

Definition at line 88 of file reader_blk.cpp.

typedef struct BlkInput BLKINPUT

Definition at line 109 of file reader_blk.cpp.

typedef enum BlkSection BLKSECTION

Definition at line 81 of file reader_blk.cpp.

Enumeration Type Documentation

enum BlkExpType

exponent indicator of the a value

Enumerator
BLK_EXP_NONE 
BLK_EXP_UNSIGNED 
BLK_EXP_SIGNED 

Definition at line 84 of file reader_blk.cpp.

enum BlkSection

section in BLK File

Enumerator
BLK_START 
BLK_PRESOLVED 
BLK_NBLOCKS 
BLK_BLOCK 
BLK_MASTERCONSS 
BLK_END 

Definition at line 77 of file reader_blk.cpp.

Function Documentation

static SCIP_RETCODE fillDecompStruct ( SCIP *  scip,
BLKINPUT blkinput,
DEC_DECOMP decomp,
SCIP_READERDATA *  readerdata 
)
static
static SCIP_Bool getNextLine ( BLKINPUT blkinput)
static

reads the next line from the input file into the line buffer; skips comments; returns whether a line could be read

Parameters
blkinputBLK reading data

Definition at line 241 of file reader_blk.cpp.

References BLK_MAX_LINELEN, commentchars, BlkInput::file, BlkInput::haserror, BlkInput::linebuf, BlkInput::linenumber, and BlkInput::linepos.

Referenced by getNextToken().

static SCIP_Bool getNextToken ( BLKINPUT blkinput)
static

reads the next token from the input file into the token buffer; returns whether a token was read

Parameters
blkinputBLK reading data

Definition at line 299 of file reader_blk.cpp.

References BLK_END, BLK_EXP_NONE, BLK_MAX_LINELEN, getNextLine(), isDelimChar(), isTokenChar(), isValueChar(), BlkInput::linebuf, BlkInput::linenumber, BlkInput::linepos, BlkInput::npushedtokens, BlkInput::pushedtokens, BlkInput::section, swapPointers(), and BlkInput::token.

Referenced by isNewSection(), readBlock(), readMasterconss(), readNBlocks(), readPresolved(), and readStart().

static SCIP_Bool hasError ( BLKINPUT blkinput)
static

returns whether a syntax error was detected

Parameters
blkinputBLK reading data

Definition at line 168 of file reader_blk.cpp.

References BlkInput::haserror.

Referenced by readBLKFile().

static SCIP_Bool isDelimChar ( char  c)
static

returns whether the given character is a token delimiter

Parameters
cinput character

Definition at line 179 of file reader_blk.cpp.

References delimchars.

Referenced by getNextToken().

static SCIP_Bool isInt ( SCIP *  scip,
BLKINPUT blkinput,
int *  value 
)
static

returns whether the current token is a value

Parameters
scipSCIP data structure
blkinputBLK reading data
valuepointer to store the value (unchanged, if token is no value)

Definition at line 422 of file reader_blk.cpp.

References BlkInput::token.

Referenced by isNewSection(), readNBlocks(), and readPresolved().

static SCIP_Bool isNewSection ( SCIP *  scip,
BLKINPUT blkinput 
)
static

checks whether the current token is a section identifier, and if yes, switches to the corresponding section

Parameters
scipSCIP data structure
blkinputBLK reading data

Definition at line 450 of file reader_blk.cpp.

References BLK_BLOCK, BLK_END, BLK_MASTERCONSS, BLK_NBLOCKS, BLK_PRESOLVED, BlkInput::blocknr, getNextToken(), isInt(), BlkInput::linenumber, BlkInput::nblocks, pushToken(), BlkInput::section, swapTokenBuffer(), syntaxError(), and BlkInput::token.

Referenced by readBlock(), readMasterconss(), readNBlocks(), readPresolved(), and readStart().

static SCIP_Bool isTokenChar ( char  c)
static

returns whether the given character is a single token

Parameters
cinput character

Definition at line 188 of file reader_blk.cpp.

References tokenchars.

Referenced by getNextToken().

static SCIP_Bool isValueChar ( char  c,
char  nextc,
SCIP_Bool  firstchar,
SCIP_Bool *  hasdot,
BLKEXPTYPE exptype 
)
static

returns whether the current character is member of a value string

Parameters
cinput character
nextcnext input character
firstcharis the given character the first char of the token?
hasdotpointer to update the dot flag
exptypepointer to update the exponent type

Definition at line 197 of file reader_blk.cpp.

References BLK_EXP_NONE, BLK_EXP_SIGNED, and BLK_EXP_UNSIGNED.

Referenced by getNextToken().

static void pushToken ( BLKINPUT blkinput)
static

puts the current token on the token stack, such that it is read at the next call to getNextToken()

Parameters
blkinputBLK reading data

Definition at line 398 of file reader_blk.cpp.

References BLK_MAX_PUSHEDTOKENS, BlkInput::npushedtokens, BlkInput::pushedtokens, swapPointers(), and BlkInput::token.

Referenced by isNewSection().

static SCIP_RETCODE readBLKFile ( SCIP *  scip,
SCIP_READER *  reader,
BLKINPUT blkinput,
const char *  filename 
)
static

reads an BLK file

Bug:
GCG should be able to presolve the problem first
Parameters
scipSCIP data structure
readerreader data structure
blkinputBLK reading data
filenamename of the input file

Definition at line 909 of file reader_blk.cpp.

References BLK_BLOCK, BLK_END, BLK_MASTERCONSS, BLK_NBLOCKS, BLK_PRESOLVED, BLK_START, DECdecompCreate(), DECdecompFree(), BlkInput::file, fillDecompStruct(), hasError(), BlkInput::haspresolvesection, BlkInput::nblocks, NOVALUE, BlkInput::presolved, readBlock(), readMasterconss(), readNBlocks(), readPresolved(), readStart(), SCIPconshdlrDecompCreateSeeedpool(), SCIPconshdlrDecompCreateSeeedpoolUnpresolved(), SCIPconshdlrDecompCreateUserSeeed(), and BlkInput::section.

Referenced by SCIPreadBlk().

static SCIP_RETCODE readBlock ( SCIP *  scip,
BLKINPUT blkinput,
SCIP_READERDATA *  readerdata 
)
static

reads a block section

Parameters
scipSCIP data structure
blkinputBLK reading data
readerdatareader data

Definition at line 637 of file reader_blk.cpp.

References BlkInput::blocknr, getNextToken(), isNewSection(), LINKINGVALUE, NOVALUE, SCIPconshdlrDecompUserSeeedSetVarToBlock(), SCIPconshdlrDecompUserSeeedSetVarToLinking(), syntaxError(), and BlkInput::token.

Referenced by readBLKFile().

static SCIP_RETCODE readMasterconss ( SCIP *  scip,
BLKINPUT blkinput,
SCIP_READERDATA *  readerdata 
)
static

reads the masterconss section

Parameters
scipSCIP data structure
blkinputBLK reading data
readerdatareader data

Definition at line 716 of file reader_blk.cpp.

References getNextToken(), isNewSection(), BlkInput::nblocks, NOVALUE, SCIPconshdlrDecompUserSeeedSetConsToMaster(), syntaxError(), and BlkInput::token.

Referenced by readBLKFile().

static SCIP_RETCODE readNBlocks ( SCIP *  scip,
BLKINPUT blkinput 
)
static

reads the nblocks section

Parameters
scipSCIP data structure
blkinputBLK reading data

Definition at line 597 of file reader_blk.cpp.

References getNextToken(), isInt(), isNewSection(), BlkInput::nblocks, NOVALUE, SCIPconshdlrDecompUserSeeedSetnumberOfBlocks(), and syntaxError().

Referenced by readBLKFile().

static SCIP_RETCODE readPresolved ( SCIP *  scip,
BLKINPUT blkinput 
)
static

reads the presolved section

Parameters
scipSCIP data structure
blkinputDEC reading data

Definition at line 561 of file reader_blk.cpp.

References getNextToken(), BlkInput::haspresolvesection, isInt(), isNewSection(), BlkInput::presolved, and syntaxError().

Referenced by readBLKFile().

static SCIP_RETCODE readStart ( SCIP *  scip,
BLKINPUT blkinput 
)
static

reads the header of the file

Parameters
scipSCIP data structure
blkinputBLK reading data

Definition at line 540 of file reader_blk.cpp.

References getNextToken(), and isNewSection().

Referenced by readBLKFile().

static SCIP_DECL_READERFREE ( readerFreeBlk  )
static

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

Definition at line 1109 of file reader_blk.cpp.

static SCIP_DECL_READERREAD ( readerReadBlk  )
static

problem reading method of reader

Definition at line 1124 of file reader_blk.cpp.

References SCIPreadBlk().

static SCIP_DECL_READERWRITE ( readerWriteBlk  )
static

problem writing method of reader

Definition at line 1140 of file reader_blk.cpp.

SCIP_RETCODE SCIPincludeReaderBlk ( SCIP *  scip)

includes the blk file reader in SCIP

Parameters
scipSCIP data structure

Definition at line 1150 of file reader_blk.cpp.

References READER_DESC, READER_EXTENSION, and READER_NAME.

Referenced by SCIPincludeGcgPlugins().

SCIP_RETCODE SCIPreadBlk ( SCIP *  scip,
const char *  filename,
SCIP_RESULT *  result 
)
Parameters
scipSCIP data structure
filenamefull path and name of file to read, or NULL if stdin should be used
resultpointer to store the result of the file reading call

Definition at line 1168 of file reader_blk.cpp.

References BLK_MAX_LINELEN, BLK_MAX_PUSHEDTOKENS, BLK_START, BlkInput::blocknr, BlkInput::file, BlkInput::haserror, BlkInput::haspresolvesection, BlkInput::linebuf, BlkInput::linenumber, BlkInput::linepos, BlkInput::nblocks, BlkInput::npushedtokens, BlkInput::presolved, BlkInput::pushedtokens, readBLKFile(), READER_NAME, BlkInput::section, BlkInput::token, and BlkInput::tokenbuf.

Referenced by SCIP_DECL_READERREAD().

static void swapPointers ( char **  pointer1,
char **  pointer2 
)
static

swaps the addresses of two pointers

Parameters
pointer1first pointer
pointer2second pointer

Definition at line 285 of file reader_blk.cpp.

Referenced by getNextToken(), pushToken(), and swapTokenBuffer().

static void swapTokenBuffer ( BLKINPUT blkinput)
static

swaps the current token with the token buffer

Parameters
blkinputBLK reading data

Definition at line 411 of file reader_blk.cpp.

References swapPointers(), BlkInput::token, and BlkInput::tokenbuf.

Referenced by isNewSection().

static void syntaxError ( SCIP *  scip,
BLKINPUT blkinput,
const char *  msg 
)
static

issues an error message and marks the BLK data to have errors

Parameters
scipSCIP data structure
blkinputBLK reading data
msgerror message

Definition at line 140 of file reader_blk.cpp.

References BLK_END, BlkInput::haserror, BlkInput::linebuf, BlkInput::linenumber, BlkInput::linepos, BlkInput::section, and BlkInput::token.

Referenced by isNewSection(), readBlock(), readMasterconss(), readNBlocks(), and readPresolved().

Variable Documentation

const char commentchars[] = "\\"
static

Definition at line 129 of file reader_blk.cpp.

Referenced by getNextLine(), and gcg::Seeed::writeAsDec().

const char delimchars[] = " \f\n\r\t\v"
static

Definition at line 127 of file reader_blk.cpp.

Referenced by isDelimChar().

const int LINKINGVALUE = -2
static

Definition at line 126 of file reader_blk.cpp.

Referenced by fillDecompStruct(), and readBlock().

const int NOVALUE = -1
static
const char tokenchars[] = "-+:<>="
static

Definition at line 128 of file reader_blk.cpp.

Referenced by isTokenChar().