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-2024 Zuse Institute Berlin (ZIB) */
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"
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
45extern "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 */
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 */
359SCIP_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 */
367SCIP_EXPORT
368void 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 */
374SCIP_EXPORT
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_VAR ** x
Definition: circlepacking.c:63
common defines and data types used in all packages of SCIP
#define SCIP_Bool
Definition: def.h:91
#define SCIP_Real
Definition: def.h:173
#define nnodes
Definition: gastrans.c:74
memory allocation routines
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:437
SCIP_RETCODE SCIPrealarrayExtend(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4088
SCIP_Bool SCIPboolarrayGetVal(SCIP_BOOLARRAY *boolarray, int idx)
Definition: misc.c:5013
SCIP_RETCODE SCIPboolarrayFree(SCIP_BOOLARRAY **boolarray)
Definition: misc.c:4811
SCIP_RETCODE SCIPboolarrayCopy(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem, SCIP_BOOLARRAY *sourceboolarray)
Definition: misc.c:4787
int SCIPptrarrayGetMaxIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5465
SCIP_RETCODE SCIPrealarraySetVal(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Real val)
Definition: misc.c:4295
SCIP_RETCODE SCIPintarraySetVal(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, int val)
Definition: misc.c:4666
SCIP_RETCODE SCIPintarrayFree(SCIP_INTARRAY **intarray)
Definition: misc.c:4445
void SCIPdisjointsetFree(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem)
Definition: misc.c:11347
int SCIPptrarrayGetMinIdx(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5455
SCIP_RETCODE SCIPptrarrayExtend(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:5180
SCIP_RETCODE SCIPboolarrayExtend(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4825
SCIP_RETCODE SCIPptrarrayCopy(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem, SCIP_PTRARRAY *sourceptrarray)
Definition: misc.c:5143
int SCIPboolarrayGetMaxIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:5112
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
Definition: misc.c:10092
SCIP_RETCODE SCIPdisjointsetCreate(SCIP_DISJOINTSET **djset, BMS_BLKMEM *blkmem, int ncomponents)
Definition: misc.c:11229
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
Definition: misc.c:10076
SCIP_RETCODE SCIPintarrayCopy(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem, SCIP_INTARRAY *sourceintarray)
Definition: misc.c:4422
SCIP_RETCODE SCIPptrarrayClear(SCIP_PTRARRAY *ptrarray)
Definition: misc.c:5335
int SCIPrealarrayGetMaxIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:4392
SCIP_RETCODE SCIPdigraphCreate(SCIP_DIGRAPH **digraph, BMS_BLKMEM *blkmem, int nnodes)
Definition: misc.c:7377
int SCIPintarrayGetMaxIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4756
SCIP_RETCODE SCIPintarrayCreate(SCIP_INTARRAY **intarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4402
SCIP_Real SCIPrealarrayGetVal(SCIP_REALARRAY *realarray, int idx)
Definition: misc.c:4274
SCIP_RETCODE SCIPptrarrayFree(SCIP_PTRARRAY **ptrarray)
Definition: misc.c:5166
SCIP_RETCODE SCIPintarrayClear(SCIP_INTARRAY *intarray)
Definition: misc.c:4614
SCIP_RETCODE SCIPrealarrayIncVal(SCIP_REALARRAY *realarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Real incval)
Definition: misc.c:4364
int SCIPrealarrayGetMinIdx(SCIP_REALARRAY *realarray)
Definition: misc.c:4382
SCIP_RETCODE SCIPrealarrayCreate(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4030
SCIP_RETCODE SCIPrealarrayClear(SCIP_REALARRAY *realarray)
Definition: misc.c:4243
int SCIPboolarrayGetMinIdx(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:5102
int SCIPintarrayGetMinIdx(SCIP_INTARRAY *intarray)
Definition: misc.c:4746
SCIP_RETCODE SCIPrealarrayCopy(SCIP_REALARRAY **realarray, BMS_BLKMEM *blkmem, SCIP_REALARRAY *sourcerealarray)
Definition: misc.c:4050
void * SCIPptrarrayGetVal(SCIP_PTRARRAY *ptrarray, int idx)
Definition: misc.c:5366
void SCIPrandomSetSeed(SCIP_RANDNUMGEN *randnumgen, unsigned int initseed)
Definition: misc.c:10022
SCIP_RETCODE SCIPintarrayExtend(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int minidx, int maxidx)
Definition: misc.c:4459
SCIP_RETCODE SCIPboolarrayCreate(SCIP_BOOLARRAY **boolarray, BMS_BLKMEM *blkmem)
Definition: misc.c:4767
SCIP_Real SCIPnegateReal(SCIP_Real x)
Definition: misc.c:10358
SCIP_RETCODE SCIPboolarrayClear(SCIP_BOOLARRAY *boolarray)
Definition: misc.c:4982
SCIP_RETCODE SCIPintarrayIncVal(SCIP_INTARRAY *intarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, int incval)
Definition: misc.c:4734
int SCIPintarrayGetVal(SCIP_INTARRAY *intarray, int idx)
Definition: misc.c:4645
SCIP_RETCODE SCIPdigraphCopy(SCIP_DIGRAPH **targetdigraph, SCIP_DIGRAPH *sourcedigraph, BMS_BLKMEM *targetblkmem)
Definition: misc.c:7454
SCIP_RETCODE SCIPptrarrayCreate(SCIP_PTRARRAY **ptrarray, BMS_BLKMEM *blkmem)
Definition: misc.c:5123
SCIP_RETCODE SCIPptrarraySetVal(SCIP_PTRARRAY *ptrarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, void *val)
Definition: misc.c:5387
SCIP_RETCODE SCIPrealarrayFree(SCIP_REALARRAY **realarray)
Definition: misc.c:4074
SCIP_RETCODE SCIPboolarraySetVal(SCIP_BOOLARRAY *boolarray, int arraygrowinit, SCIP_Real arraygrowfac, int idx, SCIP_Bool val)
Definition: misc.c:5034
public data structures and miscellaneous methods
type definitions for miscellaneous datastructures
type definitions for return codes for SCIP methods
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
type definitions for global SCIP settings