Scippy

    SCIP

    Solving Constraint Integer Programs

    pub_network.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 pub_network.h
    26 * @ingroup PUBLICCOREAPI
    27 * @brief Methods for detecting network matrices
    28 * @author Rolf van der Hulst
    29 *
    30 * This file contains algorithms for incrementally growing (augmenting) network matrices,
    31 * which are a large subclass of totally unimodular matrices.
    32 *
    33 * @addtogroup NetworkMatrix
    34 *
    35 * @{
    36 *
    37 * A matrix \f$M \in \{-1,0,1\}^{m\times n} \f$ is a network matrix if there exists a directed graph \f$G = (V,A)\f$
    38 * with \f$|A| = m+n\f$ arcs and a spanning forest \f$T\f$ with \f$|T| = m\f$ such that \f$M\f$'s rows index \f$T\f$ and
    39 * \f$M\f$'s columns index \f$A\setminus T\f$,
    40 * and for each arc \f$ a = (u,v) \in A\setminus T\f$ and each arc \f$t\in T\f$
    41 * \f[
    42 * M_{t,a} = \begin{cases}
    43 * +1 & \textrm{if the unique } u-v \textrm{ path in } T \textrm{ passes through } a \textrm{ forwardly}, \\
    44 * -1 & \textrm{if the unique } u-v \textrm{ path in } T \textrm{ passes through } a \textrm{ backwardly}, \\
    45 * 0 & \textrm{if the unique } u-v \textrm{ path in } T \textrm{ does not pass through } a
    46 * \end{cases}
    47 * \f]
    48 * holds.
    49 *
    50 * The main difficulty with detecting network matrices is that there may exist many pairs of a graph and a spanning tree
    51 * that realize a matrix. The algorithms in this file maintain and update an SPQR forest, which is a graph decomposition
    52 * that represents all graphs that correspond to a given network matrix.
    53 *
    54 * Note that all addition algorithms expect that each nonzero is given exactly once and not more often; in particular,
    55 * it is up to the user to ensure this when interleaving column and row addition steps.
    56 *
    57 * More details can be found in:
    58 * - R.P. van der Hulst and M. Walter "A Row-wise Algorithm for Graph Realization"
    59 * - R.E. Bixby and D.K. Wagner "An almost linear-time algorithm for graph realization"
    60 *
    61 * Note that although these publications contain the methods for undirected graphs (and binary matrices),
    62 * their ideas are relatively easily extended to directed graphs and ternary matrices.
    63 * Implementation details are described in further detail in network.c
    64 */
    65
    66/* TODO add method that realizes a SCIP digraph from the decomposition */
    67/* TODO add method that *cleanly* removes complete components of the SPQR tree */
    68/* TODO add node-arc incidence matrix methods */
    69/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    70
    71#ifndef __SCIP_NETWORK_H__
    72#define __SCIP_NETWORK_H__
    73
    74#include "scip/def.h"
    75#include "scip/type_retcode.h"
    76#include "scip/type_mem.h"
    77#include "scip/type_misc.h"
    79
    80#ifdef cplusplus
    81extern "C" {
    82#endif
    83
    84/** this class stores a decomposition of the network matrix using SPQR trees */
    86
    87/** create an empty network matrix decomposition that can store a matrix with at most the given dimensions
    88 *
    89 * Initially, the network matrix decomposition stores an empty submatrix
    90 */
    91SCIP_EXPORT
    93 BMS_BLKMEM* blkmem, /**< Block memory */
    94 SCIP_NETMATDEC** pdec, /**< buffer to store pointer to created decomposition */
    95 int nrows, /**< The maximal number of rows that the decomposition can expect */
    96 int ncols /**< The maximal number of columns that the decomposition can expect */
    97);
    98
    99/** frees a network matrix decomposition */
    100SCIP_EXPORT
    102 SCIP_NETMATDEC** pdec /**< pointer to the network matrix decomposition to free */
    103);
    104
    105/** tries to add a given column to the network matrix. Any nonzero row indices in the column that are not yet in the
    106 * network matrix decomposition are added, too.
    107 *
    108 * @note Each column and row may be added only once. Trying to add a column that is already in the decomposition will
    109 * result in an error.
    110 *
    111 * Note that the first call to this method for a given decomposition may be a bit slower,
    112 * due to memory initialization.
    113 */
    114SCIP_EXPORT
    116 SCIP_NETMATDEC* dec, /**< Network matrix decomposition */
    117 int column, /**< The column to add */
    118 int* nonzrows, /**< The column's nonzero row indices */
    119 double* nonzvals, /**< The column's nonzero entries */
    120 int nnonzs, /**< The number of nonzeros in the column */
    121 SCIP_Bool* success /**< Buffer to store whether the column was added */
    122);
    123
    124/** tries to add a given row to the network matrix. Any nonzero column indices in the row that are not yet in the
    125 * network matrix decomposition are added, too.
    126 *
    127 * @note Each column and row may be added only once. Trying to add a row that is already in the decomposition will
    128 * result in an error.
    129 *
    130 * Note that the first call to this method for a given decomposition may be a bit slower,
    131 * due to memory initialization.
    132 *
    133 * If the user is only interested in determining if a certain (sub)matrix is network or not, using
    134 * SCIPnetmatdecTryAddCol() will generally be faster, unless the (sub)matrix has many more columns than rows.
    135 *
    136 */
    137SCIP_EXPORT
    139 SCIP_NETMATDEC* dec, /**< Network matrix decomposition */
    140 int row, /**< The row to add */
    141 int* nonzcols, /**< The row's nonzero column indices */
    142 double* nonzvals, /**< The row's nonzero entries */
    143 int nnonzs, /**< The number of nonzeros in the row */
    144 SCIP_Bool* success /**< Buffer to store whether the row was added */
    145);
    146
    147/** checks if the network matrix decomposition contains the given row */
    148SCIP_EXPORT
    150 SCIP_NETMATDEC* dec, /**< The network matrix decomposition */
    151 int row /**< The row index that is checked */
    152);
    153
    154/** checks if the network matrix decomposition contains the given column */
    155SCIP_EXPORT
    157 SCIP_NETMATDEC* dec, /**< The network matrix decomposition */
    158 int column /**< The column index that is checked */
    159);
    160
    161/** removes a connected component of the matrix from the network decomposition
    162 *
    163 * @note This method is 'stupid', and does not delete the associated graph data structure in the decomposition.
    164 * Moreover, it does not explicitly check if the rows/columns that the user provides are a connected
    165 * component of the submatrix given by the decomposition. If this is not the case, this will lead to buggy behavior.
    166 * Use with care!
    167 */
    168SCIP_EXPORT
    170 SCIP_NETMATDEC* dec, /**< The network matrix decomposition */
    171 int* componentrows, /**< Array of rows to delete */
    172 int nrows, /**< The number of rows to delete */
    173 int* componentcols, /**< Array of columns to delete */
    174 int ncols /**< The number of columns to delete */
    175);
    176
    177/** checks if the network matrix decomposition is minimal.
    178 *
    179 * A network matrix decomposition is minimal if it does not contain adjacent parallel or series skeletons.
    180 * The network matrix decomposition we compute should always be minimal.
    181 * This method should only be used in tests or asserts.
    182 */
    183SCIP_EXPORT
    185 SCIP_NETMATDEC* dec /**< The network matrix decomposition */
    186);
    187
    188/** checks if the cycle stored in the Decomposition matches the given array
    189 *
    190 * This method should only be used in tests
    191 */
    192SCIP_EXPORT
    194 BMS_BUFMEM * bufmem, /**< Buffer memory */
    195 SCIP_NETMATDEC* dec, /**< The network matrix decomposition */
    196 int column, /**< The column to check */
    197 int* nonzrowidx, /**< Array with the column's nonzero row indices */
    198 double* nonzvals, /**< Array with the column's nonzero values */
    199 int nnonzs, /**< Number of nonzeros in the column */
    200 int* pathrowstorage, /**< A buffer to hold the computed path's rows. Should have size equal or
    201 * greater than the number of rows in the decomposition. */
    202 SCIP_Bool* pathsignstorage /**< A buffer to store the computed path's row signs. Should have size
    203 * equal or greater than the number of rows in the decomposition. */
    204);
    205
    206/** Constructs a realization of an underlying directed graph belonging to the network matrix.
    207 *
    208 * The arc data of the digraph contains the row/column indices of the graph. If index < nrows, then the index is the
    209 * corresponding row. If the index >= nrows, then index-nrows is the column index.
    210 * Since many different realizations are possible, we use the default orientation of the two-separations to associate
    211 * pairs of nodes to each other. In particular, we choose to connect the nodes of different 2-connected components
    212 * in node 0. This way, the rank of the underlying matrix is equal to m+1-c, where c is the number of undirected
    213 * connected components of the graph where the row/tree edges have been left out.
    214 */
    215SCIP_EXPORT
    217 SCIP_NETMATDEC* dec, /**< The network matrix decomposition */
    218 BMS_BLKMEM * blkmem, /**< The block memory to use for the created digraph */
    219 SCIP_DIGRAPH** pdigraph, /**< Pointer to the pointer to store the created digraph */
    220 SCIP_Bool createrowarcs /**< Should the row arcs be added to the created digraph? */
    221);
    222/**@} */
    223
    224#ifdef cplusplus
    225}
    226#endif
    227
    228#endif /*__SCIP_NETWORK_H__ */
    common defines and data types used in all packages of SCIP
    #define SCIP_Bool
    Definition: def.h:91
    SCIP_Bool SCIPnetmatdecVerifyCycle(BMS_BUFMEM *bufmem, SCIP_NETMATDEC *dec, int column, int *nonzrowidx, double *nonzvals, int nnonzs, int *pathrowstorage, SCIP_Bool *pathsignstorage)
    Definition: network.c:11685
    SCIP_RETCODE SCIPnetmatdecCreateDiGraph(SCIP_NETMATDEC *dec, BMS_BLKMEM *blkmem, SCIP_DIGRAPH **pdigraph, SCIP_Bool createrowarcs)
    Definition: network.c:11701
    SCIP_Bool SCIPnetmatdecContainsRow(SCIP_NETMATDEC *dec, int row)
    Definition: network.c:11651
    void SCIPnetmatdecRemoveComponent(SCIP_NETMATDEC *dec, int *componentrows, int nrows, int *componentcols, int ncols)
    Definition: network.c:11667
    SCIP_Bool SCIPnetmatdecContainsColumn(SCIP_NETMATDEC *dec, int column)
    Definition: network.c:11659
    SCIP_RETCODE SCIPnetmatdecTryAddRow(SCIP_NETMATDEC *dec, int row, int *nonzcols, double *nonzvals, int nnonzs, SCIP_Bool *success)
    Definition: network.c:11627
    SCIP_RETCODE SCIPnetmatdecCreate(BMS_BLKMEM *blkmem, SCIP_NETMATDEC **pdec, int nrows, int ncols)
    Definition: network.c:11566
    SCIP_RETCODE SCIPnetmatdecTryAddCol(SCIP_NETMATDEC *dec, int column, int *nonzrows, double *nonzvals, int nnonzs, SCIP_Bool *success)
    Definition: network.c:11603
    SCIP_Bool SCIPnetmatdecIsMinimal(SCIP_NETMATDEC *dec)
    Definition: network.c:11678
    void SCIPnetmatdecFree(SCIP_NETMATDEC **pdec)
    Definition: network.c:11584
    memory allocation routines
    struct BMS_BlkMem BMS_BLKMEM
    Definition: memory.h:437
    SCIP_NETMATDECDATA * dec
    Definition: network.c:11561
    type definitions for block memory pools and memory buffers
    type definitions for miscellaneous datastructures
    type definitions for return codes for SCIP methods
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63