Scippy

SCIP

Solving Constraint Integer Programs

scip_randnumgen.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-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 scip_randnumgen.c
17  * @ingroup OTHER_CFILES
18  * @brief public methods for random numbers
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/misc.h"
37 #include "scip/pub_message.h"
38 #include "scip/scip_mem.h"
39 #include "scip/scip_randnumgen.h"
40 #include "scip/set.h"
41 #include "scip/struct_scip.h"
42 
43 /** creates and initializes a random number generator
44  *
45  * @note The initial seed is changed using SCIPinitializeRandomSeed()
46  */
48  SCIP* scip, /**< SCIP data structure */
49  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
50  unsigned int initialseed, /**< initial random seed */
51  SCIP_Bool useglobalseed /**< should the supplied seed be initialized by SCIP's global seed shift? */
52  )
53 {
54  unsigned int modifiedseed;
55 
56  assert(scip != NULL);
57  assert(randnumgen != NULL);
58 
59  if( useglobalseed )
60  modifiedseed = SCIPinitializeRandomSeed(scip, initialseed);
61  else
62  modifiedseed = initialseed;
63 
64  SCIP_CALL( SCIPrandomCreate(randnumgen, SCIPblkmem(scip), modifiedseed) );
65 
66  return SCIP_OKAY;
67 }
68 
69 /** frees a random number generator */
71  SCIP* scip, /**< SCIP data structure */
72  SCIP_RANDNUMGEN** randnumgen /**< random number generator */
73  )
74 {
75  assert(scip != NULL);
76  assert(randnumgen != NULL);
77 
78  SCIPrandomFree(randnumgen, SCIPblkmem(scip));
79 }
80 
81 /** initializes a random number generator with a given start seed
82  *
83  * @note The seed is changed using SCIPinitializeRandomSeed()
84  */
86  SCIP* scip, /**< SCIP data structure */
87  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
88  unsigned int seed /**< new random seed */
89  )
90 {
91  unsigned int modifiedseed;
92 
93  assert(scip != NULL);
94  assert(randnumgen != NULL);
95 
96  modifiedseed = SCIPinitializeRandomSeed(scip, seed);
97 
98  SCIPrandomSetSeed(randnumgen, modifiedseed);
99 }
100 
101 /** modifies an initial seed value with the global shift of random seeds */
103  SCIP* scip, /**< SCIP data structure */
104  unsigned int initialseedvalue /**< initial seed value to be modified */
105  )
106 {
107  assert(scip != NULL);
108 
109  return SCIPsetInitializeRandomSeed(scip->set, initialseedvalue);
110 }
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
unsigned int SCIPsetInitializeRandomSeed(SCIP_SET *set, unsigned int initialseedvalue)
Definition: set.c:7169
public methods for memory management
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
unsigned int SCIPinitializeRandomSeed(SCIP *scip, unsigned int initialseedvalue)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
internal miscellaneous methods
#define NULL
Definition: lpi_spx1.cpp:155
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:9943
void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:9873
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:370
SCIP main data structure.
#define SCIP_Bool
Definition: def.h:70
void SCIPsetRandomSeed(SCIP *scip, SCIP_RANDNUMGEN *randnumgen, unsigned int seed)
public methods for random numbers
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:9927