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-2024 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file event_newsol.c
26 * @brief eventhdlr that adds new solutions to the candidate pool for the exchange heuristic
27 * @author Leon Eifler
28 */
29
30/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31
32#include <assert.h>
33#include <string.h>
34
35#include "event_newsol.h"
36#include "heur_cyckerlin.h"
37#include "probdata_cyc.h"
38
39#define EVENTHDLR_NAME "newsol"
40#define EVENTHDLR_DESC "event handler for solution events"
41
42/** copy method for event handler plugins (called when SCIP copies plugins) */
43static
44SCIP_DECL_EVENTCOPY(eventCopyNewsol)
45{ /*lint --e{715}*/
46 assert(scip != NULL);
47 assert(eventhdlr != NULL);
48 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
49
50 /* call inclusion method of event handler */
52
53 return SCIP_OKAY;
54}
55
56/** initialization method of event handler (called after problem was transformed) */
57static
58SCIP_DECL_EVENTINIT(eventInitNewsol)
59{ /*lint --e{715}*/
60 assert(scip != NULL);
61 assert(eventhdlr != NULL);
62 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
63
64 /* notify SCIP that your event handler wants to react on the event type best solution found */
66
67 return SCIP_OKAY;
68}
69
70/** deinitialization method of event handler (called before transformed problem is freed) */
71static
72SCIP_DECL_EVENTEXIT(eventExitNewsol)
73{ /*lint --e{715}*/
74 assert(scip != NULL);
75 assert(eventhdlr != NULL);
76 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
77
78 /* notify SCIP that your event handler wants to drop the event type best solution found */
80
81 return SCIP_OKAY;
82}
83
84/** execution method of event handler */
85static
86SCIP_DECL_EVENTEXEC(eventExecNewsol)
87{ /*lint --e{715}*/
88 SCIP_SOL* newsol;
89
90 assert(eventhdlr != NULL);
91 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
92 assert(event != NULL);
93 assert(scip != NULL);
95
97 return SCIP_OKAY;
98
99 SCIPdebugMsg(scip, "exec method of event handler for newsol solution found\n");
100
101 newsol = SCIPeventGetSol(event);
102 assert(newsol != NULL);
103
104 SCIPdebugMsg(scip, "catch event for solution %p with obj=%g.\n", (void*) newsol, SCIPgetSolOrigObj(scip, newsol));
105
107
108 return SCIP_OKAY;
109}
110
111/** includes event handler for best solution found */
113 SCIP* scip /**< SCIP data structure */
114 )
115{
116 SCIP_EVENTHDLRDATA* eventhdlrdata;
117 SCIP_EVENTHDLR* eventhdlr;
118 eventhdlrdata = NULL;
119
120 eventhdlr = NULL;
121 /* create event handler for events on watched variables */
123 eventExecNewsol, eventhdlrdata) );
124
125 assert(eventhdlr != NULL);
126
127 SCIP_CALL( SCIPsetEventhdlrCopy(scip, eventhdlr, eventCopyNewsol) );
128 SCIP_CALL( SCIPsetEventhdlrInit(scip, eventhdlr, eventInitNewsol) );
129 SCIP_CALL( SCIPsetEventhdlrExit(scip, eventhdlr, eventExitNewsol) );
130
131 return SCIP_OKAY;
132}
#define NULL
Definition: def.h:266
#define SCIP_CALL(x)
Definition: def.h:373
static SCIP_DECL_EVENTEXEC(eventExecNewsol)
Definition: event_newsol.c:86
SCIP_RETCODE SCIPincludeEventHdlrNewsol(SCIP *scip)
Definition: event_newsol.c:112
static SCIP_DECL_EVENTCOPY(eventCopyNewsol)
Definition: event_newsol.c:44
static SCIP_DECL_EVENTEXIT(eventExitNewsol)
Definition: event_newsol.c:72
#define EVENTHDLR_DESC
Definition: event_newsol.c:40
#define EVENTHDLR_NAME
Definition: event_newsol.c:39
static SCIP_DECL_EVENTINIT(eventInitNewsol)
Definition: event_newsol.c:58
eventhdlr that adds new solutions to the candidate pool for the exchange heuristic
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:390
#define SCIPdebugMsg
Definition: scip_message.h:78
SCIP_RETCODE SCIPsetEventhdlrCopy(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTCOPY((*eventcopy)))
Definition: scip_event.c:136
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:104
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:324
SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTEXIT((*eventexit)))
Definition: scip_event.c:178
SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTINIT((*eventinit)))
Definition: scip_event.c:164
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:1030
SCIP_SOL * SCIPeventGetSol(SCIP_EVENT *event)
Definition: event.c:1337
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:286
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:320
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1296
SCIP_RETCODE addCandSolCyckerlin(SCIP *scip, SCIP_SOL *sol)
Improvement heuristic that trades bin-variables between clusters.
problem data for cycle clustering problem
struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
Definition: type_event.h:155
#define SCIP_EVENTTYPE_BESTSOLFOUND
Definition: type_event.h:105
@ SCIP_OKAY
Definition: type_retcode.h:42
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
@ SCIP_STAGE_SOLVING
Definition: type_set.h:53