26 #if defined(_WIN32) || defined(_WIN64) 34 #define READER_NAME "diffreader" 35 #define READER_DESC "file reader for changes in the LP file" 36 #define READER_EXTENSION "diff" 41 #define LP_MAX_LINELEN 65536 42 #define LP_MAX_PUSHEDTOKENS 2 43 #define LP_INIT_COEFSSIZE 8192 102 assert(lpinput !=
NULL);
104 SCIPerrorMessage(
"Syntax error in line %d ('%s'): %s \n", lpinput->linenumber, lpinput->token, msg);
105 if( lpinput->linebuf[strlen(lpinput->linebuf)-1] ==
'\n' )
113 (void)
SCIPsnprintf(formatstr, 256,
" %%%ds\n", lpinput->linepos);
115 lpinput->section =
LP_END;
116 lpinput->haserror =
TRUE;
125 assert(lpinput !=
NULL);
127 return lpinput->haserror;
185 assert(hasdot !=
NULL);
186 assert(exptype !=
NULL);
188 if( isdigit((
unsigned char)c) )
190 else if( (*exptype ==
LP_EXP_NONE) && !(*hasdot) && (c ==
'.') && isdigit((
unsigned char)nextc) )
195 else if( !firstchar && (*exptype ==
LP_EXP_NONE) && (c ==
'e' || c ==
'E') )
197 if( nextc ==
'+' || nextc ==
'-' )
202 else if( isdigit((
unsigned char)nextc) )
208 else if( (*exptype ==
LP_EXP_SIGNED) && (c ==
'+' || c ==
'-') )
228 assert(lpinput !=
NULL);
231 if( !lpinput->endline && lpinput->comment )
238 (void)
SCIPfgets(lpinput->linebuf, (
int)
sizeof(lpinput->linebuf), lpinput->file);
242 lpinput->comment =
FALSE;
243 lpinput->endline =
TRUE;
247 lpinput->linepos = 0;
250 if(
SCIPfgets(lpinput->linebuf, (
int)
sizeof(lpinput->linebuf), lpinput->file) ==
NULL )
258 lpinput->linenumber++;
266 lpinput->endline =
FALSE;
267 last = strrchr(lpinput->linebuf,
' ');
271 SCIPwarningMessage(scip,
"we read %d characters from the file; this might indicate a corrupted input file!",
278 SCIPfseek(lpinput->file, -(
long) strlen(last) - 1, SEEK_CUR);
279 SCIPdebugMsg(scip,
"correct buffer, reread the last %ld characters\n", (
long) strlen(last) + 1);
286 lpinput->endline =
TRUE;
289 lpinput->comment =
FALSE;
296 commentstart = strchr(lpinput->linebuf,
commentchars[i]);
297 if( commentstart !=
NULL )
299 *commentstart =
'\0';
300 *(commentstart+1) =
'\0';
302 lpinput->comment =
TRUE;
320 *pointer1 = *pointer2;
336 assert(lpinput !=
NULL);
340 if( lpinput->npushedtokens > 0 )
342 swapPointers(&lpinput->token, &lpinput->pushedtokens[lpinput->npushedtokens-1]);
343 lpinput->npushedtokens--;
345 SCIPdebugMsg(scip,
"(line %d) read token again: '%s'\n", lpinput->linenumber, lpinput->token);
350 buf = lpinput->linebuf;
353 if( buf[lpinput->linepos] ==
'\0' )
357 lpinput->section =
LP_END;
358 SCIPdebugMsg(scip,
"(line %d) end of file\n", lpinput->linenumber);
361 assert(lpinput->linepos == 0);
372 if(
isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1],
TRUE, &hasdot, &exptype) )
380 lpinput->token[tokenlen] = buf[lpinput->linepos];
384 while(
isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1],
FALSE, &hasdot, &exptype) );
393 lpinput->token[tokenlen] = buf[lpinput->linepos];
396 if( tokenlen == 1 &&
isTokenChar(lpinput->token[0]) )
405 if( tokenlen >= 1 && lpinput->token[tokenlen-1] ==
'^' && buf[lpinput->linepos] ==
'2' )
410 && (lpinput->token[tokenlen-1] ==
'<' || lpinput->token[tokenlen-1] ==
'>' || lpinput->token[tokenlen-1] ==
'=')
411 && buf[lpinput->linepos] ==
'=' )
415 else if( lpinput->token[tokenlen-1] ==
'=' && (buf[lpinput->linepos] ==
'<' || buf[lpinput->linepos] ==
'>') )
417 lpinput->token[tokenlen-1] = buf[lpinput->linepos];
422 lpinput->token[tokenlen] =
'\0';
424 SCIPdebugMsg(scip,
"(line %d) read token: '%s'\n", lpinput->linenumber, lpinput->token);
435 assert(lpinput !=
NULL);
438 swapPointers(&lpinput->pushedtokens[lpinput->npushedtokens], &lpinput->token);
439 lpinput->npushedtokens++;
448 assert(lpinput !=
NULL);
451 swapPointers(&lpinput->pushedtokens[lpinput->npushedtokens], &lpinput->tokenbuf);
452 lpinput->npushedtokens++;
461 assert(lpinput !=
NULL);
476 assert(lpinput !=
NULL);
485 iscolon = (*lpinput->token ==
':');
496 len = strlen(lpinput->token);
500 if( len > 1 && (len < 9 || len == 15) )
505 while( lpinput->token[c] !=
'\0' )
507 token[c] = toupper(lpinput->token[c]);
513 if( (len == 3 && strcmp(token,
"MIN") == 0)
514 || (len == 7 && strcmp(token,
"MINIMUM") == 0)
515 || (len == 8 && strcmp(token,
"MINIMIZE") == 0) )
517 SCIPdebugMsg(scip,
"(line %d) new section: OBJECTIVE\n", lpinput->linenumber);
523 if( (len == 3 && strcmp(token,
"MAX") == 0)
524 || (len == 7 && strcmp(token,
"MAXIMUM") == 0)
525 || (len == 8 && strcmp(token,
"MAXIMIZE") == 0) )
527 SCIPdebugMsg(scip,
"(line %d) new section: OBJECTIVE\n", lpinput->linenumber);
533 if( len == 3 && strcmp(token,
"END") == 0 )
535 SCIPdebugMsg(scip,
"(line %d) new section: END\n", lpinput->linenumber);
536 lpinput->section =
LP_END;
551 assert(lpinput !=
NULL);
552 assert(sign !=
NULL);
553 assert(*sign == +1 || *sign == -1);
555 if( lpinput->token[1] ==
'\0' )
557 if( *lpinput->token ==
'+' )
559 else if( *lpinput->token ==
'-' )
577 assert(lpinput !=
NULL);
578 assert(value !=
NULL);
580 if( strcasecmp(lpinput->token,
"INFINITY") == 0 || strcasecmp(lpinput->token,
"INF") == 0 )
590 val = strtod(lpinput->token, &endptr);
591 if( endptr != lpinput->token && *endptr ==
'\0' )
608 assert(lpinput !=
NULL);
610 if( strcmp(lpinput->token,
"<") == 0 )
616 else if( strcmp(lpinput->token,
">") == 0 )
622 else if( strcmp(lpinput->token,
"=") == 0 )
640 assert(name !=
NULL);
658 assert(lpinput !=
NULL);
692 assert(lpinput !=
NULL);
693 assert(name !=
NULL);
694 assert(coefssize !=
NULL);
695 assert(vars !=
NULL);
696 assert(coefs !=
NULL);
697 assert(ncoefs !=
NULL);
698 assert(newsection !=
NULL);
723 if( strcmp(lpinput->token,
":") == 0 )
729 SCIPdebugMsg(scip,
"(line %d) read constraint name: '%s'\n", lpinput->linenumber, name);
761 if(
isSign(lpinput, &coefsign) )
763 SCIPdebugMsg(scip,
"(line %d) read coefficient sign: %+d\n", lpinput->linenumber, coefsign);
769 if(
isValue(scip, lpinput, &coef) )
771 SCIPdebugMsg(scip,
"(line %d) read coefficient value: %g with sign %+d\n", lpinput->linenumber, coef, coefsign);
774 syntaxError(scip, lpinput,
"two consecutive values.");
786 syntaxError(scip, lpinput,
"no sense allowed in objective");
798 if( (isobjective || (!havevalue && !havesign)) &&
isNewSection(scip, lpinput) )
800 if( havesign && !havevalue )
802 SCIPwarningMessage(scip,
"skipped single sign %c without value or variable in objective\n", coefsign == 1 ?
'+' :
'-');
804 else if( isobjective && havevalue && !
SCIPisZero(scip, coef) )
806 SCIPwarningMessage(scip,
"constant term %+g in objective is skipped\n", coef * coefsign);
814 if( *lpinput->token ==
'[' )
816 syntaxError(scip, lpinput,
"diff reader does not support quadratic objective function.");
821 if( *ncoefs > 0 && !havesign )
823 syntaxError(scip, lpinput,
"expected sign ('+' or '-') or sense ('<' or '>').");
828 if( *lpinput->token ==
'^' )
830 syntaxError(scip, lpinput,
"diff reader does not support quadratic objective function.");
840 SCIPdebugMsg(scip,
"(line %d) read linear coefficient: %+g<%s>\n", lpinput->linenumber, coefsign * coef,
SCIPvarGetName(var));
844 if( *ncoefs >= *coefssize )
848 oldcoefssize = *coefssize;
850 *coefssize =
MAX(*coefssize, (*ncoefs)+1);
854 assert(*ncoefs < *coefssize);
857 (*vars)[*ncoefs] = var;
858 (*coefs)[*ncoefs] = coefsign * coef;
886 assert(lpinput !=
NULL);
909 assert(lpinput !=
NULL);
912 lpinput->file =
SCIPfopen(filename,
"r");
913 if( lpinput->file ==
NULL )
934 switch( lpinput->section )
966 assert(reader !=
NULL);
1019 const char* filename,
1027 lpinput.file =
NULL;
1028 lpinput.linebuf[0] =
'\0';
1029 lpinput.probname[0] =
'\0';
1030 lpinput.objname[0] =
'\0';
1032 lpinput.token[0] =
'\0';
1034 lpinput.tokenbuf[0] =
'\0';
1040 lpinput.npushedtokens = 0;
1041 lpinput.linenumber = 0;
1042 lpinput.linepos = 0;
1045 lpinput.haserror =
FALSE;
1046 lpinput.comment =
FALSE;
1047 lpinput.endline =
FALSE;
1061 if( lpinput.haserror )
enum SCIP_Result SCIP_RESULT
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
static SCIP_DECL_READERCOPY(readerCopyDiff)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
int SCIPmemccpy(char *dest, const char *src, char stop, unsigned int cnt)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
SCIP_STAGE SCIPgetStage(SCIP *scip)
static SCIP_Bool isValueChar(char c, char nextc, SCIP_Bool firstchar, SCIP_Bool *hasdot, LPEXPTYPE *exptype)
SCIP_RETCODE SCIPreadDiff(SCIP *scip, SCIP_READER *reader, const char *filename, SCIP_RESULT *result)
static SCIP_RETCODE readDiffFile(SCIP *scip, LPINPUT *lpinput, const char *filename)
static SCIP_Bool getNextToken(SCIP *scip, LPINPUT *lpinput)
static void pushToken(LPINPUT *lpinput)
static SCIP_Bool isValue(SCIP *scip, LPINPUT *lpinput, SCIP_Real *value)
const char * SCIPreaderGetName(SCIP_READER *reader)
SCIP_RETCODE SCIPincludeReaderDiff(SCIP *scip)
#define LP_MAX_PUSHEDTOKENS
static SCIP_Bool getNextLine(SCIP *scip, LPINPUT *lpinput)
SCIP_RETCODE SCIPchgReoptObjective(SCIP *scip, SCIP_OBJSENSE objsense, SCIP_VAR **vars, SCIP_Real *coefs, int nvars)
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
enum SCIP_Retcode SCIP_RETCODE
static SCIP_Bool isTokenChar(char c)
static SCIP_Bool isDelimChar(char c)
static void pushBufferToken(LPINPUT *lpinput)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
int SCIPfseek(SCIP_FILE *stream, long offset, int whence)
static SCIP_Bool isSense(LPINPUT *lpinput, LPSENSE *sense)
SCIP_RETCODE SCIPfreeReoptSolve(SCIP *scip)
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)
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
static SCIP_RETCODE getVariable(SCIP *scip, char *name, SCIP_VAR **var)
static const char commentchars[]
static void swapPointers(char **pointer1, char **pointer2)
struct SCIP_File SCIP_FILE
SCIP_Bool SCIPisReoptEnabled(SCIP *scip)
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
SCIPInterval sign(const SCIPInterval &x)
const char * SCIPvarGetName(SCIP_VAR *var)
static SCIP_RETCODE readStart(SCIP *scip, LPINPUT *lpinput)
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
static void syntaxError(SCIP *scip, LPINPUT *lpinput, const char *msg)
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
void SCIPprintSysError(const char *message)
enum SCIP_Objsense SCIP_OBJSENSE
static SCIP_Bool hasError(LPINPUT *lpinput)
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
static SCIP_DECL_READERREAD(readerReadDiff)
static SCIP_RETCODE readObjective(SCIP *scip, LPINPUT *lpinput)
static SCIP_DECL_READERFREE(readerFreeDiff)
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
static void swapTokenBuffer(LPINPUT *lpinput)
#define BMSclearMemoryArray(ptr, num)
int SCIPfclose(SCIP_FILE *fp)
#define LP_INIT_COEFSSIZE
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
static SCIP_Bool isNewSection(SCIP *scip, LPINPUT *lpinput)
static SCIP_Bool isSign(LPINPUT *lpinput, int *sign)