Scippy

SCIP

Solving Constraint Integer Programs

symmetry.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 symmetry.h
17  * @ingroup PUBLICCOREAPI
18  * @brief methods for handling symmetries
19  * @author Christopher Hojny
20  * @author Marc Pfetsch
21  */
22 
23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
24 
25 #ifndef __SCIP_SYMMETRY_H__
26 #define __SCIP_SYMMETRY_H__
27 
28 #include "scip/def.h"
29 #include "scip/pub_misc.h"
30 #include "scip/type_retcode.h"
31 #include "scip/type_scip.h"
32 #include "scip/type_var.h"
33 #include <symmetry/type_symmetry.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 
40 /**@addtogroup PublicSymmetryMethods
41  *
42  * @{
43  */
44 
45 
46 /** compute non-trivial orbits of symmetry group
47  *
48  * The non-tivial orbits of the group action are stored in the array orbits of length npermvars. This array contains
49  * the indices of variables from the permvars array such that variables that are contained in the same orbit appear
50  * consecutively in the orbits array. The variables of the i-th orbit have indices
51  * orbits[orbitbegins[i]], ... , orbits[orbitbegins[i + 1] - 1].
52  * Note that the description of the orbits ends at orbitbegins[norbits] - 1.
53  */
54 SCIP_EXPORT
56  SCIP* scip, /**< SCIP instance */
57  SCIP_VAR** permvars, /**< variables considered in a permutation array */
58  int npermvars, /**< length of a permutation array */
59  int** perms, /**< matrix containing in each row a permutation of the symmetry group */
60  int nperms, /**< number of permutations encoded in perms */
61  int* orbits, /**< array of non-trivial orbits */
62  int* orbitbegins, /**< array containing begin positions of new orbits in orbits array */
63  int* norbits /**< pointer to number of orbits currently stored in orbits */
64  );
65 
66 
67 /** compute non-trivial orbits of symmetry group using filtered generators
68  *
69  * The non-trivial orbits of the group action are stored in the array orbits of length npermvars. This array contains
70  * the indices of variables from the permvars array such that variables that are contained in the same orbit appear
71  * consecutively in the orbits array. The variables of the i-th orbit have indices
72  * orbits[orbitbegins[i]], ... , orbits[orbitbegins[i + 1] - 1].
73  * Note that the description of the orbits ends at orbitbegins[norbits] - 1.
74  *
75  * Only permutations that are not inactive (as marked by @p inactiveperms) are used. Thus, one can use this array to
76  * filter out permutations.
77  */
78 SCIP_EXPORT
80  SCIP* scip, /**< SCIP instance */
81  int npermvars, /**< length of a permutation array */
82  int** permstrans, /**< transposed matrix containing in each column a
83  * permutation of the symmetry group */
84  int nperms, /**< number of permutations encoded in perms */
85  SCIP_Shortbool* inactiveperms, /**< array to store whether permutations are inactive */
86  int* orbits, /**< array of non-trivial orbits */
87  int* orbitbegins, /**< array containing begin positions of new orbits in orbits array */
88  int* norbits, /**< pointer to number of orbits currently stored in orbits */
89  int* components, /**< array containing the indices of permutations sorted by components */
90  int* componentbegins, /**< array containing in i-th position the first position of
91  * component i in components array */
92  int* vartocomponent, /**< array containing for each permvar the index of the component it is
93  * contained in (-1 if not affected) */
94  unsigned* componentblocked, /**< array to store which symmetry methods have been used on a component
95  * using the same bitset information as for misc/usesymmetry */
96  int ncomponents, /**< number of components of symmetry group */
97  int nmovedpermvars /**< number of variables moved by any permutation in a symmetry component
98  * that is handled by orbital fixing */
99  );
100 
101 /** compute non-trivial orbits of symmetry group
102  *
103  * The non-tivial orbits of the group action are stored in the array orbits of length npermvars. This array contains
104  * the indices of variables from the permvars array such that variables that are contained in the same orbit appear
105  * consecutively in the orbits array. The variables of the i-th orbit have indices
106  * orbits[orbitbegins[i]], ... , orbits[orbitbegins[i + 1] - 1].
107  * Note that the description of the orbits ends at orbitbegins[norbits] - 1.
108  *
109  * This function is adapted from SCIPcomputeOrbitsFilterSym().
110  */
111 SCIP_EXPORT
113  SCIP* scip, /**< SCIP instance */
114  int npermvars, /**< length of a permutation array */
115  int** permstrans, /**< transposed matrix containing in each column a permutation of the symmetry group */
116  int nperms, /**< number of permutations encoded in perms */
117  int* components, /**< array containing the indices of permutations sorted by components */
118  int* componentbegins, /**< array containing in i-th position the first position of component i in components array */
119  int* vartocomponent, /**< array containing for each permvar the index of the component it is
120  * contained in (-1 if not affected) */
121  int ncomponents, /**< number of components of symmetry group */
122  int* orbits, /**< array of non-trivial orbits */
123  int* orbitbegins, /**< array containing begin positions of new orbits in orbits array */
124  int* norbits, /**< pointer to number of orbits currently stored in orbits */
125  int* varorbitmap /**< array for storing the orbits for each variable */
126  );
127 
128 /** Compute orbit of a given variable and store it in @p orbit. The first entry of the orbit will
129  * be the given variable index and the rest is filled with the remaining variables excluding
130  * the ones specified in @p ignoredvars.
131  *
132  * @pre orbit is an initialized array of size propdata->npermvars
133  * @pre at least one of @p perms and @p permstrans should not be NULL
134  */
135 SCIP_EXPORT
137  SCIP* scip, /**< SCIP instance */
138  int npermvars, /**< number of variables in permvars */
139  int** perms, /**< the generators of the permutation group (or NULL) */
140  int** permstrans, /**< the transposed matrix of generators (or NULL) */
141  int* components, /**< the components of the permutation group */
142  int* componentbegins, /**< array containing the starting index of each component */
143  SCIP_Shortbool* ignoredvars, /**< array indicating which variables should be ignored */
144  SCIP_Shortbool* varfound, /**< bitmap to mark which variables have been added (or NULL) */
145  int varidx, /**< index of variable for which the orbit is requested */
146  int component, /**< component that var is in */
147  int * orbit, /**< array in which the orbit should be stored */
148  int* orbitsize /**< buffer to store the size of the orbit */
149  );
150 
151 /** Checks whether a permutation is a composition of 2-cycles and in this case determine the number of overall
152  * 2-cycles and binary 2-cycles. It is a composition of 2-cycles iff @p ntwocyclesperm > 0 upon termination.
153  */
154 SCIP_EXPORT
156  int* perm, /**< permutation */
157  SCIP_VAR** vars, /**< array of variables perm is acting on */
158  int nvars, /**< number of variables */
159  int* ntwocyclesperm, /**< pointer to store number of 2-cycles */
160  int* nbincyclesperm, /**< pointer to store number of binary cycles */
161  SCIP_Bool earlytermination /**< whether we terminate early if not all affected variables are binary */
162  );
163 
164 /** determine number of variables affected by symmetry group */
165 SCIP_EXPORT
167  SCIP* scip, /**< SCIP instance */
168  int** perms, /**< permutations */
169  int nperms, /**< number of permutations in perms */
170  SCIP_VAR** permvars, /**< variables corresponding to permutations */
171  int npermvars, /**< number of permvars in perms */
172  int* nvarsaffected /**< pointer to store number of all affected variables */
173  );
174 
175 /** compute components of symmetry group */
176 SCIP_EXPORT
178  SCIP* scip, /**< SCIP instance */
179  int** perms, /**< permutation generators as
180  * (either nperms x npermvars or npermvars x nperms) matrix */
181  int nperms, /**< number of permutations */
182  SCIP_VAR** permvars, /**< variables on which permutations act */
183  int npermvars, /**< number of variables for permutations */
184  SCIP_Bool transposed, /**< transposed permutation generators as (npermvars x nperms) matrix */
185  int** components, /**< array containing the indices of permutations sorted by components */
186  int** componentbegins, /**< array containing in i-th position the first position of
187  * component i in components array */
188  int** vartocomponent, /**< array containing for each permvar the index of the component it is
189  * contained in (-1 if not affected) */
190  unsigned** componentblocked, /**< array to store which symmetry methods have been used on a component
191  * using the same bitset information as for misc/usesymmetry */
192  int* ncomponents /**< pointer to store number of components of symmetry group */
193  );
194 
195 /** Given a matrix with nrows and \#perms + 1 columns whose first nfilledcols columns contain entries of variables, this routine
196  * checks whether the 2-cycles of perm intersect each row of column coltoextend in exactly one position. In this case,
197  * we add one column to the suborbitope of the first nfilledcols columns.
198  *
199  * @pre Every non-trivial cycle of perm is a 2-cycle.
200  * @pre perm has nrows many 2-cycles
201  */
202 SCIP_EXPORT
204  int** suborbitope, /**< matrix containing suborbitope entries */
205  int nrows, /**< number of rows of suborbitope */
206  int nfilledcols, /**< number of columns of suborbitope which are filled with entries */
207  int coltoextend, /**< index of column that should be extended by perm */
208  int* perm, /**< permutation */
209  SCIP_Bool leftextension, /**< whether we extend the suborbitope to the left */
210  int** nusedelems, /**< pointer to array storing how often an element was used in the orbitope */
211  SCIP_VAR** permvars, /**< permutation vars array */
212  SCIP_Shortbool* rowisbinary, /**< array encoding whether variables in an orbitope row are binary */
213  SCIP_Bool* success, /**< pointer to store whether extension was successful */
214  SCIP_Bool* infeasible /**< pointer to store if the number of intersecting cycles is too small */
215  );
216 
217 /** generate variable matrix for orbitope constraint handler */
218 SCIP_EXPORT
220  SCIP* scip, /**< SCIP instance */
221  SCIP_VAR**** vars, /**< pointer to matrix of orbitope variables */
222  int nrows, /**< number of rows of orbitope */
223  int ncols, /**< number of columns of orbitope */
224  SCIP_VAR** permvars, /**< superset of variables that are contained in orbitope */
225  int npermvars, /**< number of variables in permvars array */
226  int** orbitopevaridx, /**< permuted index table of variables in permvars that are contained in orbitope */
227  int* columnorder, /**< permutation to reorder column of orbitopevaridx */
228  int* nusedelems, /**< array storing how often an element was used in the orbitope */
229  SCIP_Shortbool* rowisbinary, /**< array encoding whether a row contains only binary variables */
230  SCIP_Bool* infeasible, /**< pointer to store whether the potential orbitope is not an orbitope */
231  SCIP_Bool storelexorder, /**< whether the lexicographic order induced by the orbitope shall be stored */
232  int** lexorder, /**< pointer to array storing the lexorder (or NULL) */
233  int* nvarsorder, /**< pointer to store number of variables in lexorder (or NULL) */
234  int* maxnvarsorder /**< pointer to store maximum number of variables in lexorder (or NULL) */
235  );
236 
237 /** checks whether an orbitope is a packing or partitioning orbitope */
239  SCIP* scip, /**< SCIP data structure */
240  SCIP_VAR*** vars, /**< variable matrix of orbitope constraint */
241  int nrows, /**< pointer to number of rows of variable matrix */
242  int ncols, /**< number of columns of variable matrix */
243  SCIP_Bool** pprows, /**< pointer to store which rows are are contained in
244  * packing/partitioning constraints or NULL if not needed */
245  int* npprows, /**< pointer to store how many rows are contained
246  * in packing/partitioning constraints or NULL if not needed */
247  SCIP_ORBITOPETYPE* type /**< pointer to store type of orbitope constraint after strengthening */
248  );
249 
250 /** @} */
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif
SCIP_RETCODE SCIPcomputeComponentsSym(SCIP *scip, int **perms, int nperms, SCIP_VAR **permvars, int npermvars, SCIP_Bool transposed, int **components, int **componentbegins, int **vartocomponent, unsigned **componentblocked, int *ncomponents)
Definition: symmetry.c:757
enum SCIP_OrbitopeType SCIP_ORBITOPETYPE
SCIP_RETCODE SCIPcomputeOrbitsSym(SCIP *scip, SCIP_VAR **permvars, int npermvars, int **perms, int nperms, int *orbits, int *orbitbegins, int *norbits)
Definition: symmetry.c:40
SCIP_RETCODE SCIPcomputeOrbitsFilterSym(SCIP *scip, int npermvars, int **permstrans, int nperms, SCIP_Shortbool *inactiveperms, int *orbits, int *orbitbegins, int *norbits, int *components, int *componentbegins, int *vartocomponent, unsigned *componentblocked, int ncomponents, int nmovedpermvars)
Definition: symmetry.c:154
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
type definitions for return codes for SCIP methods
type definitions for SCIP&#39;s main datastructure
SCIP_RETCODE SCIPisPackingPartitioningOrbitope(SCIP *scip, SCIP_VAR ***vars, int nrows, int ncols, SCIP_Bool **pprows, int *npprows, SCIP_ORBITOPETYPE *type)
Definition: symmetry.c:1152
#define SCIP_Shortbool
Definition: def.h:92
type definitions for problem variables
public data structures and miscellaneous methods
SCIP_RETCODE SCIPdetermineNVarsAffectedSym(SCIP *scip, int **perms, int nperms, SCIP_VAR **permvars, int npermvars, int *nvarsaffected)
Definition: symmetry.c:575
#define SCIP_Bool
Definition: def.h:84
SCIP_RETCODE SCIPisInvolutionPerm(int *perm, SCIP_VAR **vars, int nvars, int *ntwocyclesperm, int *nbincyclesperm, SCIP_Bool earlytermination)
Definition: symmetry.c:524
SCIP_RETCODE SCIPgenerateOrbitopeVarsMatrix(SCIP *scip, SCIP_VAR ****vars, int nrows, int ncols, SCIP_VAR **permvars, int npermvars, int **orbitopevaridx, int *columnorder, int *nusedelems, SCIP_Shortbool *rowisbinary, SCIP_Bool *infeasible, SCIP_Bool storelexorder, int **lexorder, int *nvarsorder, int *maxnvarsorder)
Definition: symmetry.c:961
SCIP_RETCODE SCIPextendSubOrbitope(int **suborbitope, int nrows, int nfilledcols, int coltoextend, int *perm, SCIP_Bool leftextension, int **nusedelems, SCIP_VAR **permvars, SCIP_Shortbool *rowisbinary, SCIP_Bool *success, SCIP_Bool *infeasible)
Definition: symmetry.c:627
type definitions for symmetry computations
SCIP_RETCODE SCIPcomputeOrbitVar(SCIP *scip, int npermvars, int **perms, int **permstrans, int *components, int *componentbegins, SCIP_Shortbool *ignoredvars, SCIP_Shortbool *varfound, int varidx, int component, int *orbit, int *orbitsize)
Definition: symmetry.c:302
SCIP_RETCODE SCIPcomputeOrbitsComponentsSym(SCIP *scip, int npermvars, int **permstrans, int nperms, int *components, int *componentbegins, int *vartocomponent, int ncomponents, int *orbits, int *orbitbegins, int *norbits, int *varorbitmap)
Definition: symmetry.c:402
common defines and data types used in all packages of SCIP