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 */
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 
328 /* SCIP disjoint set data structure
329  *
330  * internal disjoint set functions (see \ref DisjointSet for public methods)
331  */
332 
333 /** creates a disjoint set (union find) structure \p djset for \p ncomponents many components (of size one) */
334 extern
336  SCIP_DISJOINTSET** djset, /**< disjoint set (union find) data structure */
337  BMS_BLKMEM* blkmem, /**< block memory */
338  int ncomponents /**< number of components */
339  );
340 
341 /** frees the disjoint set (union find) data structure */
342 extern
344  SCIP_DISJOINTSET** djset, /**< pointer to disjoint set (union find) data structure */
345  BMS_BLKMEM* blkmem /**< block memory */
346  );
347 
348 
349 /** SCIP digraph functions
350  *
351  * internal digraph functions (see \ref DirectedGraph for public digraph methods)
352  */
353 
354 /** creates directed graph structure */
355 extern
357  SCIP_DIGRAPH** digraph, /**< pointer to store the created directed graph */
358  BMS_BLKMEM* blkmem, /**< block memory to store the data */
359  int nnodes /**< number of nodes */
360  );
361 
362 /** copies directed graph structure
363  *
364  * @note The data in nodedata is copied verbatim. This possibly has to be adapted by the user.
365  */
366 extern
368  SCIP_DIGRAPH** targetdigraph, /**< pointer to store the copied directed graph */
369  SCIP_DIGRAPH* sourcedigraph, /**< source directed graph */
370  BMS_BLKMEM* targetblkmem /**< block memory to store the target block memory, or NULL to use the same
371  * the same block memory as used for the \p sourcedigraph */
372  );
373 
374 /*
375  * Additional math functions
376  */
377 
378 /** negates a number
379  *
380  * negation of a number that can be used to avoid that a negation is optimized away by a compiler
381  */
382 extern
384  SCIP_Real x /**< value to negate */
385  );
386 
387 /** internal random number generator methods
388  *
389  * see \ref RandomNumbers for public random number generator methods
390  */
391 
392 /** creates and initializes a random number generator */
393 extern
395  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
396  BMS_BLKMEM* blkmem, /**< block memory */
397  unsigned int initialseed /**< initial random seed */
398  );
399 
400 /** frees a random number generator */
401 extern
402 void SCIPrandomFree(
403  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
404  BMS_BLKMEM* blkmem /**< block memory */
405  );
406 
407 /** initializes a random number generator with a given start seed */
408 extern
409 void SCIPrandomSetSeed(
410  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
411  unsigned int initseed /**< initial random seed */
412  );
413 
414 #ifdef __cplusplus
415 }
416 #endif
417 
418 #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
int SCIPboolarrayGetMaxIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4929
int SCIPrealarrayGetMaxIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:4209
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:10724
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
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:9592
SCIP_Real SCIPnegateReal(SCIP_Real x)
Definition: misc.c:9843
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:69
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_RETCODE SCIPboolarrayFree(SCIP_BOOLARRAY **boolarray)
Definition: misc.c:4628
void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:9522
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:157
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:426
SCIP_RETCODE SCIPdisjointsetCreate(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem, int ncomponents)
Definition: misc.c:10606
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 SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:9576
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