Scippy

SCIP

Solving Constraint Integer Programs

symmetry_graph.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-2025 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file symmetry_graph.h
26 * @ingroup PUBLICCOREAPI
27 * @brief methods for dealing with symmetry detection graphs
28 * @author Christopher Hojny
29 */
30
31/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32
33#ifndef __SCIP_SYMMETRY_GRAPH_H__
34#define __SCIP_SYMMETRY_GRAPH_H__
35
36#include "scip/def.h"
37#include "scip/type_retcode.h"
38#include "scip/type_scip.h"
39#include "scip/type_var.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46
47/**@addtogroup SymGraph
48 *
49 * @{
50 */
51
52/** creates and initializes a symmetry detection graph with memory for the given number of nodes and edges
53 *
54 * @note at some point, the graph needs to be freed!
55 */
56SCIP_EXPORT
58 SCIP* scip, /**< SCIP data structure */
59 SYM_SYMTYPE symtype, /**< type of symmetries encoded in graph */
60 SYM_GRAPH** graph, /**< pointer to hold symmetry detection graph */
61 SCIP_VAR** symvars, /**< variables used in symmetry detection */
62 int nsymvars, /**< number of variables used in symmetry detection */
63 int nopnodes, /**< number of operator nodes */
64 int nvalnodes, /**< number of value nodes */
65 int nconsnodes, /**< number of constraint nodes */
66 int nedges /**< number of edges */
67 );
68
69/** frees a symmetry detection graph */
70SCIP_EXPORT
72 SCIP* scip, /**< SCIP data structure */
73 SYM_GRAPH** graph /**< pointer to symmetry detection graph */
74 );
75
76/** clears data of symmetry detection graph */
77SCIP_EXPORT
79 SCIP* scip, /**< SCIP data structure */
80 SYM_GRAPH* graph, /**< symmetry detection graph */
81 SCIP_VAR** symvars, /**< variables used in symmetry detection */
82 int nsymvars, /**< number of variables used in symmetry detection */
83 SYM_SYMTYPE symtype /**< type of symmetries encoded in graph */
84 );
85
86/** copies an existing graph and changes variable nodes according to a permutation */
87SCIP_EXPORT
89 SCIP* scip, /**< SCIP data structure */
90 SYM_GRAPH** graph, /**< pointer to hold copy of symmetry detection graph */
91 SYM_GRAPH* origgraph, /**< graph to be copied */
92 int* perm, /**< permutation of variables */
93 SYM_SPEC fixedtype /**< variable types that must be fixed by symmetries */
94 );
95
96/** copies a symmetry detection graph into another symmetry detection graph */
97SCIP_EXPORT
99 SCIP* scip, /**< SCIP pointer */
100 SYM_GRAPH* sourcegraph, /**< graph to be copied */
101 SYM_GRAPH* targetgraph, /**< graph into which copy shall be included */
102 SCIP_CONS* sourcecons, /**< constraint associated with sourcegraph */
103 int* rootidx /**< pointer to hold index of root node of sourcegraph in targetgraph
104 * (or -1 if root cannot be detected) */
105 );
106
107/** adds a symmetry detection graph for a linear constraint to existing graph
108 *
109 * For permutation symmetries, a constraint node is added that is connected to all
110 * variable nodes in the constraint. Edges are colored according to the variable coefficients.
111 * For signed permutation symmetries, also edges connecting the constraint node and
112 * the negated variable nodes are added, these edges are colored by the negative coefficients.
113 */
114SCIP_EXPORT
116 SCIP* scip, /**< SCIP data structure */
117 SYM_GRAPH* graph, /**< symmetry detection graph */
118 SCIP_VAR** vars, /**< variable array of linear constraint */
119 SCIP_Real* vals, /**< coefficients of linear constraint */
120 int nvars, /**< number of variables in linear constraint */
121 SCIP_CONS* cons, /**< constraint for which we encode symmetries */
122 SCIP_Real lhs, /**< left-hand side of constraint */
123 SCIP_Real rhs, /**< right-hand side of constraint */
124 SCIP_Bool* success /**< pointer to store whether graph could be built */
125 );
126
127/** adds nodes and edges corresponding to the aggregation of a variable to a symmetry detection graph
128 *
129 * For permutation symmetries, the root node is connected with all variable nodes in the aggregation.
130 * Edges are colored according to the variable coefficients.
131 * For signed permutation symmetries, also edges connecting the root node and the negated variable
132 * nodes are added, these edges are colored by the negative coefficients.
133 */
134SCIP_EXPORT
136 SCIP* scip, /**< SCIP data structure */
137 SYM_GRAPH* graph, /**< symmetry detection graph */
138 int rootidx, /**< index of root node of the aggregation */
139 SCIP_VAR** vars, /**< array of variables in aggregation */
140 SCIP_Real* vals, /**< coefficients of variables */
141 int nvars, /**< number of variables in aggregation */
142 SCIP_Real constant /**< constant of aggregation */
143 );
144
145/*
146 * methods for adding and accessing nodes
147 */
148
149/** adds an operator node to a symmetry detection graph and returns its node index */
150SCIP_EXPORT
152 SCIP* scip, /**< SCIP data structure */
153 SYM_GRAPH* graph, /**< symmetry detection graph */
154 int op, /**< int associated with operator of node */
155 int* nodeidx /**< pointer to hold index of created node */
156 );
157
158/** adds a value node to a symmetry detection graph and returns its node index */
159SCIP_EXPORT
161 SCIP* scip, /**< SCIP data structure */
162 SYM_GRAPH* graph, /**< symmetry detection graph */
163 SCIP_Real val, /**< value of node */
164 int* nodeidx /**< pointer to hold index of created node */
165 );
166
167/** adds a constraint node to a symmetry detection graph and returns its node index */
168SCIP_EXPORT
170 SCIP* scip, /**< SCIP data structure */
171 SYM_GRAPH* graph, /**< symmetry detection graph */
172 SCIP_CONS* cons, /**< constraint of node */
173 SCIP_Real lhs, /**< left-hand side of node */
174 SCIP_Real rhs, /**< right-hand side of node */
175 int* nodeidx /**< pointer to hold index of created node */
176 );
177
178/** returns the (hypothetical) node index of a variable */
179SCIP_EXPORT
181 SCIP* scip, /**< SCIP data structure */
182 SYM_GRAPH* graph, /**< symmetry detection graph */
183 SCIP_VAR* var /**< variable */
184 );
185
186/** returns the (hypothetical) node index of a negated variable */
187SCIP_EXPORT
189 SCIP* scip, /**< SCIP data structure */
190 SYM_GRAPH* graph, /**< symmetry detection graph */
191 SCIP_VAR* var /**< variable */
192 );
193
194/** updates the lhs of a constraint node */
195SCIP_EXPORT
197 SYM_GRAPH* graph, /**< symmetry detection graph */
198 int nodeidx, /**< index of constraint node in graph */
199 SCIP_Real newlhs /**< new left-hand side of node */
200 );
201
202/** updates the rhs of a constraint node */
203SCIP_EXPORT
205 SYM_GRAPH* graph, /**< symmetry detection graph */
206 int nodeidx, /**< index of constraint node in graph */
207 SCIP_Real newrhs /**< new reft-hand side of node */
208 );
209
210/** registers a variable node (corresponding to active variable) to be fixed by symmetry */
211SCIP_EXPORT
213 SYM_GRAPH* graph, /**< symmetry detection graph */
214 SCIP_VAR* var /**< active variable that needs to be fixed */
215 );
216
217/*
218 * methods for adding edges
219 */
220
221/** adds an edge to a symmetry detection graph */
222SCIP_EXPORT
224 SCIP* scip, /**< SCIP data structure */
225 SYM_GRAPH* graph, /**< symmetry detection graph */
226 int first, /**< first node index of edge */
227 int second, /**< second node index of edge */
228 SCIP_Bool hasval, /**< whether the edge has a value */
229 SCIP_Real val /**< value of the edge (is it has a value) */
230 );
231
232/*
233 * methods to compute colors
234 */
235
236/** computes colors of nodes and edges */
237SCIP_EXPORT
239 SCIP* scip, /**< SCIP data structure */
240 SYM_GRAPH* graph, /**< symmetry detection graph */
241 SYM_SPEC fixedtype /**< variable types that must be fixed by symmetries */
242 );
243
244/*
245 * general methods
246 */
247
248/** returns the type of symmetries encoded in graph */
249SCIP_EXPORT
251 SYM_GRAPH* graph /**< symmetry detection graph */
252 );
253
254/** returns the variables in a symmetry detection graph */
255SCIP_EXPORT
257 SYM_GRAPH* graph /**< symmetry detection graph */
258 );
259
260/** returns the number of variables in a symmetry detection graph */
261SCIP_EXPORT
263 SYM_GRAPH* graph /**< symmetry detection graph */
264 );
265
266/** returns the number of constraint nodes in a symmetry detection graph */
267SCIP_EXPORT
269 SYM_GRAPH* graph /**< symmetry detection graph */
270 );
271
272/** returns the number of non-variable nodes in a graph */
273SCIP_EXPORT
275 SYM_GRAPH* graph /**< symmetry detection graph */
276 );
277
278/** returns the number of edges in a graph */
279SCIP_EXPORT
281 SYM_GRAPH* graph /**< symmetry detection graph */
282 );
283
284/** return the first node index of an edge */
285SCIP_EXPORT
287 SYM_GRAPH* graph, /**< symmetry detection graph */
288 int edgeidx /**< index of edge */
289 );
290
291/** return the second node index of an edge */
292SCIP_EXPORT
294 SYM_GRAPH* graph, /**< symmetry detection graph */
295 int edgeidx /**< index of edge */
296 );
297
298/** returns the color of a variable node */
299SCIP_EXPORT
301 SYM_GRAPH* graph, /**< symmetry detection graph */
302 int nodeidx /**< index of variable node */
303 );
304
305/** returns the type of a node */
306SCIP_EXPORT
308 SYM_GRAPH* graph, /**< symmetry detection graph */
309 int nodeidx /**< index of node */
310 );
311
312/** returns the color of a non-variable node */
313SCIP_EXPORT
315 SYM_GRAPH* graph, /**< symmetry detection graph */
316 int nodeidx /**< index of node */
317 );
318
319/** returns whether an edge is colored */
320SCIP_EXPORT
322 SYM_GRAPH* graph, /**< symmetry detection graph */
323 int edgeidx /**< index of edge */
324 );
325
326/** returns color of an edge */
327SCIP_EXPORT
329 SYM_GRAPH* graph, /**< symmetry detection graph */
330 int edgeidx /**< index of edge */
331 );
332
333/** returns the number of unique variable colors in the graph */
334SCIP_EXPORT
336 SYM_GRAPH* graph /**< symmetry detection graph */
337 );
338
339/** returns whether the graph has a unique edge type */
340SCIP_EXPORT
342 SYM_GRAPH* graph /**< symmetry detection graph */
343 );
344
345/** creates consnodeperm array for symmetry detection graph
346 *
347 * @note @p colors of symmetry detection graph must have been computed
348 */
349SCIP_EXPORT
351 SCIP* scip, /**< SCIP data structure */
352 SYM_GRAPH* graph /**< symmetry detection graph */
353 );
354
355/** returns consnodeperm array for symmetry detection graph
356 *
357 * @note @p colors of symmetry detection graph must have been computed
358 */
359SCIP_EXPORT
361 SCIP* scip, /**< SCIP data structure */
362 SYM_GRAPH* graph /**< symmetry detection graph */
363 );
364
365/** frees consnodeperm array for symmetry detection graph */
366SCIP_EXPORT
368 SCIP* scip, /**< SCIP data structure */
369 SYM_GRAPH* graph /**< symmetry detection graph */
370 );
371
372/** Transforms given variables, scalars, and constant to the corresponding active variables, scalars, and constant.
373 *
374 * For permutation symmetries, active variables as encoded in SCIP are used. For signed permutation symmetries,
375 * active variables are shifted such that their domain is centered at 0 (if both their upper and lower bounds
376 * are finite).
377 *
378 * @note @p constant needs to be initialized!
379 */
380SCIP_EXPORT
382 SCIP* scip, /**< SCIP data structure */
383 SYM_SYMTYPE symtype, /**< type of symmetries for which variables are required */
384 SCIP_VAR*** vars, /**< pointer to vars array to get active variables for */
385 SCIP_Real** scalars, /**< pointer to scalars a_1, ..., a_n in linear sum a_1*x_1 + ... + a_n*x_n + c */
386 int* nvars, /**< pointer to number of variables and values in vars and vals array */
387 SCIP_Real* constant, /**< pointer to constant c in linear sum a_1*x_1 + ... + a_n*x_n + c */
388 SCIP_Bool transformed /**< transformed constraint? */
389 );
390
391/** frees symmetry information of an expression */
392SCIP_EXPORT
394 SCIP* scip, /**< SCIP data structure */
395 SYM_EXPRDATA** symdata /**< symmetry information of an expression */
396 );
397
398/** returns number of coefficients from exprdata */
399SCIP_EXPORT
401 SYM_EXPRDATA* symdata /**< symmetry information of an expression */
402 );
403
404/** returns number of coefficients form exprdata */
405SCIP_EXPORT
407 SYM_EXPRDATA* symdata /**< symmetry information of an expression */
408 );
409
410/** gets coefficient of expression from parent expression */
411SCIP_EXPORT
413 SCIP* scip, /**< SCIP data structure */
414 SCIP_EXPR* expr, /**< expression for which coefficient needs to be found */
415 SCIP_EXPR* parentexpr, /**< parent of expr */
416 SCIP_Real* coef, /**< buffer to store coefficient */
417 SCIP_Bool* success /**< whether a coefficient is found */
418 );
419
420
421/** @} */
422
423#ifdef __cplusplus
424}
425#endif
426
427#endif
common defines and data types used in all packages of SCIP
#define SCIP_Bool
Definition: def.h:91
#define SCIP_Real
Definition: def.h:156
SYM_NODETYPE SCIPgetSymgraphNodeType(SYM_GRAPH *graph, int nodeidx)
SCIP_RETCODE SCIPaddSymgraphEdge(SCIP *scip, SYM_GRAPH *graph, int first, int second, SCIP_Bool hasval, SCIP_Real val)
SCIP_RETCODE SCIPfreeSymgraph(SCIP *scip, SYM_GRAPH **graph)
int SCIPgetSymgraphEdgeFirst(SYM_GRAPH *graph, int edgeidx)
SCIP_RETCODE SCIPaddSymgraphOpnode(SCIP *scip, SYM_GRAPH *graph, int op, int *nodeidx)
int * SCIPgetSymgraphConsnodeperm(SCIP *scip, SYM_GRAPH *graph)
SCIP_RETCODE SCIPgetSymActiveVariables(SCIP *scip, SYM_SYMTYPE symtype, SCIP_VAR ***vars, SCIP_Real **scalars, int *nvars, SCIP_Real *constant, SCIP_Bool transformed)
SCIP_Bool SCIPhasGraphUniqueEdgetype(SYM_GRAPH *graph)
int SCIPgetSymgraphVarnodeColor(SYM_GRAPH *graph, int nodeidx)
SCIP_RETCODE SCIPaddSymgraphValnode(SCIP *scip, SYM_GRAPH *graph, SCIP_Real val, int *nodeidx)
SCIP_RETCODE SCIPcreateSymgraph(SCIP *scip, SYM_SYMTYPE symtype, SYM_GRAPH **graph, SCIP_VAR **symvars, int nsymvars, int nopnodes, int nvalnodes, int nconsnodes, int nedges)
int SCIPgetSymgraphNEdges(SYM_GRAPH *graph)
int SCIPgetSymgraphVarnodeidx(SCIP *scip, SYM_GRAPH *graph, SCIP_VAR *var)
SCIP_RETCODE SCIPcomputeSymgraphColors(SCIP *scip, SYM_GRAPH *graph, SYM_SPEC fixedtype)
SYM_SYMTYPE SCIPgetSymgraphSymtype(SYM_GRAPH *graph)
SCIP_RETCODE SCIPcopySymgraphAsSubgraph(SCIP *scip, SYM_GRAPH *sourcegraph, SYM_GRAPH *targetgraph, SCIP_CONS *sourcecons, int *rootidx)
SCIP_RETCODE SCIPaddSymgraphConsnode(SCIP *scip, SYM_GRAPH *graph, SCIP_CONS *cons, SCIP_Real lhs, SCIP_Real rhs, int *nodeidx)
SCIP_RETCODE SCIPcreateSymgraphConsnodeperm(SCIP *scip, SYM_GRAPH *graph)
int SCIPgetSymgraphEdgeSecond(SYM_GRAPH *graph, int edgeidx)
int SCIPgetSymgraphNConsnodes(SYM_GRAPH *graph)
SCIP_RETCODE SCIPaddSymgraphVarAggregation(SCIP *scip, SYM_GRAPH *graph, int rootidx, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Real constant)
int SCIPgetSymExprdataNConstants(SYM_EXPRDATA *symdata)
SCIP_RETCODE SCIPupdateSymgraphRhs(SYM_GRAPH *graph, int nodeidx, SCIP_Real newrhs)
SCIP_RETCODE SCIPfreeSymgraphConsnodeperm(SCIP *scip, SYM_GRAPH *graph)
SCIP_RETCODE SCIPupdateSymgraphLhs(SYM_GRAPH *graph, int nodeidx, SCIP_Real newlhs)
int SCIPgetSymgraphNVars(SYM_GRAPH *graph)
int SCIPgetSymgraphNegatedVarnodeidx(SCIP *scip, SYM_GRAPH *graph, SCIP_VAR *var)
SCIP_Bool SCIPisSymgraphEdgeColored(SYM_GRAPH *graph, int edgeidx)
SCIP_RETCODE SCIPfreeSymDataExpr(SCIP *scip, SYM_EXPRDATA **symdata)
SCIP_VAR ** SCIPgetSymgraphVars(SYM_GRAPH *graph)
int SCIPgetSymgraphNodeColor(SYM_GRAPH *graph, int nodeidx)
int SCIPgetSymgraphEdgeColor(SYM_GRAPH *graph, int edgeidx)
SCIP_RETCODE SCIPextendPermsymDetectionGraphLinear(SCIP *scip, SYM_GRAPH *graph, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_CONS *cons, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool *success)
int SCIPgetSymgraphNNodes(SYM_GRAPH *graph)
SCIP_Real * SCIPgetSymExprdataConstants(SYM_EXPRDATA *symdata)
SCIP_RETCODE SCIPclearSymgraph(SCIP *scip, SYM_GRAPH *graph, SCIP_VAR **symvars, int nsymvars, SYM_SYMTYPE symtype)
SCIP_RETCODE SCIPcopySymgraph(SCIP *scip, SYM_GRAPH **graph, SYM_GRAPH *origgraph, int *perm, SYM_SPEC fixedtype)
SCIP_RETCODE SCIPfixSymgraphVarnode(SYM_GRAPH *graph, SCIP_VAR *var)
int SCIPgetSymgraphNVarcolors(SYM_GRAPH *graph)
SCIP_RETCODE SCIPgetCoefSymData(SCIP *scip, SCIP_EXPR *expr, SCIP_EXPR *parentexpr, SCIP_Real *coef, SCIP_Bool *success)
static const SCIP_Real scalars[]
Definition: lp.c:5959
type definitions for return codes for SCIP methods
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
type definitions for SCIP's main datastructure
type definitions for symmetry computations
enum SYM_Symtype SYM_SYMTYPE
Definition: type_symmetry.h:64
enum SYM_Nodetype SYM_NODETYPE
Definition: type_symmetry.h:74
uint32_t SYM_SPEC
Definition: type_symmetry.h:47
type definitions for problem variables