1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the program and library */ 4 /* SCIP --- Solving Constraint Integer Programs */ 5 /* */ 6 /* Copyright (C) 2002-2021 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 pub_matrix.h 17 * @ingroup PUBLICCOREAPI 18 * @brief public methods for matrix 19 * @author Dieter Weninger 20 */ 21 22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ 23 24 #ifndef __SCIP_PUB_MATRIX_H__ 25 #define __SCIP_PUB_MATRIX_H__ 26 27 #include "scip/def.h" 28 #include "scip/type_var.h" 29 #include "scip/type_cons.h" 30 #include "scip/type_matrix.h" 31 32 #ifdef NDEBUG 33 #include "scip/struct_matrix.h" 34 #endif 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /* 41 * methods for matrix access 42 */ 43 44 /** get column based start pointer of values */ 45 SCIP_EXPORT 46 SCIP_Real* SCIPmatrixGetColValPtr( 47 SCIP_MATRIX* matrix, /**< matrix instance */ 48 int col /**< column index */ 49 ); 50 51 /** get column based start pointer of row indices */ 52 SCIP_EXPORT 53 int* SCIPmatrixGetColIdxPtr( 54 SCIP_MATRIX* matrix, /**< matrix instance */ 55 int col /**< column index */ 56 ); 57 58 /** get the number of non-zero entries of this column */ 59 SCIP_EXPORT 60 int SCIPmatrixGetColNNonzs( 61 SCIP_MATRIX* matrix, /**< matrix instance */ 62 int col /**< column index */ 63 ); 64 65 /** get number of columns of the matrix */ 66 SCIP_EXPORT 67 int SCIPmatrixGetNColumns( 68 SCIP_MATRIX* matrix /**< matrix instance */ 69 ); 70 71 /** get upper bound of column */ 72 SCIP_EXPORT 73 SCIP_Real SCIPmatrixGetColUb( 74 SCIP_MATRIX* matrix, /**< matrix instance */ 75 int col /**< column index */ 76 ); 77 78 /** get lower bound of column */ 79 SCIP_EXPORT 80 SCIP_Real SCIPmatrixGetColLb( 81 SCIP_MATRIX* matrix, /**< matrix instance */ 82 int col /**< column index */ 83 ); 84 85 /** get number of uplocks of column */ 86 SCIP_EXPORT 87 int SCIPmatrixGetColNUplocks( 88 SCIP_MATRIX* matrix, /**< matrix instance */ 89 int col /**< column index */ 90 ); 91 92 /** get number of downlocks of column */ 93 SCIP_EXPORT 94 int SCIPmatrixGetColNDownlocks( 95 SCIP_MATRIX* matrix, /**< matrix instance */ 96 int col /**< column index */ 97 ); 98 99 /** get variable pointer of column */ 100 SCIP_EXPORT 101 SCIP_VAR* SCIPmatrixGetVar( 102 SCIP_MATRIX* matrix, /**< matrix instance */ 103 int col /**< column index */ 104 ); 105 106 /** get name of column/variable */ 107 SCIP_EXPORT 108 const char* SCIPmatrixGetColName( 109 SCIP_MATRIX* matrix, /**< matrix instance */ 110 int col /**< column index */ 111 ); 112 113 /** get row based start pointer of values */ 114 SCIP_EXPORT 115 SCIP_Real* SCIPmatrixGetRowValPtr( 116 SCIP_MATRIX* matrix, /**< matrix instance */ 117 int row /**< row index */ 118 ); 119 120 /** get row based start pointer of column indices */ 121 SCIP_EXPORT 122 int* SCIPmatrixGetRowIdxPtr( 123 SCIP_MATRIX* matrix, /**< matrix instance */ 124 int row /**< row index */ 125 ); 126 127 /** get number of non-zeros of this row */ 128 SCIP_EXPORT 129 int SCIPmatrixGetRowNNonzs( 130 SCIP_MATRIX* matrix, /**< matrix instance */ 131 int row /**< row index */ 132 ); 133 134 /** get name of row */ 135 SCIP_EXPORT 136 const char* SCIPmatrixGetRowName( 137 SCIP_MATRIX* matrix, /**< matrix instance */ 138 int row /**< row index */ 139 ); 140 141 /** get number of rows of the matrix */ 142 SCIP_EXPORT 143 int SCIPmatrixGetNRows( 144 SCIP_MATRIX* matrix /**< matrix instance */ 145 ); 146 147 /** get left-hand-side of row */ 148 SCIP_EXPORT 149 SCIP_Real SCIPmatrixGetRowLhs( 150 SCIP_MATRIX* matrix, /**< matrix instace */ 151 int row /**< row index */ 152 ); 153 154 /** get right-hand-side of row */ 155 SCIP_EXPORT 156 SCIP_Real SCIPmatrixGetRowRhs( 157 SCIP_MATRIX* matrix, /**< matrix instance */ 158 int row /**< row index */ 159 ); 160 161 /** flag indicating if right-hand-side of row is infinity */ 162 SCIP_EXPORT 163 SCIP_Bool SCIPmatrixIsRowRhsInfinity( 164 SCIP_MATRIX* matrix, /**< matrix instance */ 165 int row /**< row index */ 166 ); 167 168 /** get number of non-zeros of matrix */ 169 SCIP_EXPORT 170 int SCIPmatrixGetNNonzs( 171 SCIP_MATRIX* matrix /**< matrix instance */ 172 ); 173 174 /** get minimal activity of row */ 175 SCIP_EXPORT 176 SCIP_Real SCIPmatrixGetRowMinActivity( 177 SCIP_MATRIX* matrix, /**< matrix instance */ 178 int row /**< row index */ 179 ); 180 181 /** get maximal activity of row */ 182 SCIP_EXPORT 183 SCIP_Real SCIPmatrixGetRowMaxActivity( 184 SCIP_MATRIX* matrix, /**< matrix instance */ 185 int row /**< row index */ 186 ); 187 188 /** get number of negative infinities present within minimal activity */ 189 SCIP_EXPORT 190 int SCIPmatrixGetRowNMinActNegInf( 191 SCIP_MATRIX* matrix, /**< matrix instance */ 192 int row /**< row index */ 193 ); 194 195 /** get number of positive infinities present within minimal activity */ 196 SCIP_EXPORT 197 int SCIPmatrixGetRowNMinActPosInf( 198 SCIP_MATRIX* matrix, /**< matrix instance */ 199 int row /**< row index */ 200 ); 201 202 /** get number of negative infinities present within maximal activity */ 203 SCIP_EXPORT 204 int SCIPmatrixGetRowNMaxActNegInf( 205 SCIP_MATRIX* matrix, /**< matrix instance */ 206 int row /**< row index */ 207 ); 208 209 /** get number of positive infinities present within maximal activity */ 210 SCIP_EXPORT 211 int SCIPmatrixGetRowNMaxActPosInf( 212 SCIP_MATRIX* matrix, /**< matrix instance */ 213 int row /**< row index */ 214 ); 215 216 /** get constraint pointer for constraint representing row */ 217 SCIP_EXPORT 218 SCIP_CONS* SCIPmatrixGetCons( 219 SCIP_MATRIX* matrix, /**< matrix instance */ 220 int row /**< row index */ 221 ); 222 223 /** get if conflicting uplocks of variable present */ 224 SCIP_EXPORT 225 SCIP_Bool SCIPmatrixUplockConflict( 226 SCIP_MATRIX* matrix, /**< matrix instance */ 227 int col /**< column index */ 228 ); 229 230 /** get if conflicting downlocks of variable present */ 231 SCIP_EXPORT 232 SCIP_Bool SCIPmatrixDownlockConflict( 233 SCIP_MATRIX* matrix, /**< matrix instance */ 234 int col /**< column index */ 235 ); 236 237 238 #ifdef NDEBUG 239 240 /* In optimized mode, the function calls are overwritten by defines to reduce the number of function calls and 241 * speed up the algorithms. 242 */ 243 244 #define SCIPmatrixGetColValPtr(matrix,col) (matrix->colmatval + matrix->colmatbeg[col]) 245 #define SCIPmatrixGetColIdxPtr(matrix,col) (matrix->colmatind + matrix->colmatbeg[col]) 246 #define SCIPmatrixGetColNNonzs(matrix,col) (matrix->colmatcnt[col]) 247 #define SCIPmatrixGetNColumns(matrix) (matrix->ncols) 248 #define SCIPmatrixGetColUb(matrix,col) (matrix->ub[col]) 249 #define SCIPmatrixGetColLb(matrix,col) (matrix->lb[col]) 250 #define SCIPmatrixGetColNUplocks(matrix,col) (matrix->nuplocks[col]) 251 #define SCIPmatrixGetColNDownlocks(matrix,col) (matrix->ndownlocks[col]) 252 #define SCIPmatrixGetVar(matrix,col) (matrix->vars[col]) 253 #define SCIPmatrixGetColName(matrix,col) (SCIPvarGetName(matrix->vars[col])) 254 #define SCIPmatrixGetRowValPtr(matrix,row) (matrix->rowmatval + matrix->rowmatbeg[row]) 255 #define SCIPmatrixGetRowIdxPtr(matrix,row) (matrix->rowmatind + matrix->rowmatbeg[row]) 256 #define SCIPmatrixGetRowNNonzs(matrix,row) (matrix->rowmatcnt[row]) 257 #define SCIPmatrixGetRowName(matrix,row) (SCIPconsGetName(matrix->cons[row])) 258 #define SCIPmatrixGetNRows(matrix) (matrix->nrows) 259 #define SCIPmatrixGetRowLhs(matrix,row) (matrix->lhs[row]) 260 #define SCIPmatrixGetRowRhs(matrix,row) (matrix->rhs[row]) 261 #define SCIPmatrixIsRowRhsInfinity(matrix,row) (matrix->isrhsinfinite[row]) 262 #define SCIPmatrixGetNNonzs(matrix) (matrix->nnonzs) 263 #define SCIPmatrixGetRowMinActivity(matrix,row) (matrix->minactivity[row]) 264 #define SCIPmatrixGetRowMaxActivity(matrix,row) (matrix->maxactivity[row]) 265 #define SCIPmatrixGetRowNMinActNegInf(matrix,row) (matrix->minactivityneginf[row]) 266 #define SCIPmatrixGetRowNMinActPosInf(matrix,row) (matrix->minactivityposinf[row]) 267 #define SCIPmatrixGetRowNMaxActNegInf(matrix,row) (matrix->maxactivityneginf[row]) 268 #define SCIPmatrixGetRowNMaxActPosInf(matrix,row) (matrix->maxactivityposinf[row]) 269 #define SCIPmatrixGetCons(matrix,row) (matrix->cons[row]) 270 271 #endif 272 273 /** initialize matrix by copying all check constraints 274 * 275 * @note Completeness is checked by testing whether all check constraints are from a list of linear constraint handlers 276 * that can be represented. 277 */ 278 SCIP_EXPORT 279 SCIP_RETCODE SCIPmatrixCreate( 280 SCIP* scip, /**< current scip instance */ 281 SCIP_MATRIX** matrixptr, /**< pointer to constraint matrix object to be initialized */ 282 SCIP_Bool onlyifcomplete, /**< should matrix creation be skipped if matrix will not be complete? */ 283 SCIP_Bool* initialized, /**< was the initialization successful? */ 284 SCIP_Bool* complete, /**< are all constraint represented within the matrix? */ 285 SCIP_Bool* infeasible, /**< pointer to return whether problem was detected to be infeasible during matrix creation */ 286 int* naddconss, /**< pointer to count number of added (linear) constraints during matrix creation */ 287 int* ndelconss, /**< pointer to count number of deleted specialized linear constraints during matrix creation */ 288 int* nchgcoefs, /**< pointer to count number of changed coefficients during matrix creation */ 289 int* nchgbds, /**< pointer to count number of changed bounds during matrix creation */ 290 int* nfixedvars /**< pointer to count number of fixed variables during matrix creation */ 291 ); 292 293 /** frees the constraint matrix */ 294 SCIP_EXPORT 295 void SCIPmatrixFree( 296 SCIP* scip, /**< current SCIP instance */ 297 SCIP_MATRIX** matrix /**< constraint matrix object */ 298 ); 299 300 /** print one row of the MIP matrix */ 301 SCIP_EXPORT 302 void SCIPmatrixPrintRow( 303 SCIP* scip, /**< current SCIP instance */ 304 SCIP_MATRIX* matrix, /**< constraint matrix object */ 305 int row /**< row index */ 306 ); 307 308 /** detect parallel rows, rhs/lhs are ignored */ 309 SCIP_EXPORT 310 SCIP_RETCODE SCIPmatrixGetParallelRows( 311 SCIP* scip, /**< current SCIP instance */ 312 SCIP_MATRIX* matrix, /**< matrix containing the constraints */ 313 SCIP_Real* scale, /**< scale factors of rows */ 314 int* pclass /**< parallel row classes */ 315 ); 316 317 /** removes the bounds of a column and updates the activities accordingly */ 318 SCIP_EXPORT 319 void SCIPmatrixRemoveColumnBounds( 320 SCIP* scip, /**< current scip instance */ 321 SCIP_MATRIX* matrix, /**< constraint matrix */ 322 int col /**< column variable to remove bounds from */ 323 ); 324 325 /** detect parallel columns, obj ignored */ 326 SCIP_EXPORT 327 SCIP_RETCODE SCIPmatrixGetParallelCols( 328 SCIP* scip, /**< current SCIP instance */ 329 SCIP_MATRIX* matrix, /**< matrix containing the constraints */ 330 SCIP_Real* scale, /**< scale factors of cols */ 331 int* pclass, /**< parallel column classes */ 332 SCIP_Bool* varineq /**< indicating if variable is within an equation */ 333 ); 334 335 336 #ifdef __cplusplus 337 } 338 #endif 339 340 #endif 341