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-2019 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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_randnumgen.c
17  * @brief public methods for random numbers
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Gerald Gamrath
21  * @author Robert Lion Gottwald
22  * @author Stefan Heinz
23  * @author Gregor Hendel
24  * @author Thorsten Koch
25  * @author Alexander Martin
26  * @author Marc Pfetsch
27  * @author Michael Winkler
28  * @author Kati Wolter
29  *
30  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include "scip/misc.h"
36 #include "scip/pub_message.h"
37 #include "scip/scip_mem.h"
38 #include "scip/scip_randnumgen.h"
39 #include "scip/set.h"
40 #include "scip/struct_scip.h"
41 
42 /** creates and initializes a random number generator
43  *
44  * @note The initial seed is changed using SCIPinitializeRandomSeed()
45  */
47  SCIP* scip, /**< SCIP data structure */
48  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
49  unsigned int initialseed, /**< initial random seed */
50  SCIP_Bool useglobalseed /**< should the supplied seed be initialized by SCIP's global seed shift? */
51  )
52 {
53  unsigned int modifiedseed;
54 
55  assert(scip != NULL);
56  assert(randnumgen != NULL);
57 
58  if( useglobalseed )
59  modifiedseed = SCIPinitializeRandomSeed(scip, initialseed);
60  else
61  modifiedseed = initialseed;
62 
63  SCIP_CALL( SCIPrandomCreate(randnumgen, SCIPblkmem(scip), modifiedseed) );
64 
65  return SCIP_OKAY;
66 }
67 
68 /** frees a random number generator */
70  SCIP* scip, /**< SCIP data structure */
71  SCIP_RANDNUMGEN** randnumgen /**< random number generator */
72  )
73 {
74  assert(scip != NULL);
75  assert(randnumgen != NULL);
76 
77  SCIPrandomFree(randnumgen, SCIPblkmem(scip));
78 }
79 
80 /** initializes a random number generator with a given start seed
81  *
82  * @note The seed is changed using SCIPinitializeRandomSeed()
83  */
85  SCIP* scip, /**< SCIP data structure */
86  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
87  unsigned int seed /**< new random seed */
88  )
89 {
90  unsigned int modifiedseed;
91 
92  assert(scip != NULL);
93  assert(randnumgen != NULL);
94 
95  modifiedseed = SCIPinitializeRandomSeed(scip, seed);
96 
97  SCIPrandomSetSeed(randnumgen, modifiedseed);
98 }
99 
100 /** modifies an initial seed value with the global shift of random seeds */
102  SCIP* scip, /**< SCIP data structure */
103  unsigned int initialseedvalue /**< initial seed value to be modified */
104  )
105 {
106  assert(scip != NULL);
107 
108  return SCIPsetInitializeRandomSeed(scip->set, initialseedvalue);
109 }
#define NULL
Definition: def.h:253
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
unsigned int SCIPsetInitializeRandomSeed(SCIP_SET *set, unsigned int initialseedvalue)
Definition: set.c:7125
public methods for memory management
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
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:47
internal miscellaneous methods
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:9602
void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:9532
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:365
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:62
public methods for message output
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:9586