57#define READER_NAME "cipreader"
58#define READER_DESC "file reader for CIP (Constraint Integer Program) format"
59#define READER_EXTENSION "cip"
61#define DEFAULT_CIP_WRITEFIXEDVARS TRUE
121 char* windowsendlinechar;
126 cipinput->endfile = (
SCIPfgets(cipinput->strbuf, cipinput->len, cipinput->file) ==
NULL);
128 if( cipinput->endfile )
135 cipinput->linenumber++;
136 endline = strchr(cipinput->strbuf,
'\n');
137 endcharacter = strchr(cipinput->strbuf,
';');
139 while( endline ==
NULL || (endcharacter ==
NULL && cipinput->section ==
CIP_CONSTRAINTS && strncmp(cipinput->strbuf,
"END", 3) != 0 ) )
144 if( endline ==
NULL )
145 pos = cipinput->len - 1;
147 pos = (int) (endline - cipinput->strbuf);
154 if( pos + cipinput->readingsize >= cipinput->len )
161 cipinput->endfile = (
SCIPfgets(&(cipinput->strbuf[pos]), cipinput->len - pos, cipinput->file) ==
NULL);
163 if( cipinput->endfile )
170 cipinput->linenumber++;
171 endline = strrchr(&cipinput->strbuf[pos],
'\n');
172 endcharacter = strchr(&cipinput->strbuf[pos],
';');
179 windowsendlinechar = strrchr(cipinput->strbuf,
'\r');
180 if( windowsendlinechar !=
NULL && windowsendlinechar + 1 == endline )
186 if( cipinput->section ==
CIP_CONSTRAINTS && endcharacter !=
NULL && endline - endcharacter != 1 )
188 SCIPerrorMessage(
"Constraint line has to end with ';\\n' (line: %d).\n", cipinput->linenumber);
189 cipinput->haserror =
TRUE;
209 buf = cipinput->strbuf;
211 if( strncmp(buf,
"STATISTICS", 9) == 0 )
217 if( strncmp(buf,
"VARIABLES", 8) == 0 || strncmp(buf,
"FIXED", 5) == 0 || strncmp(buf,
"CONSTRAINTS", 11) == 0 || strncmp(buf,
"OBJECTIVE", 9) == 0 )
219 SCIPerrorMessage(
"Syntax Error: File has to start with 'STATISTICS' section.\n");
220 cipinput->haserror =
TRUE;
234 buf = cipinput->strbuf;
236 if( strncmp(buf,
"OBJECTIVE", 9) == 0 )
244 if( strncmp(buf,
" Problem name", 14) == 0 )
249 name = strchr(buf,
':');
253 SCIPwarningMessage(
scip,
"did not find problem name (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
261 if(
NULL != (s = strpbrk(name,
"#\r\n")) )
287 buf = cipinput->strbuf;
289 if( strncmp(buf,
"VARIABLES", 8) == 0 )
291 else if( strncmp(buf,
"FIXED", 5) == 0 )
293 else if( strncmp(buf,
"CONSTRAINTS", 11) == 0 )
295 else if( strncmp(buf,
"END", 3) == 0 )
310 name = strchr(buf,
':');
314 SCIPwarningMessage(
scip,
"did not find objective sense (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
330 SCIPwarningMessage(
scip,
"unknown objective sense '%s' (line: %d):\n%s\n", name, cipinput->linenumber, cipinput->strbuf);
342 name = strchr(buf,
':');
354 if( cipinput->objoffsetexact !=
NULL )
371 cipinput->objoffset = 0.0;
376 SCIPwarningMessage(
scip,
"could not parse offset (line: %d)\n%s\n", cipinput->linenumber, cipinput->strbuf);
384 name = strchr(buf,
':');
396 if( cipinput->objscaleexact !=
NULL )
413 cipinput->objscale = 1.0;
418 SCIPwarningMessage(
scip,
"could not parse objective scale (line: %d)\n%s\n", cipinput->linenumber, cipinput->strbuf);
440 buf = cipinput->strbuf;
442 if( strncmp(buf,
"FIXED", 5) == 0 )
444 else if( strncmp(buf,
"CONSTRAINTS", 4) == 0 )
446 else if( strncmp(buf,
"END", 3) == 0 )
455 SCIP_CALL(
SCIPparseVar(
scip, &
var, buf, initial, removable,
NULL,
NULL,
NULL,
NULL,
NULL, &endptr, &success) );
459 SCIPerrorMessage(
"syntax error in variable information (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
460 cipinput->haserror =
TRUE;
465 if( cipinput->objscaleexact !=
NULL )
482 if( cipinput->objscale != 1.0 )
510 buf = cipinput->strbuf;
512 if( strncmp(buf,
"CONSTRAINTS", 11) == 0 )
514 else if( strncmp(buf,
"END", 3) == 0 )
523 SCIP_CALL(
SCIPparseVar(
scip, &
var, buf,
TRUE,
FALSE,
NULL,
NULL,
NULL,
NULL,
NULL, &endptr, &success) );
527 SCIPerrorMessage(
"syntax error in variable information (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
528 cipinput->haserror =
TRUE;
535 while( *buf !=
'\0' && (*buf ==
' ' || *buf ==
',') )
539 if( strncmp(buf,
"fixed:", 6) == 0 )
544 else if( strncmp(buf,
"negated:", 8) == 0 )
557 SCIPerrorMessage(
"could not parse negated variable (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
558 cipinput->haserror =
TRUE;
583 SCIP_CALL(
SCIPcreateConsExactLinear(
scip, &lincons, name, 2,
vars, vals, vals[0], vals[0],
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
TRUE,
FALSE) );
594 SCIP_CALL(
SCIPcreateConsLinear(
scip, &lincons, name, 2,
vars, vals, 1.0, 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
TRUE,
FALSE) );
602 else if( strncmp(buf,
"aggregated:", 11) == 0 )
616 if( strncmp(str,
"indslack", 8) == 0 )
621 else if( strncmp(str,
"t_indslack", 10) == 0 )
642 SCIPerrorMessage(
"expected constant when aggregated variable information (line: %d):\n%s\n", cipinput->linenumber, buf);
643 cipinput->haserror =
TRUE;
674 if( success && requsize > nvarssize )
678 nvarssize = requsize;
680 assert(!success || requsize <= nvarssize);
687 SCIP_CALL(
SCIPcreateConsExactLinear(
scip, &lincons, name,
nvars + 1,
vars, vals, rhs, rhs,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
TRUE,
FALSE) );
703 SCIPerrorMessage(
"expected constant when aggregated variable information (line: %d):\n%s\n", cipinput->linenumber, buf);
704 cipinput->haserror =
TRUE;
734 if( success && requsize > nvarssize )
738 nvarssize = requsize;
740 assert(!success || requsize <= nvarssize);
747 SCIP_CALL(
SCIPcreateConsLinear(
scip, &lincons, name,
nvars + 1,
vars, vals, rhs, rhs,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
TRUE,
FALSE) );
763 SCIPwarningMessage(
scip,
"Could not read (multi-)aggregated variable <%s>: dependent variables unkown - consider changing the order (line: %d):\n%s\n",
769 SCIPerrorMessage(
"unknown section when parsing variables (line: %d):\n%s\n", cipinput->linenumber, buf);
770 cipinput->haserror =
TRUE;
805 buf = cipinput->strbuf;
807 if( strncmp(buf,
"END", 3) == 0 )
823 len = (int)strlen(buf);
826 SCIPerrorMessage(
"syntax error: expected constraint in line %d.\n", cipinput->linenumber);
827 cipinput->haserror =
TRUE;
830 if ( buf[len - 1] !=
';' )
832 SCIPerrorMessage(
"syntax error: line has to end with ';' (line: %d)\n", cipinput->linenumber);
833 cipinput->haserror =
TRUE;
839 copybuf[len - 1] =
'\0';
843 initial,
separate, enforce, check,
propagate, local, modifiable, dynamic, removable,
FALSE, &success);
852 SCIPerrorMessage(
"syntax error when reading constraint (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf);
853 cipinput->haserror =
TRUE;
917 cipinput.len = 131071;
920 cipinput.linenumber = 0;
922 cipinput.haserror =
FALSE;
923 cipinput.endfile =
FALSE;
924 cipinput.readingsize = 65535;
925 cipinput.objoffset = 0.0;
926 cipinput.objscale = 1.0;
937 cipinput.objoffsetexact =
NULL;
938 cipinput.objscaleexact =
NULL;
941 SCIP_CALL_TERMINATE( retcode,
SCIPcreateProb(
scip, filename,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL), TERMINATE );
948 initialvar = !dynamiccols;
949 removablevar = dynamiccols;
951 while( cipinput.section !=
CIP_END && !cipinput.haserror )
956 if( cipinput.endfile )
959 switch( cipinput.section )
987 if( cipinput.haserror )
991 if( cipinput.objoffsetexact !=
NULL )
995 SCIPrationalMult(cipinput.objoffsetexact, cipinput.objoffsetexact, cipinput.objscaleexact);
1002 if( cipinput.objoffset != 0.0 )
1004 cipinput.objoffset *= cipinput.objscale;
1009 if( cipinput.section !=
CIP_END )
1012 cipinput.haserror =
TRUE;
1019 if( cipinput.objscaleexact !=
NULL )
1021 if( cipinput.objoffsetexact !=
NULL )
1072 SCIPinfoMessage(
scip, file,
" Variables : %d (%d binary, %d integer, %d implicit integer, %d continuous)\n",
1073 nvars, nbinvars, nintvars, nimplvars, ncontvars);
1074 SCIPinfoMessage(
scip, file,
" Constraints : %d initial, %d maximal\n", startnconss, maxnconss);
1079 if( objoffsetexact !=
NULL )
1093 if( objoffset != 0.0 )
1097 if( objscaleexact !=
NULL )
1115 if ( nfixedvars > 0 )
1121 if (
nvars + nfixedvars > 0 )
1135 if ( varhash !=
NULL )
1149 if( readerdata->writefixedvars && nfixedvars > 0 )
1157 while ( nwritten < nfixedvars )
1159 SCIPdebugMsg(
scip,
"written %d of %d fixed variables.\n", nwritten, nfixedvars);
1160 for (
i = 0;
i < nfixedvars; ++
i)
1228 for (j = 0; j < naggrvars; ++j)
1235 if ( j >= naggrvars )
1248 SCIPerrorMessage(
"Only fixed variables are allowed to be present in fixedvars list.\n");
1260 for(
i = 0;
i < nconss; ++
i )
1270 if( nfixedvars > 0 )
1308 "reading/cipreader/writefixedvars",
"should fixed and aggregated variables be printed (if not, re-parsing might fail)",
Constraint handler for linear constraints in their most general form, .
Constraint handler for linear constraints in their most general form, .
#define SCIP_CALL_TERMINATE(retcode, x, TERM)
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
int SCIPfclose(SCIP_FILE *fp)
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
SCIP_RETCODE SCIPcreateConsExactLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_RATIONAL **vals, SCIP_RATIONAL *lhs, SCIP_RATIONAL *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)
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)
SCIP_RETCODE SCIPincludeReaderCip(SCIP *scip)
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
SCIP_RETCODE SCIPsetProbName(SCIP *scip, const char *name)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
SCIP_RETCODE SCIPaddOrigObjoffset(SCIP *scip, SCIP_Real addval)
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)
SCIP_RETCODE SCIPaddOrigObjoffsetExact(SCIP *scip, SCIP_RATIONAL *addval)
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
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_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
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)
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
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)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_Bool SCIPisExact(SCIP *scip)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPreallocBufferArray(scip, ptr, num)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
void SCIPrationalMult(SCIP_RATIONAL *res, SCIP_RATIONAL *op1, SCIP_RATIONAL *op2)
#define SCIPrationalDebugMessage
void SCIPrationalSetReal(SCIP_RATIONAL *res, SCIP_Real real)
void SCIPrationalFreeBuffer(BMS_BUFMEM *bufmem, SCIP_RATIONAL **rational)
SCIP_RETCODE SCIPrationalCreateBuffer(BMS_BUFMEM *bufmem, SCIP_RATIONAL **rational)
SCIP_Bool SCIPrationalIsZero(SCIP_RATIONAL *rational)
void SCIPrationalMessage(SCIP_MESSAGEHDLR *msg, FILE *file, SCIP_RATIONAL *rational)
SCIP_Bool SCIPrationalIsEQReal(SCIP_RATIONAL *rat, SCIP_Real real)
SCIP_RETCODE SCIPrationalCreateBufferArray(BMS_BUFMEM *mem, SCIP_RATIONAL ***rational, int size)
SCIP_RETCODE SCIPrationalReallocBufferArray(BMS_BUFMEM *mem, SCIP_RATIONAL ***result, int oldlen, int newlen)
void SCIPrationalMultReal(SCIP_RATIONAL *res, SCIP_RATIONAL *op1, SCIP_Real op2)
void SCIPrationalFreeBufferArray(BMS_BUFMEM *mem, SCIP_RATIONAL ***ratbufarray, int size)
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader,)
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
SCIP_READERDATA * SCIPreaderGetData(SCIP_READER *reader)
SCIP_RETCODE SCIPsetReaderWrite(SCIP *scip, SCIP_READER *reader,)
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader,)
const char * SCIPreaderGetName(SCIP_READER *reader)
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader,)
void SCIPreaderMarkExact(SCIP_READER *reader)
SCIP_Bool SCIPparseRational(SCIP *scip, const char *str, SCIP_RATIONAL *value, char **endptr)
SCIP_Bool SCIPparseReal(SCIP *scip, const char *str, SCIP_Real *value, char **endptr)
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
SCIP_RETCODE SCIPparseVarName(SCIP *scip, const char *str, SCIP_VAR **var, char **endptr)
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)
int SCIPvarGetIndex(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
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 SCIPparseVarsLinearsumExact(SCIP *scip, char *str, SCIP_VAR **vars, SCIP_RATIONAL **vals, int *nvars, int varssize, int *requiredsize, char **endptr, SCIP_Bool *success)
SCIP_RETCODE SCIPflattenVarAggregationGraph(SCIP *scip, SCIP_VAR *var)
SCIP_VAR ** SCIPvarGetMultaggrVars(SCIP_VAR *var)
int SCIPvarGetMultaggrNVars(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
SCIP_RETCODE SCIPprintVar(SCIP *scip, SCIP_VAR *var, FILE *file)
SCIP_RETCODE SCIPchgVarObjExact(SCIP *scip, SCIP_VAR *var, SCIP_RATIONAL *newobj)
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
SCIP_RATIONAL * SCIPvarGetObjExact(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetAggrVar(SCIP_VAR *var)
int SCIPsnprintf(char *t, int len, const char *s,...)
void SCIPprintSysError(const char *message)
SCIP_RETCODE SCIPskipSpace(char **s)
int SCIPstrncasecmp(const char *s1, const char *s2, int length)
assert(minobj< SCIPgetCutoffbound(scip))
static SCIP_Bool propagate
memory allocation routines
#define BMSclearMemoryArray(ptr, num)
wrapper functions to map file i/o to standard or zlib file i/o
struct SCIP_File SCIP_FILE
public methods for message output
#define SCIPdebugPrintCons(x, y, z)
public data structures and miscellaneous methods
public methods for input file readers
public methods for problem variables
wrapper for rational number arithmetic
static SCIP_RETCODE getObjective(SCIP *scip, CIPINPUT *cipinput)
static SCIP_RETCODE getConstraint(SCIP *scip, CIPINPUT *cipinput, SCIP_Bool initial, SCIP_Bool dynamic, SCIP_Bool removable)
enum CipSection CIPSECTION
static SCIP_RETCODE getInputString(SCIP *scip, CIPINPUT *cipinput)
static SCIP_RETCODE getVariable(SCIP *scip, CIPINPUT *cipinput, SCIP_Bool initial, SCIP_Bool removable)
static void getStart(SCIP *scip, CIPINPUT *cipinput)
static SCIP_RETCODE getStatistics(SCIP *scip, CIPINPUT *cipinput)
#define DEFAULT_CIP_WRITEFIXEDVARS
static SCIP_RETCODE getFixedVariable(SCIP *scip, CIPINPUT *cipinput)
public methods for constraint handler plugins and constraints
public methods for exact solving
public methods for memory management
public methods for message handling
public methods for numerical tolerances
public methods for SCIP parameter handling
public methods for global and local (sub)problems
public methods for reader plugins
public methods for SCIP variables
static SCIP_RETCODE separate(SCIP *scip, SCIP_SEPA *sepa, SCIP_SOL *sol, SCIP_RESULT *result)
Main separation function.
struct SCIP_Cons SCIP_CONS
#define SCIP_DECL_HASHKEYEQ(x)
#define SCIP_DECL_HASHGETKEY(x)
#define SCIP_DECL_HASHKEYVAL(x)
struct SCIP_HashTable SCIP_HASHTABLE
enum SCIP_Objsense SCIP_OBJSENSE
struct SCIP_Rational SCIP_RATIONAL
#define SCIP_DECL_READERWRITE(x)
struct SCIP_ReaderData SCIP_READERDATA
struct SCIP_Reader SCIP_READER
#define SCIP_DECL_READERREAD(x)
#define SCIP_DECL_READERCOPY(x)
#define SCIP_DECL_READERFREE(x)
enum SCIP_Retcode SCIP_RETCODE
@ SCIP_VARSTATUS_ORIGINAL
@ SCIP_VARSTATUS_MULTAGGR
@ SCIP_VARSTATUS_AGGREGATED