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