Scippy

SCIP

Solving Constraint Integer Programs

scip_timing.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-2022 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 scip_timing.c
17  * @ingroup OTHER_CFILES
18  * @brief public methods for timing
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Gerald Gamrath
22  * @author Leona Gottwald
23  * @author Stefan Heinz
24  * @author Gregor Hendel
25  * @author Thorsten Koch
26  * @author Alexander Martin
27  * @author Marc Pfetsch
28  * @author Michael Winkler
29  * @author Kati Wolter
30  *
31  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "scip/clock.h"
37 #include "scip/conflict.h"
38 #include "scip/debug.h"
39 #include "scip/pub_message.h"
40 #include "scip/reader.h"
41 #include "scip/scip_numerics.h"
42 #include "scip/scip_timing.h"
43 #include "scip/set.h"
44 #include "scip/stat.h"
45 #include "scip/struct_scip.h"
46 #include "scip/struct_set.h"
47 #include "scip/struct_stat.h"
48 
49 /** gets current time of day in seconds (standard time zone)
50  *
51  * @return the current time of day in seconds (standard time zone).
52  */
54  SCIP* scip /**< SCIP data structure */
55  )
56 {
57  assert(scip != NULL);
58 
59  return SCIPclockGetTimeOfDay();
60 }
61 
62 /** creates a clock using the default clock type
63  *
64  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
65  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
66  */
68  SCIP* scip, /**< SCIP data structure */
69  SCIP_CLOCK** clck /**< pointer to clock timer */
70  )
71 {
72  assert(scip != NULL);
73 
75 
76  return SCIP_OKAY;
77 }
78 
79 /** creates a clock counting the CPU user seconds
80  *
81  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
82  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
83  */
85  SCIP* scip, /**< SCIP data structure */
86  SCIP_CLOCK** clck /**< pointer to clock timer */
87  )
88 {
89  assert(scip != NULL);
90 
92 
93  return SCIP_OKAY;
94 }
95 
96 /** creates a clock counting the wall clock seconds
97  *
98  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
99  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
100  */
102  SCIP* scip, /**< SCIP data structure */
103  SCIP_CLOCK** clck /**< pointer to clock timer */
104  )
105 {
106  assert(scip != NULL);
107 
109 
110  return SCIP_OKAY;
111 }
112 
113 /** frees a clock
114  *
115  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
116  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
117  */
119  SCIP* scip, /**< SCIP data structure */
120  SCIP_CLOCK** clck /**< pointer to clock timer */
121  )
122 {
123  assert(scip != NULL);
124 
125  SCIPclockFree(clck);
126 
127  return SCIP_OKAY;
128 }
129 
130 /** resets the time measurement of a clock to zero and completely stops the clock
131  *
132  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
133  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
134  */
136  SCIP* scip, /**< SCIP data structure */
137  SCIP_CLOCK* clck /**< clock timer */
138  )
139 {
140  assert(scip != NULL);
141 
142  SCIPclockReset(clck);
143 
144  return SCIP_OKAY;
145 }
146 
147 /** starts the time measurement of a clock
148  *
149  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
150  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
151  */
153  SCIP* scip, /**< SCIP data structure */
154  SCIP_CLOCK* clck /**< clock timer */
155  )
156 {
157  assert(scip != NULL);
158 
159  SCIPclockStart(clck, scip->set);
160 
161  return SCIP_OKAY;
162 }
163 
164 /** stops the time measurement of a clock
165  *
166  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
167  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
168  */
170  SCIP* scip, /**< SCIP data structure */
171  SCIP_CLOCK* clck /**< clock timer */
172  )
173 {
174  assert(scip != NULL);
175 
176  SCIPclockStop(clck, scip->set);
177 
178  return SCIP_OKAY;
179 }
180 
181 /** enables or disables \p clck */
183  SCIP_CLOCK* clck, /**< the clock to be disabled/enabled */
184  SCIP_Bool enable /**< should the clock be enabled or disabled? */
185  )
186 {
187  SCIPclockEnableOrDisable(clck, enable);
188 }
189 
190 /** enables or disables all statistic clocks of SCIP concerning plugin statistics,
191  * LP execution time, strong branching time, etc.
192  *
193  * Method reads the value of the parameter timing/statistictiming. In order to disable statistic timing,
194  * set the parameter to FALSE.
195  *
196  * @note: The (pre-)solving time clocks which are relevant for the output during (pre-)solving
197  * are not affected by this method
198  *
199  * @see: For completely disabling all timing of SCIP, consider setting the parameter timing/enabled to FALSE
200  *
201  * @pre This method can be called if SCIP is in one of the following stages:
202  * - \ref SCIP_STAGE_INIT
203  * - \ref SCIP_STAGE_PROBLEM
204  * - \ref SCIP_STAGE_TRANSFORMING
205  * - \ref SCIP_STAGE_TRANSFORMED
206  * - \ref SCIP_STAGE_INITPRESOLVE
207  * - \ref SCIP_STAGE_PRESOLVING
208  * - \ref SCIP_STAGE_EXITPRESOLVE
209  * - \ref SCIP_STAGE_PRESOLVED
210  * - \ref SCIP_STAGE_INITSOLVE
211  * - \ref SCIP_STAGE_SOLVING
212  * - \ref SCIP_STAGE_SOLVED
213  * - \ref SCIP_STAGE_EXITSOLVE
214  * - \ref SCIP_STAGE_FREETRANS
215  *
216  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
217  */
219  SCIP* scip /**< SCIP data structure */
220  )
221 {
222  SCIP_CALL( SCIPcheckStage(scip, "SCIPenableOrDisableStatisticTiming", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
223 
225 
226  if( scip->set->stage > SCIP_STAGE_INIT )
227  {
228  assert(scip->stat != NULL);
230  }
231  if( scip->set->stage >= SCIP_STAGE_TRANSFORMING )
232  {
233  assert(scip->conflict != NULL);
235  }
236 
237  return SCIP_OKAY;
238 }
239 
240 /** starts the current solving time
241  *
242  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
243  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
244  *
245  * @pre This method can be called if SCIP is in one of the following stages:
246  * - \ref SCIP_STAGE_PROBLEM
247  * - \ref SCIP_STAGE_TRANSFORMING
248  * - \ref SCIP_STAGE_TRANSFORMED
249  * - \ref SCIP_STAGE_INITPRESOLVE
250  * - \ref SCIP_STAGE_PRESOLVING
251  * - \ref SCIP_STAGE_EXITPRESOLVE
252  * - \ref SCIP_STAGE_PRESOLVED
253  * - \ref SCIP_STAGE_INITSOLVE
254  * - \ref SCIP_STAGE_SOLVING
255  * - \ref SCIP_STAGE_SOLVED
256  * - \ref SCIP_STAGE_EXITSOLVE
257  * - \ref SCIP_STAGE_FREETRANS
258  *
259  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
260  */
262  SCIP* scip /**< SCIP data structure */
263  )
264 {
265  SCIP_CALL( SCIPcheckStage(scip, "SCIPstartSolvingTime", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
266 
267  SCIPclockStart(scip->stat->solvingtime, scip->set);
268  SCIPclockStart(scip->stat->solvingtimeoverall, scip->set);
269 
270  return SCIP_OKAY;
271 }
272 
273 /** stops the current solving time in seconds
274  *
275  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
276  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
277  *
278  * @pre This method can be called if SCIP is in one of the following stages:
279  * - \ref SCIP_STAGE_PROBLEM
280  * - \ref SCIP_STAGE_TRANSFORMING
281  * - \ref SCIP_STAGE_TRANSFORMED
282  * - \ref SCIP_STAGE_INITPRESOLVE
283  * - \ref SCIP_STAGE_PRESOLVING
284  * - \ref SCIP_STAGE_EXITPRESOLVE
285  * - \ref SCIP_STAGE_PRESOLVED
286  * - \ref SCIP_STAGE_INITSOLVE
287  * - \ref SCIP_STAGE_SOLVING
288  * - \ref SCIP_STAGE_SOLVED
289  * - \ref SCIP_STAGE_EXITSOLVE
290  * - \ref SCIP_STAGE_FREETRANS
291  *
292  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
293  */
295  SCIP* scip /**< SCIP data structure */
296  )
297 {
298  SCIP_CALL( SCIPcheckStage(scip, "SCIPstopSolvingTime", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
299 
300  SCIPclockStop(scip->stat->solvingtime, scip->set);
301  SCIPclockStop(scip->stat->solvingtimeoverall, scip->set);
302 
303  return SCIP_OKAY;
304 }
305 
306 /** gets the measured time of a clock in seconds
307  *
308  * @return the measured time of a clock in seconds.
309  */
311  SCIP* scip, /**< SCIP data structure */
312  SCIP_CLOCK* clck /**< clock timer */
313  )
314 {
315  assert(scip != NULL);
316 
317  return SCIPclockGetTime(clck);
318 }
319 
320 /** sets the measured time of a clock to the given value in seconds
321  *
322  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
323  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
324  */
326  SCIP* scip, /**< SCIP data structure */
327  SCIP_CLOCK* clck, /**< clock timer */
328  SCIP_Real sec /**< time in seconds to set the clock's timer to */
329  )
330 {
331  assert(scip != NULL);
332 
333  SCIPclockSetTime(clck, sec);
334 
335  return SCIP_OKAY;
336 }
337 
338 /** gets the current total SCIP time in seconds, possibly accumulated over several problems.
339  *
340  * @return the current total SCIP time in seconds, ie. the total time since the SCIP instance has been created
341  */
343  SCIP* scip /**< SCIP data structure */
344  )
345 {
346  assert(scip != NULL);
347 
348  return SCIPclockGetTime(scip->totaltime);
349 }
350 
351 /** gets the current solving time in seconds
352  *
353  * @return the current solving time in seconds.
354  *
355  * @pre This method can be called if SCIP is in one of the following stages:
356  * - \ref SCIP_STAGE_PROBLEM
357  * - \ref SCIP_STAGE_TRANSFORMING
358  * - \ref SCIP_STAGE_TRANSFORMED
359  * - \ref SCIP_STAGE_INITPRESOLVE
360  * - \ref SCIP_STAGE_PRESOLVING
361  * - \ref SCIP_STAGE_EXITPRESOLVE
362  * - \ref SCIP_STAGE_PRESOLVED
363  * - \ref SCIP_STAGE_INITSOLVE
364  * - \ref SCIP_STAGE_SOLVING
365  * - \ref SCIP_STAGE_SOLVED
366  *
367  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
368  */
370  SCIP* scip /**< SCIP data structure */
371  )
372 {
373  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetSolvingTime", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
374 
375  return SCIPclockGetTime(scip->stat->solvingtime);
376 }
377 
378 /** gets the current reading time in seconds
379  *
380  * @return the current reading time in seconds.
381  *
382  * @pre This method can be called if SCIP is in one of the following stages:
383  * - \ref SCIP_STAGE_PROBLEM
384  * - \ref SCIP_STAGE_TRANSFORMING
385  * - \ref SCIP_STAGE_TRANSFORMED
386  * - \ref SCIP_STAGE_INITPRESOLVE
387  * - \ref SCIP_STAGE_PRESOLVING
388  * - \ref SCIP_STAGE_EXITPRESOLVE
389  * - \ref SCIP_STAGE_PRESOLVED
390  * - \ref SCIP_STAGE_INITSOLVE
391  * - \ref SCIP_STAGE_SOLVING
392  * - \ref SCIP_STAGE_SOLVED
393  *
394  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
395  */
397  SCIP* scip /**< SCIP data structure */
398  )
399 {
400  SCIP_Real readingtime;
401  int r;
402 
403  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetReadingTime", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
404 
405  readingtime = 0.0;
406 
407  /* sum up the reading time of all readers */
408  for( r = 0; r < scip->set->nreaders; ++r )
409  {
410  assert(scip->set->readers[r] != NULL);
411  assert(!SCIPisNegative(scip, SCIPreaderGetReadingTime(scip->set->readers[r])));
412  readingtime += SCIPreaderGetReadingTime(scip->set->readers[r]);
413  }
414 
415  return readingtime;
416 }
417 
418 /** gets the current presolving time in seconds
419  *
420  * @return the current presolving time in seconds.
421  *
422  * @pre This method can be called if SCIP is in one of the following stages:
423  * - \ref SCIP_STAGE_INITPRESOLVE
424  * - \ref SCIP_STAGE_PRESOLVING
425  * - \ref SCIP_STAGE_EXITPRESOLVE
426  * - \ref SCIP_STAGE_PRESOLVED
427  * - \ref SCIP_STAGE_INITSOLVE
428  * - \ref SCIP_STAGE_SOLVING
429  * - \ref SCIP_STAGE_SOLVED
430  *
431  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
432  */
434  SCIP* scip /**< SCIP data structure */
435  )
436 {
437  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetPresolvingTime", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
438 
439  return SCIPclockGetTime(scip->stat->presolvingtime);
440 }
441 
442 /** gets the time need to solve the first LP in the root node
443  *
444  * @return the solving time for the first LP in the root node in seconds.
445  *
446  * @pre This method can be called if SCIP is in one of the following stages:
447  * - \ref SCIP_STAGE_TRANSFORMING
448  * - \ref SCIP_STAGE_TRANSFORMED
449  * - \ref SCIP_STAGE_INITPRESOLVE
450  * - \ref SCIP_STAGE_PRESOLVING
451  * - \ref SCIP_STAGE_EXITPRESOLVE
452  * - \ref SCIP_STAGE_PRESOLVED
453  * - \ref SCIP_STAGE_INITSOLVE
454  * - \ref SCIP_STAGE_SOLVING
455  * - \ref SCIP_STAGE_SOLVED
456  *
457  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
458  */
460  SCIP* scip /**< SCIP data structure */
461  )
462 {
463  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetFirstLPTime", FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
464 
465  return scip->stat->firstlptime;
466 }
void SCIPconflictEnableOrDisableClocks(SCIP_CONFLICT *conflict, SCIP_Bool enable)
Definition: conflict.c:9613
SCIP_STAT * stat
Definition: struct_scip.h:70
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:369
SCIP_READER ** readers
Definition: struct_set.h:70
SCIP_CONFLICT * conflict
Definition: struct_scip.h:87
SCIP_RETCODE SCIPsetClockTime(SCIP *scip, SCIP_CLOCK *clck, SCIP_Real sec)
Definition: scip_timing.c:325
SCIP_Real SCIPgetReadingTime(SCIP *scip)
Definition: scip_timing.c:396
internal methods for clocks and timing issues
SCIP_RETCODE SCIPcreateCPUClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip_timing.c:84
SCIP_CLOCK * totaltime
Definition: struct_scip.h:67
public methods for timing
SCIP_RETCODE SCIPstopClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:169
SCIP_Bool time_statistictiming
Definition: struct_set.h:588
void SCIPclockStop(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:351
#define FALSE
Definition: def.h:87
void SCIPstatEnableOrDisableStatClocks(SCIP_STAT *stat, SCIP_Bool enable)
Definition: stat.c:741
void SCIPclockStart(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:281
void SCIPsetClockEnabled(SCIP_CLOCK *clck, SCIP_Bool enable)
Definition: scip_timing.c:182
SCIP_STAGE stage
Definition: struct_set.h:65
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_RETCODE SCIPenableOrDisableStatisticTiming(SCIP *scip)
Definition: scip_timing.c:218
SCIP_RETCODE SCIPfreeClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip_timing.c:118
void SCIPclockEnableOrDisable(SCIP_CLOCK *clck, SCIP_Bool enable)
Definition: clock.c:251
SCIP_Real SCIPgetPresolvingTime(SCIP *scip)
Definition: scip_timing.c:433
public methods for numerical tolerances
SCIP_RETCODE SCIPcreateWallClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip_timing.c:101
void SCIPclockSetTime(SCIP_CLOCK *clck, SCIP_Real sec)
Definition: clock.c:523
SCIP_RETCODE SCIPcreateClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip_timing.c:67
void SCIPclockReset(SCIP_CLOCK *clck)
Definition: clock.c:200
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2177
SCIP_CLOCK * solvingtimeoverall
Definition: struct_stat.h:152
SCIP_Real SCIPclockGetTime(SCIP_CLOCK *clck)
Definition: clock.c:429
#define NULL
Definition: lpi_spx1.cpp:155
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:384
SCIP main data structure.
SCIP_RETCODE SCIPstopSolvingTime(SCIP *scip)
Definition: scip_timing.c:294
SCIP_RETCODE SCIPclockCreate(SCIP_CLOCK **clck, SCIP_CLOCKTYPE clocktype)
Definition: clock.c:161
#define SCIP_Bool
Definition: def.h:84
SCIP_Real SCIPreaderGetReadingTime(SCIP_READER *reader)
Definition: reader.c:598
SCIP_CLOCK * presolvingtime
Definition: struct_stat.h:153
SCIP_Real SCIPgetClockTime(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:310
internal methods for input file readers
void SCIPclockFree(SCIP_CLOCK **clck)
Definition: clock.c:176
SCIP_RETCODE SCIPstartSolvingTime(SCIP *scip)
Definition: scip_timing.c:261
int nreaders
Definition: struct_set.h:106
methods for debugging
SCIP_Real SCIPclockGetTimeOfDay(void)
Definition: clock.c:605
datastructures for problem statistics
SCIP_Real SCIPgetTimeOfDay(SCIP *scip)
Definition: scip_timing.c:53
void SCIPsetEnableOrDisablePluginClocks(SCIP_SET *set, SCIP_Bool enabled)
Definition: set.c:864
SCIP_Real * r
Definition: circlepacking.c:50
internal methods for conflict analysis
SCIP_RETCODE SCIPresetClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:135
SCIP_CLOCK * solvingtime
Definition: struct_stat.h:151
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
#define SCIP_Real
Definition: def.h:177
internal methods for problem statistics
SCIP_Real SCIPgetTotalTime(SCIP *scip)
Definition: scip_timing.c:342
SCIP_Real firstlptime
Definition: struct_stat.h:133
#define SCIP_CALL_ABORT(x)
Definition: def.h:363
SCIP_RETCODE SCIPstartClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:152
datastructures for global SCIP settings
SCIP_Real SCIPgetFirstLPTime(SCIP *scip)
Definition: scip_timing.c:459