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 <ctype.h>
36 #include <stdarg.h>
37 #include <assert.h>
38 #include <string.h>
39 #if defined(_WIN32) || defined(_WIN64)
40 #else
41 #include <strings.h> /*lint --e{766}*/
42 #endif
43 
44 
45 #include "lpi/lpi.h"
46 #include "nlpi/exprinterpret.h"
47 #include "nlpi/nlpi.h"
48 #include "scip/benders.h"
49 #include "scip/benderscut.h"
50 #include "scip/branch.h"
51 #include "scip/branch_nodereopt.h"
52 #include "scip/clock.h"
53 #include "scip/compr.h"
54 #include "scip/concsolver.h"
55 #include "scip/concurrent.h"
56 #include "scip/conflict.h"
57 #include "scip/conflictstore.h"
58 #include "scip/cons.h"
59 #include "scip/cons_linear.h"
60 #include "scip/cutpool.h"
61 #include "scip/cuts.h"
62 #include "scip/debug.h"
63 #include "scip/def.h"
64 #include "scip/dialog.h"
65 #include "scip/dialog_default.h"
66 #include "scip/disp.h"
67 #include "scip/event.h"
68 #include "scip/heur.h"
69 #include "scip/heur_ofins.h"
70 #include "scip/heur_reoptsols.h"
72 #include "scip/heuristics.h"
73 #include "scip/history.h"
74 #include "scip/implics.h"
75 #include "scip/interrupt.h"
76 #include "scip/lp.h"
77 #include "scip/mem.h"
78 #include "scip/message_default.h"
79 #include "scip/misc.h"
80 #include "scip/nlp.h"
81 #include "scip/nodesel.h"
82 #include "scip/paramset.h"
83 #include "scip/presol.h"
84 #include "scip/presolve.h"
85 #include "scip/pricer.h"
86 #include "scip/pricestore.h"
87 #include "scip/primal.h"
88 #include "scip/prob.h"
89 #include "scip/prop.h"
90 #include "scip/reader.h"
91 #include "scip/relax.h"
92 #include "scip/reopt.h"
93 #include "scip/retcode.h"
94 #include "scip/scipbuildflags.h"
95 #include "scip/scipcoreplugins.h"
96 #include "scip/scipgithash.h"
97 #include "scip/sepa.h"
98 #include "scip/sepastore.h"
99 #include "scip/set.h"
100 #include "scip/sol.h"
101 #include "scip/solve.h"
102 #include "scip/stat.h"
103 #include "scip/syncstore.h"
104 #include "scip/table.h"
105 #include "scip/tree.h"
106 #include "scip/var.h"
107 #include "scip/visual.h"
108 #include "xml/xml.h"
109 
110 #include "scip/scip_mem.h"
111 #include "scip/scip_randnumgen.h"
112 #include "scip/scip_var.h"
113 
114 #include "scip/pub_message.h"
115 
116 
117 /* In debug mode, we include the SCIP's structure in scip.c, such that no one can access
118  * this structure except the interface methods in scip.c.
119  * In optimized mode, the structure is included in scip.h, because some of the methods
120  * are implemented as defines for performance reasons (e.g. the numerical comparisons)
121  */
122 #ifndef NDEBUG
123 #include "scip/struct_scip.h"
124 #endif
125 
126 /** creates and initializes a random number generator
127  *
128  * @note The initial seed is changed using SCIPinitializeRandomSeed()
129  */
131  SCIP* scip, /**< SCIP data structure */
132  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
133  unsigned int initialseed, /**< initial random seed */
134  SCIP_Bool useglobalseed /**< should the supplied seed be initialized by SCIP's global seed shift? */
135  )
136 {
137  unsigned int modifiedseed;
138 
139  assert(scip != NULL);
140  assert(randnumgen != NULL);
141 
142  if( useglobalseed )
143  modifiedseed = SCIPinitializeRandomSeed(scip, initialseed);
144  else
145  modifiedseed = initialseed;
146 
147  SCIP_CALL( SCIPrandomCreate(randnumgen, SCIPblkmem(scip), modifiedseed) );
148 
149  return SCIP_OKAY;
150 }
151 
152 /** frees a random number generator */
154  SCIP* scip, /**< SCIP data structure */
155  SCIP_RANDNUMGEN** randnumgen /**< random number generator */
156  )
157 {
158  assert(scip != NULL);
159  assert(randnumgen != NULL);
160 
161  SCIPrandomFree(randnumgen, SCIPblkmem(scip));
162 }
163 
164 /** initializes a random number generator with a given start seed
165  *
166  * @note The seed is changed using SCIPinitializeRandomSeed()
167  */
169  SCIP* scip, /**< SCIP data structure */
170  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
171  unsigned int seed /**< new random seed */
172  )
173 {
174  unsigned int modifiedseed;
175 
176  assert(scip != NULL);
177  assert(randnumgen != NULL);
178 
179  modifiedseed = SCIPinitializeRandomSeed(scip, seed);
180 
181  SCIPrandomSetSeed(randnumgen, modifiedseed);
182 }
183 
184 /** modifies an initial seed value with the global shift of random seeds */
186  SCIP* scip, /**< SCIP data structure */
187  unsigned int initialseedvalue /**< initial seed value to be modified */
188  )
189 {
190  assert(scip != NULL);
191 
192  return SCIPsetInitializeRandomSeed(scip->set, initialseedvalue);
193 }
internal methods for separators
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
#define NULL
Definition: def.h:246
internal methods for managing events
default message handler
trivialnegation primal heuristic
internal methods for storing primal CIP solutions
methods to interpret (evaluate) an expression tree "fast"
internal methods for branch and bound tree
unsigned int SCIPsetInitializeRandomSeed(SCIP_SET *set, unsigned int initialseedvalue)
Definition: set.c:7133
public methods for memory management
methods for implications, variable bounds, and cliques
internal methods for clocks and timing issues
void SCIPsetRandomSeed(SCIP *scip, SCIP_RANDNUMGEN *randnumgen, unsigned int seed)
internal methods for NLPI solver interfaces
interface methods for specific LP solvers
internal methods for displaying statistics tables
methods for the aggregation rows
internal methods for Benders&#39; decomposition
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
methods commonly used by primal heuristics
internal methods for branching rules and branching candidate storage
datastructures for concurrent solvers
internal methods for handling parameter settings
methods for creating output for visualization tools (VBC, BAK)
nodereopt branching rule
public methods for SCIP variables
internal methods for LP management
internal methods for branching and inference history
internal methods for collecting primal CIP solutions and primal informations
internal methods for propagators
git hash methods
internal methods for storing and manipulating the main problem
methods for block memory pools and memory buffers
register additional core functionality that is designed as plugins
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:128
internal methods for presolvers
internal methods for NLP management
internal miscellaneous methods
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:9592
void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:9522
internal methods for node selectors and node priority queues
internal methods for variable pricers
internal methods for global SCIP settings
internal methods for storing conflicts
#define SCIP_CALL(x)
Definition: def.h:358
SCIP main data structure.
internal methods for storing priced variables
internal methods for relaxators
internal methods for storing separated cuts
methods commonly used for presolving
methods for catching the user CTRL-C interrupt
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
internal methods for problem variables
data structures and methods for collecting reoptimization information
the function declarations for the synchronization store
internal methods for user interface dialog
#define SCIP_Bool
Definition: def.h:69
internal methods for input file readers
methods for debugging
reoptsols primal heuristic
internal methods for storing cuts in a cut pool
Constraint handler for linear constraints in their most general form, .
helper functions for concurrent scip solvers
internal methods for return codes for SCIP methods
internal methods for conflict analysis
internal methods for tree compressions
public methods for random numbers
internal methods for main solving loop and node processing
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
default user interface dialog
internal methods for problem statistics
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:9576
internal methods for constraints and constraint handlers
declarations for XML parsing
build flags methods
unsigned int SCIPinitializeRandomSeed(SCIP *scip, unsigned int initialseedvalue)
common defines and data types used in all packages of SCIP
internal methods for primal heuristics
internal methods for Benders&#39; decomposition cuts
internal methods for displaying runtime statistics
OFINS - Objective Function Induced Neighborhood Search - a primal heuristic for reoptimization.