Scippy

SCIP

Solving Constraint Integer Programs

misc.h
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 misc.h
17  * @ingroup INTERNALAPI
18  * @brief internal miscellaneous methods
19  * @author Tobias Achterberg
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #ifndef __SCIP_MISC_H__
25 #define __SCIP_MISC_H__
26 
27 
28 #include "scip/def.h"
29 #include "blockmemshell/memory.h"
30 #include "scip/type_retcode.h"
31 #include "scip/type_set.h"
32 #include "scip/type_misc.h"
33 #include "scip/pub_misc.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Dynamic Arrays
41  */
42 
43 /** creates a dynamic array of real values */
45  SCIP_REALARRAY** realarray, /**< pointer to store the real array */
46  BMS_BLKMEM* blkmem /**< block memory */
47  );
48 
49 /** creates a copy of a dynamic array of real values */
51  SCIP_REALARRAY** realarray, /**< pointer to store the copied real array */
52  BMS_BLKMEM* blkmem, /**< block memory */
53  SCIP_REALARRAY* sourcerealarray /**< dynamic real array to copy */
54  );
55 
56 /** frees a dynamic array of real values */
58  SCIP_REALARRAY** realarray /**< pointer to the real array */
59  );
60 
61 /** extends dynamic array to be able to store indices from minidx to maxidx */
63  SCIP_REALARRAY* realarray, /**< dynamic real array */
64  int arraygrowinit, /**< initial size of array */
65  SCIP_Real arraygrowfac, /**< growing factor of array */
66  int minidx, /**< smallest index to allocate storage for */
67  int maxidx /**< largest index to allocate storage for */
68  );
69 
70 /** clears a dynamic real array */
72  SCIP_REALARRAY* realarray /**< dynamic real array */
73  );
74 
75 /** gets value of entry in dynamic array */
77  SCIP_REALARRAY* realarray, /**< dynamic real array */
78  int idx /**< array index to get value for */
79  );
80 
81 /** sets value of entry in dynamic array */
83  SCIP_REALARRAY* realarray, /**< dynamic real array */
84  int arraygrowinit, /**< initial size of array */
85  SCIP_Real arraygrowfac, /**< growing factor of array */
86  int idx, /**< array index to set value for */
87  SCIP_Real val /**< value to set array index to */
88  );
89 
90 /** increases value of entry in dynamic array */
92  SCIP_REALARRAY* realarray, /**< dynamic real array */
93  int arraygrowinit, /**< initial size of array */
94  SCIP_Real arraygrowfac, /**< growing factor of array */
95  int idx, /**< array index to increase value for */
96  SCIP_Real incval /**< value to increase array index */
97  );
98 
99 /** returns the minimal index of all stored non-zero elements */
101  SCIP_REALARRAY* realarray /**< dynamic real array */
102  );
103 
104 /** returns the maximal index of all stored non-zero elements */
106  SCIP_REALARRAY* realarray /**< dynamic real array */
107  );
108 
109 /** creates a dynamic array of int values */
111  SCIP_INTARRAY** intarray, /**< pointer to store the int array */
112  BMS_BLKMEM* blkmem /**< block memory */
113  );
114 
115 /** creates a copy of a dynamic array of int values */
117  SCIP_INTARRAY** intarray, /**< pointer to store the copied int array */
118  BMS_BLKMEM* blkmem, /**< block memory */
119  SCIP_INTARRAY* sourceintarray /**< dynamic int array to copy */
120  );
121 
122 /** frees a dynamic array of int values */
124  SCIP_INTARRAY** intarray /**< pointer to the int array */
125  );
126 
127 /** extends dynamic array to be able to store indices from minidx to maxidx */
129  SCIP_INTARRAY* intarray, /**< dynamic int array */
130  int arraygrowinit, /**< initial size of array */
131  SCIP_Real arraygrowfac, /**< growing factor of array */
132  int minidx, /**< smallest index to allocate storage for */
133  int maxidx /**< largest index to allocate storage for */
134  );
135 
136 /** clears a dynamic int array */
138  SCIP_INTARRAY* intarray /**< dynamic int array */
139  );
140 
141 /** gets value of entry in dynamic array */
143  SCIP_INTARRAY* intarray, /**< dynamic int array */
144  int idx /**< array index to get value for */
145  );
146 
147 /** sets value of entry in dynamic array */
149  SCIP_INTARRAY* intarray, /**< dynamic int array */
150  int arraygrowinit, /**< initial size of array */
151  SCIP_Real arraygrowfac, /**< growing factor of array */
152  int idx, /**< array index to set value for */
153  int val /**< value to set array index to */
154  );
155 
156 /** increases value of entry in dynamic array */
158  SCIP_INTARRAY* intarray, /**< dynamic int array */
159  int arraygrowinit, /**< initial size of array */
160  SCIP_Real arraygrowfac, /**< growing factor of array */
161  int idx, /**< array index to increase value for */
162  int incval /**< value to increase array index */
163  );
164 
165 /** returns the minimal index of all stored non-zero elements */
167  SCIP_INTARRAY* intarray /**< dynamic int array */
168  );
169 
170 /** returns the maximal index of all stored non-zero elements */
172  SCIP_INTARRAY* intarray /**< dynamic int array */
173  );
174 
175 /** creates a dynamic array of bool values */
177  SCIP_BOOLARRAY** boolarray, /**< pointer to store the bool array */
178  BMS_BLKMEM* blkmem /**< block memory */
179  );
180 
181 /** creates a copy of a dynamic array of bool values */
183  SCIP_BOOLARRAY** boolarray, /**< pointer to store the copied bool array */
184  BMS_BLKMEM* blkmem, /**< block memory */
185  SCIP_BOOLARRAY* sourceboolarray /**< dynamic bool array to copy */
186  );
187 
188 /** frees a dynamic array of bool values */
190  SCIP_BOOLARRAY** boolarray /**< pointer to the bool array */
191  );
192 
193 /** extends dynamic array to be able to store indices from minidx to maxidx */
195  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
196  int arraygrowinit, /**< initial size of array */
197  SCIP_Real arraygrowfac, /**< growing factor of array */
198  int minidx, /**< smallest index to allocate storage for */
199  int maxidx /**< largest index to allocate storage for */
200  );
201 
202 /** clears a dynamic bool array */
204  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
205  );
206 
207 /** gets value of entry in dynamic array */
209  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
210  int idx /**< array index to get value for */
211  );
212 
213 /** sets value of entry in dynamic array */
215  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
216  int arraygrowinit, /**< initial size of array */
217  SCIP_Real arraygrowfac, /**< growing factor of array */
218  int idx, /**< array index to set value for */
219  SCIP_Bool val /**< value to set array index to */
220  );
221 
222 /** returns the minimal index of all stored non-zero elements */
224  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
225  );
226 
227 /** returns the maximal index of all stored non-zero elements */
229  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
230  );
231 
232 /** creates a dynamic array of pointer values */
234  SCIP_PTRARRAY** ptrarray, /**< pointer to store the ptr array */
235  BMS_BLKMEM* blkmem /**< block memory */
236  );
237 
238 /** creates a copy of a dynamic array of pointer values */
240  SCIP_PTRARRAY** ptrarray, /**< pointer to store the copied ptr array */
241  BMS_BLKMEM* blkmem, /**< block memory */
242  SCIP_PTRARRAY* sourceptrarray /**< dynamic ptr array to copy */
243  );
244 
245 /** frees a dynamic array of pointer values */
247  SCIP_PTRARRAY** ptrarray /**< pointer to the ptr array */
248  );
249 
250 /** extends dynamic array to be able to store indices from minidx to maxidx */
252  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
253  int arraygrowinit, /**< initial size of array */
254  SCIP_Real arraygrowfac, /**< growing factor of array */
255  int minidx, /**< smallest index to allocate storage for */
256  int maxidx /**< largest index to allocate storage for */
257  );
258 
259 /** clears a dynamic pointer array */
261  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
262  );
263 
264 /** gets value of entry in dynamic array */
265 void* SCIPptrarrayGetVal(
266  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
267  int idx /**< array index to get value for */
268  );
269 
270 /** sets value of entry in dynamic array */
272  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
273  int arraygrowinit, /**< initial size of array */
274  SCIP_Real arraygrowfac, /**< growing factor of array */
275  int idx, /**< array index to set value for */
276  void* val /**< value to set array index to */
277  );
278 
279 /** returns the minimal index of all stored non-zero elements */
281  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
282  );
283 
284 /** returns the maximal index of all stored non-zero elements */
286  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
287  );
288 
289 
290 /* SCIP disjoint set data structure
291  *
292  * internal disjoint set functions (see \ref DisjointSet for public methods)
293  */
294 
295 /** creates a disjoint set (union find) structure \p djset for \p ncomponents many components (of size one) */
297  SCIP_DISJOINTSET** djset, /**< disjoint set (union find) data structure */
298  BMS_BLKMEM* blkmem, /**< block memory */
299  int ncomponents /**< number of components */
300  );
301 
302 /** frees the disjoint set (union find) data structure */
304  SCIP_DISJOINTSET** djset, /**< pointer to disjoint set (union find) data structure */
305  BMS_BLKMEM* blkmem /**< block memory */
306  );
307 
308 
309 /** SCIP digraph functions
310  *
311  * internal digraph functions (see \ref DirectedGraph for public digraph methods)
312  */
313 
314 /** creates directed graph structure */
316  SCIP_DIGRAPH** digraph, /**< pointer to store the created directed graph */
317  BMS_BLKMEM* blkmem, /**< block memory to store the data */
318  int nnodes /**< number of nodes */
319  );
320 
321 /** copies directed graph structure
322  *
323  * @note The data in nodedata is copied verbatim. This possibly has to be adapted by the user.
324  */
326  SCIP_DIGRAPH** targetdigraph, /**< pointer to store the copied directed graph */
327  SCIP_DIGRAPH* sourcedigraph, /**< source directed graph */
328  BMS_BLKMEM* targetblkmem /**< block memory to store the target block memory, or NULL to use the same
329  * the same block memory as used for the \p sourcedigraph */
330  );
331 
332 /*
333  * Additional math functions
334  */
335 
336 /** negates a number
337  *
338  * negation of a number that can be used to avoid that a negation is optimized away by a compiler
339  */
341  SCIP_Real x /**< value to negate */
342  );
343 
344 /** internal random number generator methods
345  *
346  * see \ref RandomNumbers for public random number generator methods
347  */
348 
349 /** creates and initializes a random number generator */
352  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
353  BMS_BLKMEM* blkmem, /**< block memory */
354  unsigned int initialseed /**< initial random seed */
355  );
356 
357 /** frees a random number generator */
359 void SCIPrandomFree(
360  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
361  BMS_BLKMEM* blkmem /**< block memory */
362  );
363 
364 /** initializes a random number generator with a given start seed */
366 void SCIPrandomSetSeed(
367  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
368  unsigned int initseed /**< initial random seed */
369  );
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 
375 #endif
SCIP_RETCODE SCIPrealarrayCreate(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem)
Definition: misc.c:3847
void * SCIPptrarrayGetVal(SCIP_PTRARRAY *ptrarray, int idx)
Definition: misc.c:5183
SCIP_RETCODE SCIPptrarrayCopy(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem, SCIP_PTRARRAY *sourceptrarray)
Definition: misc.c:4960
SCIP_RETCODE SCIPrealarraySetVal(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Real val)
Definition: misc.c:4112
int SCIPintarrayGetMinIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4563
type definitions for miscellaneous datastructures
SCIP_EXPORT SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:9586
int SCIPboolarrayGetMaxIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4929
SCIP_EXPORT void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:9602
int SCIPrealarrayGetMaxIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:4209
#define SCIP_EXPORT
Definition: def.h:98
int SCIPrealarrayGetMinIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:4199
SCIP_RETCODE SCIPptrarrayExtend(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4997
SCIP_RETCODE SCIPboolarrayCopy(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem, SCIP_BOOLARRAY *sourceboolarray)
Definition: misc.c:4604
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
type definitions for global SCIP settings
SCIP_RETCODE SCIPrealarrayIncVal(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Real incval)
Definition: misc.c:4181
int SCIPptrarrayGetMinIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5272
type definitions for return codes for SCIP methods
SCIP_RETCODE SCIPintarrayIncVal(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, int incval)
Definition: misc.c:4551
SCIP_Real SCIPrealarrayGetVal(SCIP_REALARRAY *realarray, int idx)
Definition: misc.c:4091
SCIP_RETCODE SCIPintarrayFree(SCIP_INTARRAY **intarray)
Definition: misc.c:4262
SCIP_RETCODE SCIPintarrayCopy(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem, SCIP_INTARRAY *sourceintarray)
Definition: misc.c:4239
SCIP_VAR ** x
Definition: circlepacking.c:54
SCIP_RETCODE SCIPintarraySetVal(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, int val)
Definition: misc.c:4483
SCIP_RETCODE SCIPrealarrayCopy(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem, SCIP_REALARRAY *sourcerealarray)
Definition: misc.c:3867
void SCIPdisjointsetFree(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem)
Definition: misc.c:10734
SCIP_RETCODE SCIPdigraphCreate(SCIP_DIGRAPH **digraph, BMS_BLKMEM *blkmem, int nnodes)
Definition: misc.c:7136
SCIP_RETCODE SCIPboolarraySetVal(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Bool val)
Definition: misc.c:4851
SCIP_Real SCIPnegateReal(SCIP_Real x)
Definition: misc.c:9853
SCIP_RETCODE SCIPboolarrayClear(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4799
SCIP_RETCODE SCIPboolarrayCreate(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4584
public data structures and miscellaneous methods
SCIP_RETCODE SCIPptrarrayFree(SCIP_PTRARRAY **ptrarray)
Definition: misc.c:4983
#define SCIP_Bool
Definition: def.h:70
SCIP_RETCODE SCIPintarrayExtend(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4276
int SCIPptrarrayGetMaxIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5282
int SCIPintarrayGetMaxIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4573
SCIP_RETCODE SCIPrealarrayExtend(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:3905
SCIP_EXPORT void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:9532
SCIP_RETCODE SCIPboolarrayFree(SCIP_BOOLARRAY **boolarray)
Definition: misc.c:4628
SCIP_RETCODE SCIPptrarrayClear(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5152
int SCIPboolarrayGetMinIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4919
SCIP_RETCODE SCIPintarrayCreate(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4219
SCIP_RETCODE SCIPrealarrayFree(SCIP_REALARRAY **realarray)
Definition: misc.c:3891
SCIP_RETCODE SCIPptrarraySetVal(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, void *val)
Definition: misc.c:5204
#define SCIP_Real
Definition: def.h:164
SCIP_RETCODE SCIPdigraphCopy(SCIP_DIGRAPH **targetdigraph, SCIP_DIGRAPH *sourcedigraph, BMS_BLKMEM *targetblkmem)
Definition: misc.c:7208
#define nnodes
Definition: gastrans.c:65
common defines and data types used in all packages of SCIP
SCIP_RETCODE SCIPrealarrayClear(SCIP_REALARRAY *realarray)
Definition: misc.c:4060
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:427
SCIP_RETCODE SCIPdisjointsetCreate(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem, int ncomponents)
Definition: misc.c:10616
SCIP_RETCODE SCIPintarrayClear(SCIP_INTARRAY *intarray)
Definition: misc.c:4431
SCIP_RETCODE SCIPptrarrayCreate(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4940
SCIP_Bool SCIPboolarrayGetVal(SCIP_BOOLARRAY *boolarray, int idx)
Definition: misc.c:4830
SCIP_RETCODE SCIPboolarrayExtend(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4642
int SCIPintarrayGetVal(SCIP_INTARRAY *intarray, int idx)
Definition: misc.c:4462
memory allocation routines