1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                           */
3 /*                  This file is part of the program and library             */
4 /*         SCIP --- Solving Constraint Integer Programs                      */
5 /*                                                                           */
6 /*    Copyright (C) 2002-2021 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 scipopt.org.         */
13 /*                                                                           */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file   struct_event.h
17  * @ingroup INTERNALAPI
18  * @brief  datastructures for managing events
19  * @author Tobias Achterberg
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #ifndef __SCIP_STRUCT_EVENT_H__
25 #define __SCIP_STRUCT_EVENT_H__
26 
27 
28 #include "scip/def.h"
29 #include "scip/type_clock.h"
30 #include "scip/type_event.h"
31 #include "scip/type_var.h"
32 #include "scip/type_sol.h"
33 #include "scip/type_tree.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /** data for variable addition events */
40 struct SCIP_EventVarAdded
41 {
42    SCIP_VAR*             var;                /**< variable that was added to the problem */
43 };
44 
45 /** data for variable deletion events */
46 struct SCIP_EventVarDeleted
47 {
48    SCIP_VAR*             var;                /**< variable that will be deleted from the problem */
49 };
50 
51 /** data for variable fixing events */
52 struct SCIP_EventVarFixed
53 {
54    SCIP_VAR*             var;                /**< variable that was fixed */
55 };
56 
57 /** data for locks change events */
58 struct SCIP_EventVarUnlocked
59 {
60    SCIP_VAR*             var;                /**< variable for which the lock numbers were changed */
61 };
62 
63 /** data for objective value change events */
64 struct SCIP_EventObjChg
65 {
66    SCIP_Real             oldobj;             /**< old objective value before value changed */
67    SCIP_Real             newobj;             /**< new objective value after value changed */
68    SCIP_VAR*             var;                /**< variable whose objective value changed */
69 };
70 
71 /** data for bound change events */
72 struct SCIP_EventBdChg
73 {
74    SCIP_Real             oldbound;           /**< old bound before bound changed */
75    SCIP_Real             newbound;           /**< new bound after bound changed */
76    SCIP_VAR*             var;                /**< variable whose bound changed */
77 };
78 
79 /** data for domain hole events */
80 struct SCIP_EventHole
81 {
82    SCIP_Real             left;               /**< left bound of open interval in hole */
83    SCIP_Real             right;              /**< right bound of open interval in hole */
84    SCIP_VAR*             var;                /**< variable for which a hole was removed */
85 };
86 
87 /** data for implication added events */
88 struct SCIP_EventImplAdd
89 {
90    SCIP_VAR*             var;                /**< variable for which an implication, variable bound, or clique was added */
91 };
92 
93 /** data for variable type change events */
94 struct SCIP_EventTypeChg
95 {
96    SCIP_VARTYPE          oldtype;            /**< old variable type */
97    SCIP_VARTYPE          newtype;            /**< new variable type */
98    SCIP_VAR*             var;                /**< variable whose type changed */
99 };
100 
101 /** data for row addition to separation storage events */
102 struct SCIP_EventRowAddedSepa
103 {
104    SCIP_ROW*             row;                /**< row that was added to separation storage */
105 };
106 
107 /** data for row deletion from separation storage events */
108 struct SCIP_EventRowDeletedSepa
109 {
110    SCIP_ROW*             row;                /**< row that was deleted from separation storage */
111 };
112 
113 /** data for row addition to LP events */
114 struct SCIP_EventRowAddedLP
115 {
116    SCIP_ROW*             row;                /**< row that was added to the LP */
117 };
118 
119 /** data for row deletion from LP events */
120 struct SCIP_EventRowDeletedLP
121 {
122    SCIP_ROW*             row;                /**< row that was deleted from the LP */
123 };
124 
125 /** data for row coefficient change events */
126 struct SCIP_EventRowCoefChanged
127 {
128    SCIP_ROW*             row;                /**< row which coefficient has changed */
129    SCIP_COL*             col;                /**< column which coefficient has changed */
130    SCIP_Real             oldval;             /**< old value of coefficient */
131    SCIP_Real             newval;             /**< new value of coefficient */
132 };
133 
134 /** data for row constant change events */
135 struct SCIP_EventRowConstChanged
136 {
137    SCIP_ROW*             row;                /**< row which constant has changed */
138    SCIP_Real             oldval;             /**< old value of constant */
139    SCIP_Real             newval;             /**< new value of constant */
140 };
141 
142 /** data for row side change events */
143 struct SCIP_EventRowSideChanged
144 {
145    SCIP_ROW*             row;                /**< row which side has changed */
146    SCIP_SIDETYPE         side;               /**< which side has changed */
147    SCIP_Real             oldval;             /**< old value of side */
148    SCIP_Real             newval;             /**< new value of side */
149 };
150 
151 /** event data structure */
152 struct SCIP_Event
153 {
154    union
155    {
156       SCIP_EVENTVARADDED eventvaradded;       /**< data for variable addition events */
157       SCIP_EVENTVARDELETED eventvardeleted;   /**< data for variable deletion events */
158       SCIP_EVENTVARFIXED eventvarfixed;       /**< data for variable fixing events */
159       SCIP_EVENTVARUNLOCKED eventvarunlocked; /**< data for locks change events */
160       SCIP_EVENTOBJCHG   eventobjchg;         /**< data for objective value change events */
161       SCIP_EVENTBDCHG    eventbdchg;          /**< data for bound change events */
162       SCIP_EVENTHOLE     eventhole;           /**< data for domain hole events */
163       SCIP_EVENTIMPLADD  eventimpladd;        /**< data for implication added events */
164       SCIP_EVENTTYPECHG  eventtypechg;        /**< data for variable type change events */
165       SCIP_EVENTROWADDEDSEPA eventrowaddedsepa; /**< data for row addition to separation storage events */
166       SCIP_EVENTROWDELETEDSEPA eventrowdeletedsepa; /**< data for row deletion from separation storage events */
167       SCIP_EVENTROWADDEDLP eventrowaddedlp;   /**< data for row addition to LP events */
168       SCIP_EVENTROWDELETEDLP eventrowdeletedlp; /**< data for row deletion from LP events */
169       SCIP_EVENTROWCOEFCHANGED eventrowcoefchanged; /**< data for row coefficient change events */
170       SCIP_EVENTROWCONSTCHANGED eventrowconstchanged; /**< data for row constant change events */
171       SCIP_EVENTROWSIDECHANGED eventrowsidechanged; /**< data for row side change events */
172       SCIP_NODE*         node;                /**< data for node and LP events */
173       SCIP_SOL*          sol;                 /**< data for primal solution events */
174    } data;
175    SCIP_EVENTTYPE        eventtype;          /**< type of event */
176 };
177 
178 /** event filter to select events to be processed by an event handler */
179 struct SCIP_EventFilter
180 {
181    SCIP_EVENTTYPE*       eventtypes;         /**< array with types of event to process; 0 marks a deleted event catch entry */
182    SCIP_EVENTHDLR**      eventhdlrs;         /**< array with event handlers to process the event */
183    SCIP_EVENTDATA**      eventdata;          /**< array with user data for the issued event */
184    int*                  nextpos;            /**< linked lists for free, delayed added and delayed deleted slot positions */
185    int                   size;               /**< size of filter arrays (available slots in arrays) */
186    int                   len;                /**< number entries in filter arrays (used and deleted) */
187    int                   firstfreepos;       /**< first deleted slot; remaining slots are in poslist */
188    int                   firstdeletedpos;    /**< first delayed deleted slot; remaining slots are in poslist */
189    SCIP_EVENTTYPE        eventmask;          /**< mask for events that are handled by any event handler in the filter */
190    SCIP_EVENTTYPE        delayedeventmask;   /**< mask for delayed added events */
191    SCIP_Bool             delayupdates;       /**< should additions and deletions to the filter be delayed? */
192 };
193 
194 /** event handler */
195 struct SCIP_Eventhdlr
196 {
197    char*                 name;               /**< name of event handler */
198    char*                 desc;               /**< description of event handler */
199    SCIP_DECL_EVENTCOPY   ((*eventcopy));     /**< copy method of event handler or NULL if you don't want to copy your plugin into sub-SCIPs */
200    SCIP_DECL_EVENTFREE   ((*eventfree));     /**< destructor of event handler */
201    SCIP_DECL_EVENTINIT   ((*eventinit));     /**< initialize event handler */
202    SCIP_DECL_EVENTEXIT   ((*eventexit));     /**< deinitialize event handler */
203    SCIP_DECL_EVENTINITSOL((*eventinitsol));  /**< solving process initialization method of event handler */
204    SCIP_DECL_EVENTEXITSOL((*eventexitsol));  /**< solving process deinitialization method of event handler */
205    SCIP_DECL_EVENTDELETE ((*eventdelete));   /**< free specific event data */
206    SCIP_DECL_EVENTEXEC   ((*eventexec));     /**< execute event handler */
207    SCIP_EVENTHDLRDATA*   eventhdlrdata;      /**< event handler data */
208    SCIP_CLOCK*           setuptime;          /**< time spend for setting up this event handler for the next stages */
209    SCIP_CLOCK*           eventtime;          /**< time spend in this event handler execution method */
210    SCIP_Bool             initialized;        /**< is event handler initialized? */
211 };
212 
213 /** event queue to cache events and process them later */
214 struct SCIP_EventQueue
215 {
216    SCIP_EVENT**          events;             /**< array with queued events */
217    int                   eventssize;         /**< number of available slots in events array */
218    int                   nevents;            /**< number of events in queue (used slots if events array) */
219    SCIP_Bool             delayevents;        /**< should the events be delayed and processed later? */
220 };
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif
227