27 #if defined(_WIN32) || defined(_WIN64) 36 #define READER_NAME "cipreader" 37 #define READER_DESC "file reader for CIP (Constraint Integer Program) format" 38 #define READER_EXTENSION "cip" 40 #define DEFAULT_CIP_WRITEFIXEDVARS TRUE 44 struct SCIP_ReaderData
96 char* windowsendlinechar;
98 assert(cipinput !=
NULL);
101 cipinput->endfile = (
SCIPfgets(cipinput->strbuf, cipinput->len, cipinput->file) ==
NULL);
103 if( cipinput->endfile )
110 cipinput->linenumber++;
111 endline = strchr(cipinput->strbuf,
'\n');
113 endcharacter = strchr(cipinput->strbuf,
';');
114 while( endline ==
NULL || (endcharacter ==
NULL && cipinput->section ==
CIP_CONSTRAINTS && strncmp(cipinput->strbuf,
"END", 3) != 0 ) )
119 if( endline ==
NULL )
120 pos = cipinput->len - 1;
122 pos = (int) (endline - cipinput->strbuf);
129 if( pos + cipinput->readingsize >= cipinput->len )
136 cipinput->endfile = (
SCIPfgets(&(cipinput->strbuf[pos]), cipinput->len - pos, cipinput->file) ==
NULL);
138 if( cipinput->endfile )
145 cipinput->linenumber++;
146 endline = strrchr(cipinput->strbuf,
'\n');
147 endcharacter = strchr(cipinput->strbuf,
';');
149 assert(endline !=
NULL);
154 windowsendlinechar = strrchr(cipinput->strbuf,
'\r');
155 if( windowsendlinechar !=
NULL && windowsendlinechar + 1 == endline )
159 assert(windowsendlinechar ==
NULL);
161 if( cipinput->section ==
CIP_CONSTRAINTS && endcharacter !=
NULL && endline - endcharacter != 1 )
163 SCIPerrorMessage(
"Constraint line has to end with ';\\n' (line: %d).\n", cipinput->linenumber);
164 cipinput->haserror =
TRUE;
182 buf = cipinput->strbuf;
184 if( strncmp(buf,
"STATISTICS", 9) == 0 )
190 if( strncmp(buf,
"VARIABLES", 8) == 0 || strncmp(buf,
"FIXED", 5) == 0 || strncmp(buf,
"CONSTRAINTS", 11) == 0 || strncmp(buf,
"OBJECTIVE", 9) == 0 )
192 SCIPerrorMessage(
"Syntax Error: File has to start with 'STATISTICS' section.\n");
193 cipinput->haserror =
TRUE;
207 buf = cipinput->strbuf;
209 if( strncmp(buf,
"OBJECTIVE", 9) == 0 )
217 if( strncmp(buf,
" Problem name", 14) == 0 )
222 name = strchr(buf,
':');
226 SCIPwarningMessage(scip,
"did not find problem name (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
234 if(
NULL != (s = strpbrk(name,
"#\r\n")) )
238 while( isspace((
unsigned char)* name) )
262 assert(objscale !=
NULL);
263 assert(objoffset !=
NULL);
265 buf = cipinput->strbuf;
267 if( strncmp(buf,
"VARIABLES", 8) == 0 )
269 else if( strncmp(buf,
"FIXED", 5) == 0 )
271 else if( strncmp(buf,
"CONSTRAINTS", 11) == 0 )
273 else if( strncmp(buf,
"END", 3) == 0 )
282 while ( isspace((
unsigned char)* buf) )
285 if( strncasecmp(buf,
"Sense", 5) == 0 )
289 name = strchr(buf,
':');
293 SCIPwarningMessage(scip,
"did not find objective sense (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
301 while( isspace((
unsigned char)* name) )
304 if( strncasecmp(name,
"minimize", 3) == 0 )
306 else if( strncasecmp(name,
"maximize", 3) == 0 )
310 SCIPwarningMessage(scip,
"unknown objective sense '%s' (line: %d):\n%s\n", name, cipinput->linenumber, cipinput->strbuf);
318 else if( strncasecmp(buf,
"Offset", 6) == 0 )
323 name = strchr(buf,
':');
335 while(isspace((
unsigned char)*name))
341 SCIPdebugMsg(scip,
"offset <%g> (total: %g)\n", off, *objoffset);
345 SCIPwarningMessage(scip,
"could not parse offset (line: %d)\n%s\n", cipinput->linenumber, cipinput->strbuf);
349 else if( strncasecmp(buf,
"Scale", 5) == 0 )
354 name = strchr(buf,
':');
366 while(isspace((
unsigned char)*name))
372 SCIPdebugMsg(scip,
"objscale <%g> (total: %g)\n", scale, *objscale);
376 SCIPwarningMessage(scip,
"could not parse objective scale (line: %d)\n%s\n", cipinput->linenumber, cipinput->strbuf);
399 buf = cipinput->strbuf;
401 if( strncmp(buf,
"FIXED", 5) == 0 )
403 else if( strncmp(buf,
"CONSTRAINTS", 4) == 0 )
405 else if( strncmp(buf,
"END", 3) == 0 )
414 SCIP_CALL(
SCIPparseVar(scip, &var, buf, initial, removable,
NULL,
NULL,
NULL,
NULL,
NULL, &endptr, &success) );
418 SCIPerrorMessage(
"syntax error in variable information (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
419 cipinput->haserror =
TRUE;
423 if( objscale != 1.0 )
450 buf = cipinput->strbuf;
452 if( strncmp(buf,
"CONSTRAINTS", 11) == 0 )
454 else if( strncmp(buf,
"END", 3) == 0 )
463 SCIP_CALL(
SCIPparseVar(scip, &var, buf,
TRUE,
FALSE,
NULL,
NULL,
NULL,
NULL,
NULL, &endptr, &success) );
467 SCIPerrorMessage(
"syntax error in variable information (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
468 cipinput->haserror =
TRUE;
475 while ( *buf !=
'\0' && (*buf ==
' ' || *buf ==
',') )
479 if ( strncmp(buf,
"fixed:", 6) == 0 )
484 else if ( strncmp(buf,
"negated:", 8) == 0 )
496 if ( negvar ==
NULL )
498 SCIPerrorMessage(
"could not parse negated variable (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
499 cipinput->haserror =
TRUE;
517 SCIP_CALL(
SCIPcreateConsLinear(scip, &lincons, name, 2, vars, vals, 1.0, 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
TRUE,
FALSE) );
522 else if ( strncmp(buf,
"aggregated:", 11) == 0 )
541 SCIPerrorMessage(
"expected constant when aggregated variable information (line: %d):\n%s\n", cipinput->linenumber, buf);
542 cipinput->haserror =
TRUE;
548 while ( *str !=
'\0' && isspace(*str) )
572 if ( success && requsize > nvarssize )
575 nvarssize = requsize;
580 assert( ! success || requsize <= nvarssize);
590 if ( strncmp(str,
"indslack", 8) == 0 )
592 (void) strcpy(name,
"indlin");
595 else if ( strncmp(str,
"t_indslack", 10) == 0 )
597 (void) strcpy(name,
"indlin");
605 SCIP_CALL(
SCIPcreateConsLinear(scip, &lincons, name, nvars + 1, vars, vals, -rhs, -rhs,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
TRUE,
FALSE) );
612 SCIPwarningMessage(scip,
"Could not read (multi-)aggregated variable <%s>: dependent variables unkown - consider changing the order (line: %d):\n%s\n",
621 SCIPerrorMessage(
"unknown section when parsing variables (line: %d):\n%s\n", cipinput->linenumber, buf);
622 cipinput->haserror =
TRUE;
657 buf = cipinput->strbuf;
659 if( strncmp(buf,
"END", 3) == 0 )
665 SCIPdebugMsg(scip,
"parse constraints in line %d\n", cipinput->linenumber);
675 len = (int)strlen(buf);
678 SCIPerrorMessage(
"syntax error: expected constraint in line %d.\n", cipinput->linenumber);
679 cipinput->haserror =
TRUE;
682 if ( buf[len - 1] !=
';' )
684 SCIPerrorMessage(
"syntax error: line has to end with ';' (line: %d)\n", cipinput->linenumber);
685 cipinput->haserror =
TRUE;
691 copybuf[len - 1] =
'\0';
695 initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable,
FALSE, &success);
704 SCIPerrorMessage(
"syntax error when reading constraint (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
705 cipinput->haserror =
TRUE;
725 assert(reader !=
NULL);
742 assert(readerdata !=
NULL);
772 cipinput.len = 131071;
775 cipinput.linenumber = 0;
777 cipinput.haserror =
FALSE;
778 cipinput.endfile =
FALSE;
779 cipinput.readingsize = 65535;
788 initialvar = !dynamiccols;
789 removablevar = dynamiccols;
794 while( cipinput.section !=
CIP_END && !cipinput.haserror )
799 if( cipinput.endfile )
802 switch( cipinput.section )
814 retcode =
getVariable(
scip, &cipinput, initialvar, removablevar, objscale);
818 cipinput.haserror =
TRUE;
829 cipinput.haserror =
TRUE;
836 retcode =
getConstraint(
scip, &cipinput, initialconss, dynamicconss, dynamicrows);
840 cipinput.haserror =
TRUE;
857 objoffset *= objscale;
862 SCIPdebugMsg(
scip,
"added variables <objoffset> for objective offset of <%g>\n", objoffset);
865 if( cipinput.section !=
CIP_END && !cipinput.haserror )
876 if( cipinput.haserror )
916 assert(reader !=
NULL);
921 SCIPinfoMessage(
scip, file,
" Variables : %d (%d binary, %d integer, %d implicit integer, %d continuous)\n",
922 nvars, nbinvars, nintvars, nimplvars, ncontvars);
923 SCIPinfoMessage(
scip, file,
" Constraints : %d initial, %d maximal\n", startnconss, maxnconss);
932 if ( nfixedvars > 0 )
938 if ( nvars + nfixedvars > 0 )
945 for( i = 0; i < nvars; ++i )
950 assert( var !=
NULL );
952 if ( varhash !=
NULL )
964 assert(readerdata !=
NULL);
966 if( readerdata->writefixedvars && nfixedvars > 0 )
974 while ( nwritten < nfixedvars )
976 SCIPdebugMsg(
scip,
"written %d of %d fixed variables.\n", nwritten, nfixedvars);
977 for (i = 0; i < nfixedvars; ++i)
983 assert( var !=
NULL );
1004 assert( tmpvar !=
NULL );
1020 assert( tmpvar !=
NULL );
1043 assert(aggrvars !=
NULL || naggrvars == 0);
1045 for (j = 0; j < naggrvars; ++j)
1052 if ( j >= naggrvars )
1065 SCIPerrorMessage(
"Only fixed variables are allowed to be present in fixedvars list.\n");
1077 for( i = 0; i < nconss; ++i )
1087 if( nfixedvars > 0 )
1090 assert(varhash ==
NULL);
1122 "reading/cipreader/writefixedvars",
"should fixed and aggregated variables be printed (if not, re-parsing might fail)",
SCIP_RETCODE SCIPflattenVarAggregationGraph(SCIP *scip, SCIP_VAR *var)
static SCIP_DECL_HASHGETKEY(hashGetKeyVar)
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
SCIP_VAR ** SCIPvarGetMultaggrVars(SCIP_VAR *var)
const char * SCIPreaderGetName(SCIP_READER *reader)
SCIP_RETCODE SCIPparseVarName(SCIP *scip, const char *str, SCIP_VAR **var, char **endptr)
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
SCIP_RETCODE SCIPparseCons(SCIP *scip, SCIP_CONS **cons, const char *str, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode, SCIP_Bool *success)
static SCIP_RETCODE getInputString(SCIP *scip, CIPINPUT *cipinput)
int SCIPsnprintf(char *t, int len, const char *s,...)
enum SCIP_Retcode SCIP_RETCODE
#define SCIPfreeBlockMemory(scip, ptr)
static SCIP_RETCODE getObjective(SCIP *scip, CIPINPUT *cipinput, SCIP_Real *objscale, SCIP_Real *objoffset)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
#define SCIPdebugPrintCons(x, y, z)
static SCIP_DECL_READERCOPY(readerCopyCip)
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
SCIP_RETCODE SCIPparseVarsLinearsum(SCIP *scip, const char *str, SCIP_VAR **vars, SCIP_Real *vals, int *nvars, int varssize, int *requiredsize, char **endptr, SCIP_Bool *success)
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
SCIP_READERDATA * SCIPreaderGetData(SCIP_READER *reader)
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
static SCIP_DECL_READERREAD(readerReadCip)
static SCIP_RETCODE getFixedVariable(SCIP *scip, CIPINPUT *cipinput)
static SCIP_RETCODE getVariable(SCIP *scip, CIPINPUT *cipinput, SCIP_Bool initial, SCIP_Bool removable, SCIP_Real objscale)
static SCIP_DECL_READERWRITE(readerWriteCip)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
struct SCIP_File SCIP_FILE
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
static SCIP_DECL_READERFREE(readerFreeCip)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
static SCIP_RETCODE getStatistics(SCIP *scip, CIPINPUT *cipinput)
static void getStart(SCIP *scip, CIPINPUT *cipinput)
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
#define SCIPallocBufferArray(scip, ptr, num)
struct SCIP_ReaderData SCIP_READERDATA
static SCIP_DECL_HASHKEYVAL(hashKeyValVar)
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
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
SCIP_Bool SCIPstrToRealValue(const char *str, SCIP_Real *value, char **endptr)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetAggrVar(SCIP_VAR *var)
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
SCIP_RETCODE SCIPsetReaderWrite(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERWRITE((*readerwrite)))
Constraint handler for linear constraints in their most general form, .
int SCIPvarGetMultaggrNVars(SCIP_VAR *var)
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define DEFAULT_CIP_WRITEFIXEDVARS
SCIP_RETCODE SCIPsetProbName(SCIP *scip, const char *name)
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
enum CipSection CIPSECTION
static SCIP_DECL_HASHKEYEQ(hashKeyEqVar)
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
int SCIPvarGetIndex(SCIP_VAR *var)
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
#define BMSclearMemoryArray(ptr, num)
int SCIPfclose(SCIP_FILE *fp)
static SCIP_RETCODE getConstraint(SCIP *scip, CIPINPUT *cipinput, SCIP_Bool initial, SCIP_Bool dynamic, SCIP_Bool removable)
SCIP_RETCODE SCIPparseVar(SCIP *scip, SCIP_VAR **var, const char *str, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARCOPY((*varcopy)), SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_VARDATA *vardata, char **endptr, SCIP_Bool *success)
SCIP_RETCODE SCIPprintVar(SCIP *scip, SCIP_VAR *var, FILE *file)
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
#define SCIPreallocBufferArray(scip, ptr, num)
SCIP_RETCODE SCIPincludeReaderCip(SCIP *scip)