Scippy

    SCIP

    Solving Constraint Integer Programs

    scip_exact.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 scip_exact.c
    26 * @brief public methods for exact solving
    27 * @author Leon Eifler
    28 *
    29 * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
    30 */
    31
    32/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    33
    34#include <ctype.h>
    35#include <stdarg.h>
    36#include <assert.h>
    37#include <string.h>
    38#ifndef _WIN32
    39#include <strings.h> /*lint --e{766}*/
    40#endif
    41
    42
    43#include "lpi/lpi.h"
    44#include "scip/exprinterpret.h"
    45#include "scip/nlpi.h"
    46#include "scip/benders.h"
    47#include "scip/benderscut.h"
    48#include "scip/branch.h"
    50#include "scip/clock.h"
    51#include "scip/compr.h"
    52#include "scip/concsolver.h"
    53#include "scip/concurrent.h"
    54#include "scip/conflict.h"
    55#include "scip/conflictstore.h"
    56#include "scip/cons.h"
    57#include "scip/cons_linear.h"
    58#include "scip/cutpool.h"
    59#include "scip/cuts.h"
    60#include "scip/debug.h"
    61#include "scip/def.h"
    62#include "scip/dialog.h"
    63#include "scip/dialog_default.h"
    64#include "scip/disp.h"
    65#include "scip/event.h"
    66#include "scip/heur.h"
    67#include "scip/heur_ofins.h"
    68#include "scip/heur_reoptsols.h"
    70#include "scip/heuristics.h"
    71#include "scip/history.h"
    72#include "scip/implics.h"
    73#include "scip/interrupt.h"
    74#include "scip/lp.h"
    76#include "scip/mem.h"
    78#include "scip/misc.h"
    79#include "scip/nlp.h"
    80#include "scip/nodesel.h"
    81#include "scip/paramset.h"
    82#include "scip/presol.h"
    83#include "scip/presolve.h"
    84#include "scip/pricer.h"
    85#include "scip/pricestore.h"
    86#include "scip/primal.h"
    87#include "scip/prob.h"
    88#include "scip/prop.h"
    89#include "scip/reader.h"
    90#include "scip/relax.h"
    91#include "scip/reopt.h"
    92#include "scip/retcode.h"
    93#include "scip/sepastoreexact.h"
    94#include "scip/scipbuildflags.h"
    96#include "scip/scipgithash.h"
    97#include "scip/sepa.h"
    98#include "scip/sepastore.h"
    99#include "scip/set.h"
    100#include "scip/sol.h"
    101#include "scip/solve.h"
    102#include "scip/stat.h"
    103#include "scip/syncstore.h"
    104#include "scip/table.h"
    105#include "scip/tree.h"
    106#include "scip/var.h"
    107#include "scip/visual.h"
    108#include "xml/xml.h"
    109
    110#include "scip/scip_cons.h"
    111#include "scip/scip_copy.h"
    112#include "scip/scip_exact.h"
    113#include "scip/scip_general.h"
    114#include "scip/scip_mem.h"
    115#include "scip/scip_message.h"
    116#include "scip/scip_nlp.h"
    117#include "scip/scip_numerics.h"
    118#include "scip/scip_param.h"
    119#include "scip/scip_prob.h"
    120#include "scip/scip_sol.h"
    121#include "scip/scip_solve.h"
    123#include "scip/scip_var.h"
    124
    125#include "scip/pub_cons.h"
    126#include "scip/pub_fileio.h"
    127#include "scip/pub_message.h"
    128#include "scip/pub_misc.h"
    129#include "scip/pub_sol.h"
    130#include "scip/pub_var.h"
    131#include "scip/pub_lpexact.h"
    132
    133
    134/* In debug mode, we include the SCIP's structure in scip.c, such that no one can access
    135 * this structure except the interface methods in scip.c.
    136 * In optimized mode, the structure is included in scip.h, because some of the methods
    137 * are implemented as defines for performance reasons (e.g. the numerical comparisons)
    138 */
    139#ifndef NDEBUG
    140#include "scip/struct_scip.h"
    141#endif
    142
    143/** enables or disables exact solving mode
    144 *
    145 * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
    146 * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
    147 *
    148 * @pre This method can be called if @p scip is in one of the following stages:
    149 * - \ref SCIP_STAGE_INIT
    150 */
    152 SCIP* scip, /**< SCIP data structure */
    153 SCIP_Bool enable /**< enable exact solving (TRUE) or disable it (FALSE) */
    154 )
    155{
    156 assert(scip != NULL);
    157
    158#ifndef SCIP_WITH_EXACTSOLVE
    159 if( enable )
    160 {
    161 SCIPerrorMessage("SCIP was compiled without exact solve support: cannot enable exact solving mode.\n");
    162 return SCIP_ERROR;
    163 }
    164#else
    165 /* skip if nothing has changed */
    166 if( enable == scip->set->exact_enable )
    167 return SCIP_OKAY;
    168
    169 /* check stage and throw an error */
    171 {
    172 SCIPerrorMessage("Exact solving mode can only be enabled/disabled before reading/creating a problem.\n");
    173 return SCIP_INVALIDCALL;
    174 }
    175
    176 /* reoptimization in combination with exact solving has not been implemented */
    177 if( scip->set->reopt_enable )
    178 {
    179 SCIPerrorMessage("Exact solving mode not (yet) compatible with reoptimization.\n");
    180 return SCIP_INVALIDCALL;
    181 }
    182
    183 scip->set->exact_enable = enable;
    184#endif
    185
    186 return SCIP_OKAY;
    187}
    188
    189/** returns whether the solution process should be probably correct
    190 *
    191 * @return Returns TRUE if \SCIP is in exact solving mode, otherwise FALSE
    192 */
    194 SCIP* scip /**< SCIP data structure */
    195 )
    196{
    197 assert(scip != NULL);
    198 assert(scip->set != NULL);
    199
    200 return (scip->set->exact_enable);
    201}
    202
    203/** returns whether aggregation is allowed to use negative slack in exact solving mode
    204 *
    205 * @return Returns TRUE if \SCIP is not in exact solving mode or aggregation is allowed to use negative slack
    206 *
    207 * @pre This method can be called if @p scip is in one of the following stages:
    208 * - \ref SCIP_STAGE_SOLVING
    209 *
    210 * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
    211 */
    213 SCIP* scip /**< SCIP data structure */
    214 )
    215{
    216 assert(scip != NULL);
    217 assert(scip->set != NULL);
    218
    220
    221 return (!SCIPisExact(scip)) || (scip->set->exact_allownegslack);
    222}
    223
    224/** branches on an LP solution exactly; does not call branching rules, since fractionalities are assumed to small;
    225 * if no fractional variables exist, the result is SCIP_DIDNOTRUN;
    226 *
    227 * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
    228 * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
    229 *
    230 * @pre This method can be called if @p scip is in one of the following stages:
    231 * - \ref SCIP_STAGE_SOLVING
    232 *
    233 * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
    234 */
    236 SCIP* scip, /**< SCIP data structure */
    237 SCIP_RESULT* result /**< pointer to store the result of the branching (s. branch.h) */
    238 )
    239{
    241
    242 SCIP_CALL( SCIPbranchExecLPExact(scip->mem->probmem, scip->set, scip->stat, scip->transprob, scip->origprob,
    243 scip->tree, scip->reopt, scip->lp, scip->branchcand, scip->eventqueue, scip->eventfilter,
    244 scip->primal->cutoffbound, TRUE, result) );
    245
    246 return SCIP_OKAY;
    247}
    248
    249/** adds row to exact separation storage
    250 *
    251 * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
    252 * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
    253 *
    254 * @pre This method can be called if @p scip is in one of the following stages:
    255 * - \ref SCIP_STAGE_SOLVING
    256 */
    258 SCIP* scip, /**< SCIP data structure */
    259 SCIP_ROWEXACT* rowexact /**< exact row to add */
    260 )
    261{
    263
    264 SCIP_CALL( SCIPsepastoreExactAddCut(scip->sepastoreexact, scip->set, scip->eventqueue, rowexact) );
    265
    266 return SCIP_OKAY;
    267}
    internal methods for Benders' decomposition cuts
    SCIP_RETCODE SCIPbranchExecLPExact(BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_BRANCHCAND *branchcand, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_Real cutoffbound, SCIP_Bool allowaddcons, SCIP_RESULT *result)
    Definition: branch.c:2913
    internal methods for branching rules and branching candidate storage
    nodereopt branching rule
    internal methods for clocks and timing issues
    internal methods for tree compressions
    datastructures for concurrent solvers
    helper functions for concurrent scip solvers
    internal methods for conflict analysis
    internal methods for storing conflicts
    internal methods for constraints and constraint handlers
    Constraint handler for linear constraints in their most general form, .
    internal methods for storing cuts in a cut pool
    methods for the aggregation rows
    methods for debugging
    #define SCIPcheckStage(scip, method, init, problem, transforming, transformed, initpresolve, presolving, exitpresolve, presolved, initsolve, solving, solved, exitsolve, freetrans, freescip)
    Definition: debug.h:364
    common defines and data types used in all packages of SCIP
    #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_ABORT(x)
    Definition: def.h:334
    #define SCIP_CALL(x)
    Definition: def.h:355
    internal methods for user interface dialog
    default user interface dialog
    internal methods for displaying runtime statistics
    internal methods for managing events
    methods to interpret (evaluate) an expression "fast"
    SCIP_STAGE SCIPgetStage(SCIP *scip)
    Definition: scip_general.c:444
    SCIP_RETCODE SCIPbranchLPExact(SCIP *scip, SCIP_RESULT *result)
    Definition: scip_exact.c:235
    SCIP_Bool SCIPallowNegSlack(SCIP *scip)
    Definition: scip_exact.c:212
    SCIP_Bool SCIPisExact(SCIP *scip)
    Definition: scip_exact.c:193
    SCIP_RETCODE SCIPaddRowExact(SCIP *scip, SCIP_ROWEXACT *rowexact)
    Definition: scip_exact.c:257
    SCIP_RETCODE SCIPenableExactSolving(SCIP *scip, SCIP_Bool enable)
    Definition: scip_exact.c:151
    internal methods for primal heuristics
    OFINS - Objective Function Induced Neighborhood Search - a primal heuristic for reoptimization.
    reoptsols primal heuristic
    trivialnegation primal heuristic
    methods commonly used by primal heuristics
    internal methods for branching and inference history
    methods for implications, variable bounds, and cliques
    methods for catching the user CTRL-C interrupt
    internal methods for LP management
    safe exact rational bounding methods
    interface methods for specific LP solvers
    methods for block memory pools and memory buffers
    default message handler
    internal miscellaneous methods
    internal methods for NLP management
    internal methods for NLP solver interfaces
    internal methods for node selectors and node priority queues
    internal methods for handling parameter settings
    internal methods for presolvers
    methods commonly used for presolving
    internal methods for variable pricers
    internal methods for storing priced variables
    internal methods for collecting primal CIP solutions and primal informations
    internal methods for storing and manipulating the main problem
    internal methods for propagators
    public methods for managing constraints
    wrapper functions to map file i/o to standard or zlib file i/o
    public methods for LP management
    public methods for message output
    #define SCIPerrorMessage
    Definition: pub_message.h:64
    public data structures and miscellaneous methods
    public methods for primal CIP solutions
    public methods for problem variables
    internal methods for input file readers
    internal methods for relaxators
    data structures and methods for collecting reoptimization information
    internal methods for return codes for SCIP methods
    public methods for constraint handler plugins and constraints
    public methods for problem copies
    public methods for exact solving
    general public methods
    public methods for memory management
    public methods for message handling
    public methods for nonlinear relaxation
    public methods for numerical tolerances
    public methods for SCIP parameter handling
    public methods for global and local (sub)problems
    public methods for solutions
    public solving methods
    public methods for querying solving statistics
    public methods for SCIP variables
    build flags methods
    register additional core functionality that is designed as plugins
    git hash methods
    internal methods for separators
    internal methods for storing separated cuts
    SCIP_RETCODE SCIPsepastoreExactAddCut(SCIP_SEPASTOREEXACT *sepastoreexact, SCIP_SET *set, SCIP_EVENTQUEUE *eventqueue, SCIP_ROWEXACT *cut)
    internal methods for storing separated exact cuts
    internal methods for global SCIP settings
    internal methods for storing primal CIP solutions
    internal methods for main solving loop and node processing
    internal methods for Benders' decomposition
    internal methods for problem statistics
    SCIP main data structure.
    the function declarations for the synchronization store
    internal methods for displaying statistics tables
    internal methods for branch and bound tree
    enum SCIP_Result SCIP_RESULT
    Definition: type_result.h:61
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    @ SCIP_INVALIDCALL
    Definition: type_retcode.h:51
    @ SCIP_ERROR
    Definition: type_retcode.h:43
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63
    @ SCIP_STAGE_PROBLEM
    Definition: type_set.h:45
    internal methods for problem variables
    methods for creating output for visualization tools (VBC, BAK)
    declarations for XML parsing