Scippy

SCIP

Solving Constraint Integer Programs

event_newsol.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file event_newsol.c
17  * @brief eventhdlr that adds new solutions to the candidate pool for the exchange heuristic
18  * @author Leon Eifler
19  */
20 
21 /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 #include <string.h>
25 
26 #include "event_newsol.h"
27 #include "heur_cyckerlin.h"
28 #include "probdata_cyc.h"
29 
30 #define EVENTHDLR_NAME "newsol"
31 #define EVENTHDLR_DESC "event handler for solution events"
32 
33 /** copy method for event handler plugins (called when SCIP copies plugins) */
34 static
35 SCIP_DECL_EVENTCOPY(eventCopyNewsol)
36 { /*lint --e{715}*/
37  assert(scip != NULL);
38  assert(eventhdlr != NULL);
39  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
40 
41  /* call inclusion method of event handler */
43 
44  return SCIP_OKAY;
45 }
46 
47 /** initialization method of event handler (called after problem was transformed) */
48 static
49 SCIP_DECL_EVENTINIT(eventInitNewsol)
50 { /*lint --e{715}*/
51  assert(scip != NULL);
52  assert(eventhdlr != NULL);
53  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
54 
55  /* notify SCIP that your event handler wants to react on the event type best solution found */
57 
58  return SCIP_OKAY;
59 }
60 
61 /** deinitialization method of event handler (called before transformed problem is freed) */
62 static
63 SCIP_DECL_EVENTEXIT(eventExitNewsol)
64 { /*lint --e{715}*/
65  assert(scip != NULL);
66  assert(eventhdlr != NULL);
67  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
68 
69  /* notify SCIP that your event handler wants to drop the event type best solution found */
71 
72  return SCIP_OKAY;
73 }
74 
75 /** execution method of event handler */
76 static
77 SCIP_DECL_EVENTEXEC(eventExecNewsol)
78 { /*lint --e{715}*/
79  SCIP_SOL* newsol;
80 
81  assert(eventhdlr != NULL);
82  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
83  assert(event != NULL);
84  assert(scip != NULL);
86 
88  return SCIP_OKAY;
89 
90  SCIPdebugMsg(scip, "exec method of event handler for newsol solution found\n");
91 
92  newsol = SCIPeventGetSol(event);
93  assert(newsol != NULL);
94 
95  SCIPdebugMsg(scip, "catch event for solution %p with obj=%g.\n", (void*) newsol, SCIPgetSolOrigObj(scip, newsol));
96 
98 
99  return SCIP_OKAY;
100 }
101 
102 /** includes event handler for best solution found */
104  SCIP* scip /**< SCIP data structure */
105  )
106 {
107  SCIP_EVENTHDLRDATA* eventhdlrdata;
108  SCIP_EVENTHDLR* eventhdlr;
109  eventhdlrdata = NULL;
110 
111  eventhdlr = NULL;
112  /* create event handler for events on watched variables */
114  eventExecNewsol, eventhdlrdata) );
115 
116  assert(eventhdlr != NULL);
117 
118  SCIP_CALL( SCIPsetEventhdlrCopy(scip, eventhdlr, eventCopyNewsol) );
119  SCIP_CALL( SCIPsetEventhdlrInit(scip, eventhdlr, eventInitNewsol) );
120  SCIP_CALL( SCIPsetEventhdlrExit(scip, eventhdlr, eventExitNewsol) );
121 
122  return SCIP_OKAY;
123 }
#define NULL
Definition: def.h:246
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:411
SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTEXIT((*eventexit)))
Definition: scip_event.c:246
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip_event.c:172
eventhdlr that adds new solutions to the candidate pool for the exchange heuristic ...
struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
Definition: type_event.h:138
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:314
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
static SCIP_DECL_EVENTEXIT(eventExitNewsol)
Definition: event_newsol.c:63
#define SCIPdebugMsg
Definition: scip_message.h:88
static SCIP_DECL_EVENTCOPY(eventCopyNewsol)
Definition: event_newsol.c:35
SCIP_RETCODE SCIPsetEventhdlrCopy(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTCOPY((*eventcopy)))
Definition: scip_event.c:204
SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTINIT((*eventinit)))
Definition: scip_event.c:232
#define SCIP_CALL(x)
Definition: def.h:358
#define EVENTHDLR_NAME
Definition: event_newsol.c:30
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:354
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:995
SCIP_RETCODE SCIPincludeEventHdlrNewsol(SCIP *scip)
Definition: event_newsol.c:103
static SCIP_DECL_EVENTINIT(eventInitNewsol)
Definition: event_newsol.c:49
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:388
problem data for cycle clustering problem
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1493
static SCIP_DECL_EVENTEXEC(eventExecNewsol)
Definition: event_newsol.c:77
#define SCIP_EVENTTYPE_BESTSOLFOUND
Definition: type_event.h:88
SCIP_RETCODE addCandSolCyckerlin(SCIP *scip, SCIP_SOL *sol)
Improvement heuristic that trades bin-variables between clusters.
#define EVENTHDLR_DESC
Definition: event_newsol.c:31
SCIP_SOL * SCIPeventGetSol(SCIP_EVENT *event)
Definition: event.c:1259