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 2002-2022 Zuse Institute Berlin */
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 misc.h
26  * @ingroup INTERNALAPI
27  * @brief internal miscellaneous methods
28  * @author Tobias Achterberg
29  */
30 
31 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32 
33 #ifndef __SCIP_MISC_H__
34 #define __SCIP_MISC_H__
35 
36 
37 #include "scip/def.h"
38 #include "blockmemshell/memory.h"
39 #include "scip/type_retcode.h"
40 #include "scip/type_set.h"
41 #include "scip/type_misc.h"
42 #include "scip/pub_misc.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /*
49  * Dynamic Arrays
50  */
51 
52 /** creates a dynamic array of real values */
54  SCIP_REALARRAY** realarray, /**< pointer to store the real array */
55  BMS_BLKMEM* blkmem /**< block memory */
56  );
57 
58 /** creates a copy of a dynamic array of real values */
60  SCIP_REALARRAY** realarray, /**< pointer to store the copied real array */
61  BMS_BLKMEM* blkmem, /**< block memory */
62  SCIP_REALARRAY* sourcerealarray /**< dynamic real array to copy */
63  );
64 
65 /** frees a dynamic array of real values */
67  SCIP_REALARRAY** realarray /**< pointer to the real array */
68  );
69 
70 /** extends dynamic array to be able to store indices from minidx to maxidx */
72  SCIP_REALARRAY* realarray, /**< dynamic real array */
73  int arraygrowinit, /**< initial size of array */
74  SCIP_Real arraygrowfac, /**< growing factor of array */
75  int minidx, /**< smallest index to allocate storage for */
76  int maxidx /**< largest index to allocate storage for */
77  );
78 
79 /** clears a dynamic real array */
81  SCIP_REALARRAY* realarray /**< dynamic real array */
82  );
83 
84 /** gets value of entry in dynamic array */
86  SCIP_REALARRAY* realarray, /**< dynamic real array */
87  int idx /**< array index to get value for */
88  );
89 
90 /** sets 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 set value for */
96  SCIP_Real val /**< value to set array index to */
97  );
98 
99 /** increases value of entry in dynamic array */
101  SCIP_REALARRAY* realarray, /**< dynamic real array */
102  int arraygrowinit, /**< initial size of array */
103  SCIP_Real arraygrowfac, /**< growing factor of array */
104  int idx, /**< array index to increase value for */
105  SCIP_Real incval /**< value to increase array index */
106  );
107 
108 /** returns the minimal index of all stored non-zero elements */
110  SCIP_REALARRAY* realarray /**< dynamic real array */
111  );
112 
113 /** returns the maximal index of all stored non-zero elements */
115  SCIP_REALARRAY* realarray /**< dynamic real array */
116  );
117 
118 /** creates a dynamic array of int values */
120  SCIP_INTARRAY** intarray, /**< pointer to store the int array */
121  BMS_BLKMEM* blkmem /**< block memory */
122  );
123 
124 /** creates a copy of a dynamic array of int values */
126  SCIP_INTARRAY** intarray, /**< pointer to store the copied int array */
127  BMS_BLKMEM* blkmem, /**< block memory */
128  SCIP_INTARRAY* sourceintarray /**< dynamic int array to copy */
129  );
130 
131 /** frees a dynamic array of int values */
133  SCIP_INTARRAY** intarray /**< pointer to the int array */
134  );
135 
136 /** extends dynamic array to be able to store indices from minidx to maxidx */
138  SCIP_INTARRAY* intarray, /**< dynamic int array */
139  int arraygrowinit, /**< initial size of array */
140  SCIP_Real arraygrowfac, /**< growing factor of array */
141  int minidx, /**< smallest index to allocate storage for */
142  int maxidx /**< largest index to allocate storage for */
143  );
144 
145 /** clears a dynamic int array */
147  SCIP_INTARRAY* intarray /**< dynamic int array */
148  );
149 
150 /** gets value of entry in dynamic array */
152  SCIP_INTARRAY* intarray, /**< dynamic int array */
153  int idx /**< array index to get value for */
154  );
155 
156 /** sets 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 set value for */
162  int val /**< value to set array index to */
163  );
164 
165 /** increases value of entry in dynamic array */
167  SCIP_INTARRAY* intarray, /**< dynamic int array */
168  int arraygrowinit, /**< initial size of array */
169  SCIP_Real arraygrowfac, /**< growing factor of array */
170  int idx, /**< array index to increase value for */
171  int incval /**< value to increase array index */
172  );
173 
174 /** returns the minimal index of all stored non-zero elements */
176  SCIP_INTARRAY* intarray /**< dynamic int array */
177  );
178 
179 /** returns the maximal index of all stored non-zero elements */
181  SCIP_INTARRAY* intarray /**< dynamic int array */
182  );
183 
184 /** creates a dynamic array of bool values */
186  SCIP_BOOLARRAY** boolarray, /**< pointer to store the bool array */
187  BMS_BLKMEM* blkmem /**< block memory */
188  );
189 
190 /** creates a copy of a dynamic array of bool values */
192  SCIP_BOOLARRAY** boolarray, /**< pointer to store the copied bool array */
193  BMS_BLKMEM* blkmem, /**< block memory */
194  SCIP_BOOLARRAY* sourceboolarray /**< dynamic bool array to copy */
195  );
196 
197 /** frees a dynamic array of bool values */
199  SCIP_BOOLARRAY** boolarray /**< pointer to the bool array */
200  );
201 
202 /** extends dynamic array to be able to store indices from minidx to maxidx */
204  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
205  int arraygrowinit, /**< initial size of array */
206  SCIP_Real arraygrowfac, /**< growing factor of array */
207  int minidx, /**< smallest index to allocate storage for */
208  int maxidx /**< largest index to allocate storage for */
209  );
210 
211 /** clears a dynamic bool array */
213  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
214  );
215 
216 /** gets value of entry in dynamic array */
218  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
219  int idx /**< array index to get value for */
220  );
221 
222 /** sets value of entry in dynamic array */
224  SCIP_BOOLARRAY* boolarray, /**< dynamic bool array */
225  int arraygrowinit, /**< initial size of array */
226  SCIP_Real arraygrowfac, /**< growing factor of array */
227  int idx, /**< array index to set value for */
228  SCIP_Bool val /**< value to set array index to */
229  );
230 
231 /** returns the minimal index of all stored non-zero elements */
233  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
234  );
235 
236 /** returns the maximal index of all stored non-zero elements */
238  SCIP_BOOLARRAY* boolarray /**< dynamic bool array */
239  );
240 
241 /** creates a dynamic array of pointer values */
243  SCIP_PTRARRAY** ptrarray, /**< pointer to store the ptr array */
244  BMS_BLKMEM* blkmem /**< block memory */
245  );
246 
247 /** creates a copy of a dynamic array of pointer values */
249  SCIP_PTRARRAY** ptrarray, /**< pointer to store the copied ptr array */
250  BMS_BLKMEM* blkmem, /**< block memory */
251  SCIP_PTRARRAY* sourceptrarray /**< dynamic ptr array to copy */
252  );
253 
254 /** frees a dynamic array of pointer values */
256  SCIP_PTRARRAY** ptrarray /**< pointer to the ptr array */
257  );
258 
259 /** extends dynamic array to be able to store indices from minidx to maxidx */
261  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
262  int arraygrowinit, /**< initial size of array */
263  SCIP_Real arraygrowfac, /**< growing factor of array */
264  int minidx, /**< smallest index to allocate storage for */
265  int maxidx /**< largest index to allocate storage for */
266  );
267 
268 /** clears a dynamic pointer array */
270  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
271  );
272 
273 /** gets value of entry in dynamic array */
274 void* SCIPptrarrayGetVal(
275  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
276  int idx /**< array index to get value for */
277  );
278 
279 /** sets value of entry in dynamic array */
281  SCIP_PTRARRAY* ptrarray, /**< dynamic ptr array */
282  int arraygrowinit, /**< initial size of array */
283  SCIP_Real arraygrowfac, /**< growing factor of array */
284  int idx, /**< array index to set value for */
285  void* val /**< value to set array index to */
286  );
287 
288 /** returns the minimal index of all stored non-zero elements */
290  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
291  );
292 
293 /** returns the maximal index of all stored non-zero elements */
295  SCIP_PTRARRAY* ptrarray /**< dynamic ptr array */
296  );
297 
298 
299 /* SCIP disjoint set data structure
300  *
301  * internal disjoint set functions (see \ref DisjointSet for public methods)
302  */
303 
304 /** creates a disjoint set (union find) structure \p djset for \p ncomponents many components (of size one) */
306  SCIP_DISJOINTSET** djset, /**< disjoint set (union find) data structure */
307  BMS_BLKMEM* blkmem, /**< block memory */
308  int ncomponents /**< number of components */
309  );
310 
311 /** frees the disjoint set (union find) data structure */
313  SCIP_DISJOINTSET** djset, /**< pointer to disjoint set (union find) data structure */
314  BMS_BLKMEM* blkmem /**< block memory */
315  );
316 
317 
318 /** SCIP digraph functions
319  *
320  * internal digraph functions (see \ref DirectedGraph for public digraph methods)
321  */
322 
323 /** creates directed graph structure */
325  SCIP_DIGRAPH** digraph, /**< pointer to store the created directed graph */
326  BMS_BLKMEM* blkmem, /**< block memory to store the data */
327  int nnodes /**< number of nodes */
328  );
329 
330 /** copies directed graph structure
331  *
332  * @note The data in nodedata is copied verbatim. This possibly has to be adapted by the user.
333  */
335  SCIP_DIGRAPH** targetdigraph, /**< pointer to store the copied directed graph */
336  SCIP_DIGRAPH* sourcedigraph, /**< source directed graph */
337  BMS_BLKMEM* targetblkmem /**< block memory to store the target block memory, or NULL to use the same
338  * the same block memory as used for the \p sourcedigraph */
339  );
340 
341 /*
342  * Additional math functions
343  */
344 
345 /** negates a number
346  *
347  * negation of a number that can be used to avoid that a negation is optimized away by a compiler
348  */
350  SCIP_Real x /**< value to negate */
351  );
352 
353 /** internal random number generator methods
354  *
355  * see \ref RandomNumbers for public random number generator methods
356  */
357 
358 /** creates and initializes a random number generator */
359 SCIP_EXPORT
361  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
362  BMS_BLKMEM* blkmem, /**< block memory */
363  unsigned int initialseed /**< initial random seed */
364  );
365 
366 /** frees a random number generator */
367 SCIP_EXPORT
368 void SCIPrandomFree(
369  SCIP_RANDNUMGEN** randnumgen, /**< random number generator */
370  BMS_BLKMEM* blkmem /**< block memory */
371  );
372 
373 /** initializes a random number generator with a given start seed */
374 SCIP_EXPORT
375 void SCIPrandomSetSeed(
376  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
377  unsigned int initseed /**< initial random seed */
378  );
379 
380 #ifdef __cplusplus
381 }
382 #endif
383 
384 #endif
SCIP_RETCODE SCIPrealarrayCreate(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem)
Definition: misc.c:3979
void * SCIPptrarrayGetVal(SCIP_PTRARRAY *ptrarray, int idx)
Definition: misc.c:5315
SCIP_RETCODE SCIPptrarrayCopy(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem, SCIP_PTRARRAY *sourceptrarray)
Definition: misc.c:5092
SCIP_RETCODE SCIPrealarraySetVal(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Real val)
Definition: misc.c:4244
int SCIPintarrayGetMinIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4695
type definitions for miscellaneous datastructures
int SCIPboolarrayGetMaxIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:5061
int SCIPrealarrayGetMaxIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:4341
int SCIPrealarrayGetMinIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:4331
SCIP_RETCODE SCIPptrarrayExtend(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:5129
SCIP_RETCODE SCIPboolarrayCopy(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem, SCIP_BOOLARRAY *sourceboolarray)
Definition: misc.c:4736
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
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:4313
int SCIPptrarrayGetMinIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5404
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:4683
SCIP_Real SCIPrealarrayGetVal(SCIP_REALARRAY *realarray, int idx)
Definition: misc.c:4223
SCIP_RETCODE SCIPintarrayFree(SCIP_INTARRAY **intarray)
Definition: misc.c:4394
SCIP_RETCODE SCIPintarrayCopy(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem, SCIP_INTARRAY *sourceintarray)
Definition: misc.c:4371
SCIP_VAR ** x
Definition: circlepacking.c:63
SCIP_RETCODE SCIPintarraySetVal(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, int val)
Definition: misc.c:4615
SCIP_RETCODE SCIPrealarrayCopy(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem, SCIP_REALARRAY *sourcerealarray)
Definition: misc.c:3999
void SCIPdisjointsetFree(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem)
Definition: misc.c:11235
SCIP_RETCODE SCIPdigraphCreate(SCIP_DIGRAPH **digraph, BMS_BLKMEM *blkmem, int nnodes)
Definition: misc.c:7288
SCIP_RETCODE SCIPboolarraySetVal(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Bool val)
Definition: misc.c:4983
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:9996
SCIP_Real SCIPnegateReal(SCIP_Real x)
Definition: misc.c:10262
SCIP_RETCODE SCIPboolarrayClear(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4931
SCIP_RETCODE SCIPboolarrayCreate(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4716
public data structures and miscellaneous methods
SCIP_RETCODE SCIPptrarrayFree(SCIP_PTRARRAY **ptrarray)
Definition: misc.c:5115
#define SCIP_Bool
Definition: def.h:93
SCIP_RETCODE SCIPintarrayExtend(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4408
int SCIPptrarrayGetMaxIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5414
int SCIPintarrayGetMaxIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4705
SCIP_RETCODE SCIPrealarrayExtend(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4037
SCIP_RETCODE SCIPboolarrayFree(SCIP_BOOLARRAY **boolarray)
Definition: misc.c:4760
void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:9926
SCIP_RETCODE SCIPptrarrayClear(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5284
int SCIPboolarrayGetMinIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:5051
SCIP_RETCODE SCIPintarrayCreate(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4351
SCIP_RETCODE SCIPrealarrayFree(SCIP_REALARRAY **realarray)
Definition: misc.c:4023
SCIP_RETCODE SCIPptrarraySetVal(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, void *val)
Definition: misc.c:5336
#define SCIP_Real
Definition: def.h:186
SCIP_RETCODE SCIPdigraphCopy(SCIP_DIGRAPH **targetdigraph, SCIP_DIGRAPH *sourcedigraph, BMS_BLKMEM *targetblkmem)
Definition: misc.c:7365
#define nnodes
Definition: gastrans.c:74
common defines and data types used in all packages of SCIP
SCIP_RETCODE SCIPrealarrayClear(SCIP_REALARRAY *realarray)
Definition: misc.c:4192
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:439
SCIP_RETCODE SCIPdisjointsetCreate(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem, int ncomponents)
Definition: misc.c:11117
SCIP_RETCODE SCIPintarrayClear(SCIP_INTARRAY *intarray)
Definition: misc.c:4563
SCIP_RETCODE SCIPptrarrayCreate(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem)
Definition: misc.c:5072
SCIP_Bool SCIPboolarrayGetVal(SCIP_BOOLARRAY *boolarray, int idx)
Definition: misc.c:4962
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:9980
SCIP_RETCODE SCIPboolarrayExtend(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4774
int SCIPintarrayGetVal(SCIP_INTARRAY *intarray, int idx)
Definition: misc.c:4594
memory allocation routines