Scippy

SCIP

Solving Constraint Integer Programs

graphdefs.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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file graphdefs.h
17  * @brief includes graph definitions used for Steiner tree problems
18  * @author Thorsten Koch
19  * @author Daniel Rehfeldt
20  *
21  *
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 
27 
28 #ifndef APPLICATIONS_STP_SRC_GRAPHDEFS_H_
29 #define APPLICATIONS_STP_SRC_GRAPHDEFS_H_
30 
31 #include "scip/scip.h"
32 #include "misc_stp.h"
33 #include "portab.h"
34 
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 
41 
42 #define STP_SPG 0
43 #define STP_SAP 1
44 #define STP_PCSPG 2
45 #define STP_RPCSPG 3
46 #define STP_NWSPG 4
47 #define STP_DCSTP 5
48 #define STP_NWPTSPG 6
49 #define STP_RSMT 7
50 #define STP_OARSMT 8
51 #define STP_MWCSP 9
52 #define STP_DHCSTP 10
53 #define STP_GSTP 11
54 #define STP_RMWCSP 12
55 #define STP_BRMWCSP 13
56 
57 #define EAT_FREE -1
58 #define EAT_LAST -2
59 #define EAT_HIDE -3
60 
61 #define STP_TERM 0 /**< terminal */
62 #define STP_TERM_NONE -1 /**< non-terminal */
63 #define STP_TERM_PSEUDO -2 /**< pseudo-terminal (for PC/MW variants) */
64 #define STP_TERM_NONLEAF -3 /**< non-leaf (pseudo-) terminal (for PC/MW variants) */
65 
66 #define STP_CENTER_OK 0 /**< do nothing */
67 #define STP_CENTER_DEG 1 /**< find maximum degree */
68 #define STP_CENTER_SUM 2 /**< find the minimum distance sum */
69 #define STP_CENTER_MIN 3 /**< find the minimum largest distance */
70 #define STP_CENTER_ALL 4 /**< find the minimum distance sum to all knots */
71 
72 #define TERM2EDGE_NOTERM -1 /**< for PC/MW: vertex is no terminal */
73 #define TERM2EDGE_FIXEDTERM -2 /**< for PC/MW: vertex is fixed terminal; artificial root is also considered a fixed terminal */
74 #define TERM2EDGE_NONLEAFTERM -3 /**< for PC/MW: vertex is non-leaf terminal */
75 
76 #define SDSTAR_BASE_UNSET -1
77 #define SDSTAR_BASE_KILLED -2
78 
79 #define STP_DELPSEUDO_MAXGRAD 7
80 #define STP_DELPSEUDO_MAXNEDGES 21
81 
82 
83 /* ((((edge) % 2) == 0) ? ((edge) + 1) : ((edge) - 1)) without branch */
84 #define flipedge(edge) ( ((edge) + 1) - 2 * ((edge) % 2) )
85 #define flipedge_Uint(edge) ( (((unsigned int) edge) + 1) - 2 * (((unsigned int) edge) % 2) )
86 
87 #define CONNECT 0
88 #define UNKNOWN (-1)
89 #define FARAWAY 1e15
90 #define BLOCKED 1e10 /**< used for temporarily blocking an edge */
91 #define BLOCKED_MINOR (BLOCKED - 1.0) /**< used for permanently blocking an edge;
92  * different from BLOCKED because of weird prize sum in reduce_base.c */
93 
94 #define EDGE_BLOCKED 0
95 #define EDGE_MODIFIABLE 1
96 
97 #define MST_MODE 0
98 #define FSP_MODE 1
99 #define BSP_MODE 2
101 #define Is_term(a) ((a) >= 0)
102 #define Is_pseudoTerm(a) ((a) == STP_TERM_PSEUDO)
103 #define Is_nonleafTerm(a) ((a) == STP_TERM_NONLEAF)
104 #define Is_anyTerm(a) ((a) >= 0 || (a) == STP_TERM_PSEUDO || (a) == STP_TERM_NONLEAF )
105 #define Edge_anti(a) ((((a) % 2) > 0) ? (a) - 1 : (a) + 1)
106 #define Edge_even(a) ((((a) % 2) == 0) ? (a) : (a) - 1)
108 
109 /* stp file format */
110 #define STP_FILE_MAGIC 0x33d32945
111 #define STP_FILE_VERSION_MAJOR 1
112 #define STP_FILE_VERSION_MINOR 0
114 typedef enum { FF_BEA, FF_STP, FF_PRB, FF_GRD } FILETYPE;
116 
117 /** fixed graph components */
118 typedef struct fixed_graph_components FIXED;
120 
121 /** node ancestors resulting from pseudo-elimination */
122 typedef struct pseudo_ancestors PSEUDOANS;
124 
125 /** depository for several CSR storages */
128 /** bottleneck Steiner distance (implied) profit */
131 
132 /** helper needed for extracting and reinserting subgraph */
135 
136 /** CSR like graph storage */
137 typedef struct csr_storage
138 {
139  int* start; /**< start position for each node */
140  int* head; /**< edge head array */
141  SCIP_Real* cost; /**< edge cost array */
142  int* edge_id; /**< edge ids */
143  int nedges_max; /**< maximum number of edges (real number given by start[nnodes]) */
144  int nnodes; /**< number of nodes */
145 } CSR;
146 
147 
148 /** for dynamic CSR */
149 typedef struct csr_range
150 {
151  int start;
152  int end;
154 
155 
156 /** dynamic CSR */
157 typedef struct dynamic_csr_storage
158 {
159  RANGE* range; /**< CSR range */
160  int* head; /**< edge head array */
161  int* edgeid; /**< gets id from CSR edge */
162  int* id2csredge; /**< gets CRS edge from id */
163  SCIP_Real* cost; /**< edge cost array */
164  SCIP_Real* cost2; /**< second edge cost array, initialized with NULL and never freed! */
165  SCIP_Real* cost3; /**< third edge cost array, initialized with NULL and never freed! */
166  int nedges; /**< number of edges */
167  int nnodes; /**< number of nodes */
169 
170 
171 /** singleton ancestors for given undirected edge */
172 typedef struct singleton_ancestors_edge
173 {
174  IDX* ancestors; /**< ancestors */
175  IDX* revancestors; /**< reverse ancestors */
176  int* pseudoancestors; /**< pseudo ancestors */
177  int npseudoancestors; /**< number of pseudo ancestors */
178  int edge; /**< edge index */
180 
181 
182 /** Steiner graph data structure */
183 typedef struct
184 {
185  /* Nodes */
186  int norgmodelknots; /**< Number of nodes in the original model */
187  int norgmodelterms; /**< Number of terminals in the original model */
188  int ksize; /**< Count of allocated knot slots */
189  int knots; /**< Count of nodes in graph */
190  int orgknots; /**< Count of nodes prior to graph reduction */
191  int terms; /**< Count of terminals */
192  int layers; /**< Count of different networks */
193  int orgsource; /**< root of unreduced graph */
194  int source; /**< The root */
195  int* RESTRICT term; /**< Array [0..nodes-1] of networknumber for */
196  /**< knot [i], -1 if [i] is never a terminal */
197  int* RESTRICT mark; /**< Array [0..nodes-1], normally TRUE or FALSE */
198  /**< to mark nodes for inclusion in the shortest */
199  /**< path / minimum spanning tree routine */
200  int* RESTRICT grad; /**< Array [0..nodes-1] with degree of knot [i] */
201  int* RESTRICT inpbeg; /**< Array [0..nodes-1] with starting slot index */
202  /**< for the ieat array, -1 if not used */
203  int* RESTRICT outbeg; /**< Array [0..nodes-1] with starting slot index */
204  /**< for the oeat array, -1 if not used */
205  int* RESTRICT maxdeg; /**< For HCDSTP: Array [0..nodes-1] containing the maximal degrees
206  of all nodes */
207  int* term2edge; /**< (R)PCSTP and (R)MWCSP: Array [0..nodes-1] of edge to twin terminal or -1 */
209  SCIP_Real* prize; /**< For NWSTP, (R)PCSTP and (R)MWCSP: Array [0..nodes-1] of node costs */
210  SCIP_Real* costbudget; /**< budget cost value for (R)BMWCSP: Array [0..nodes-1] */
211  SCIP_Real budget; /**< budget value for (R)BMWCSP */
213  /* Edges */
214  int norgmodeledges; /**< Count of edges prior to graph transformation */
215  int hoplimit; /**< maximal number of edges allowed for a solution to be feasible
216  (only used for HCDSTPs) */
217  int esize; /**< Count of allocated edge slots */
218  int edges; /**< Count of edges in the graph */
219  int orgedges;
220  SCIP_Real* cost; /**< Array [0..edges-1] of positive edge costs */
221  SCIP_Real* cost_org_pc; /**< Array [0..edges-1] of positive edge costs for non-transformed PC/MW variants */
222  int* RESTRICT tail; /**< Array [0..edges-1] of node-number of tail of edge [i] */
223  int* RESTRICT head; /**< Array [0..edges-1] of node-number of head of edge [i] */
224  int* RESTRICT orgtail; /**< Array [0..edges-1] of node-number of tail of edge [i] prior to reduction */
225  int* RESTRICT orghead; /**< Array [0..edges-1] of node-number of head of edge [i] prior to reduction */
226  int* RESTRICT rootedgeprevs; /**< Array [0..edges-1] for PC and MW problems */
228  /* Nodes/Edges */
229  int* RESTRICT ieat; /**< Array [0..edges-1], incoming edge allocation table */
230  int* RESTRICT oeat; /**< Array [0..edges-1], outgoing edge allocation table */
232  /* History */
233  IDX** ancestors; /**< list of ancestor edges to each edge (to keep track of reductions) */
234  IDX** pcancestors; /**< list of ancestor edges to each node (to keep track of PC/MW reductions ) */
235  PSEUDOANS* pseudoancestors; /**< pseudo ancestors */
236  FIXED* fixedcomponents; /**< fixed components */
237  int* contracttrace; /**< used to trace node contractions */
239  /* Data for min cut computation todo extra struct */
240  int mincut_nnodes;
241  int mincut_nedges;
242  int* RESTRICT mincut_dist; /**< dist[i] : Distance-label of node i */
243  int* RESTRICT mincut_head; /**< head[i] : Head of active queue with label i */
244  int* RESTRICT mincut_head_inact; /**< head[i] : Head of inactive queue with label i */
245  int* RESTRICT mincut_numb; /**< numb[i] : numb[i] nodes with label i */
246  int* RESTRICT mincut_prev;
247  int* RESTRICT mincut_next;
248  int* RESTRICT mincut_temp;
249  int* RESTRICT mincut_e; /**< e[i] : Excess of node i */
250  int* RESTRICT mincut_x; /**< x[k] : Actual flow on arc k */
251  int* RESTRICT mincut_r; /**< r[k] : residual capacity of arc k */
253  /* Data for sp and mst computation */
254  int* RESTRICT path_heap;
255  int* RESTRICT path_state;
257  /* Data for grid problems */
258  int grid_dim;
259  int* grid_ncoords;
260  int** grid_coordinates;
262  /* Global information */
263  int stp_type; /**< Steiner problem variant */
264  SCIP_Bool is_packed; /**< graph already packed? */
265  SCIP_Bool withInexactReductions;
266  SCIP_Bool extended; /**< For (R)PCSTP and (R)MWCSP: signifies whether problem is in extended
267  form (TRUE) or not (FALSE) */
268  /* other adjacency storages */
269  CSR* csr_storage; /**< CSR structure or NULL */
270  DCSR* dcsr_storage; /**< Dynamic CSR structure or NULL */
272 
273 typedef struct presolve_info
274 {
275  SCIP_Real fixed;
276  SCIP_Real upper;
277  SCIP_Real lower;
278  int time;
280 
281 
282 /** ONE segment of a path */
283 typedef struct shortest_path
284 {
285  SCIP_Real dist; /* Distance to the end of the path */
286  signed int edge; /* Incoming edge to go along */
288 
289 /** Steiner nodes to terminal paths */
290 typedef struct nodes_to_terminal_paths TPATHS;
292 /** heap entry */
293 typedef struct dijkstra_heap_entry
294 {
295  SCIP_Real key;
296  int node;
298 
299 /** Dijkstra heap */
300 typedef struct dijkstra_heap
301 {
302  int capacity; /**< maximum size */
303  int size; /**< size */
304  int* position; /**< position of an index in range 0 to capacity */
305  DENTRY* entries; /**< number of components */
307 
308 
309 /** Dijkstra data */
310 typedef struct dijkstra_data
311 {
312  /* temporary arrays: */
313  int* visitlist; /**< stores all visited nodes */
314  DHEAP* dheap; /**< Dijkstra heap, initially cleaned */
315  SCIP_Real* node_distance; /**< distances array for each node, initially set to FARAWAY */
316  STP_Bool* node_visited; /**< stores whether a node has been visited, initially set to FALSE */
317  /* long-term arrays: */
318  SCIP_Real* node_bias; /**< bias of node for PC problem */
319  int nvisits; /**< number of visited nodes, initially set to -1 */
320  int edgelimit; /**< number of edges to consider */
322 
323 
324 /** Voronoi data */
325 typedef struct voronoi_storage
326 {
327  SCIP_Real* nodes_dist; /**< distance to base for each node */
328  int* nodes_predEdge; /**< predecessor edge (incoming) to each node */
329  int* nodes_base; /**< base of each node*/
330  int nnodes; /**< number of nodes */
331  SCIP_Bool usingBufferArrays; /**< are buffer arrays being used? */
333 
334 
335 /** Stores data for computation of special distance/bottleneck distance clique computations */
336 typedef struct special_distance_clique
337 {
338  DIJK* dijkdata; /**< temporary data */
339  SCIP_Real* sds; /**< array for SDs of clique */
340  int* cliquenodes; /**< nodes */
341  const int* cliqueToNodeMap; /**< makes clique nodes to original nodes; NON-OWNED! */
342  int centernode; /**< center node or, if there is none, -1 */
343  int ncliquenodes; /**< number of nodes */
345 
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 
351 
352 
353 #endif /* APPLICATIONS_STP_SRC_GRAPHDEFS_H_ */
struct special_distance_clique SDCLIQUE
FILETYPE
Definition: graphdefs.h:115
int * head
Definition: graphdefs.h:141
struct singleton_ancestors_edge SINGLETONANS
struct dijkstra_data DIJK
struct presolve_info PRESOL
struct voronoi_storage VNOI
SCIP_Real * cost
Definition: graphdefs.h:142
struct dijkstra_heap_entry DENTRY
int * start
Definition: graphdefs.h:140
miscellaneous methods used for solving Steiner problems
Definition: graphdefs.h:294
int nedges_max
Definition: graphdefs.h:144
Definition: graph_load.c:93
unsigned char STP_Bool
Definition: portab.h:34
#define SCIP_Bool
Definition: def.h:84
struct dynamic_csr_storage DCSR
Portable definitions.
struct csr_storage CSR
int * edge_id
Definition: graphdefs.h:143
struct Graph GRAPH
struct dijkstra_heap DHEAP
#define SCIP_Real
Definition: def.h:177
struct shortest_path PATH
struct csr_range RANGE
SCIP callable library.