SCIP Doxygen Documentation
 
Loading...
Searching...
No Matches
event_softtimelimit.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_softtimelimit.c
26 * @ingroup DEFPLUGINS_EVENT
27 * @brief eventhdlr for soft time limit
28 * @author Gerald Gamrath
29 */
30
31/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32
34#include "scip/pub_event.h"
35#include "scip/pub_message.h"
36#include "scip/scip_event.h"
37#include "scip/scip_mem.h"
38#include "scip/scip_message.h"
39#include "scip/scip_numerics.h"
40#include "scip/scip_param.h"
41#include <string.h>
42
43#define EVENTHDLR_NAME "softtimelimit"
44#define EVENTHDLR_DESC "event handler for soft time limit"
45
46/*
47 * Data structures
48 */
49
50/** event handler data */
51struct SCIP_EventhdlrData
52{
53 SCIP_Real softtimelimit;
54 int filterpos;
55};
56
57/*
58 * Callback methods of event handler
59 */
60
61/** copy method for event handler plugins (called when SCIP copies plugins) */
62/**! [SnippetEventCopySofttimelimit] */
63static
65{ /*lint --e{715}*/
66 assert(scip != NULL);
67 assert(eventhdlr != NULL);
69
70 /* call inclusion method of event handler */
72
73 return SCIP_OKAY;
74}
75/**! [SnippetEventCopySofttimelimit] */
76
77/** destructor of event handler to free user data (called when SCIP is exiting) */
78/**! [SnippetEventFreeSofttimelimit] */
79static
81{ /*lint --e{715}*/
82 SCIP_EVENTHDLRDATA* eventhdlrdata;
83
84 assert(scip != NULL);
85 assert(eventhdlr != NULL);
87
88 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
89 assert(eventhdlrdata != NULL);
90
91 SCIPfreeBlockMemory(scip, &eventhdlrdata);
92 SCIPeventhdlrSetData(eventhdlr, NULL);
93
94 return SCIP_OKAY;
95}
96/**! [SnippetEventFreeSofttimelimit] */
97
98
99
100/** initialization method of event handler (called after problem was transformed) */
101static
103{ /*lint --e{715}*/
104 SCIP_EVENTHDLRDATA* eventhdlrdata;
105
106 assert(scip != NULL);
107 assert(eventhdlr != NULL);
109
110 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
111 assert(eventhdlrdata != NULL);
112
113 if( eventhdlrdata->filterpos < 0 && !SCIPisNegative(scip, eventhdlrdata->softtimelimit) )
114 {
115 /* notify SCIP that your event handler wants to react on the event type best solution found */
116 SCIP_CALL( SCIPcatchEvent(scip, SCIP_EVENTTYPE_BESTSOLFOUND, eventhdlr, NULL, &eventhdlrdata->filterpos) );
117 }
118
119 return SCIP_OKAY;
120}
121
122/** deinitialization method of event handler (called before transformed problem is freed) */
123static
125{ /*lint --e{715}*/
126 SCIP_EVENTHDLRDATA* eventhdlrdata;
127
128 assert(scip != NULL);
129 assert(eventhdlr != NULL);
131
132 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
133 assert(eventhdlrdata != NULL);
134
135 /* notify SCIP that your event handler wants to drop the event type best solution found */
136 if( eventhdlrdata->filterpos >= 0 )
137 {
138 SCIP_CALL( SCIPdropEvent(scip, SCIP_EVENTTYPE_BESTSOLFOUND, eventhdlr, NULL, eventhdlrdata->filterpos) );
139 eventhdlrdata->filterpos = -1;
140 }
141
142 return SCIP_OKAY;
143}
144
145/** execution method of event handler */
146static
148{ /*lint --e{715}*/
149 SCIP_EVENTHDLRDATA* eventhdlrdata;
150 SCIP_Real timelimit;
151
152 assert(eventhdlr != NULL);
154 assert(event != NULL);
155 assert(scip != NULL);
157
158 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
159 assert(eventhdlrdata != NULL);
160
161 SCIPdebugMsg(scip, "exec method of event handler for soft time limit\n");
162
163 SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
164
165 if( eventhdlrdata->softtimelimit < timelimit )
166 {
167 SCIP_CALL( SCIPsetRealParam(scip, "limits/time", eventhdlrdata->softtimelimit) );
168 }
169
170 /* notify SCIP that your event handler wants to drop the event type best solution found */
171 SCIP_CALL( SCIPdropEvent(scip, SCIP_EVENTTYPE_BESTSOLFOUND, eventhdlr, NULL, eventhdlrdata->filterpos) );
172 eventhdlrdata->filterpos = -1;
173
174 /* print best solution value */
175 SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "changed time limit to %.1f after first solution was found\n",
176 eventhdlrdata->softtimelimit);
177
178 return SCIP_OKAY;
179}
180
181/** includes event handler for best solution found */
183 SCIP* scip /**< SCIP data structure */
184 )
185{
186 SCIP_EVENTHDLRDATA* eventhdlrdata;
187 SCIP_EVENTHDLR* eventhdlr = NULL;
188
189 SCIP_CALL( SCIPallocBlockMemory(scip, &eventhdlrdata) );
190 eventhdlrdata->filterpos = -1;
191
192 /* create event handler for events on watched variables */
194 assert(eventhdlr != NULL);
195
200
201 SCIP_CALL( SCIPaddRealParam(scip, "limits/softtime",
202 "soft time limit which should be applied after first solution was found (-1.0: disabled)",
203 &eventhdlrdata->softtimelimit, FALSE, -1.0, -1.0, SCIP_REAL_MAX, NULL, NULL) );
204
205 return SCIP_OKAY;
206}
#define NULL
Definition def.h:267
#define SCIP_REAL_MAX
Definition def.h:174
#define FALSE
Definition def.h:94
#define SCIP_CALL(x)
Definition def.h:374
SCIP_RETCODE SCIPincludeEventHdlrSofttimelimit(SCIP *scip)
#define EVENTHDLR_DESC
#define EVENTHDLR_NAME
eventhdlr for soft time limit
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
#define SCIPdebugMsg
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition scip_param.c:139
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition scip_param.c:307
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition scip_param.c:603
SCIP_RETCODE SCIPsetEventhdlrFree(SCIP *scip, SCIP_EVENTHDLR *eventhdlr,)
Definition scip_event.c:150
SCIP_RETCODE SCIPsetEventhdlrCopy(SCIP *scip, SCIP_EVENTHDLR *eventhdlr,)
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
SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr,)
Definition scip_event.c:178
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition event.c:324
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
Definition event.c:334
SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr,)
Definition scip_event.c:164
void SCIPeventhdlrSetData(SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition event.c:344
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition event.c:1030
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
#define SCIPfreeBlockMemory(scip, ptr)
Definition scip_mem.h:108
#define SCIPallocBlockMemory(scip, ptr)
Definition scip_mem.h:89
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
return SCIP_OKAY
assert(minobj< SCIPgetCutoffbound(scip))
public methods for managing events
public methods for message output
public methods for event handler plugins and event handlers
public methods for memory management
public methods for message handling
public methods for numerical tolerances
public methods for SCIP parameter handling
#define SCIP_DECL_EVENTEXIT(x)
Definition type_event.h:207
struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
Definition type_event.h:155
#define SCIP_DECL_EVENTEXEC(x)
Definition type_event.h:253
#define SCIP_DECL_EVENTCOPY(x)
Definition type_event.h:183
#define SCIP_DECL_EVENTINIT(x)
Definition type_event.h:199
#define SCIP_EVENTTYPE_BESTSOLFOUND
Definition type_event.h:105
#define SCIP_DECL_EVENTFREE(x)
Definition type_event.h:191
@ SCIP_VERBLEVEL_FULL
enum SCIP_Retcode SCIP_RETCODE