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