Scippy

SCIP

Solving Constraint Integer Programs

reader_diff.c File Reference

Detailed Description

DIFF file reader.

Author
Jakob Witzig

Definition in file reader_diff.c.

#include <ctype.h>
#include "scip/pub_fileio.h"
#include "scip/pub_message.h"
#include "scip/pub_misc.h"
#include "scip/pub_reader.h"
#include "scip/pub_var.h"
#include "scip/reader_diff.h"
#include "scip/scip_general.h"
#include "scip/scip_mem.h"
#include "scip/scip_message.h"
#include "scip/scip_numerics.h"
#include "scip/scip_prob.h"
#include "scip/scip_reader.h"
#include "scip/scip_solve.h"
#include <stdlib.h>
#include <string.h>
#include <strings.h>

Go to the source code of this file.

Macros

#define READER_NAME   "diffreader"
 
#define READER_DESC   "file reader for changes in the LP file"
 
#define READER_EXTENSION   "diff"
 
#define LP_MAX_LINELEN   65536
 
#define LP_MAX_PUSHEDTOKENS   2
 
#define LP_INIT_COEFSSIZE   8192
 

Typedefs

typedef enum LpSection LPSECTION
 
typedef enum LpExpType LPEXPTYPE
 
typedef enum LpSense LPSENSE
 
typedef struct LpInput LPINPUT
 

Enumerations

enum  LpSection {
  LP_START,
  LP_OBJECTIVE,
  LP_END,
  LP_START,
  LP_OBJECTIVE,
  LP_CONSTRAINTS,
  LP_BOUNDS,
  LP_GENERALS,
  LP_BINARIES,
  LP_SEMICONTINUOUS,
  LP_SOS,
  LP_END
}
 
enum  LpExpType {
  LP_EXP_NONE,
  LP_EXP_UNSIGNED,
  LP_EXP_SIGNED,
  LP_EXP_NONE,
  LP_EXP_UNSIGNED,
  LP_EXP_SIGNED
}
 
enum  LpSense {
  LP_SENSE_LE,
  LP_SENSE_GE,
  LP_SENSE_EQ,
  LP_SENSE_NOTHING,
  LP_SENSE_LE,
  LP_SENSE_GE,
  LP_SENSE_EQ
}
 

Functions

static void syntaxError (SCIP *scip, LPINPUT *lpinput, const char *msg)
 
static SCIP_Bool hasError (LPINPUT *lpinput)
 
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, LPEXPTYPE *exptype)
 
static SCIP_Bool getNextLine (SCIP *scip, LPINPUT *lpinput)
 
static void swapPointers (char **pointer1, char **pointer2)
 
static SCIP_Bool getNextToken (SCIP *scip, LPINPUT *lpinput)
 
static void pushToken (LPINPUT *lpinput)
 
static void pushBufferToken (LPINPUT *lpinput)
 
static void swapTokenBuffer (LPINPUT *lpinput)
 
static SCIP_Bool isNewSection (SCIP *scip, LPINPUT *lpinput)
 
static SCIP_Bool isSign (LPINPUT *lpinput, int *sign)
 
static SCIP_Bool isValue (SCIP *scip, LPINPUT *lpinput, SCIP_Real *value)
 
static SCIP_Bool isSense (LPINPUT *lpinput, LPSENSE *sense)
 
static SCIP_RETCODE getVariable (SCIP *scip, char *name, SCIP_VAR **var)
 
static SCIP_RETCODE readStart (SCIP *scip, LPINPUT *lpinput)
 
static SCIP_RETCODE readCoefficients (SCIP *scip, LPINPUT *lpinput, SCIP_Bool isobjective, char *name, int *coefssize, SCIP_VAR ***vars, SCIP_Real **coefs, int *ncoefs, SCIP_Bool *newsection)
 
static SCIP_RETCODE readObjective (SCIP *scip, LPINPUT *lpinput)
 
static SCIP_RETCODE readDiffFile (SCIP *scip, LPINPUT *lpinput, const char *filename)
 
static SCIP_DECL_READERCOPY (readerCopyDiff)
 
static SCIP_DECL_READERFREE (readerFreeDiff)
 
static SCIP_DECL_READERREAD (readerReadDiff)
 
SCIP_RETCODE SCIPincludeReaderDiff (SCIP *scip)
 
SCIP_RETCODE SCIPreadDiff (SCIP *scip, SCIP_READER *reader, const char *filename, SCIP_RESULT *result)
 

Variables

static const char commentchars [] = "\\"
 

Macro Definition Documentation

◆ READER_NAME

#define READER_NAME   "diffreader"

Definition at line 44 of file reader_diff.c.

Referenced by SCIP_DECL_READERCOPY(), and SCIPincludeReaderDiff().

◆ READER_DESC

#define READER_DESC   "file reader for changes in the LP file"

Definition at line 45 of file reader_diff.c.

Referenced by SCIPincludeReaderDiff().

◆ READER_EXTENSION

#define READER_EXTENSION   "diff"

Definition at line 46 of file reader_diff.c.

Referenced by SCIPincludeReaderDiff().

◆ LP_MAX_LINELEN

#define LP_MAX_LINELEN   65536

◆ LP_MAX_PUSHEDTOKENS

#define LP_MAX_PUSHEDTOKENS   2

Definition at line 52 of file reader_diff.c.

Referenced by pushBufferToken(), pushToken(), and SCIPreadDiff().

◆ LP_INIT_COEFSSIZE

#define LP_INIT_COEFSSIZE   8192

Definition at line 53 of file reader_diff.c.

Referenced by readCoefficients().

Typedef Documentation

◆ LPSECTION

typedef enum LpSection LPSECTION

Definition at line 60 of file reader_diff.c.

◆ LPEXPTYPE

typedef enum LpExpType LPEXPTYPE

Definition at line 66 of file reader_diff.c.

◆ LPSENSE

typedef enum LpSense LPSENSE

Definition at line 72 of file reader_diff.c.

◆ LPINPUT

typedef struct LpInput LPINPUT

Definition at line 93 of file reader_diff.c.

Enumeration Type Documentation

◆ LpSection

enum LpSection

Section in LP File

Enumerator
LP_START 
LP_OBJECTIVE 
LP_END 
LP_START 
LP_OBJECTIVE 
LP_CONSTRAINTS 
LP_BOUNDS 
LP_GENERALS 
LP_BINARIES 
LP_SEMICONTINUOUS 
LP_SOS 
LP_END 

Definition at line 56 of file reader_diff.c.

◆ LpExpType

enum LpExpType
Enumerator
LP_EXP_NONE 
LP_EXP_UNSIGNED 
LP_EXP_SIGNED 
LP_EXP_NONE 
LP_EXP_UNSIGNED 
LP_EXP_SIGNED 

Definition at line 62 of file reader_diff.c.

◆ LpSense

enum LpSense
Enumerator
LP_SENSE_LE 
LP_SENSE_GE 
LP_SENSE_EQ 
LP_SENSE_NOTHING 
LP_SENSE_LE 
LP_SENSE_GE 
LP_SENSE_EQ 

Definition at line 68 of file reader_diff.c.

Function Documentation

◆ syntaxError()

static void syntaxError ( SCIP scip,
LPINPUT lpinput,
const char *  msg 
)
static

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

Parameters
scipSCIP data structure
lpinputLP reading data
msgerror message

Definition at line 104 of file reader_diff.c.

References LP_END, NULL, SCIP_VERBLEVEL_MINIMAL, SCIPerrorMessage, SCIPsnprintf(), SCIPverbMessage(), and TRUE.

Referenced by readCoefficients().

◆ hasError()

static SCIP_Bool hasError ( LPINPUT lpinput)
static

returns whether a syntax error was detected

Parameters
lpinputLP reading data

Definition at line 131 of file reader_diff.c.

References NULL.

Referenced by readDiffFile().

◆ isDelimChar()

static SCIP_Bool isDelimChar ( char  c)
static

returns whether the given character is a token delimiter

Parameters
cinput character

Definition at line 142 of file reader_diff.c.

References FALSE, and TRUE.

Referenced by getNextToken().

◆ isTokenChar()

static SCIP_Bool isTokenChar ( char  c)
static

returns whether the given character is a single token

Parameters
cinput character

Definition at line 163 of file reader_diff.c.

References FALSE, and TRUE.

Referenced by getNextToken().

◆ isValueChar()

static SCIP_Bool isValueChar ( char  c,
char  nextc,
SCIP_Bool  firstchar,
SCIP_Bool hasdot,
LPEXPTYPE 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 187 of file reader_diff.c.

References FALSE, LP_EXP_NONE, LP_EXP_SIGNED, LP_EXP_UNSIGNED, NULL, and TRUE.

Referenced by getNextToken().

◆ getNextLine()

static SCIP_Bool getNextLine ( SCIP scip,
LPINPUT lpinput 
)
static

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

Parameters
scipSCIP data structure
lpinputLP reading data

Definition at line 231 of file reader_diff.c.

References BMSclearMemoryArray, commentchars, FALSE, LP_MAX_LINELEN, NULL, SCIPdebugMsg, SCIPfgets(), SCIPfseek(), SCIPwarningMessage(), and TRUE.

Referenced by getNextToken().

◆ swapPointers()

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

swaps the addresses of two pointers

Parameters
pointer1first pointer
pointer2second pointer

Definition at line 322 of file reader_diff.c.

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

◆ getNextToken()

static SCIP_Bool getNextToken ( SCIP scip,
LPINPUT lpinput 
)
static

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

Parameters
scipSCIP data structure
lpinputLP reading data

Definition at line 336 of file reader_diff.c.

References FALSE, getNextLine(), isDelimChar(), isTokenChar(), isValueChar(), LP_END, LP_EXP_NONE, LP_MAX_LINELEN, NULL, SCIP_Bool, SCIPdebugMsg, swapPointers(), and TRUE.

Referenced by isNewSection(), readCoefficients(), and readStart().

◆ pushToken()

static void pushToken ( LPINPUT lpinput)
static

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

Parameters
lpinputLP reading data

Definition at line 441 of file reader_diff.c.

References LP_MAX_PUSHEDTOKENS, NULL, and swapPointers().

Referenced by isNewSection(), and readCoefficients().

◆ pushBufferToken()

static void pushBufferToken ( LPINPUT lpinput)
static

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

Parameters
lpinputLP reading data

Definition at line 454 of file reader_diff.c.

References LP_MAX_PUSHEDTOKENS, NULL, and swapPointers().

Referenced by readCoefficients().

◆ swapTokenBuffer()

static void swapTokenBuffer ( LPINPUT lpinput)
static

swaps the current token with the token buffer

Parameters
lpinputLP reading data

Definition at line 467 of file reader_diff.c.

References NULL, and swapPointers().

Referenced by isNewSection(), and readCoefficients().

◆ isNewSection()

static SCIP_Bool isNewSection ( SCIP scip,
LPINPUT lpinput 
)
static

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

Parameters
scipSCIP data structure
lpinputLP reading data

Definition at line 478 of file reader_diff.c.

References FALSE, getNextToken(), LP_END, LP_MAX_LINELEN, LP_OBJECTIVE, NULL, pushToken(), SCIP_Bool, SCIP_OBJSENSE_MAXIMIZE, SCIP_OBJSENSE_MINIMIZE, SCIPdebugMsg, swapTokenBuffer(), and TRUE.

Referenced by readCoefficients(), and readStart().

◆ isSign()

static SCIP_Bool isSign ( LPINPUT lpinput,
int *  sign 
)
static

returns whether the current token is a sign

Parameters
lpinputLP reading data
signpointer to update the sign

Definition at line 556 of file reader_diff.c.

References FALSE, NULL, and TRUE.

Referenced by readCoefficients().

◆ isValue()

static SCIP_Bool isValue ( SCIP scip,
LPINPUT lpinput,
SCIP_Real value 
)
static

returns whether the current token is a value

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

Definition at line 581 of file reader_diff.c.

References FALSE, NULL, SCIPinfinity(), and TRUE.

Referenced by readCoefficients().

◆ isSense()

static SCIP_Bool isSense ( LPINPUT lpinput,
LPSENSE sense 
)
static

returns whether the current token is an equation sense

Parameters
lpinputLP reading data
sensepointer to store the equation sense, or NULL

Definition at line 613 of file reader_diff.c.

References FALSE, LP_SENSE_EQ, LP_SENSE_GE, LP_SENSE_LE, NULL, and TRUE.

Referenced by readCoefficients().

◆ getVariable()

static SCIP_RETCODE getVariable ( SCIP scip,
char *  name,
SCIP_VAR **  var 
)
static

returns the variable with the given name, or creates a new variable if it does not exist

Parameters
scipSCIP data structure
namename of the variable
varpointer to store the variable

Definition at line 644 of file reader_diff.c.

References NULL, SCIP_OKAY, SCIP_READERROR, and SCIPfindVar().

Referenced by readCoefficients().

◆ readStart()

static SCIP_RETCODE readStart ( SCIP scip,
LPINPUT lpinput 
)
static

reads the header of the file

Parameters
scipSCIP data structure
lpinputLP reading data

Definition at line 663 of file reader_diff.c.

References getNextToken(), isNewSection(), NULL, and SCIP_OKAY.

Referenced by readDiffFile().

◆ readCoefficients()

static SCIP_RETCODE readCoefficients ( SCIP scip,
LPINPUT lpinput,
SCIP_Bool  isobjective,
char *  name,
int *  coefssize,
SCIP_VAR ***  vars,
SCIP_Real **  coefs,
int *  ncoefs,
SCIP_Bool newsection 
)
static

reads an objective or constraint with name and coefficients

Parameters
scipSCIP data structure
lpinputLP reading data
isobjectiveindicates whether we are currently reading the coefficients of the objective
namepointer to store the name of the line; must be at least of size LP_MAX_LINELEN
coefssizesize of vars and coefs arrays
varspointer to store the array with variables (must be freed by caller)
coefspointer to store the array with coefficients (must be freed by caller)
ncoefspointer to store the number of coefficients
newsectionpointer to store whether a new section was encountered

Definition at line 684 of file reader_diff.c.

References FALSE, getNextToken(), getVariable(), isNewSection(), isSense(), isSign(), isValue(), LP_INIT_COEFSSIZE, LP_MAX_LINELEN, MAX, NULL, pushBufferToken(), pushToken(), SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_READERROR, SCIP_Real, SCIPallocBlockMemoryArray, SCIPdebugMsg, SCIPisZero(), SCIPmemccpy(), SCIPreallocBlockMemoryArray, SCIPvarGetName(), SCIPwarningMessage(), swapTokenBuffer(), syntaxError(), and TRUE.

Referenced by readObjective().

◆ readObjective()

static SCIP_RETCODE readObjective ( SCIP scip,
LPINPUT lpinput 
)
static

reads the objective section

Parameters
scipSCIP data structure
lpinputLP reading data

Definition at line 884 of file reader_diff.c.

References LP_MAX_LINELEN, NULL, readCoefficients(), SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPchgReoptObjective(), SCIPfreeBlockMemoryArrayNull, and TRUE.

Referenced by readDiffFile().

◆ readDiffFile()

static SCIP_RETCODE readDiffFile ( SCIP scip,
LPINPUT lpinput,
const char *  filename 
)
static

reads a diff file

Parameters
scipSCIP data structure
lpinputLP reading data
filenamename of the input file

Definition at line 913 of file reader_diff.c.

References hasError(), LP_END, LP_OBJECTIVE, LP_START, NULL, readObjective(), readStart(), SCIP_CALL, SCIP_INVALIDDATA, SCIP_NOFILE, SCIP_OKAY, SCIP_STAGE_PROBLEM, SCIPerrorMessage, SCIPfclose(), SCIPfopen(), SCIPfreeReoptSolve(), SCIPfreeTransform(), SCIPgetStage(), SCIPisReoptEnabled(), and SCIPprintSysError().

Referenced by SCIPreadDiff().

◆ SCIP_DECL_READERCOPY()

static SCIP_DECL_READERCOPY ( readerCopyDiff  )
static

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

Definition at line 973 of file reader_diff.c.

References NULL, READER_NAME, SCIP_CALL, SCIP_OKAY, SCIPincludeReaderDiff(), and SCIPreaderGetName().

◆ SCIP_DECL_READERFREE()

static SCIP_DECL_READERFREE ( readerFreeDiff  )
static

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

Definition at line 987 of file reader_diff.c.

References SCIP_OKAY.

◆ SCIP_DECL_READERREAD()

static SCIP_DECL_READERREAD ( readerReadDiff  )
static

problem reading method of reader

Definition at line 994 of file reader_diff.c.

References SCIP_CALL, SCIP_OKAY, and SCIPreadDiff().

Variable Documentation

◆ commentchars

const char commentchars[] = "\\"
static

Definition at line 95 of file reader_diff.c.

Referenced by getNextLine().