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-2015 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 email to scip@zib.de. */
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 MISCSTP 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 /** graph node structure storing number and distance */
35 typedef struct Graph_Node
36 {
37  int number; /**< node number */
38  SCIP_Real dist; /**< node distance */
39 }GNODE;
40 
41 /** a weighted-quick-union-path-compression union find structure */
42 typedef struct UnionFind_Structure
43 {
44  int* parent; /**< parent[i] stores the parent of i */
45  int* size; /**< size[i] stores number of nodes in the tree rooted at i */
46  int count; /**< number of components */
47 }UF;
48 
49 /** voronoi list node structure storing distance, incoming edge,base and pointer to next list node */
50 typedef struct Vnoi_List_Node
51 {
52  double dist; /**< Distance to the end of the path */
53  signed int edge; /**< First edge to go */
54  signed int base; /**< Voronoi base */
56 }VLIST;
57 
58 /** node */
59 typedef struct ST_Node
60 {
61  int edge; /**< edge to the node */
62  struct ST_Node *parent; /**< pointer to parent node */
63 }NODE;
64 
65 /** integer list node */
66 typedef struct Int_List_Node
67 {
68  int index; /**< int value to store */
69  struct Int_List_Node *parent; /**< pointer to parent node */
70 }IDX;
71 
72 /** Pairing heap node */
73 typedef struct PHeap_Node
74 {
75  int element; /**< int data value */
76  SCIP_Real key; /**< key value */
77  struct PHeap_Node* child; /**< pointer to child node */
78  struct PHeap_Node* sibling; /**< pointer to right sibling */
79  struct PHeap_Node* prev; /**< pointer to to previous node */
80 }PHNODE;
81 
82 
83 /**
84  * Int List
85  */
86 
87 /** append copy of list pertaining to node2 to node1 */
88 extern
89 SCIP_RETCODE SCIPintListNodeAppendCopy(
90  SCIP* scip, /**< SCIP data structure */
91  IDX** node1, /**< pointer to the last node of list to be enlarged */
92  IDX* node2 /**< pointer to the last node of source list */
93  );
94 
95 /** insert a new node */
96 extern
97 SCIP_RETCODE SCIPintListNodeInsert(
98  SCIP* scip, /**< SCIP data structure */
99  IDX** node, /**< pointer to the last list node */
100  int nodeval /**< data of the new node */
101  );
102 
103 /** free list */
104 extern
106  SCIP* scip, /**< SCIP data structure */
107  IDX** node /**< pointer to the last list node */
108  );
109 
110 /** compares distances of two GNODE structures */
111 extern
112 int GNODECmpByDist(
113  void *first_arg, /**< first argument */
114  void *second_arg /**< second argument */
115  );
116 
117 /**
118  * Linear Link Cut Tree
119  */
120 
121 /** inits a node, setting 'parent' and 'edge' to its default values */
122 extern
124  NODE* v /**< pointer to node representing the tree */
125  );
126 
127 /** renders w a child of v; v has to be the root of its tree */
128 extern
130  NODE* v, /**< pointer to node representing the tree */
131  NODE* w, /**< pointer to the child */
132  int edge /**< link edge */
133  );
134 
135 /** cut tree at given node */
136 extern
137 void SCIPlinkcuttreeCut(
138  NODE* v /**< node to cut at */
139  );
140 
141 /** finds minimal non-key-node value between node 'v' and the root of the tree **/
143  SCIP* scip, /**< SCIP data structure */
144  SCIP_Real* nodeweight, /**< node weight array */
145  int* tail, /**< arcs tails */
146  int* stdeg, /**< degree in Steiner tree */
147  NODE* v /**< the node */
148  );
149 
150 /** finds the max value between node 'v' and the root of the tree **/
151 extern
153  SCIP* scip, /**< SCIP data structure */
154  const SCIP_Real* cost, /**< edge cost array */
155  NODE* v /**< the node */
156  );
157 
158 /** makes vertex v the root of the link cut tree */
159 extern
161  NODE* v /**< the vertex to become the root */
162  );
163 
164 
165 /*
166  * Pairing Heap
167  */
168 
169 /** links nodes 'root1' and 'root2' together */
170 extern
172  SCIP* scip, /**< SCIP data structure */
173  PHNODE *root1, /**< pointer to root of first heap */
174  PHNODE *root2 /**< pointer to root of second heap */
175  );
176 
177 extern
179  SCIP* scip, /**< SCIP data structure */
180  PHNODE* root1, /**< pointer to root of first heap */
181  PHNODE* root2 /**< pointer to root of second heap */
182  );
183 
184 /** inserts a new node into the pairing heap */
185 extern
186 SCIP_RETCODE SCIPpairheapInsert(
187  SCIP* scip, /**< SCIP data structure */
188  PHNODE** root,
189  int element,
190  SCIP_Real key,
191  int* size
192  );
193 
194 /** deletes the root of the paring heap, concomitantly storing its data and key in '*element' and '*key' respectively */
195 extern
196 SCIP_RETCODE SCIPpairheapDeletemin(
197  SCIP* scip, /**< SCIP data structure */
198  int* element, /**< data of the root */
199  SCIP_Real* key, /**< key of the root */
200  PHNODE** root, /**< pointer to root of the heap */
201  int* size /**< pointer to size of the heap */
202  );
203 
204 /** links nodes 'root1' and 'root2' together, roots the resulting tree at root1 and sets root2 to NULL */
205 extern
207  SCIP* scip, /**< SCIP data structure */
208  PHNODE** root1, /**< pointer to root of first heap */
209  PHNODE** root2, /**< pointer to root of second heap */
210  int* sizeroot1, /**< pointer to size of first heap */
211  int* sizeroot2 /**< pointer to size of second heap */
212  );
213 
214 /** frees the paring heap with root 'p' */
215 extern
216 void SCIPpairheapFree(
217  SCIP* scip, /**< SCIP data structure */
218  PHNODE** root /**< root of heap to be freed */
219  );
220 
221 /** stores all elements of the pairing heap in an array */
222 extern
223 SCIP_RETCODE SCIPpairheapBuffarr(
224  SCIP* scip, /**< SCIP data structure */
225  PHNODE* root, /**< root of the heap */
226  int size, /**< size of the array */
227  int** elements /**< pointer to array */
228  );
229 
230 /*
231  * Union-Find data structure
232  */
233 
234 /** initializes the union-find structure 'uf' with 'length' many components (of size one) */
235 extern
236 SCIP_RETCODE SCIPunionfindInit(
237  SCIP* scip, /**< SCIP data structure */
238  UF* uf, /**< union find data structure */
239  int length /**< number of components */
240  );
241 
242 /** finds and returns the component identifier */
243 extern
245  UF* uf, /**< union find data structure */
246  int element /**< element to be found */
247  );
248 
249 /** merges the components containing p and q respectively */
250 extern
251 void SCIPunionfindUnion(
252  UF* uf, /**< union find data structure */
253  int p, /**< first component */
254  int q, /**< second component*/
255  SCIP_Bool compress /**< compress union find structure? */
256  );
257 
258 /** frees the data fields of the union-find structure */
259 extern
260 void SCIPunionfindFree(
261  SCIP* scip, /**< SCIP data structure */
262  UF* uf /**< union find data structure */
263  );
264 
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif
struct Graph_Node GNODE
struct UnionFind_Structure UF
int SCIPunionfindFind(UF *uf, int element)
Definition: misc_stp.c:620
struct ST_Node * parent
Definition: misc_stp.h:62
struct PHeap_Node * sibling
Definition: misc_stp.h:78
void SCIPpairheapMeldheaps(SCIP *scip, PHNODE **root1, PHNODE **root2, int *sizeroot1, int *sizeroot2)
Definition: misc_stp.c:510
struct Vnoi_List_Node VLIST
PHNODE * SCIPpairheapAddtoheap(SCIP *scip, PHNODE *root1, PHNODE *root2)
Definition: misc_stp.c:331
struct PHeap_Node * child
Definition: misc_stp.h:77
SCIP_RETCODE SCIPpairheapDeletemin(SCIP *scip, int *element, SCIP_Real *key, PHNODE **root, int *size)
Definition: misc_stp.c:473
void SCIPunionfindFree(SCIP *scip, UF *uf)
Definition: misc_stp.c:687
int number
Definition: misc_stp.h:37
void SCIPintListNodeFree(SCIP *scip, IDX **node)
Definition: misc_stp.c:140
void SCIPpairheapFree(SCIP *scip, PHNODE **root)
Definition: misc_stp.c:538
signed int edge
Definition: misc_stp.h:53
struct Vnoi_List_Node * next
Definition: misc_stp.h:55
SCIP_RETCODE SCIPintListNodeAppendCopy(SCIP *scip, IDX **node1, IDX *node2)
Definition: misc_stp.c:76
SCIP_Real dist
Definition: misc_stp.h:38
int edge
Definition: misc_stp.h:61
NODE * SCIPlinkcuttreeFindMax(SCIP *scip, const SCIP_Real *cost, NODE *v)
Definition: misc_stp.c:230
signed int base
Definition: misc_stp.h:54
Definition: grphload.c:78
SCIP_RETCODE SCIPintListNodeInsert(SCIP *scip, IDX **node, int nodeval)
Definition: misc_stp.c:59
int GNODECmpByDist(void *first_arg, void *second_arg)
void SCIPlinkcuttreeLink(NODE *v, NODE *w, int edge)
Definition: misc_stp.c:171
struct Int_List_Node IDX
NODE * SCIPlinkcuttreeFindMinMW(SCIP *scip, SCIP_Real *nodeweight, int *tail, int *stdeg, NODE *v)
Definition: misc_stp.c:193
PHNODE * SCIPpairheapMergeheaps(SCIP *scip, PHNODE *root1, PHNODE *root2)
Definition: misc_stp.c:288
void SCIPunionfindUnion(UF *uf, int p, int q, SCIP_Bool compress)
Definition: misc_stp.c:644
void SCIPlinkcuttreeEvert(NODE *v)
Definition: misc_stp.c:254
struct ST_Node NODE
SCIP_Real key
Definition: misc_stp.h:76
SCIP_RETCODE SCIPpairheapInsert(SCIP *scip, PHNODE **root, int element, SCIP_Real key, int *size)
Definition: misc_stp.c:439
void SCIPlinkcuttreeInit(NODE *v)
Definition: misc_stp.c:162
struct PHeap_Node * prev
Definition: misc_stp.h:79
int element
Definition: misc_stp.h:75
SCIP_RETCODE SCIPpairheapBuffarr(SCIP *scip, PHNODE *root, int size, int **elements)
Definition: misc_stp.c:581
void SCIPlinkcuttreeCut(NODE *v)
Definition: misc_stp.c:184
double dist
Definition: misc_stp.h:52
struct Int_List_Node * parent
Definition: misc_stp.h:69
SCIP_RETCODE SCIPunionfindInit(SCIP *scip, UF *uf, int length)
Definition: misc_stp.c:600
struct PHeap_Node PHNODE