Scippy

    SCIP

    Solving Constraint Integer Programs

    cons_orbitope.c
    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 cons_orbitope.c
    26 * @ingroup DEFPLUGINS_CONS
    27 * @brief interface for constraint handlers of type partitioning, packing, and full to ensure backwards compatibility
    28 * @author Christopher Hojny
    29 *
    30 * This interface ensures backwards compatibility to be able to add packing, partitioning, and full
    31 * orbitopes via the same function call.
    32 */
    33
    34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    35
    37#include "scip/cons_orbitope.h"
    40#include "scip/symmetry.h"
    42
    43/*
    44 * Local methods
    45 */
    46
    47/** strengthen full orbitopes to packing/partitioning orbitopes if possible */
    48static
    50 SCIP* scip, /**< SCIP data structure */
    51 SCIP_VAR*** vars, /**< variable matrix of orbitope constraint */
    52 int* nrows, /**< pointer to number of rows of variable matrix */
    53 int ncols, /**< number of columns of variable matrix */
    54 SCIP_ORBITOPETYPE* type /**< pointer to store type of orbitope constraint after strengthening */
    55 )
    56{
    57 SCIP_Bool* pprows = NULL;
    58 int npprows;
    59 int nrowsorig;
    60
    61 assert( scip != NULL );
    62 assert( vars != NULL );
    63 assert( vars != NULL );
    64 assert( *nrows > 0 );
    65 assert( ncols > 0 );
    66 assert( type != NULL );
    67
    68 nrowsorig = *nrows;
    69 SCIP_CALL( SCIPisPackingPartitioningOrbitope(scip, vars, *nrows, ncols, &pprows, &npprows, type) );
    70
    71 /* If only some rows are contained in set packing/partitioning constraints, it may still be worth it
    72 * to exploit the packing/partitioning structure on these rows, because packing/partitioning orbitopes
    73 * are more restrictive than full orbitopes. If at least three rows have this property, we discard
    74 * all rows not contained in set packing/partitioning constraints and add the smaller packing sub-orbitope.
    75 */
    76 if ( npprows >= 3 )
    77 {
    78 int r = *nrows - 1;
    79 int i;
    80
    81 assert( pprows != NULL );
    82
    83 while ( r >= 0 )
    84 {
    85 if ( ! pprows[r] )
    86 {
    87 for (i = r; i < *nrows - 1; ++i)
    88 {
    89 SCIP_VAR** varrow;
    90 varrow = vars[i];
    91 vars[i] = vars[i+1];
    92 vars[i+1] = varrow;
    93 }
    94 --(*nrows);
    95 }
    96 --r;
    97 }
    99 }
    100
    101 /* pprows might not have been initialized if there are no setppc conss */
    102 if ( pprows != NULL )
    103 {
    104 SCIPfreeBlockMemoryArray(scip, &pprows, nrowsorig);
    105 }
    106
    107 return SCIP_OKAY;
    108}
    109
    110
    111/*
    112 * constraint specific interface methods
    113 */
    114
    115/** includes the orbitope constraint handlers used by this interface */
    117 SCIP* scip /**< SCIP data structure */
    118 )
    119{
    122
    123 return SCIP_OKAY;
    124}
    125
    126
    127/** creates and captures an orbitope constraint
    128 *
    129 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
    130 */
    132 SCIP* scip, /**< SCIP data structure */
    133 SCIP_CONS** cons, /**< pointer to hold the created constraint */
    134 const char* name, /**< name of constraint */
    135 SCIP_VAR*** vars, /**< matrix of variables on which the symmetry acts */
    136 SCIP_ORBITOPETYPE orbitopetype, /**< type of orbitope constraint */
    137 int nrows, /**< number of rows of variable matrix */
    138 int ncols, /**< number of columns of variable matrix */
    139 SCIP_Bool resolveprop, /**< should propagation be resolved? */
    140 SCIP_Bool ismodelcons, /**< whether the orbitope is a model constraint */
    141 SCIP_Bool checkpporbitope, /**< Check if full orbitope constraints can be upgraded to pp-orbitope? */
    142 SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
    143 * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
    144 SCIP_Bool separate, /**< should the constraint be separated during LP processing?
    145 * Usually set to TRUE. */
    146 SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
    147 * TRUE for model constraints, FALSE for additional, redundant constraints. */
    148 SCIP_Bool check, /**< should the constraint be checked for feasibility?
    149 * TRUE for model constraints, FALSE for additional, redundant constraints. */
    150 SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
    151 * Usually set to TRUE. */
    152 SCIP_Bool local, /**< is constraint only valid locally?
    153 * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
    154 SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
    155 * Usually set to FALSE. In column generation applications, set to TRUE if pricing
    156 * adds coefficients to this constraint. */
    157 SCIP_Bool dynamic, /**< is constraint subject to aging?
    158 * Usually set to FALSE. Set to TRUE for own cuts which
    159 * are separated as constraints. */
    160 SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
    161 * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
    162 SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
    163 * if it may be moved to a more global node?
    164 * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
    165 )
    166{
    167 assert( nrows > 0 );
    168 assert( ncols > 0 );
    169
    170 if ( ! ismodelcons && checkpporbitope && orbitopetype != SCIP_ORBITOPETYPE_PARTITIONING
    171 && orbitopetype != SCIP_ORBITOPETYPE_PACKING )
    172 {
    173 SCIP_CALL( strengthenOrbitopeConstraint(scip, vars, &nrows, ncols, &orbitopetype) );
    174 }
    175
    176 if ( orbitopetype == SCIP_ORBITOPETYPE_FULL )
    177 {
    178 SCIP_CALL( SCIPcreateConsOrbitopeFull(scip, cons, name, vars, nrows, ncols, resolveprop, ismodelcons,
    179 initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
    180 }
    181 else
    182 {
    183 SCIP_CALL( SCIPcreateConsOrbitopePP(scip, cons, name, vars, orbitopetype, nrows, ncols,
    184 resolveprop, ismodelcons, initial, separate, enforce, check, propagate,
    185 local, modifiable, dynamic, removable, stickingatnode) );
    186 }
    187
    188 return SCIP_OKAY;
    189}
    190
    191/** creates and captures an orbitope constraint in its most basic variant, i. e., with all constraint flags set to their
    192 * default values, which can be set afterwards using SCIPsetConsFLAGNAME()
    193 *
    194 * @see SCIPcreateConsOrbitope() for the default constraint flag configuration
    195 *
    196 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
    197 */
    199 SCIP* scip, /**< SCIP data structure */
    200 SCIP_CONS** cons, /**< pointer to hold the created constraint */
    201 const char* name, /**< name of constraint */
    202 SCIP_VAR*** vars, /**< matrix of variables on which the symmetry acts */
    203 SCIP_ORBITOPETYPE orbitopetype, /**< type of orbitope constraint */
    204 int nrows, /**< number of rows of variable matrix */
    205 int ncols, /**< number of columns of variable matrix */
    206 SCIP_Bool resolveprop, /**< should propagation be resolved? */
    207 SCIP_Bool ismodelcons, /**< whether the orbitope is a model constraint */
    208 SCIP_Bool checkpporbitope /**< Check if full orbitope constraints can be upgraded to pp-orbitope? */
    209 )
    210{
    211 SCIP_CALL( SCIPcreateConsOrbitope(scip, cons, name, vars, orbitopetype, nrows, ncols,
    212 resolveprop, ismodelcons, checkpporbitope,
    214
    215 return SCIP_OKAY;
    216}
    SCIP_Real * r
    Definition: circlepacking.c:59
    SCIP_RETCODE SCIPcreateConsBasicOrbitope(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR ***vars, SCIP_ORBITOPETYPE orbitopetype, int nrows, int ncols, SCIP_Bool resolveprop, SCIP_Bool ismodelcons, SCIP_Bool checkpporbitope)
    SCIP_RETCODE SCIPincludeConshdlrOrbitope(SCIP *scip)
    SCIP_RETCODE SCIPcreateConsOrbitope(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR ***vars, SCIP_ORBITOPETYPE orbitopetype, int nrows, int ncols, SCIP_Bool resolveprop, SCIP_Bool ismodelcons, SCIP_Bool checkpporbitope, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
    static SCIP_RETCODE strengthenOrbitopeConstraint(SCIP *scip, SCIP_VAR ***vars, int *nrows, int ncols, SCIP_ORBITOPETYPE *type)
    Definition: cons_orbitope.c:49
    interface for constraint handlers of type partitioning, packing, and full
    constraint handler for full orbitope constraints w.r.t. the full symmetric group
    constraint handler for partitioning/packing orbitope constraints w.r.t. the full symmetric group
    #define NULL
    Definition: def.h:248
    #define SCIP_Bool
    Definition: def.h:91
    #define TRUE
    Definition: def.h:93
    #define FALSE
    Definition: def.h:94
    #define SCIP_CALL(x)
    Definition: def.h:355
    SCIP_RETCODE SCIPcreateConsOrbitopePP(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR ***vars, SCIP_ORBITOPETYPE orbitopetype, int nrows, int ncols, SCIP_Bool resolveprop, SCIP_Bool ismodelcons, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
    SCIP_RETCODE SCIPcreateConsOrbitopeFull(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR ***vars, int nrows, int ncols, SCIP_Bool resolveprop, SCIP_Bool ismodelcons, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
    SCIP_RETCODE SCIPincludeConshdlrOrbitopeFull(SCIP *scip)
    SCIP_RETCODE SCIPincludeConshdlrOrbitopePP(SCIP *scip)
    #define SCIPfreeBlockMemoryArray(scip, ptr, num)
    Definition: scip_mem.h:110
    SCIP_RETCODE SCIPisPackingPartitioningOrbitope(SCIP *scip, SCIP_VAR ***vars, int nrows, int ncols, SCIP_Bool **pprows, int *npprows, SCIP_ORBITOPETYPE *type)
    Definition: symmetry.c:1193
    memory allocation routines
    static SCIP_RETCODE separate(SCIP *scip, SCIP_SEPA *sepa, SCIP_SOL *sol, SCIP_RESULT *result)
    Main separation function.
    Definition: sepa_flower.c:1221
    methods for handling symmetries
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63
    type definitions for symmetry computations
    @ SCIP_ORBITOPETYPE_PACKING
    @ SCIP_ORBITOPETYPE_FULL
    @ SCIP_ORBITOPETYPE_PARTITIONING
    enum SCIP_OrbitopeType SCIP_ORBITOPETYPE