68 #define EVENTHDLR_NAME "boundwriting" 69 #define EVENTHDLR_DESC "event handler for writing current primalbound and global dualbound and for all open nodes the dualbound" 71 #define DEFAULT_FREQ 0LL 72 #define DEFAULT_FILENAME "" 73 #define DEFAULT_WRITESUBMIPDUALBOUND FALSE 89 struct SCIP_EventhdlrData
112 assert(eventhdlrdata !=
NULL);
114 eventhdlrdata->filename =
NULL;
115 eventhdlrdata->file =
NULL;
116 eventhdlrdata->isopen =
FALSE;
117 eventhdlrdata->oldfilename[0] =
'\0';
118 eventhdlrdata->filenumber = 1;
136 assert(subscip !=
NULL);
137 assert(vars !=
NULL);
138 assert(bounds !=
NULL);
139 assert(boundtypes !=
NULL);
141 assert(varmap !=
NULL);
144 for( v = nvars - 1; v >= 0; --v )
147 assert(subscipvar !=
NULL);
176 assert(scip !=
NULL);
177 assert(eventhdlrdata !=
NULL);
179 file = eventhdlrdata->file;
180 writesubmipdualbound = eventhdlrdata->writesubmipdualbound;
204 if( writesubmipdualbound )
280 assert(scip !=
NULL);
294 for( v = 2; v >= 0; --v )
313 assert(nopennodes >= 0);
316 for( n = nopennodes - 1; n >= 0 && !
SCIPisStopped(scip); --n )
320 if( writesubmipdualbound )
361 if( nbranchvars > size )
434 assert(scip !=
NULL);
435 assert(eventhdlr !=
NULL);
452 assert(scip !=
NULL);
453 assert(eventhdlr !=
NULL);
456 assert(eventhdlrdata !=
NULL);
457 assert(!eventhdlrdata->isopen);
458 assert(eventhdlrdata->file ==
NULL);
471 assert(scip !=
NULL);
472 assert(eventhdlr !=
NULL);
479 assert(eventhdlrdata !=
NULL);
491 assert(scip !=
NULL);
492 assert(eventhdlr !=
NULL);
499 assert(eventhdlrdata !=
NULL);
501 if( eventhdlrdata->isopen )
503 (void) fclose(eventhdlrdata->file);
504 eventhdlrdata->isopen =
FALSE;
506 eventhdlrdata->file =
NULL;
507 eventhdlrdata->oldfilename[0] =
'\0';
508 eventhdlrdata->filenumber = 1;
519 assert(scip !=
NULL);
520 assert(eventhdlr !=
NULL);
522 assert(event !=
NULL);
525 SCIPdebugMsg(scip,
"exec method of event handler for writing primal- and dualbounds\n");
528 assert(eventhdlrdata !=
NULL);
532 if( strlen(eventhdlrdata->filename) > 0 && !eventhdlrdata->isopen )
534 assert(eventhdlrdata->file ==
NULL);
535 assert(eventhdlrdata->oldfilename[0] ==
'\0');
537 eventhdlrdata->file = fopen(eventhdlrdata->filename,
"w");
538 (void)strncpy(eventhdlrdata->oldfilename, eventhdlrdata->filename,
SCIP_MAXSTRLEN);
540 if( eventhdlrdata->file ==
NULL )
542 SCIPerrorMessage(
"cannot create file <%s> for writing\n", eventhdlrdata->filename);
546 eventhdlrdata->isopen =
TRUE;
550 SCIPinfoMessage(scip, eventhdlrdata->file,
"\t (%d Presolved Constraints, %d Presolved Variables, (%d binary, %d integer, %d implicit integer, %d continuous))\n",
SCIPgetNConss(scip),
SCIPgetNVars(scip),
SCIPgetNBinVars(scip),
SCIPgetNIntVars(scip),
SCIPgetNImplVars(scip),
SCIPgetNContVars(scip));
557 if( eventhdlrdata->freq == 0 || (
SCIPgetNNodes(scip) % eventhdlrdata->freq) != 0 )
561 if( strlen(eventhdlrdata->filename) > 0 )
568 assert(eventhdlrdata->file ==
NULL);
569 assert(!eventhdlrdata->isopen);
571 if( eventhdlrdata->oldfilename[0] ==
'\0' )
572 (void)strncpy(eventhdlrdata->oldfilename, eventhdlrdata->filename,
SCIP_MAXSTRLEN);
575 pch=strrchr(eventhdlrdata->filename,
'.');
577 assert(eventhdlrdata->filenumber > 0);
578 n=sprintf(number,
"%"SCIP_LONGINT_FORMAT
"", eventhdlrdata->filenumber * eventhdlrdata->freq);
585 (void)strncpy(name, eventhdlrdata->filename, (
unsigned int)(
SCIP_MAXSTRLEN - n));
586 strncat(name, number, (
unsigned int)n);
595 len = (int) (pch-(eventhdlrdata->filename));
597 (void)strncpy(name, eventhdlrdata->filename, (
unsigned int)len);
599 strncat(name, number, (
unsigned int)n);
603 if( len + n + strlen(&(eventhdlrdata->filename[len])) <
SCIP_MAXSTRLEN )
605 strncat(name, &(eventhdlrdata->filename[len]), strlen(&(eventhdlrdata->filename[len])));
606 name[strlen(eventhdlrdata->filename)+n] =
'\0';
610 eventhdlrdata->file = fopen(name,
"w");
612 if( eventhdlrdata->file ==
NULL )
614 SCIPerrorMessage(
"cannot create file <%s> for writing\n", eventhdlrdata->filename);
618 eventhdlrdata->isopen =
TRUE;
622 SCIPinfoMessage(scip, eventhdlrdata->file,
"\t (%d Active Constraints, %d Active Variables, (%d binary, %d integer, %d implicit integer, %d continuous))\n",
SCIPgetNConss(scip),
SCIPgetNVars(scip),
SCIPgetNBinVars(scip),
SCIPgetNIntVars(scip),
SCIPgetNImplVars(scip),
SCIPgetNContVars(scip));
630 if( strlen(eventhdlrdata->filename) > 0 && eventhdlrdata->isopen )
637 assert(strcmp(tmp, eventhdlrdata->oldfilename) == 0);
643 SCIP_CALL( writeBoundsFocusNode(scip, eventhdlrdata) );
650 if( strlen(eventhdlrdata->filename) > 0 )
652 assert(eventhdlrdata->isopen);
654 (void) fclose(eventhdlrdata->file);
655 eventhdlrdata->isopen =
FALSE;
656 eventhdlrdata->file =
NULL;
657 ++(eventhdlrdata->filenumber);
679 eventExecBoundwriting, eventhdlrdata) );
680 assert(eventhdlr !=
NULL);
690 "in which frequency should all bounds be written(0: never)",
694 "filename to write all bounds to",
698 "should the dualbound of the submip-root which was created out of an open node be printed",
static SCIP_DECL_EVENTEXEC(eventExecBoundwriting)
enum SCIP_BoundType SCIP_BOUNDTYPE
int SCIPgetNIntVars(SCIP *scip)
static SCIP_RETCODE writeBounds(SCIP *scip, FILE *file, SCIP_Bool writesubmipdualbound)
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
SCIP_Real SCIPgetPrimalbound(SCIP *scip)
static SCIP_DECL_EVENTEXIT(eventExitBoundwriting)
SCIP_RETCODE SCIPgetLeaves(SCIP *scip, SCIP_NODE ***leaves, int *nleaves)
SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTEXIT((*eventexit)))
int SCIPgetNOrigVars(SCIP *scip)
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
static SCIP_DECL_EVENTFREE(eventFreeBoundwriting)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
SCIP_RETCODE SCIPsetHeuristics(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_Real SCIPinfinity(SCIP *scip)
enum SCIP_Retcode SCIP_RETCODE
int SCIPgetNNodesLeft(SCIP *scip)
#define SCIPfreeBlockMemory(scip, ptr)
SCIP_RETCODE SCIPaddStringParam(SCIP *scip, const char *name, const char *desc, char **valueptr, SCIP_Bool isadvanced, const char *defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
int SCIPnodeGetDepth(SCIP_NODE *node)
#define SCIPfreeBufferArray(scip, ptr)
static SCIP_DECL_EVENTCOPY(eventCopyBoundwriting)
SCIP_RETCODE SCIPcreate(SCIP **scip)
#define SCIPallocBlockMemory(scip, ptr)
static void initEventhdlrdata(SCIP_EVENTHDLRDATA *eventhdlrdata)
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
static SCIP_DECL_EVENTINIT(eventInitBoundwriting)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
int SCIPgetNContVars(SCIP *scip)
SCIP_RETCODE SCIPgetSiblings(SCIP *scip, SCIP_NODE ***siblings, int *nsiblings)
void SCIPnodeGetAncestorBranchings(SCIP_NODE *node, SCIP_VAR **branchvars, SCIP_Real *branchbounds, SCIP_BOUNDTYPE *boundtypes, int *nbranchvars, int branchvarssize)
const char * SCIPgetProbName(SCIP *scip)
#define SCIP_EVENTTYPE_NODEFEASIBLE
#define SCIP_EVENTTYPE_NODEBRANCHED
SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_RETCODE SCIPsetEventhdlrFree(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTFREE((*eventfree)))
SCIP_RETCODE SCIPsetEventhdlrCopy(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTCOPY((*eventcopy)))
SCIP_RETCODE SCIPincludeEventHdlrBoundwriting(SCIP *scip)
SCIP_RETCODE SCIPgetChildren(SCIP *scip, SCIP_NODE ***children, int *nchildren)
SCIP_Real SCIPgetDualbound(SCIP *scip)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
SCIP_STATUS SCIPgetStatus(SCIP *scip)
SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTINIT((*eventinit)))
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
SCIP_Real SCIPgetNodeDualbound(SCIP *scip, SCIP_NODE *node)
int SCIPgetNOrigConss(SCIP *scip)
event handler for writing primal- and dual bound for all open nodes
#define SCIPallocBufferArray(scip, ptr, num)
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
int SCIPgetNImplVars(SCIP *scip)
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
void SCIPprintSysError(const char *message)
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
#define SCIP_EVENTTYPE_NODEINFEASIBLE
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPgetTransObjscale(SCIP *scip)
int SCIPgetNBinVars(SCIP *scip)
#define SCIP_EVENTTYPE_NODESOLVED
int SCIPgetNVars(SCIP *scip)
SCIP_Real SCIPgetTransObjoffset(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_RETCODE SCIPcopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
SCIP_NODETYPE SCIPnodeGetType(SCIP_NODE *node)
SCIP_Bool SCIPisStopped(SCIP *scip)
static SCIP_RETCODE applyDomainChanges(SCIP *subscip, SCIP_VAR **vars, SCIP_Real *bounds, SCIP_BOUNDTYPE *boundtypes, int nvars, SCIP_HASHMAP *varmap)
SCIP_OBJSENSE SCIPgetObjsense(SCIP *scip)
#define DEFAULT_WRITESUBMIPDUALBOUND
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint 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 SCIPfree(SCIP **scip)