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-2018 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 */
44 extern
46  SCIP_REALARRAY** realarray, /**< pointer to store the real array */
47  BMS_BLKMEM* blkmem /**< block memory */
48  );
49 
50 /** creates a copy of a dynamic array of real values */
51 extern
53  SCIP_REALARRAY** realarray, /**< pointer to store the copied real array */
54  BMS_BLKMEM* blkmem, /**< block memory */
55  SCIP_REALARRAY* sourcerealarray /**< dynamic real array to copy */
56  );
57 
58 /** frees a dynamic array of real values */
59 extern
61  SCIP_REALARRAY** realarray /**< pointer to the real array */
62  );
63 
64 /** extends dynamic array to be able to store indices from minidx to maxidx */
65 extern
67  SCIP_REALARRAY* realarray, /**< dynamic real array */
68  int arraygrowinit, /**< initial size of array */
69  SCIP_Real arraygrowfac, /**< growing factor of array */
70  int minidx, /**< smallest index to allocate storage for */
71  int maxidx /**< largest index to allocate storage for */
72  );
73 
74 /** clears a dynamic real array */
75 extern
77  SCIP_REALARRAY* realarray /**< dynamic real array */
78  );
79 
80 /** gets value of entry in dynamic array */
81 extern
83  SCIP_REALARRAY* realarray, /**< dynamic real array */
84  int idx /**< array index to get value for */
85  );
86 
87 /** sets value of entry in dynamic array */
88 extern
90  SCIP_REALARRAY* realarray, /**< dynamic real array */
91  int arraygrowinit, /**< initial size of array */
92  SCIP_Real arraygrowfac, /**< growing factor of array */
93  int idx, /**< array index to set value for */
94  SCIP_Real val /**< value to set array index to */
95  );
96 
97 /** increases value of entry in dynamic array */
98 extern
100  SCIP_REALARRAY* realarray, /**< dynamic real array */
101  int arraygrowinit, /**< initial size of array */
102  SCIP_Real arraygrowfac, /**< growing factor of array */
103  int idx, /**< array index to increase value for */
104  SCIP_Real incval /**< value to increase array index */
105  );
106 
107 /** returns the minimal index of all stored non-zero elements */
108 extern
110  SCIP_REALARRAY* realarray /**< dynamic real array */
111  );
112 
113 /** returns the maximal index of all stored non-zero elements */
114 extern
116  SCIP_REALARRAY* realarray /**< dynamic real array */
117  );
118 
119 /** creates a dynamic array of int values */
120 extern
122  SCIP_INTARRAY** intarray, /**< pointer to store the int array */
123  BMS_BLKMEM* blkmem /**< block memory */
124  );
125 
126 /** creates a copy of a dynamic array of int values */
127 extern
129  SCIP_INTARRAY** intarray, /**< pointer to store the copied int array */
130  BMS_BLKMEM* blkmem, /**< block memory */
131  SCIP_INTARRAY* sourceintarray /**< dynamic int array to copy */
132  );
133 
134 /** frees a dynamic array of int values */
135 extern
137  SCIP_INTARRAY** intarray /**< pointer to the int array */
138  );
139 
140 /** extends dynamic array to be able to store indices from minidx to maxidx */
141 extern
143  SCIP_INTARRAY* intarray, /**< dynamic int array */
144  int arraygrowinit, /**< initial size of array */
145  SCIP_Real arraygrowfac, /**< growing factor of array */
146  int minidx, /**< smallest index to allocate storage for */
147  int maxidx /**< largest index to allocate storage for */
148  );
149 
150 /** clears a dynamic int array */
151 extern
153  SCIP_INTARRAY* intarray /**< dynamic int array */
154  );
155 
156 /** gets value of entry in dynamic array */
157 extern
159  SCIP_INTARRAY* intarray, /**< dynamic int array */
160  int idx /**< array index to get value for */
161  );
162 
163 /** sets value of entry in dynamic array */
164 extern
166  SCIP_INTARRAY* intarray, /**< dynamic int array */
167  int arraygrowinit, /**< initial size of array */
168  SCIP_Real arraygrowfac, /**< growing factor of array */
169  int idx, /**< array index to set value for */
170  int val /**< value to set array index to */
171  );
172 
173 /** increases value of entry in dynamic array */
174 extern
176  SCIP_INTARRAY* intarray, /**< dynamic int array */
177  int arraygrowinit, /**< initial size of array */
178  SCIP_Real arraygrowfac, /**< growing factor of array */
179  int idx, /**< array index to increase value for */
180  int incval /**< value to increase array index */
181  );
182 
183 /** returns the minimal index of all stored non-zero elements */
184 extern
186  SCIP_INTARRAY* intarray /**< dynamic int array */
187  );
188 
189 /** returns the maximal index of all stored non-zero elements */
190 extern
192  SCIP_INTARRAY* intarray /**< dynamic int array */
193  );
194 
195 /** creates a dynamic array of bool values */
196 extern
198  SCIP_BOOLARRAY** boolarray, /**< pointer to store the bool array */
199  BMS_BLKMEM* blkmem /**< block memory */
200  );
201 
202 /** creates a copy of a dynamic array of bool values */
203 extern
205  SCIP_BOOLARRAY** boolarray, /**< pointer to store the copied bool array */
206  BMS_BLKMEM* blkmem, /**< block memory */
207  SCIP_BOOLARRAY* sourceboolarray /**< dynamic bool array to copy */
208  );
209 
210 /** frees a dynamic array of bool values */
211 extern
213  SCIP_BOOLARRAY** boolarray /**< pointer to the bool array */
214  );
215 
216 /** extends dynamic array to be able to store indices from minidx to maxidx */
217 extern
219  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
220  int arraygrowinit, /**< initial size of array */
221  SCIP_Real arraygrowfac, /**< growing factor of array */
222  int minidx, /**< smallest index to allocate storage for */
223  int maxidx /**< largest index to allocate storage for */
224  );
225 
226 /** clears a dynamic bool array */
227 extern
229  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
230  );
231 
232 /** gets value of entry in dynamic array */
233 extern
235  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
236  int idx /**< array index to get value for */
237  );
238 
239 /** sets value of entry in dynamic array */
240 extern
242  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
243  int arraygrowinit, /**< initial size of array */
244  SCIP_Real arraygrowfac, /**< growing factor of array */
245  int idx, /**< array index to set value for */
246  SCIP_Bool val /**< value to set array index to */
247  );
248 
249 /** returns the minimal index of all stored non-zero elements */
250 extern
252  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
253  );
254 
255 /** returns the maximal index of all stored non-zero elements */
256 extern
258  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
259  );
260 
261 /** creates a dynamic array of pointer values */
262 extern
264  SCIP_PTRARRAY** ptrarray, /**< pointer to store the ptr array */
265  BMS_BLKMEM* blkmem /**< block memory */
266  );
267 
268 /** creates a copy of a dynamic array of pointer values */
269 extern
271  SCIP_PTRARRAY** ptrarray, /**< pointer to store the copied ptr array */
272  BMS_BLKMEM* blkmem, /**< block memory */
273  SCIP_PTRARRAY* sourceptrarray /**< dynamic ptr array to copy */
274  );
275 
276 /** frees a dynamic array of pointer values */
277 extern
279  SCIP_PTRARRAY** ptrarray /**< pointer to the ptr array */
280  );
281 
282 /** extends dynamic array to be able to store indices from minidx to maxidx */
283 extern
285  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
286  int arraygrowinit, /**< initial size of array */
287  SCIP_Real arraygrowfac, /**< growing factor of array */
288  int minidx, /**< smallest index to allocate storage for */
289  int maxidx /**< largest index to allocate storage for */
290  );
291 
292 /** clears a dynamic pointer array */
293 extern
295  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
296  );
297 
298 /** gets value of entry in dynamic array */
299 extern
300 void* SCIPptrarrayGetVal(
301  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
302  int idx /**< array index to get value for */
303  );
304 
305 /** sets value of entry in dynamic array */
306 extern
308  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
309  int arraygrowinit, /**< initial size of array */
310  SCIP_Real arraygrowfac, /**< growing factor of array */
311  int idx, /**< array index to set value for */
312  void* val /**< value to set array index to */
313  );
314 
315 /** returns the minimal index of all stored non-zero elements */
316 extern
318  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
319  );
320 
321 /** returns the maximal index of all stored non-zero elements */
322 extern
324  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
325  );
326 
327 /** creates a disjoint set (union find) structure \p uf for \p ncomponents many components (of size one) */
328 extern
330  SCIP_DISJOINTSET** djset, /**< disjoint set (union find) data structure */
331  BMS_BLKMEM* blkmem, /**< block memory */
332  int ncomponents /**< number of components */
333  );
334 
335 /** frees the disjoint set (union find) data structure */
336 extern
338  SCIP_DISJOINTSET** djset, /**< pointer to disjoint set (union find) data structure */
339  BMS_BLKMEM* blkmem /**< block memory */
340  );
341 
342 /** SCIP digraph functions
343  *
344  * internal digraph functions (see \ref DirectedGraph for public digraph methods)
345  */
346 
347 /** creates directed graph structure */
348 extern
350  SCIP_DIGRAPH** digraph, /**< pointer to store the created directed graph */
351  BMS_BLKMEM* blkmem, /**< block memory to store the data */
352  int nnodes /**< number of nodes */
353  );
354 
355 /** copies directed graph structure
356  *
357  * @note The data in nodedata is copied verbatim. This possibly has to be adapted by the user.
358  */
359 extern
361  SCIP_DIGRAPH** targetdigraph, /**< pointer to store the copied directed graph */
362  SCIP_DIGRAPH* sourcedigraph, /**< source directed graph */
363  BMS_BLKMEM* targetblkmem /**< block memory to store the target block memory, or NULL to use the same
364  * the same block memory as used for the \p sourcedigraph */
365  );
366 
367 /*
368  * Additional math functions
369  */
370 
371 /** negates a number
372  *
373  * negation of a number that can be used to avoid that a negation is optimized away by a compiler
374  */
375 extern
377  SCIP_Real x /**< value to negate */
378  );
379 
380 /** internal random number generator methods
381  *
382  * see \ref RandomNumbers for public random number generator methods
383  */
384 
385 /** creates and initializes a random number generator */
386 extern
388  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
389  BMS_BLKMEM* blkmem, /**< block memory */
390  unsigned int initialseed /**< initial random seed */
391  );
392 
393 /** frees a random number generator */
394 extern
395 void SCIPrandomFree(
396  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
397  BMS_BLKMEM* blkmem /**< block memory */
398  );
399 
400 /** initializes a random number generator with a given start seed */
401 extern
402 void SCIPrandomSetSeed(
403  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
404  unsigned int initseed /**< initial random seed */
405  );
406 
407 #ifdef __cplusplus
408 }
409 #endif
410 
411 #endif
SCIP_RETCODE SCIPrealarrayCreate(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem)
Definition: misc.c:3611
void * SCIPptrarrayGetVal(SCIP_PTRARRAY *ptrarray, int idx)
Definition: misc.c:4947
SCIP_RETCODE SCIPptrarrayCopy(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem, SCIP_PTRARRAY *sourceptrarray)
Definition: misc.c:4724
SCIP_RETCODE SCIPrealarraySetVal(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Real val)
Definition: misc.c:3876
int SCIPintarrayGetMinIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4327
type definitions for miscellaneous datastructures
int SCIPboolarrayGetMaxIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4693
int SCIPrealarrayGetMaxIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:3973
int SCIPrealarrayGetMinIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:3963
SCIP_RETCODE SCIPptrarrayExtend(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4761
SCIP_RETCODE SCIPboolarrayCopy(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem, SCIP_BOOLARRAY *sourceboolarray)
Definition: misc.c:4368
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:3945
int SCIPptrarrayGetMinIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5036
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:4315
SCIP_Real SCIPrealarrayGetVal(SCIP_REALARRAY *realarray, int idx)
Definition: misc.c:3855
SCIP_RETCODE SCIPintarrayFree(SCIP_INTARRAY **intarray)
Definition: misc.c:4026
SCIP_RETCODE SCIPintarrayCopy(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem, SCIP_INTARRAY *sourceintarray)
Definition: misc.c:4003
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:4247
SCIP_RETCODE SCIPrealarrayCopy(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem, SCIP_REALARRAY *sourcerealarray)
Definition: misc.c:3631
void SCIPdisjointsetFree(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem)
Definition: misc.c:10488
SCIP_RETCODE SCIPdigraphCreate(SCIP_DIGRAPH **digraph, BMS_BLKMEM *blkmem, int nnodes)
Definition: misc.c:6900
SCIP_RETCODE SCIPboolarraySetVal(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Bool val)
Definition: misc.c:4615
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:9356
SCIP_Real SCIPnegateReal(SCIP_Real x)
Definition: misc.c:9607
SCIP_RETCODE SCIPboolarrayClear(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4563
SCIP_RETCODE SCIPboolarrayCreate(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4348
public data structures and miscellaneous methods
SCIP_RETCODE SCIPptrarrayFree(SCIP_PTRARRAY **ptrarray)
Definition: misc.c:4747
#define SCIP_Bool
Definition: def.h:62
SCIP_RETCODE SCIPintarrayExtend(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4040
int SCIPptrarrayGetMaxIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5046
int SCIPintarrayGetMaxIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4337
SCIP_RETCODE SCIPrealarrayExtend(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:3669
SCIP_RETCODE SCIPboolarrayFree(SCIP_BOOLARRAY **boolarray)
Definition: misc.c:4392
void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:9286
SCIP_RETCODE SCIPptrarrayClear(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:4916
int SCIPboolarrayGetMinIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4683
SCIP_RETCODE SCIPintarrayCreate(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem)
Definition: misc.c:3983
SCIP_RETCODE SCIPrealarrayFree(SCIP_REALARRAY **realarray)
Definition: misc.c:3655
SCIP_RETCODE SCIPptrarraySetVal(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, void *val)
Definition: misc.c:4968
#define SCIP_Real
Definition: def.h:150
SCIP_RETCODE SCIPdigraphCopy(SCIP_DIGRAPH **targetdigraph, SCIP_DIGRAPH *sourcedigraph, BMS_BLKMEM *targetblkmem)
Definition: misc.c:6972
#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:3824
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:419
SCIP_RETCODE SCIPdisjointsetCreate(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem, int ncomponents)
Definition: misc.c:10370
SCIP_RETCODE SCIPintarrayClear(SCIP_INTARRAY *intarray)
Definition: misc.c:4195
SCIP_RETCODE SCIPptrarrayCreate(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4704
SCIP_Bool SCIPboolarrayGetVal(SCIP_BOOLARRAY *boolarray, int idx)
Definition: misc.c:4594
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:9340
SCIP_RETCODE SCIPboolarrayExtend(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4406
int SCIPintarrayGetVal(SCIP_INTARRAY *intarray, int idx)
Definition: misc.c:4226
memory allocation routines