Scippy

SCIP

Solving Constraint Integer Programs

dpborderinterns.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 dpborderinterns.h
17  * @brief Dynamic programming internals for Steiner tree (sub-) problems with small number of terminals
18  * @author Daniel Rehfeldt
19  *
20  * Internal methods and data structures for DP.
21  *
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #ifndef APPLICATIONS_STP_SRC_DPBORDERINTERNS_H_
27 #define APPLICATIONS_STP_SRC_DPBORDERINTERNS_H_
28 
29 
30 #include "scip/scip.h"
31 #include "graph.h"
32 #include "stpvector.h"
33 #include "dpborder_hashmap.h"
34 
35 #define BPBORDER_MAXNPARTITIONS 50000000
36 #define BPBORDER_MAXBORDERSIZE 16
37 #define DPB_Ptype char
38 #define DPBORDER_GROWTH_FACTOR 4
39 
40 
41 /** nodes sequence structure */
43 {
44  int* nodessquence; /**< ordering of the nodes */
45  uint64_t maxnpartitions; /**< maximum number of partitions */
46  int maxbordersize; /**< maximum size of any border */
47  int nnodes; /**< number of nodes of underlying graph */
48 } DPBSEQUENCE;
49 
50 
51 /** nodes sequence structure */
53 {
54  STP_Vectype(int) bordernodesMapToOrg;/**< maps border nodes to original nodes */
55  int globalstartidx; /**< start position of level in global data */
56  int nbordernodes; /**< size of border */
57  int extnode; /**< extension nodes */
58  SCIP_Bool exnodeIsTerm; /**< is the extension node a terminal? */
59 } DPBLEVEL;
60 
61 
62 /** single partition */
64 {
65  DPB_Ptype* partchars; /**< partition characters */
66  int partsize; /**< size of partition */
67  DPB_Ptype delimiter; /**< delimiter */
68 } DPBPART;
69 
70 
71 
72 /** DP border structure */
74 {
75  DPBHASHMAP hashmap; /**< hash map */
76  DPBSEQUENCE* dpbsequence; /**< ordering of nodes */
77  STP_Vectype(DPBLEVEL*) borderlevels; /**< data for each border */
78  SCIP_Bool* nodes_isBorder; /**< marks whether node is in current border */
79  int* nodes_outdeg; /**< degree w.r.t. not yet visited nodes */
80  int* bordercharmap; /**< maps last border chars to current border chars */
81  SCIP_Real* borderchardists; /**< distance for last border nodes (chars) to extension nodes */
82  STP_Vectype(int) bordernodes; /**< current border nodes */
83  STP_Vectype(int) prevbordernodes; /**< nodes that are in previous but not current border */
84  DPB_Ptype* global_partitions; /**< partitions */
85  STP_Vectype(int) global_partstarts; /**< CSR like starts of partitions in array "global_partitions" */
86  STP_Vectype(SCIP_Real) global_partcosts; /**< costs of each partition */
87  STP_Vectype(int) global_predparts; /**< predecessor partitions; of size global_npartitions */
88  STP_Vectype(SCIP_Bool) global_partsUseExt; /**< partition uses extension node? */
89  SCIP_Real global_obj; /**< objective */
90  int global_npartitions; /**< number of global partitions */
91  int global_partcap; /**< capacity of array global_partitions */
92  int global_optposition; /**< index of best solution partition */
93  int ntermsvisited; /**< number of already visited nodes */
94  int nterms; /**< number of terminals */
95  int nnodes; /**< number of nodes of underlying graph */
96  DPB_Ptype extborderchar; /**< -1 if extnode is not contained! */
97 };
98 
99 /*
100  * Inline methods
101  */
102 
103 
104 /** gets border delimiter for given iteration */
105 static inline
107  const DPBORDER* dpborder, /**< border */
108  int iteration /**< iteration number */
109 )
110 {
111  assert(iteration >= 0);
112  assert(dpborder->borderlevels[iteration]->nbordernodes > 0);
113  assert(dpborder->borderlevels[iteration]->nbordernodes <= BPBORDER_MAXBORDERSIZE);
114 
115  return dpborder->borderlevels[iteration]->nbordernodes;
116 }
117 
118 
119 /** gets border delimiter */
120 static inline
122  const DPBORDER* dpborder /**< border */
123 )
124 {
125  const int pos = StpVecGetSize(dpborder->borderlevels) - 1;
126 
127  assert(pos >= 0);
128  assert(dpborder->borderlevels[pos]->nbordernodes >= 0);
129  assert(dpborder->borderlevels[pos]->nbordernodes <= BPBORDER_MAXBORDERSIZE);
130 
131  return dpborder->borderlevels[pos]->nbordernodes;
132 }
133 
134 
135 /** gets top level */
136 static inline
138  const DPBORDER* dpborder /**< border */
139 )
140 {
141  const int pos = StpVecGetSize(dpborder->borderlevels) - 1;
142  assert(pos >= 0);
143  assert(dpborder->borderlevels[pos]);
144 
145  return dpborder->borderlevels[pos];
146 }
147 
148 
149 /** gets previous level */
150 static inline
152  const DPBORDER* dpborder /**< border */
153 )
154 {
155  const int pos = StpVecGetSize(dpborder->borderlevels) - 1;
156  assert(pos >= 1);
157  assert(dpborder->borderlevels[pos - 1]);
158 
159  return dpborder->borderlevels[pos - 1];
160 }
161 
162 
163 /*
164  * Internal interface methods
165  */
166 
167 extern SCIP_Real dpborder_partGetConnectionCost(const DPBORDER*, const DPBPART*, const int*, int);
168 extern int dpborder_partglobalGetCard(int, int, const DPBORDER*);
169 extern int dpborder_partGetIdxNew(SCIP*, const DPBPART*, const int*, int, DPBORDER*);
171 extern STP_Vectype(int) dpborder_partGetCandstarts(SCIP*, const DPBPART*, const DPBORDER*);
172 extern SCIP_Bool dpborder_partIsValid(const DPBPART*);
173 extern void dpborder_partPrint(const DPBPART*);
174 extern void dpborder_markSolNodes(const DPBORDER*, STP_Bool* RESTRICT);
176 extern void dpborder_dpbsequenceFree(SCIP*, DPBSEQUENCE**);
177 extern void dpborder_dpbsequenceCopy(const DPBSEQUENCE*, DPBSEQUENCE*);
179 extern void dpborder_dpblevelFree(SCIP*, DPBLEVEL**);
183 
184 #endif /* APPLICATIONS_STP_SRC_DPBORDERINTERNS_H_ */
#define StpVecGetSize(vec)
Definition: stpvector.h:139
SCIP_Real dpborder_partGetConnectionCost(const DPBORDER *, const DPBPART *, const int *, int)
SCIP_RETCODE dpborder_coreUpdateOrdering(SCIP *, const GRAPH *, DPBORDER *)
static DPBLEVEL * dpborder_getPredLevel(const DPBORDER *dpborder)
SCIP_RETCODE dpborder_dpblevelInit(SCIP *, DPBLEVEL **)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
includes various files containing graph methods used for Steiner tree problems
static DPBLEVEL * dpborder_getTopLevel(const DPBORDER *dpborder)
static int dpborder_getTopDelimiter(const DPBORDER *dpborder)
struct dynamic_programming_border_nodes_sequence DPBSEQUENCE
header only, simple implementation of an STL like vector
int dpborder_partGetIdxNewExclusive(SCIP *, const DPBPART *, DPBORDER *)
struct dynamic_programming_border_partition DPBPART
void dpborder_partPrint(const DPBPART *)
void dpborder_dpbsequenceFree(SCIP *, DPBSEQUENCE **)
SCIP_RETCODE dpborder_coreComputeOrderingSimple(SCIP *, const GRAPH *, DPBORDER *)
SCIP_RETCODE dpborder_dpbsequenceInit(SCIP *, const GRAPH *, DPBSEQUENCE **)
Definition: dpborder_base.c:97
const DPBPART const DPBORDER *SCIP_Bool dpborder_partIsValid(const DPBPART *)
int dpborder_partGetIdxNew(SCIP *, const DPBPART *, const int *, int, DPBORDER *)
unsigned char STP_Bool
Definition: portab.h:34
STP_Vectype(int) dpborder_partGetCandstarts(SCIP *
#define SCIP_Bool
Definition: def.h:84
void dpborder_markSolNodes(const DPBORDER *, STP_Bool *RESTRICT)
SCIP_RETCODE dpborder_coreSolve(SCIP *, const GRAPH *, DPBORDER *, SCIP_Bool *)
#define BPBORDER_MAXBORDERSIZE
static int dpborder_getDelimiter(const DPBORDER *dpborder, int iteration)
Special hashmap for DP-border Steiner tree algorithm.
#define DPB_Ptype
void dpborder_dpblevelFree(SCIP *, DPBLEVEL **)
#define SCIP_Real
Definition: def.h:177
void dpborder_dpbsequenceCopy(const DPBSEQUENCE *, DPBSEQUENCE *)
int dpborder_partglobalGetCard(int, int, const DPBORDER *)
SCIP callable library.
struct dynamic_programming_border_level DPBLEVEL