Scippy

SCIP

Solving Constraint Integer Programs

misc_stp.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-2022 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 scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file misc_stp.h
17  * @brief miscellaneous methods used for solving Steiner problems
18  * @author Daniel Rehfeldt
19  *
20  * This file includes miscellaneous methods used for solving Steiner problems. For more details see \ref STP_MISC page.
21  */
22 
23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
24 
25 #ifndef __SCIP_MISC_STP_H__
26 #define __SCIP_MISC_STP_H__
27 
28 #include "scip/scip.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define SWAP_INTS(int1, int2) \
35  do \
36  { \
37  const int _tmp_ = int1; \
38  int1 = int2; \
39  int2 = _tmp_; \
40  } while(0)
41 
42 
43 #define SWAP_REALS(real1, real2) \
44  do \
45  { \
46  const SCIP_Real _tmp_ = real1; \
47  real1 = real2; \
48  real2 = _tmp_; \
49  } while(0)
50 
51 
52 /** graph node structure storing number and distance */
53 typedef struct Graph_Node
54 {
55  int number; /**< node number */
56  SCIP_Real dist; /**< node distance */
57 } GNODE;
58 
59 
60 /** Voronoi list node structure storing distance, incoming edge,base and pointer to next list node */
61 typedef struct Vnoi_List_Node
62 {
63  double dist; /**< Distance to the end of the path */
64  signed int edge; /**< First edge to go */
65  signed int base; /**< Voronoi base */
67 } VLIST;
68 
69 /** link-cut_node */
70 typedef struct link_cut_node
71 {
72  int edge; /**< edge to the node */
73  int parent; /**< index of parent node */
74 } LCNODE;
75 
76 
77 /** a weighted-quick-union-path-compression union find structure */
78 typedef struct UnionFind_Structure
79 {
80  int* parent; /**< parent[i] stores the parent of i */
81  int* size; /**< size[i] stores number of nodes in the tree rooted at i */
82  int nComponents; /**< number of components */
83  int nElements; /**< number of elements */
84 } UF;
85 
86 
87 /** integer list node */
88 typedef struct Int_List_Node
89 {
90  int index; /**< int value to store */
91  struct Int_List_Node *parent; /**< pointer to parent node */
92 } IDX;
93 
94 
95 /** Pairing heap node */
96 typedef struct PHeap_Node
97 {
98  struct PHeap_Node* child; /**< pointer to child node */
99  struct PHeap_Node* sibling; /**< pointer to right sibling */
100  struct PHeap_Node* prev; /**< pointer to to previous node */
101  SCIP_Real key; /**< key value */
102  int element; /**< integer data value */
103 } PHNODE;
104 
105 
106 /** returns maximum of given SCIP_Real values */
107 SCIP_EXPORT
109  const SCIP_Real* realarr, /**< array of reals */
110  unsigned nreals /**< size of array of reals */
111  );
112 
113 /**
114  * Int List
115  */
116 
117 /** append copy of list pertaining to node2 to node1 */
118 SCIP_EXPORT
120  SCIP* scip, /**< SCIP data structure */
121  IDX** node1, /**< pointer to the last node of list to be enlarged */
122  IDX* node2, /**< pointer to the last node of source list */
123  SCIP_Bool* conflict /**< pointer to store whether a conflict has been detected by the method */
124  );
125 
126 /** append list pertaining to node2 to (non-empty!) node1 */
127 SCIP_EXPORT
129  IDX* node1, /**< pointer to the last node of non-empty list to be enlarged */
130  IDX* node2 /**< pointer to the last node of source list */
131  );
132 
133 /** insert a new node */
134 SCIP_EXPORT
136  SCIP* scip, /**< SCIP data structure */
137  IDX** node, /**< pointer to the last list node */
138  int nodeval /**< data of the new node */
139  );
140 
141 /** free list */
142 SCIP_EXPORT
144  SCIP* scip, /**< SCIP data structure */
145  IDX** node /**< pointer to the last list node */
146  );
147 
148 /** compares distances of two GNODE structures */
149 SCIP_EXPORT
150 int GNODECmpByDist(
151  void *first_arg, /**< first argument */
152  void *second_arg /**< second argument */
153  );
154 
155 /**
156  * Linear Link Cut Tree
157  */
158 
159 /** inits a node, setting 'parent' and 'edge' to its default values */
160 SCIP_EXPORT
162  LCNODE* v /**< pointer to node representing the tree */
163  );
164 
165 /** renders w a child of v; v has to be the root of its tree */
166 SCIP_EXPORT
168  LCNODE* tree, /**< the tree */
169  int v, /**< pointer to node representing the tree */
170  int w, /**< pointer to node of another tree */
171  int edge /**< link edge */
172  );
173 
174 /** cut tree at given node */
175 SCIP_EXPORT
177  LCNODE* v /**< node to cut at */
178  );
179 
180 /** finds minimum weight chain between node 'start' and distinct root node (for maximum-weight connected subgraph) **/
181 SCIP_EXPORT
183  SCIP* scip, /**< SCIP data structure */
184  const LCNODE* tree, /**< tree */
185  const SCIP_Real* nodeweight, /**< node weight array */
186  const int* heads, /**< head of an arc */
187  const int* stdeg, /**< degree in Steiner tree */
188  const SCIP_Bool* nodeIsBlocked, /**< has node been blocked? */
189  int start, /**< the node to start at */
190  int* first, /**< first node of chain */
191  int* last /**< last node of chain */
192  );
193 
194 
195 /** finds maximum cost chain between node 'start' and distinct root node **/
196 SCIP_EXPORT
198  SCIP* scip, /**< SCIP data structure */
199  const LCNODE* tree, /**< tree */
200  const SCIP_Real* edgecosts, /**< edge cost array */
201  const SCIP_Real* prizes, /**< node weight array for PC/RPC */
202  const int* heads, /**< head of an arc */
203  const int* nonTermDeg, /**< degree in Steiner tree, or UNKNOWN if vertex is terminal */
204  const SCIP_Bool* nodeIsBlocked, /**< has node been blocked? */
205  int start, /**< the node to start at (NOT the root!) */
206  int* first, /**< first node of chain */
207  int* last /**< last node of chain */
208  );
209 
210 
211 /** finds the max value between node 'v' and the root of the tree **/
212 SCIP_EXPORT
214  const LCNODE* tree, /**< tree */
215  const SCIP_Real* cost, /**< edge cost array */
216  int v /**< the node */
217  );
218 
219 
220 /** makes vertex v the root of the link cut tree */
221 SCIP_EXPORT
223  LCNODE* RESTRICT tree, /**< tree */
224  int root_new /**< the vertex to become the root */
225  );
226 
227 
228 /*
229  * Pairing Heap
230  */
231 
232 /** links nodes 'root1' and 'root2' together */
233 SCIP_EXPORT
235  SCIP* scip, /**< SCIP data structure */
236  PHNODE *root1, /**< pointer to root of first heap */
237  PHNODE *root2 /**< pointer to root of second heap */
238  );
239 
240 /** inserts a new node into the pairing heap */
241 SCIP_EXPORT
243  SCIP* scip, /**< SCIP data structure */
244  PHNODE** root,
245  PHNODE* pheapelems, /**< data array */
246  int element,
247  SCIP_Real key,
248  int* size
249  );
250 
251 /** deletes the root of the paring heap, concomitantly storing its data and key in '*element' and '*key' respectively */
252 SCIP_EXPORT
254  SCIP* scip, /**< SCIP data structure */
255  int* element, /**< data of the root */
256  SCIP_Real* key, /**< key of the root */
257  PHNODE** root, /**< pointer to root of the heap */
258  int* size /**< pointer to size of the heap */
259  );
260 
261 /** links nodes 'root1' and 'root2' together, roots the resulting tree at root1 and sets root2 to NULL */
262 SCIP_EXPORT
264  SCIP* scip, /**< SCIP data structure */
265  PHNODE** root1, /**< pointer to root of first heap */
266  PHNODE** root2, /**< pointer to root of second heap */
267  int* sizeroot1, /**< pointer to size of first heap */
268  int* sizeroot2 /**< pointer to size of second heap */
269  );
270 
271 /** frees the paring heap with root 'p' */
272 SCIP_EXPORT
273 void SCIPpairheapFree(
274  SCIP* scip, /**< SCIP data structure */
275  PHNODE** root /**< root of heap to be freed */
276  );
277 
278 /** stores all elements of the pairing heap in an array */
279 SCIP_EXPORT
281  SCIP* scip, /**< SCIP data structure */
282  const PHNODE* root, /**< root of the heap */
283  int size, /**< size of the array */
284  int** elements /**< pointer to array (will be allocated) */
285  );
286 
287 
288 
289 /*
290  * Union-Find data structure
291  */
292 
293 /** initializes the union-find structure 'uf' with 'length' many components (of size one) */
294 SCIP_EXPORT
296  SCIP* scip, /**< SCIP data structure */
297  UF* uf, /**< union find data structure */
298  int length /**< number of components */
299  );
300 
301 /** clears the union-find structure 'uf'*/
302 SCIP_EXPORT
304  SCIP* scip, /**< SCIP data structure */
305  UF* uf /**< union find data structure */
306  );
307 
308 
309 /** is the union-find structure 'uf' clear? */
310 SCIP_EXPORT
312  SCIP* scip, /**< SCIP data structure */
313  const UF* uf /**< union find data structure */
314  );
315 
316 
317 /** finds and returns the component identifier */
318 SCIP_EXPORT
320  UF* uf, /**< union find data structure */
321  int element /**< element to be found */
322  );
323 
324 /** Merges the components containing p and q respectively.
325  * Identifier of 'p' will always be used if 'compress' is FALSE. */
326 SCIP_EXPORT
328  UF* uf, /**< union find data structure */
329  int p, /**< first component */
330  int q, /**< second component*/
331  SCIP_Bool compress /**< compress union find structure? */
332  );
333 
334 /** frees the data fields of the union-find structure */
335 SCIP_EXPORT
337  SCIP* scip, /**< SCIP data structure */
338  UF* uf /**< union find data structure */
339  );
340 
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 
346 #endif
SCIP_RETCODE SCIPStpunionfindInit(SCIP *scip, UF *uf, int length)
Definition: misc_stp.c:817
struct link_cut_node LCNODE
void SCIPStpunionfindFreeMembers(SCIP *scip, UF *uf)
Definition: misc_stp.c:955
int SCIPlinkcuttreeFindMax(const LCNODE *tree, const SCIP_Real *cost, int v)
Definition: misc_stp.c:533
SCIP_Real SCIPlinkcuttreeFindMaxChain(SCIP *scip, const LCNODE *tree, const SCIP_Real *edgecosts, const SCIP_Real *prizes, const int *heads, const int *nonTermDeg, const SCIP_Bool *nodeIsBlocked, int start, int *first, int *last)
Definition: misc_stp.c:445
SCIP_Real SCIPlinkcuttreeFindMinChainMw(SCIP *scip, const LCNODE *tree, const SCIP_Real *nodeweight, const int *heads, const int *stdeg, const SCIP_Bool *nodeIsBlocked, int start, int *first, int *last)
Definition: misc_stp.c:381
struct PHeap_Node * sibling
Definition: misc_stp.h:99
void SCIPpairheapMeldheaps(SCIP *scip, PHNODE **root1, PHNODE **root2, int *sizeroot1, int *sizeroot2)
Definition: misc_stp.c:708
void SCIPStpunionfindClear(SCIP *scip, UF *uf)
Definition: misc_stp.c:841
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
struct PHeap_Node * child
Definition: misc_stp.h:98
SCIP_RETCODE SCIPpairheapDeletemin(SCIP *scip, int *element, SCIP_Real *key, PHNODE **root, int *size)
Definition: misc_stp.c:671
int number
Definition: misc_stp.h:55
void SCIPintListNodeFree(SCIP *scip, IDX **node)
Definition: misc_stp.c:325
SCIP_Real miscstp_maxReal(const SCIP_Real *realarr, unsigned nreals)
Definition: misc_stp.c:142
void SCIPpairheapFree(SCIP *scip, PHNODE **root)
Definition: misc_stp.c:736
void SCIPlinkcuttreeEvert(LCNODE *RESTRICT tree, int root_new)
Definition: misc_stp.c:559
SCIP_VAR * w
Definition: circlepacking.c:58
signed int edge
Definition: misc_stp.h:64
struct Vnoi_List_Node * next
Definition: misc_stp.h:66
struct Vnoi_List_Node VLIST
void SCIPlinkcuttreeCutNode(LCNODE *v)
Definition: misc_stp.c:372
int SCIPStpunionfindFind(UF *uf, int element)
Definition: misc_stp.c:885
SCIP_Real dist
Definition: misc_stp.h:56
SCIP_RETCODE SCIPintListNodeAppendCopy(SCIP *scip, IDX **node1, IDX *node2, SCIP_Bool *conflict)
Definition: misc_stp.c:197
signed int base
Definition: misc_stp.h:65
void SCIPlinkcuttreeInitNode(LCNODE *v)
Definition: misc_stp.c:347
Definition: graph_load.c:93
SCIP_RETCODE SCIPintListNodeInsert(SCIP *scip, IDX **node, int nodeval)
Definition: misc_stp.c:180
int GNODECmpByDist(void *first_arg, void *second_arg)
void SCIPlinkcuttreeLink(LCNODE *tree, int v, int w, int edge)
Definition: misc_stp.c:357
#define SCIP_Bool
Definition: def.h:84
PHNODE * SCIPpairheapMergeheaps(SCIP *scip, PHNODE *root1, PHNODE *root2)
Definition: misc_stp.c:592
struct Graph_Node GNODE
void SCIPStpunionfindUnion(UF *uf, int p, int q, SCIP_Bool compress)
Definition: misc_stp.c:912
SCIP_RETCODE SCIPpairheapInsert(SCIP *scip, PHNODE **root, PHNODE *pheapelems, int element, SCIP_Real key, int *size)
Definition: misc_stp.c:636
struct PHeap_Node PHNODE
SCIP_Real key
Definition: misc_stp.h:101
void SCIPintListNodeAppend(IDX *node1, IDX *node2)
Definition: misc_stp.c:309
struct PHeap_Node * prev
Definition: misc_stp.h:100
int element
Definition: misc_stp.h:102
SCIP_Bool SCIPStpunionfindIsClear(SCIP *scip, const UF *uf)
Definition: misc_stp.c:861
SCIP_RETCODE SCIPpairheapBuffarr(SCIP *scip, const PHNODE *root, int size, int **elements)
Definition: misc_stp.c:761
#define SCIP_Real
Definition: def.h:177
double dist
Definition: misc_stp.h:63
struct Int_List_Node * parent
Definition: misc_stp.h:91
struct UnionFind_Structure UF
SCIP callable library.
struct Int_List_Node IDX