Scippy

    SCIP

    Solving Constraint Integer Programs

    misc_linear.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 misc_linear.c
    26 * @ingroup OTHER_CFILES
    27 * @brief miscellaneous methods for linear constraints
    28 * @author Jakob Witzig
    29 * @author Ambros Gleixner
    30 */
    31
    32/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    33
    34#include <assert.h>
    35#include <string.h>
    36
    37#include "scip/def.h"
    38#include "scip/scip.h"
    40#include "scip/cons_setppc.h"
    41#include "scip/scipdefplugins.h"
    42
    43
    44/** returns the right-hand side of an arbitrary SCIP constraint that can be represented as a single linear constraint
    45 *
    46 * @note The success pointer indicates if the individual contraint handler was able to return the involved values
    47 */
    49 SCIP* scip, /**< SCIP data structure */
    50 SCIP_CONS* cons, /**< constraint for which right-hand side is queried */
    51 SCIP_Bool* success /**< pointer to store whether a valid right-hand side was returned */
    52 )
    53{
    54 SCIP_CONSHDLR* conshdlr;
    55 const char* conshdlrname;
    56 SCIP_Real rhs;
    57
    58 assert(scip != NULL);
    59 assert(cons != NULL);
    60 assert(success != NULL);
    61
    62 conshdlr = SCIPconsGetHdlr(cons);
    63 assert(conshdlr != NULL);
    64 conshdlrname = SCIPconshdlrGetName(conshdlr);
    65
    66 *success = TRUE;
    67 rhs = SCIP_INVALID;
    68
    69 if( strcmp(conshdlrname, "linear") == 0 )
    70 {
    71 rhs = SCIPgetRhsLinear(scip, cons);
    72 }
    73 else if( strcmp(conshdlrname, "setppc") == 0 )
    74 {
    75 switch( SCIPgetTypeSetppc(scip, cons) )
    76 {
    77 case SCIP_SETPPCTYPE_PARTITIONING: /* fall through intended */
    79 rhs = 1.0;
    80 break;
    81
    83 rhs = SCIPinfinity(scip);
    84 break;
    85 }
    86 }
    87 else if( strcmp(conshdlrname, "logicor") == 0 )
    88 {
    89 rhs = SCIPinfinity(scip);
    90 }
    91 else if( strcmp(conshdlrname, "knapsack") == 0 )
    92 {
    93 rhs = SCIPgetCapacityKnapsack(scip, cons);
    94 }
    95 else if( strcmp(conshdlrname, "varbound") == 0 )
    96 {
    97 rhs = SCIPgetRhsVarbound(scip, cons);
    98 }
    99 else
    100 {
    101 SCIPwarningMessage(scip, "Cannot return rhs for constraint of type <%s>\n", conshdlrname);
    102 *success = FALSE;
    103 }
    104
    105 return rhs;
    106}
    107
    108/** returns the left-hand side of an arbitrary SCIP constraint that can be represented as a single linear constraint
    109 *
    110 * @note The success pointer indicates if the individual contraint handler was able to return the involved values
    111 */
    113 SCIP* scip, /**< SCIP data structure */
    114 SCIP_CONS* cons, /**< constraint to get left-hand side for */
    115 SCIP_Bool* success /**< pointer to store whether a valid left-hand side was returned */
    116 )
    117{
    118 SCIP_CONSHDLR* conshdlr;
    119 const char* conshdlrname;
    120 SCIP_Real lhs;
    121
    122 assert(scip != NULL);
    123 assert(cons != NULL);
    124 assert(success != NULL);
    125
    126 conshdlr = SCIPconsGetHdlr(cons);
    127 assert(conshdlr != NULL);
    128 conshdlrname = SCIPconshdlrGetName(conshdlr);
    129
    130 *success = TRUE;
    131 lhs = SCIP_INVALID;
    132
    133 if( strcmp(conshdlrname, "linear") == 0 )
    134 {
    135 lhs = SCIPgetLhsLinear(scip, cons);
    136 }
    137 else if( strcmp(conshdlrname, "setppc") == 0 )
    138 {
    139 switch( SCIPgetTypeSetppc(scip, cons) )
    140 {
    141 case SCIP_SETPPCTYPE_PARTITIONING: /* fall through intended */
    143 lhs = 1.0;
    144 break;
    145
    147 lhs = -SCIPinfinity(scip);
    148 break;
    149 }
    150 }
    151 else if( strcmp(conshdlrname, "logicor") == 0 )
    152 {
    153 lhs = 1.0;
    154 }
    155 else if( strcmp(conshdlrname, "knapsack") == 0 )
    156 {
    157 lhs = -SCIPinfinity(scip);
    158 }
    159 else if( strcmp(conshdlrname, "varbound") == 0 )
    160 {
    161 lhs = SCIPgetLhsVarbound(scip, cons);
    162 }
    163 else
    164 {
    165 SCIPwarningMessage(scip, "Cannot return lhs for constraint of type <%s>\n", conshdlrname);
    166 *success = FALSE;
    167 }
    168
    169 return lhs;
    170}
    171
    172/** returns the exact right-hand side of an arbitrary SCIP constraint that can be represented as a single linear constraint
    173 *
    174 * @note The success pointer indicates if the individual contraint handler was able to return the involved values
    175 */
    177 SCIP* scip, /**< SCIP data structure */
    178 SCIP_CONS* cons, /**< constraint for which right-hand side is queried */
    179 SCIP_Bool* success /**< pointer to store whether a valid right-hand side was returned */
    180 )
    181{
    182 SCIP_CONSHDLR* conshdlr;
    183 const char* conshdlrname;
    184 SCIP_RATIONAL* rhs = NULL;
    185
    186 assert(scip != NULL);
    187 assert(cons != NULL);
    188 assert(success != NULL);
    189
    190 conshdlr = SCIPconsGetHdlr(cons);
    191 assert(conshdlr != NULL);
    192 conshdlrname = SCIPconshdlrGetName(conshdlr);
    193
    194 *success = TRUE;
    195
    196 if( strcmp(conshdlrname, "exactlinear") == 0 )
    197 {
    198 rhs = SCIPgetRhsExactLinear(scip, cons);
    199 }
    200 else
    201 {
    202 SCIPwarningMessage(scip, "Cannot return exact rhs for constraint of type <%s>\n", conshdlrname);
    203 *success = FALSE;
    204 }
    205
    206 return rhs;
    207}
    208
    209/** returns the exact left-hand side of an arbitrary SCIP constraint that can be represented as a single linear constraint
    210 *
    211 * @note The success pointer indicates if the individual contraint handler was able to return the involved values
    212 */
    214 SCIP* scip, /**< SCIP data structure */
    215 SCIP_CONS* cons, /**< constraint to get left-hand side for */
    216 SCIP_Bool* success /**< pointer to store whether a valid left-hand side was returned */
    217 )
    218{
    219 SCIP_CONSHDLR* conshdlr;
    220 const char* conshdlrname;
    221 SCIP_RATIONAL* lhs = NULL;
    222
    223 assert(scip != NULL);
    224 assert(cons != NULL);
    225 assert(success != NULL);
    226
    227 conshdlr = SCIPconsGetHdlr(cons);
    228 assert(conshdlr != NULL);
    229 conshdlrname = SCIPconshdlrGetName(conshdlr);
    230
    231 *success = TRUE;
    232
    233 if( strcmp(conshdlrname, "exactlinear") == 0 )
    234 {
    235 lhs = SCIPgetLhsExactLinear(scip, cons);
    236 }
    237 else
    238 {
    239 SCIPwarningMessage(scip, "Cannot return exact lhs for constraint of type <%s>\n", conshdlrname);
    240 *success = FALSE;
    241 }
    242
    243 return lhs;
    244}
    245
    246/** returns the value array of an arbitrary SCIP constraint that can be represented as a single linear constraint
    247 *
    248 * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
    249 * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
    250 *
    251 * @note The success pointer indicates if the individual contraint handler was able to return the involved values
    252 */
    254 SCIP* scip, /**< SCIP data structure */
    255 SCIP_CONS* cons, /**< constraint for which the coefficients are wanted */
    256 SCIP_Real* vals, /**< array to store the coefficients of the constraint */
    257 int varssize, /**< available slots in vals array needed to check if the array is large enough */
    258 SCIP_Bool* success /**< pointer to store whether the coefficients are successfully copied */
    259 )
    260{
    261 SCIP_CONSHDLR* conshdlr;
    262 const char* conshdlrname;
    263 int nvars;
    264 int i;
    265
    266 assert(scip != NULL);
    267 assert(cons != NULL);
    268 assert(vals != NULL);
    269 assert(success != NULL);
    270
    271 conshdlr = SCIPconsGetHdlr(cons);
    272 assert(conshdlr != NULL);
    273
    274 conshdlrname = SCIPconshdlrGetName(conshdlr);
    275
    276 *success = TRUE;
    277
    278 SCIP_CALL( SCIPgetConsNVars(scip, cons, &nvars, success) );
    279
    280 if( !(*success) )
    281 {
    282 SCIPwarningMessage(scip, "Cannot return value array for constraint of type <%s>\n", conshdlrname);
    283 return SCIP_OKAY;
    284 }
    285
    286 if( varssize < nvars )
    287 {
    288 SCIPwarningMessage(scip, "Cannot return value array for constraint of type <%s> (insufficient memory provided)\n", conshdlrname);
    289 *success = FALSE;
    290 return SCIP_OKAY;
    291 }
    292
    293 if( strcmp(conshdlrname, "linear") == 0 )
    294 {
    295 SCIP_Real* linvals;
    296
    297 linvals = SCIPgetValsLinear(scip, cons);
    298 assert(nvars == 0 || linvals != NULL);
    299
    300 for( i = 0; i < nvars; i++ )
    301 {
    302 vals[i] = linvals[i];
    303 }
    304 }
    305 else if( strcmp(conshdlrname, "setppc") == 0 )
    306 {
    307 for( i = 0; i < nvars; i++ )
    308 {
    309 vals[i] = 1.0;
    310 }
    311 }
    312 else if( strcmp(conshdlrname, "logicor") == 0 )
    313 {
    314 for( i = 0; i < nvars; i++ )
    315 {
    316 vals[i] = 1.0;
    317 }
    318 }
    319 else if( strcmp(conshdlrname, "knapsack") == 0 )
    320 {
    321 SCIP_Longint* weights;
    322
    323 weights = SCIPgetWeightsKnapsack(scip, cons);
    324 assert(nvars == 0 || weights != NULL);
    325
    326 for( i = 0; i < nvars; i++ )
    327 {
    328 vals[i] = (SCIP_Real)weights[i];
    329 }
    330 }
    331 else if( strcmp(conshdlrname, "varbound") == 0 )
    332 {
    333 assert(nvars == 2);
    334
    335 vals[0] = 1.0;
    336 vals[1] = SCIPgetVbdcoefVarbound(scip, cons);
    337 }
    338 else if( strcmp(conshdlrname, "SOS1") == 0 )
    339 {
    340 SCIP_Real* weights;
    341
    342 weights = SCIPgetWeightsSOS1(scip, cons);
    343 assert(nvars == 0 || weights != NULL);
    344
    345 for( i = 0; i < nvars; i++ )
    346 {
    347 vals[i] = weights[i];
    348 }
    349 }
    350 else if( strcmp(conshdlrname, "SOS2") == 0 )
    351 {
    352 SCIP_Real* weights;
    353
    354 weights = SCIPgetWeightsSOS2(scip, cons);
    355 assert(nvars == 0 || weights != NULL);
    356
    357 for( i = 0; i < nvars; i++ )
    358 {
    359 vals[i] = weights[i];
    360 }
    361 }
    362 else
    363 {
    364 SCIPwarningMessage(scip, "Cannot return value array for constraint of type <%s>\n", conshdlrname);
    365 *success = FALSE;
    366 }
    367
    368 return SCIP_OKAY;
    369}
    370
    371/** returns the value array of an arbitrary SCIP constraint that can be represented as a single linear constraint
    372 *
    373 * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
    374 * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
    375 *
    376 * @note The success pointer indicates if the individual contraint handler was able to return the involved values
    377 */
    379 SCIP* scip, /**< SCIP data structure */
    380 SCIP_CONS* cons, /**< constraint for which the coefficients are wanted */
    381 SCIP_RATIONAL** vals, /**< array to store the coefficients of the constraint */
    382 int varssize, /**< available slots in vals array needed to check if the array is large enough */
    383 SCIP_Bool* success /**< pointer to store whether the coefficients are successfully copied */
    384 )
    385{
    386 SCIP_CONSHDLR* conshdlr;
    387 const char* conshdlrname;
    388 int nvars;
    389 int i;
    390
    391 assert(scip != NULL);
    392 assert(cons != NULL);
    393 assert(vals != NULL);
    394 assert(success != NULL);
    395
    396 conshdlr = SCIPconsGetHdlr(cons);
    397 assert(conshdlr != NULL);
    398
    399 conshdlrname = SCIPconshdlrGetName(conshdlr);
    400
    401 *success = TRUE;
    402
    403 SCIP_CALL( SCIPgetConsNVars(scip, cons, &nvars, success) );
    404
    405 if( !(*success) )
    406 {
    407 SCIPwarningMessage(scip, "Cannot return exact value array for constraint of type <%s>\n", conshdlrname);
    408 return SCIP_OKAY;
    409 }
    410
    411 if( varssize < nvars )
    412 {
    413 SCIPwarningMessage(scip, "Cannot return exact value array for constraint of type <%s> (insufficient memory provided)\n", conshdlrname);
    414 *success = FALSE;
    415 return SCIP_OKAY;
    416 }
    417
    418 if( strcmp(conshdlrname, "exactlinear") == 0 )
    419 {
    420 SCIP_RATIONAL** weights;
    421 weights = SCIPgetValsExactLinear(scip, cons);
    422 for( i = 0; i < nvars; i++ )
    423 SCIPrationalSetRational(vals[i], weights[i]);
    424 }
    425 else
    426 {
    427 SCIPwarningMessage(scip, "Cannot return exact value array for constraint of type <%s>\n", conshdlrname);
    428 *success = FALSE;
    429 }
    430
    431 return SCIP_OKAY;
    432}
    433
    434/** returns the dual farkas sol of an arbitrary SCIP constraint that can be represented as a single linear constraint
    435 *
    436 * @note The success pointer indicates if the individual contraint handler was able to return the dual farkas solution
    437 */
    439 SCIP* scip, /**< SCIP data structure */
    440 SCIP_CONS* cons, /**< constraint to get the dual farkas solution for */
    441 SCIP_Real* dualfarkas, /**< pointer to store the dual farkas solution */
    442 SCIP_Bool* success /**< pointer to store whether the dual farkas solution is successfully returned */
    443 )
    444{
    445 SCIP_CONSHDLR* conshdlr;
    446 const char* conshdlrname;
    447
    448 assert(scip != NULL);
    449 assert(cons != NULL);
    450
    451 conshdlr = SCIPconsGetHdlr(cons);
    452 assert(conshdlr != NULL);
    453 conshdlrname = SCIPconshdlrGetName(conshdlr);
    454
    455 *success = TRUE;
    456
    457 if( strcmp(conshdlrname, "linear") == 0 )
    458 {
    459 *dualfarkas = SCIPgetDualfarkasLinear(scip, cons);
    460 }
    461 else if( strcmp(conshdlrname, "setppc") == 0 )
    462 {
    463 *dualfarkas = SCIPgetDualfarkasSetppc(scip, cons);
    464 }
    465 else if( strcmp(conshdlrname, "logicor") == 0 )
    466 {
    467 *dualfarkas = SCIPgetDualfarkasLogicor(scip, cons);
    468 }
    469 else if( strcmp(conshdlrname, "knapsack") == 0 )
    470 {
    471 *dualfarkas = SCIPgetDualfarkasKnapsack(scip, cons);
    472 }
    473 else if( strcmp(conshdlrname, "varbound") == 0 )
    474 {
    475 *dualfarkas = SCIPgetDualfarkasVarbound(scip, cons);
    476 }
    477 /* these are Benders' specific constraint handlers */
    478 else if( strcmp(conshdlrname, "origbranch") == 0 || strcmp(conshdlrname, "masterbranch") == 0 )
    479 {
    480 *dualfarkas = 0.0;
    481 }
    482 else
    483 {
    484 SCIPwarningMessage(scip, "Cannot return dual farkas solution for constraint of type <%s>\n", conshdlrname);
    485 *dualfarkas = 0.0;
    486 *success = FALSE;
    487 }
    488}
    489
    490/** returns the dual sol of an arbitrary SCIP constraint that can be represented as a single linear constraint
    491 *
    492 * @note The success pointer indicates if the individual contraint handler was able to return the dual solution
    493 */
    495 SCIP* scip, /**< SCIP data structure */
    496 SCIP_CONS* cons, /**< constraint to get the dual solution for */
    497 SCIP_Real* dualsol, /**< pointer to store the dual solution */
    498 SCIP_Bool* success /**< pointer to store whether the dual solution is successfully returned */
    499 )
    500{
    501 SCIP_CONSHDLR* conshdlr;
    502 const char* conshdlrname;
    503
    504 assert(scip != NULL);
    505 assert(cons != NULL);
    506
    507 conshdlr = SCIPconsGetHdlr(cons);
    508 assert(conshdlr != NULL);
    509 conshdlrname = SCIPconshdlrGetName(conshdlr);
    510
    511 *success = TRUE;
    512
    513 if( strcmp(conshdlrname, "linear") == 0 )
    514 {
    515 *dualsol = SCIPgetDualsolLinear(scip, cons);
    516 }
    517 else if( strcmp(conshdlrname, "setppc") == 0 )
    518 {
    519 *dualsol = SCIPgetDualsolSetppc(scip, cons);
    520 }
    521 else if( strcmp(conshdlrname, "logicor") == 0 )
    522 {
    523 *dualsol = SCIPgetDualsolLogicor(scip, cons);
    524 }
    525 else if( strcmp(conshdlrname, "knapsack") == 0 )
    526 {
    527 *dualsol = SCIPgetDualsolKnapsack(scip, cons);
    528 }
    529 else if( strcmp(conshdlrname, "varbound") == 0 )
    530 {
    531 *dualsol = SCIPgetDualsolVarbound(scip, cons);
    532 }
    533 /* these are Benders' specific constraint handlers */
    534 else if( strcmp(conshdlrname, "origbranch") == 0 || strcmp(conshdlrname, "masterbranch") == 0 )
    535 {
    536 *dualsol = 0.0;
    537 }
    538 else
    539 {
    540 SCIPwarningMessage(scip, "Cannot return dual solution for constraint of type <%s>\n", conshdlrname);
    541 *dualsol = 0.0;
    542 *success = FALSE;
    543 }
    544}
    545
    546/** returns the row of an arbitrary SCIP constraint that can be represented as a single linear constraint
    547 * or NULL of no row is available
    548 */
    550 SCIP* scip, /**< SCIP data structure */
    551 SCIP_CONS* cons /**< constraint for which row is queried */
    552 )
    553{
    554 SCIP_CONSHDLR* conshdlr;
    555 const char* conshdlrname;
    556
    557 assert(scip != NULL);
    558 assert(cons != NULL);
    559
    560 conshdlr = SCIPconsGetHdlr(cons);
    561 assert(conshdlr != NULL);
    562 conshdlrname = SCIPconshdlrGetName(conshdlr);
    563
    564 if( strcmp(conshdlrname, "linear") == 0 )
    565 {
    566 return SCIPgetRowLinear(scip, cons);
    567 }
    568 else if( strcmp(conshdlrname, "setppc") == 0 )
    569 {
    570 return SCIPgetRowSetppc(scip, cons);
    571 }
    572 else if( strcmp(conshdlrname, "logicor") == 0 )
    573 {
    574 return SCIPgetRowLogicor(scip, cons);
    575 }
    576 else if( strcmp(conshdlrname, "knapsack") == 0 )
    577 {
    578 return SCIPgetRowKnapsack(scip, cons);
    579 }
    580 else if( strcmp(conshdlrname, "varbound") == 0 )
    581 {
    582 return SCIPgetRowVarbound(scip, cons);
    583 }
    584 else if( strcmp(conshdlrname, "exactlinear") == 0 )
    585 {
    586 return SCIPgetRowExactLinear(scip, cons);
    587 }
    588#ifdef SCIP_DEBUG
    589 else
    590 {
    591 SCIPdebugMsg(scip, "Cannot return row for constraint of type <%s>\n", conshdlrname);
    592 }
    593#endif
    594
    595 return NULL;
    596}
    597
    598/** creates and returns the row of an arbitrary SCIP constraint that can be represented as a single linear constraint */
    600 SCIP* scip, /**< SCIP data structure */
    601 SCIP_CONS* cons, /**< constraint for which row is queried */
    602 SCIP_ROW** row /**< pointer to store the created row */
    603 )
    604{
    605 SCIP_CONSHDLR* conshdlr;
    606 const char* conshdlrname;
    607
    608 assert(scip != NULL);
    609 assert(cons != NULL);
    610
    611 conshdlr = SCIPconsGetHdlr(cons);
    612 assert(conshdlr != NULL);
    613 conshdlrname = SCIPconshdlrGetName(conshdlr);
    614
    616 {
    617 *row = SCIPconsGetRow(scip, cons);
    618 return SCIP_OKAY;
    619 }
    620
    621 if( strcmp(conshdlrname, "linear") == 0 )
    622 {
    623 *row = SCIPgetRowLinear(scip, cons);
    624 if( *row == NULL )
    625 {
    627 *row = SCIPgetRowLinear(scip, cons);
    628 }
    629 }
    630 else if( strcmp(conshdlrname, "setppc") == 0 )
    631 {
    632 *row = SCIPgetRowSetppc(scip, cons);
    633 if( *row == NULL )
    634 {
    636 *row = SCIPgetRowSetppc(scip, cons);
    637 }
    638 }
    639 else if( strcmp(conshdlrname, "logicor") == 0 )
    640 {
    641 *row = SCIPgetRowLogicor(scip, cons);
    642 if( *row == NULL )
    643 {
    645 *row = SCIPgetRowLogicor(scip, cons);
    646 }
    647 }
    648 else if( strcmp(conshdlrname, "knapsack") == 0 )
    649 {
    650 *row = SCIPgetRowKnapsack(scip, cons);
    651 if( *row == NULL )
    652 {
    654 *row = SCIPgetRowKnapsack(scip, cons);
    655 }
    656 }
    657 else if( strcmp(conshdlrname, "varbound") == 0 )
    658 {
    659 *row = SCIPgetRowVarbound(scip, cons);
    660 if( *row == NULL )
    661 {
    663 *row = SCIPgetRowVarbound(scip, cons);
    664 }
    665 }
    666
    667 return SCIP_OKAY;
    668}
    669
    670/** adds the given variable to the input constraint.
    671 * If the constraint is setppc or logicor the value is ignored. If the constraint is knapsack, then the value is
    672 * converted to an int. A warning is passed if the SCIP_Real is not an integer.
    673 * TODO: Allow val to be a pointer.
    674 */
    676 SCIP* scip, /**< SCIP data structure */
    677 SCIP_CONS* cons, /**< constraint for which row is queried */
    678 SCIP_VAR* var, /**< variable of the constraint entry */
    679 SCIP_Real val /**< the coefficient of the constraint entry */
    680 )
    681{
    682 SCIP_CONSHDLR* conshdlr;
    683 const char* conshdlrname;
    684
    685 assert(scip != NULL);
    686 assert(cons != NULL);
    687 assert(var != NULL);
    688
    689 conshdlr = SCIPconsGetHdlr(cons);
    690 assert(conshdlr != NULL);
    691 conshdlrname = SCIPconshdlrGetName(conshdlr);
    692
    693 if( strcmp(conshdlrname, "linear") == 0 )
    694 {
    695 SCIP_CALL( SCIPaddCoefLinear(scip, cons, var, val) );
    696 }
    697 else if( strcmp(conshdlrname, "setppc") == 0 )
    698 {
    699 SCIP_CALL( SCIPaddCoefSetppc(scip, cons, var) );
    700 }
    701 else if( strcmp(conshdlrname, "logicor") == 0 )
    702 {
    703 SCIP_CALL( SCIPaddCoefLogicor(scip, cons, var) );
    704 }
    705 else if( strcmp(conshdlrname, "knapsack") == 0 )
    706 {
    707 if( !SCIPisIntegral(scip, val) )
    708 {
    709 SCIPerrorMessage("The coefficient value %g is not valid. "
    710 "The coefficient for a knapsack constraint must be integer.\n", val);
    711 return SCIP_ERROR;
    712 }
    713
    714 SCIP_CALL( SCIPaddCoefKnapsack(scip, cons, var, (SCIP_Longint)val) );
    715 }
    716 else if( strcmp(conshdlrname, "varbound") == 0 )
    717 {
    718 SCIPerrorMessage("Sorry, can't add coefficient for constraint of type <%s>\n", conshdlrname);
    719 return SCIP_ERROR;
    720 }
    721 else
    722 {
    723 SCIPerrorMessage("Sorry, can't add coefficient for constraint of type <%s>\n", conshdlrname);
    724 return SCIP_ERROR;
    725 }
    726
    727 return SCIP_OKAY;
    728}
    Constraint handler for the set partitioning / packing / covering constraints .
    common defines and data types used in all packages of SCIP
    #define NULL
    Definition: def.h:248
    #define SCIP_Longint
    Definition: def.h:141
    #define SCIP_INVALID
    Definition: def.h:178
    #define SCIP_Bool
    Definition: def.h:91
    #define SCIP_Real
    Definition: def.h:156
    #define TRUE
    Definition: def.h:93
    #define FALSE
    Definition: def.h:94
    #define SCIP_CALL(x)
    Definition: def.h:355
    SCIP_RETCODE SCIPcreateRowLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualsolLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetVbdcoefVarbound(SCIP *scip, SCIP_CONS *cons)
    SCIP_RATIONAL * SCIPgetLhsExactLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_RETCODE SCIPcreateRowKnapsack(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_RATIONAL * SCIPgetRhsExactLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualfarkasVarbound(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real * SCIPgetWeightsSOS2(SCIP *scip, SCIP_CONS *cons)
    Definition: cons_sos2.c:2790
    SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
    SCIP_RETCODE SCIPaddCoefKnapsack(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Longint weight)
    SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualsolLogicor(SCIP *scip, SCIP_CONS *cons)
    SCIP_ROW * SCIPgetRowSetppc(SCIP *scip, SCIP_CONS *cons)
    Definition: cons_setppc.c:9718
    SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_ROW * SCIPgetRowVarbound(SCIP *scip, SCIP_CONS *cons)
    SCIP_ROW * SCIPgetRowLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_ROW * SCIPgetRowLogicor(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real * SCIPgetWeightsSOS1(SCIP *scip, SCIP_CONS *cons)
    Definition: cons_sos1.c:10844
    SCIP_RETCODE SCIPcreateRowLogicor(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualfarkasLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_RETCODE SCIPaddCoefSetppc(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
    Definition: cons_setppc.c:9573
    SCIP_Longint * SCIPgetWeightsKnapsack(SCIP *scip, SCIP_CONS *cons)
    SCIP_Longint SCIPgetCapacityKnapsack(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetLhsVarbound(SCIP *scip, SCIP_CONS *cons)
    SCIP_SETPPCTYPE SCIPgetTypeSetppc(SCIP *scip, SCIP_CONS *cons)
    Definition: cons_setppc.c:9642
    SCIP_Real SCIPgetRhsVarbound(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualfarkasLogicor(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualfarkasKnapsack(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualsolVarbound(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualsolSetppc(SCIP *scip, SCIP_CONS *cons)
    Definition: cons_setppc.c:9664
    SCIP_ROW * SCIPgetRowKnapsack(SCIP *scip, SCIP_CONS *cons)
    SCIP_RETCODE SCIPcreateRowVarbound(SCIP *scip, SCIP_CONS *cons)
    SCIP_RETCODE SCIPcreateRowSetppc(SCIP *scip, SCIP_CONS *cons)
    Definition: cons_setppc.c:9741
    SCIP_Real SCIPgetDualsolKnapsack(SCIP *scip, SCIP_CONS *cons)
    SCIP_RATIONAL ** SCIPgetValsExactLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_Real SCIPgetDualfarkasSetppc(SCIP *scip, SCIP_CONS *cons)
    Definition: cons_setppc.c:9690
    SCIP_ROW * SCIPgetRowExactLinear(SCIP *scip, SCIP_CONS *cons)
    SCIP_RETCODE SCIPaddCoefLogicor(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
    @ SCIP_SETPPCTYPE_PARTITIONING
    Definition: cons_setppc.h:87
    @ SCIP_SETPPCTYPE_COVERING
    Definition: cons_setppc.h:89
    @ SCIP_SETPPCTYPE_PACKING
    Definition: cons_setppc.h:88
    SCIP_STAGE SCIPgetStage(SCIP *scip)
    Definition: scip_general.c:444
    #define SCIPdebugMsg
    Definition: scip_message.h:78
    void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
    Definition: scip_message.c:120
    const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
    Definition: cons.c:4316
    SCIP_RETCODE SCIPgetConsNVars(SCIP *scip, SCIP_CONS *cons, int *nvars, SCIP_Bool *success)
    Definition: scip_cons.c:2621
    SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
    Definition: cons.c:8409
    void SCIPrationalSetRational(SCIP_RATIONAL *res, SCIP_RATIONAL *src)
    Definition: rational.cpp:569
    SCIP_Real SCIPinfinity(SCIP *scip)
    SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
    SCIP_RATIONAL * SCIPconsGetRhsExact(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
    Definition: misc_linear.c:176
    SCIP_Real SCIPconsGetLhs(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
    Definition: misc_linear.c:112
    void SCIPconsGetDualfarkas(SCIP *scip, SCIP_CONS *cons, SCIP_Real *dualfarkas, SCIP_Bool *success)
    Definition: misc_linear.c:438
    SCIP_RETCODE SCIPgetConsValsExact(SCIP *scip, SCIP_CONS *cons, SCIP_RATIONAL **vals, int varssize, SCIP_Bool *success)
    Definition: misc_linear.c:378
    SCIP_RETCODE SCIPconsAddCoef(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
    Definition: misc_linear.c:675
    SCIP_RETCODE SCIPgetConsVals(SCIP *scip, SCIP_CONS *cons, SCIP_Real *vals, int varssize, SCIP_Bool *success)
    Definition: misc_linear.c:253
    SCIP_RATIONAL * SCIPconsGetLhsExact(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
    Definition: misc_linear.c:213
    SCIP_Real SCIPconsGetRhs(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
    Definition: misc_linear.c:48
    void SCIPconsGetDualsol(SCIP *scip, SCIP_CONS *cons, SCIP_Real *dualsol, SCIP_Bool *success)
    Definition: misc_linear.c:494
    SCIP_RETCODE SCIPconsCreateRow(SCIP *scip, SCIP_CONS *cons, SCIP_ROW **row)
    Definition: misc_linear.c:599
    SCIP_ROW * SCIPconsGetRow(SCIP *scip, SCIP_CONS *cons)
    Definition: misc_linear.c:549
    #define SCIPerrorMessage
    Definition: pub_message.h:64
    internal miscellaneous methods for linear constraints
    SCIP callable library.
    default SCIP plugins
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    @ SCIP_ERROR
    Definition: type_retcode.h:43
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63
    @ SCIP_STAGE_INITSOLVE
    Definition: type_set.h:52
    @ SCIP_STAGE_SOLVING
    Definition: type_set.h:53