Scippy

SCIP

Solving Constraint Integer Programs

struct_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-2025 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 struct_misc.h
26 * @ingroup INTERNALAPI
27 * @brief miscellaneous datastructures
28 * @author Tobias Achterberg
29 */
30
31/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32
33#ifndef __SCIP_STRUCT_MISC_H__
34#define __SCIP_STRUCT_MISC_H__
35
36
37#include "scip/def.h"
39#include "scip/type_misc.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/** data structure for sparse solutions */
47{
48 SCIP_VAR** vars; /**< variables */
49 SCIP_Longint* lbvalues; /**< array of lower bounds */
50 SCIP_Longint* ubvalues; /**< array of upper bounds */
51 int nvars; /**< number of variables */
52};
53
54typedef union {
55 void* ptr; /**< pointer element */
56 unsigned int uinteger; /**< unsigned integer element */
58
59/** (circular) Queue data structure */
61{
62 SCIP_Real sizefac; /**< memory growing factor */
63 SCIP_QUEUEELEMENT* slots; /**< array of element slots */
64 int firstfree; /**< first free slot */
65 int firstused; /**< first used slot */
66 int size; /**< total number of available element slots */
67};
68
69/** priority queue data structure
70 * Elements are stored in an array, which grows dynamically in size as new elements are added to the queue.
71 * The ordering is done through a pointer comparison function.
72 * The array is organized as follows. The root element (that is the "best" element \f$ r \f$ with \f$ r \leq x \f$ for all \f$ x \f$ )
73 * is stored in position 0. The children of an element at position \f$ p \f$ are stored at positions \f$ q_1 = 2*p+1 \f$ and
74 * \f$ q_2 = 2*p+2 \f$ . That means, the parent of the element at position \f$ q \f$ is at position \f$ p = (q-1)/2 \f$ .
75 * At any time, the condition holds that \f$ p \leq q \f$ for each parent \f$ p \f$ and its children \f$ q \f$ .
76 * Insertion and removal of single elements needs time \f$ O(log n) \f$ .
77 */
79{
80 SCIP_Real sizefac; /**< memory growing factor */
81 SCIP_DECL_SORTPTRCOMP((*ptrcomp)); /**< compares two data elements */
82 SCIP_DECL_PQUEUEELEMCHGPOS((*elemchgpos));/**< callback to act on position change of elem in priority queue, or NULL */
83 void** slots; /**< array of element slots */
84 int len; /**< number of used element slots */
85 int size; /**< total number of available element slots */
86};
87
88/** hash table data structure */
90{
91 SCIP_DECL_HASHGETKEY((*hashgetkey)); /**< gets the key of the given element */
92 SCIP_DECL_HASHKEYEQ ((*hashkeyeq)); /**< returns TRUE iff both keys are equal */
93 SCIP_DECL_HASHKEYVAL((*hashkeyval)); /**< returns the hash value of the key */
94 BMS_BLKMEM* blkmem; /**< block memory used to store hash map entries */
95 void* userptr; /**< user pointer */
96 void** slots; /**< slots of the hash table */
97 uint32_t* hashes; /**< hash values of elements stored in slots */
98 uint32_t shift; /**< power such that 2^(32-shift) == nslots */
99 uint32_t mask; /**< mask used for fast modulo, i.e. nslots - 1 */
100 uint32_t nelements; /**< number of elements in the hashtable */
101};
102
103/** element list to store single elements of a hash table */
105{
106 void* element; /**< this element */
107 SCIP_MULTIHASHLIST* next; /**< rest of the hash table list */
108};
109
110/** multihash table data structure */
112{
113 SCIP_DECL_HASHGETKEY((*hashgetkey)); /**< gets the key of the given element */
114 SCIP_DECL_HASHKEYEQ ((*hashkeyeq)); /**< returns TRUE iff both keys are equal */
115 SCIP_DECL_HASHKEYVAL((*hashkeyval)); /**< returns the hash value of the key */
116 BMS_BLKMEM* blkmem; /**< block memory used to store hash map entries */
117 SCIP_MULTIHASHLIST** lists; /**< multihash table lists of the hash table */
118 int nlists; /**< number of lists stored in the hash table */
119 void* userptr; /**< user pointer */
120 SCIP_Longint nelements; /**< number of elements in the hashtable */
121};
122
123typedef union {
124 void* ptr; /**< pointer image */
125 int integer; /**< integer image */
126 SCIP_Real real; /**< real image */
127 SCIP_Longint longint; /**< long image */
129
130/** hash map entry */
132{
133 void* origin; /**< origin of element */
134 SCIP_HASHMAPIMAGE image; /**< image of element */
135};
136
137/** hash map data structure to map pointers on pointers */
139{
140 BMS_BLKMEM* blkmem; /**< block memory used to store hash map entries */
141 SCIP_HASHMAPENTRY* slots; /**< buffer for hashmap entries */
142 uint32_t* hashes; /**< hashes of elements */
143 uint32_t shift; /**< power such that 2^(32-shift) == nslots */
144 uint32_t mask; /**< mask used for fast modulo, i.e. nslots - 1 */
145 uint32_t nelements; /**< number of elements in the hashtable */
146 SCIP_HASHMAPTYPE hashmaptype; /**< type of entries */
147};
148
149/** lightweight hash set data structure to map pointers on pointers */
151{
152 void** slots; /**< buffer for hashmap entries */
153 uint32_t shift; /**< power such that 2^(64-shift) == nslots */
154 uint32_t nelements; /**< number of elements in the hashtable */
155};
156
157/** dynamic array for storing real values */
159{
160 BMS_BLKMEM* blkmem; /**< block memory that stores the vals array */
161 SCIP_Real* vals; /**< array values */
162 int valssize; /**< size of vals array */
163 int firstidx; /**< index of first element in vals array */
164 int minusedidx; /**< index of first non zero element in vals array */
165 int maxusedidx; /**< index of last non zero element in vals array */
166};
167
168/** dynamic array for storing int values */
170{
171 BMS_BLKMEM* blkmem; /**< block memory that stores the vals array */
172 int* vals; /**< array values */
173 int valssize; /**< size of vals array */
174 int firstidx; /**< index of first element in vals array */
175 int minusedidx; /**< index of first non zero element in vals array */
176 int maxusedidx; /**< index of last non zero element in vals array */
177};
178
179/** dynamic array for storing bool values */
181{
182 BMS_BLKMEM* blkmem; /**< block memory that stores the vals array */
183 SCIP_Bool* vals; /**< array values */
184 int valssize; /**< size of vals array */
185 int firstidx; /**< index of first element in vals array */
186 int minusedidx; /**< index of first non zero element in vals array */
187 int maxusedidx; /**< index of last non zero element in vals array */
188};
189
190/** dynamic array for storing pointers */
192{
193 BMS_BLKMEM* blkmem; /**< block memory that stores the vals array */
194 void** vals; /**< array values */
195 int valssize; /**< size of vals array */
196 int firstidx; /**< index of first element in vals array */
197 int minusedidx; /**< index of first non zero element in vals array */
198 int maxusedidx; /**< index of last non zero element in vals array */
199};
200
201/** resource activity */
203{
204 SCIP_VAR* var; /**< start time variable of the activity */
205 int duration; /**< duration of the activity */
206 int demand; /**< demand of the activity */
207};
208
209/** resource profile */
211{
212 int* timepoints; /**< time point array */
213 int* loads; /**< array holding the load for each time point */
214 int capacity; /**< capacity of the resource profile */
215 int ntimepoints; /**< current number of entries */
216 int arraysize; /**< current array size */
217};
218
219/** digraph structure to store and handle graphs */
221{
222 BMS_BLKMEM* blkmem; /**< block memory pointer to store the data */
223 int** successors; /**< adjacency list: for each node (first dimension) list of all successors */
224 void*** arcdata; /**< arc data corresponding to the arcs to successors given by the successors array */
225 void** nodedata; /**< data for each node of graph */
226 int* successorssize; /**< sizes of the successor lists for the nodes */
227 int* nsuccessors; /**< number of successors stored in the adjacency lists of the nodes */
228 int* components; /**< array to store the node indices of the components, one component after the other */
229 int* componentstarts; /**< array to store the start indices of the components in the components array */
230 int* articulations; /**< array of size narticulations to store the node indices of the articulation points */
231 int ncomponents; /**< number of undirected components stored */
232 int componentstartsize; /**< size of array componentstarts */
233 int nnodes; /**< number of nodes, nodes should be numbered from 0 to nnodes-1 */
234 int narticulations; /**< number of articulation points among the graph nodes */
235 SCIP_Bool articulationscheck; /**< TRUE if the (computed) articulation nodes are up-to-date and FALSE otherwise */
236};
237
238/** binary node data structure for binary tree */
240{
241 SCIP_BTNODE* parent; /**< pointer to the parent node */
242 SCIP_BTNODE* left; /**< pointer to the left child node */
243 SCIP_BTNODE* right; /**< pointer to the right child node */
244 void* dataptr; /**< user pointer */
245};
246
247/** binary search tree data structure */
249{
250 SCIP_BTNODE* root; /**< pointer to the dummy root node; root is left child */
251 BMS_BLKMEM* blkmem; /**< block memory used to store tree nodes */
252};
253
254/** data structure for incremental linear regression of data points (X_i, Y_i) */
256{
257 SCIP_Real intercept; /**< the current axis intercept of the regression */
258 SCIP_Real slope; /**< the current slope of the regression */
259 SCIP_Real meanx; /**< mean of all X observations */
260 SCIP_Real meany; /**< mean of all Y observations */
261 SCIP_Real sumxy; /**< accumulated sum of all products X * Y */
262 SCIP_Real variancesumx; /**< incremental variance term for X observations */
263 SCIP_Real variancesumy; /**< incremental variance term for Y observations */
264 SCIP_Real corrcoef; /**< correlation coefficient of X and Y */
265 int nobservations; /**< number of observations so far */
266};
267
268/** random number generator data */
270{
271 uint32_t seed; /**< start seed */
272 uint32_t xor_seed; /**< Xorshift seed */
273 uint32_t mwc_seed; /**< Multiply-with-carry seed */
274 uint32_t cst_seed; /**< constant seed */
275};
276
277/** disjoint set (disjoint set (union find)) data structure for querying and updating connectedness in a graph with integer vertices 0,...,n - 1 */
279{
280 int* parents; /**< array to store the parent node index for every vertex */
281 int* sizes; /**< array to store the size of the subtree rooted at each vertex */
282 int size; /**< the number of vertices in the graph */
283 int componentcount; /**< counter for the number of connected components of the graph */
284};
285
286/** a linear inequality row in preparation to become a SCIP_ROW */
288{
289 SCIP_VAR** vars; /**< variables */
290 SCIP_Real* coefs; /**< coefficients of variables */
291 int nvars; /**< number of variables (= number of coefficients) */
292 int varssize; /**< length of variables array (= lengths of coefficients array) */
293 SCIP_Real side; /**< side */
294 SCIP_SIDETYPE sidetype; /**< type of side */
295 SCIP_Bool local; /**< whether the row is only locally valid (i.e., for the current node) */
296 char name[SCIP_MAXSTRLEN]; /**< row name */
297
298 SCIP_Bool recordmodifications;/**< whether to remember variables which coefficients were modified during cleanup */
299 SCIP_VAR** modifiedvars; /**< variables which coefficient were modified by cleanup */
300 int nmodifiedvars; /**< number of variables which coefficient was modified */
301 int modifiedvarssize; /**< length of `modifiedvars` array */
302 SCIP_Bool modifiedside; /**< whether the side was modified (relaxed) by cleanup */
303};
304
305#ifdef __cplusplus
306}
307#endif
308
309#endif
common defines and data types used in all packages of SCIP
#define SCIP_MAXSTRLEN
Definition: def.h:269
#define SCIP_Longint
Definition: def.h:141
#define SCIP_Bool
Definition: def.h:91
#define SCIP_Real
Definition: def.h:156
memory allocation routines
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:437
BMS_BLKMEM * blkmem
Definition: struct_misc.h:182
SCIP_Bool * vals
Definition: struct_misc.h:183
SCIP_BTNODE * parent
Definition: struct_misc.h:241
void * dataptr
Definition: struct_misc.h:244
SCIP_BTNODE * left
Definition: struct_misc.h:242
SCIP_BTNODE * right
Definition: struct_misc.h:243
SCIP_BTNODE * root
Definition: struct_misc.h:250
BMS_BLKMEM * blkmem
Definition: struct_misc.h:251
SCIP_Bool articulationscheck
Definition: struct_misc.h:235
int ** successors
Definition: struct_misc.h:223
void ** nodedata
Definition: struct_misc.h:225
int * successorssize
Definition: struct_misc.h:226
void *** arcdata
Definition: struct_misc.h:224
int componentstartsize
Definition: struct_misc.h:232
int * articulations
Definition: struct_misc.h:230
int * componentstarts
Definition: struct_misc.h:229
int narticulations
Definition: struct_misc.h:234
BMS_BLKMEM * blkmem
Definition: struct_misc.h:222
int * components
Definition: struct_misc.h:228
int * nsuccessors
Definition: struct_misc.h:227
SCIP_HASHMAPIMAGE image
Definition: struct_misc.h:134
uint32_t nelements
Definition: struct_misc.h:145
BMS_BLKMEM * blkmem
Definition: struct_misc.h:140
SCIP_HASHMAPTYPE hashmaptype
Definition: struct_misc.h:146
uint32_t mask
Definition: struct_misc.h:144
uint32_t shift
Definition: struct_misc.h:143
SCIP_HASHMAPENTRY * slots
Definition: struct_misc.h:141
uint32_t * hashes
Definition: struct_misc.h:142
uint32_t nelements
Definition: struct_misc.h:154
void ** slots
Definition: struct_misc.h:152
uint32_t shift
Definition: struct_misc.h:153
void * userptr
Definition: struct_misc.h:95
uint32_t nelements
Definition: struct_misc.h:100
SCIP_DECL_HASHKEYVAL((*hashkeyval))
SCIP_DECL_HASHKEYEQ((*hashkeyeq))
uint32_t shift
Definition: struct_misc.h:98
uint32_t mask
Definition: struct_misc.h:99
BMS_BLKMEM * blkmem
Definition: struct_misc.h:94
void ** slots
Definition: struct_misc.h:96
SCIP_DECL_HASHGETKEY((*hashgetkey))
uint32_t * hashes
Definition: struct_misc.h:97
BMS_BLKMEM * blkmem
Definition: struct_misc.h:171
SCIP_MULTIHASHLIST * next
Definition: struct_misc.h:107
SCIP_DECL_HASHKEYEQ((*hashkeyeq))
SCIP_MULTIHASHLIST ** lists
Definition: struct_misc.h:117
SCIP_DECL_HASHGETKEY((*hashgetkey))
BMS_BLKMEM * blkmem
Definition: struct_misc.h:116
SCIP_DECL_HASHKEYVAL((*hashkeyval))
SCIP_Longint nelements
Definition: struct_misc.h:120
SCIP_DECL_SORTPTRCOMP((*ptrcomp))
void ** slots
Definition: struct_misc.h:83
SCIP_Real sizefac
Definition: struct_misc.h:80
SCIP_DECL_PQUEUEELEMCHGPOS((*elemchgpos))
int * timepoints
Definition: struct_misc.h:212
void ** vals
Definition: struct_misc.h:194
BMS_BLKMEM * blkmem
Definition: struct_misc.h:193
SCIP_Real sizefac
Definition: struct_misc.h:62
int firstused
Definition: struct_misc.h:65
SCIP_QUEUEELEMENT * slots
Definition: struct_misc.h:63
int firstfree
Definition: struct_misc.h:64
uint32_t xor_seed
Definition: struct_misc.h:272
uint32_t cst_seed
Definition: struct_misc.h:274
uint32_t mwc_seed
Definition: struct_misc.h:273
SCIP_Real * vals
Definition: struct_misc.h:161
BMS_BLKMEM * blkmem
Definition: struct_misc.h:160
SCIP_Real slope
Definition: struct_misc.h:258
SCIP_Real meany
Definition: struct_misc.h:260
SCIP_Real meanx
Definition: struct_misc.h:259
SCIP_Real variancesumx
Definition: struct_misc.h:262
SCIP_Real corrcoef
Definition: struct_misc.h:264
SCIP_Real sumxy
Definition: struct_misc.h:261
SCIP_Real intercept
Definition: struct_misc.h:257
SCIP_Real variancesumy
Definition: struct_misc.h:263
SCIP_Real side
Definition: struct_misc.h:293
SCIP_Bool modifiedside
Definition: struct_misc.h:302
SCIP_VAR ** modifiedvars
Definition: struct_misc.h:299
SCIP_VAR ** vars
Definition: struct_misc.h:289
char name[SCIP_MAXSTRLEN]
Definition: struct_misc.h:296
SCIP_Real * coefs
Definition: struct_misc.h:290
SCIP_Bool local
Definition: struct_misc.h:295
SCIP_Bool recordmodifications
Definition: struct_misc.h:298
int modifiedvarssize
Definition: struct_misc.h:301
SCIP_SIDETYPE sidetype
Definition: struct_misc.h:294
SCIP_Longint * lbvalues
Definition: struct_misc.h:49
SCIP_VAR ** vars
Definition: struct_misc.h:48
SCIP_Longint * ubvalues
Definition: struct_misc.h:50
enum SCIP_SideType SCIP_SIDETYPE
Definition: type_lp.h:68
type definitions for miscellaneous datastructures
enum SCIP_Hashmaptype SCIP_HASHMAPTYPE
Definition: type_misc.h:64
SCIP_Longint longint
Definition: struct_misc.h:127
unsigned int uinteger
Definition: struct_misc.h:56