Scippy

    SCIP

    Solving Constraint Integer Programs

    lpi_clp.cpp
    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 lpi_clp.cpp
    26 * @ingroup LPIS
    27 * @brief LP interface for Clp
    28 * @author Stefan Heinz
    29 * @author Marc Pfetsch
    30 * @author John Forrest
    31 *
    32 *
    33 * Notes on this interface:
    34 *
    35 * - Currently, Clp (Version 1.16) supports two ways of adding rows/columns from arrays: One uses a
    36 * length array that for each row/column specifies the number of nonzeros to be added. The second
    37 * uses the @p beg array that gives the starting index for each row/column. We use the latter
    38 * variant. Since for LPI there should be no gaps in the corresponding arrays, i.e., every entry in
    39 * @p val and @a ind gives a nonzero entry, one can switch between the two formats. With the current
    40 * Clp implementation both formats involve an overhead:
    41 *
    42 * - For the @p beg variant, Clp gets the end of the array from the last position in @p beg
    43 * (i.e., the entry one after the last row/column) and we have to copy and extend @p beg for this
    44 * purpose. In the matrix implementation a length information is then again computed.
    45 *
    46 * - For the @p length variant, Clp computes the number of elements from this length variant and
    47 * there exists no matrix implementation that uses the length information, i.e., it is recomputed
    48 * again.
    49 *
    50 * Concluding: the implementation of Clp/CoinPackeMatrix could be improved. The functions
    51 * affected by this are SCIPlpiLoadColLP(), SCIPlpiAddCols(), SCIPlpiAddRows()
    52 *
    53 * - In former versions Clp used an "auxiliary model" that allows to save time when the model is
    54 * scaled. This is discarded from version higher than 1.8.2.
    55 *
    56 * - Clp needs the setting of several special flags to make sure that necessary data (e.g., rays etc.)
    57 * are available. If the FASTMIP option in SCIP is true, some settings that are supposed to be faster
    58 * are used. We tried to use the best settings, while still working correctly. These settings probably
    59 * have to be adapted to future Clp versions. Maybe more possibilities will appear.
    60 *
    61 * - At several places this interface corrects the return value of some Clp functions, e.g.,
    62 * isProvenPrimalInfeasible(). Currently (Version 1.16) no change in the Clp functions will be made,
    63 * but this might change in the future.
    64 *
    65 * @todo Check about using fastDual().
    66 */
    67/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    68
    69
    70#include <ClpSimplex.hpp>
    71#include <ClpPrimalColumnSteepest.hpp>
    72#include <ClpDualRowSteepest.hpp>
    73#include <CoinIndexedVector.hpp>
    74#include <ClpConfig.h>
    75#ifndef CLP_VERSION
    76#include <config_clp.h>
    77#define CLP_VERSION VERSION
    78#endif
    79
    80#include <cassert>
    81#include <cstdlib>
    82#include <iostream>
    83#include <vector>
    84#include <string>
    85
    86#include "lpi/lpi.h"
    87#include "scip/bitencode.h"
    88#include "scip/pub_message.h"
    89
    90/* do defines for windows directly her to make the lpi more independent*/
    91#ifdef _WIN32
    92#define snprintf _snprintf
    93#endif
    94
    95/* for debugging: alternatingly write files "debug_[p|d]_[0|1].mps" after each run - use with care! */
    96#ifdef LPI_CLP_DEBUG_WRITE_FILES
    97static int fileNr = 0;
    98#endif
    99
    100/* bound for accepting primal or dual sum of infeasibilities */
    101#define SUMINFEASBOUND 1.0e-3
    102
    103/** LP interface for Clp */
    105{
    106 ClpSimplex* clp; /**< Clp simiplex solver class */
    107 int* cstat; /**< array for storing column basis status */
    108 int* rstat; /**< array for storing row basis status */
    109 int cstatsize; /**< size of cstat array */
    110 int rstatsize; /**< size of rstat array */
    111 bool startscratch; /**< start from scratch? */
    112 SCIP_PRICING pricing; /**< SCIP pricing setting */
    113 bool validFactorization; /**< whether we have a valid factorization in clp */
    114 SCIP_Bool solved; /**< was the current LP solved? */
    115 bool setFactorizationFrequency; /**< store whether the factorization frequency is set */
    116 SCIP_Bool fastmip; /**< are fast mip settings turned on */
    117 int lastalgorithm; /**< type of last algorithm call (0 = none, 1 = primal, -1 = dual, 2 = barrier) */
    118};
    119
    120
    121
    122
    123
    124
    125/** Definitions for storing basis status (copied from lpi_spx.cpp) */
    126typedef SCIP_DUALPACKET COLPACKET; /* each column needs two bits of information (basic/on_lower/on_upper) */
    127#define COLS_PER_PACKET SCIP_DUALPACKETSIZE
    128typedef SCIP_DUALPACKET ROWPACKET; /* each row needs two bit of information (basic/on_lower/on_upper) */
    129#define ROWS_PER_PACKET SCIP_DUALPACKETSIZE
    130
    131/** LPi state stores basis information */
    133{
    134 int ncols; /**< number of LP columns */
    135 int nrows; /**< number of LP rows */
    136 COLPACKET* packcstat; /**< column basis status in compressed form */
    137 ROWPACKET* packrstat; /**< row basis status in compressed form */
    138};
    139
    140
    141
    142
    143/*
    144 * dynamic memory arrays
    145 */
    146
    147/** resizes cstat array to have at least num entries */
    148static
    150 SCIP_LPI* lpi, /**< LP interface structure */
    151 int num /**< minimal number of entries in array */
    152 )
    153{
    154 assert(lpi != NULL);
    155
    156 if( num > lpi->cstatsize )
    157 {
    158 int newsize;
    159
    160 newsize = MAX(2*lpi->cstatsize, num);
    161 SCIP_ALLOC( BMSreallocMemoryArray(&lpi->cstat, newsize) );
    162 lpi->cstatsize = newsize;
    163 }
    164 assert(num <= lpi->cstatsize);
    165
    166 return SCIP_OKAY;
    167}
    168
    169/** resizes rstat array to have at least num entries */
    170static
    172 SCIP_LPI* lpi, /**< LP interface structure */
    173 int num /**< minimal number of entries in array */
    174 )
    175{
    176 assert(lpi != NULL);
    177
    178 if( num > lpi->rstatsize )
    179 {
    180 int newsize;
    181
    182 newsize = MAX(2*lpi->rstatsize, num);
    183 SCIP_ALLOC( BMSreallocMemoryArray(&lpi->rstat, newsize) );
    184 lpi->rstatsize = newsize;
    185 }
    186 assert(num <= lpi->rstatsize);
    187
    188 return SCIP_OKAY;
    189}
    190
    191
    192
    193
    194/*
    195 * LPi state methods
    196 */
    197
    198/** returns the number of packets needed to store column packet information */
    199static
    201 int ncols /**< number of columns to store */
    202 )
    203{
    204 return (ncols+(int)COLS_PER_PACKET-1)/(int)COLS_PER_PACKET;
    205}
    206
    207/** returns the number of packets needed to store row packet information */
    208static
    210 int nrows /**< number of rows to store */
    211 )
    212{
    213 return (nrows+(int)ROWS_PER_PACKET-1)/(int)ROWS_PER_PACKET;
    214}
    215
    216/** store row and column basis status in a packed LPi state object */
    217static
    219 SCIP_LPISTATE* lpistate, /**< pointer to LPi state data */
    220 const int* cstat, /**< basis status of columns in unpacked format */
    221 const int* rstat /**< basis status of rows in unpacked format */
    222 )
    223{
    224 assert(lpistate != 0);
    225 assert(lpistate->packcstat != 0);
    226 assert(lpistate->packrstat != 0);
    227
    228 SCIPencodeDualBit(cstat, lpistate->packcstat, lpistate->ncols);
    229 SCIPencodeDualBit(rstat, lpistate->packrstat, lpistate->nrows);
    230}
    231
    232/** unpacks row and column basis status from a packed LPi state object */
    233static
    235 const SCIP_LPISTATE* lpistate, /**< pointer to LPi state data */
    236 int* cstat, /**< buffer for storing basis status of columns in unpacked format */
    237 int* rstat /**< buffer for storing basis status of rows in unpacked format */
    238 )
    239{
    240 assert(lpistate != 0);
    241 assert(lpistate->packcstat != 0);
    242 assert(lpistate->packrstat != 0);
    243
    244 SCIPdecodeDualBit(lpistate->packcstat, cstat, lpistate->ncols);
    245 SCIPdecodeDualBit(lpistate->packrstat, rstat, lpistate->nrows);
    246}
    247
    248/** creates LPi state information object */
    249static
    251 SCIP_LPISTATE** lpistate, /**< pointer to LPi state */
    252 BMS_BLKMEM* blkmem, /**< block memory */
    253 int ncols, /**< number of columns to store */
    254 int nrows /**< number of rows to store */
    255 )
    256{
    257 assert(lpistate != 0);
    258 assert(blkmem != 0);
    259 assert(ncols >= 0);
    260 assert(nrows >= 0);
    261
    262 SCIP_ALLOC( BMSallocBlockMemory(blkmem, lpistate) );
    263 SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packcstat, colpacketNum(ncols)) );
    264 SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packrstat, rowpacketNum(nrows)) );
    265
    266 return SCIP_OKAY;
    267}
    268
    269/** frees LPi state information */
    270static
    272 SCIP_LPISTATE** lpistate, /**< pointer to LPi state information (like basis information) */
    273 BMS_BLKMEM* blkmem /**< block memory */
    274 )
    275{
    276 assert(blkmem != 0);
    277 assert(lpistate != 0);
    278 assert(*lpistate != 0);
    279
    280 BMSfreeBlockMemoryArray(blkmem, &(*lpistate)->packcstat, colpacketNum((*lpistate)->ncols));
    281 BMSfreeBlockMemoryArray(blkmem, &(*lpistate)->packrstat, rowpacketNum((*lpistate)->nrows));
    282 BMSfreeBlockMemory(blkmem, lpistate);
    283}
    284
    285
    286
    287
    288
    289/*
    290 * local methods
    291 */
    292
    293/** marks the current LP to be unsolved */
    294static
    296 SCIP_LPI* lpi /**< LP interface structure */
    297 )
    298{
    299 assert(lpi != NULL);
    300 lpi->solved = FALSE;
    301}
    302
    303/** set factorization frequency */
    304static
    306 SCIP_LPI* lpi /**< LP interface structure */
    307 )
    308{
    309 assert(lpi != NULL);
    310
    311 /* set the factorization frequency only once */
    312 if ( lpi->setFactorizationFrequency )
    313 return;
    314
    315 lpi->clp->defaultFactorizationFrequency();
    316 lpi->setFactorizationFrequency = true;
    317}
    318
    319/** set fastmip parameters of Clp */
    320static
    322 SCIP_LPI* lpi /**< LP interface structure */
    323 )
    324{
    325 assert(lpi != NULL);
    326
    327 lpi->fastmip = TRUE;
    328
    329 /* Perturbation:
    330 * 50 - switch on perturbation
    331 * 100 - auto perturb if takes too long (1.0e-6 largest nonzero)
    332 * 101 - we are perturbed
    333 * 102 - don't try perturbing again
    334 * - default is 100
    335 * - others are for playing
    336 *
    337 * for Clp 1.8 stable: 50 seems to be 10% faster than 100
    338 */
    339 lpi->clp->setPerturbation(50);
    340
    341 /* Special options description from ClpModell.hpp:
    342 * 1 - Don't keep changing infeasibility weight
    343 * 2 - Keep nonLinearCost round solves
    344 * 4 - Force outgoing variables to exact bound (primal)
    345 * 8 - Safe to use dense initial factorization
    346 * 16 - Just use basic variables for operation if column generation
    347 * 32 - Create ray even in BAB
    348 * 64 - Treat problem as feasible until last minute (i.e. minimize infeasibilities)
    349 * 128 - Switch off all matrix sanity checks
    350 * 256 - No row copy
    351 * 512 - If not in values pass, solution guaranteed, skip as much as possible
    352 * 1024 - In branch and bound
    353 * 2048 - Don't bother to re-factorize if < 20 iterations
    354 * 4096 - Skip some optimality checks
    355 * 8192 - Do Primal when cleaning up primal
    356 * 16384 - In fast dual (so we can switch off things)
    357 * 32768 - called from Osi
    358 * 65536 - keep arrays around as much as possible (also use maximumR/C)
    359 * 131072 - transposeTimes is -1.0 and can skip basic and fixed
    360 * 262144 - extra copy of scaled matrix
    361 * 524288 - Clp fast dual
    362 * 1048576 - don't need to finish dual (can return 3)
    363 * 2097152 - ray even if >2 pivots AND if problem is "crunched"
    364 * 4194304 - don't scale integer variables
    365 * 8388608 - Idiot when not really sure about it
    366 * 16777216 - zero costs!
    367 * 0x1000000 - is Cbc (and in branch and bound)
    368 * 0x2000000 - is in a different branch and bound
    369 *
    370 * Comments:
    371 * 2 - Nonlinear costs are used in primal for infeasibility weight.
    372 * 4 - In anti-degeneracy operations can move variables just off a bound.
    373 * 8 - Means dense nucleus in factorization - normally not safe in first factorization as
    374 * singularity handling is not useful. Is switched on if going from dual to primal or vv.
    375 * 16 - Used for "real" column generation.
    376 * 32 - Currently unclear, does not lead to produce ray
    377 * 64 - Good idea, since in B&B most problems are feasible.
    378 * 128 - Assumes user will not create tiny or duplicate elements.
    379 * 256 - Normally Clp keeps a scaled row copy for speed. For very large problems you might want to turn it off.
    380 * 512 - Means nonbasic variables should be at bounds and basis will be reasonable.
    381 * 1024 - In branch and bound - makes some rays available?
    382 * 2048 - Unclear.
    383 * 4096 - Skip some optimality checks.
    384 * 8192 - If the primal has a perturbed problem and needs to clean up, it normally uses dual - but in some cases can be better to use primal.
    385 * 16384 - Used internally.
    386 * 32768 - Just switches off some messages, e.g., empty problem.
    387 * 65536 - Unclear.
    388 * 131072 - Used internally.
    389 * 262144 - Normally Clp has unscaled column copy of matrix - this makes an extra scaled copy.
    390 * 524288 - Used internally.
    391 * 1048576 - Only set by fastDual (used internally).
    392 * 2097152 - This was fixed in 03/2018 to make sure that a ray is produced.
    393 * 4194304 - Not needed for us.
    394 * 8388608 - Unclear.
    395 * 0x1000000 - main point: does allow use of disaster handler, but also other decisions in code
    396 * 0x2000000 - main point: does allow use of disaster handler, but also other decisions in code
    397 *
    398 * Cbc seems to use the following special options:
    399 * lpi->clp->setSpecialOptions(64|128|1024|2048|4096|32768|262144|0x01000000);
    400 * Sometimes 512+8192 and 8192 or 8 are used as well.
    401 */
    402
    403 // default settings: 32|64|128|1024|32768|262144|2097152|0x2000000
    404 // Additional flags: 512, 2048, 4096 in order to speed up things.
    405 // lpi->clp->setSpecialOptions(32|64|128|512|1024|2048|4096|32768|262144|2097152|0x2000000);
    406
    407 // set default options
    408 lpi->clp->setSpecialOptions(32|64|128|1024|32768|262144|2097152|0x2000000);
    409
    410 // Do not change moreSpecialOptions().
    411
    412 // let memory grow only (do not shrink) - [needs specialOptions & 65536 != 0]
    413 // does not seem to work
    414 // lpi->clp->setPersistenceFlag(1);
    415}
    416
    417/** unset fastmip parameters of Clp (reset to default parameters) */
    418static
    420 SCIP_LPI* lpi /**< LP interface structure */
    421 )
    422{
    423 assert(lpi != NULL);
    424
    425 lpi->fastmip = FALSE;
    426
    427 // reset to default value:
    428 lpi->clp->setPerturbation(100);
    429
    430 // set default special options (see SCIPlpiCreate())
    431 lpi->clp->setSpecialOptions(32|64|128|1024|32768|262144|2097152|0x2000000);
    432
    433 // set default more special options
    434 lpi->clp->setMoreSpecialOptions(8192);
    435
    436 // turn off memory enlargement
    437 lpi->clp->setPersistenceFlag(0);
    438}
    439
    440
    441/*
    442 * LP Interface Methods
    443 */
    444
    445
    446/*
    447 * Miscellaneous Methods
    448 */
    449
    450/**@name Miscellaneous Methods */
    451/**@{ */
    452
    453/** gets name and version of LP solver */
    455 void
    456 )
    457{
    458 // Currently Clp has no function to get version, so we hard code it ...
    459 return "Clp " CLP_VERSION;
    460}
    461
    462/** gets description of LP solver (developer, webpage, ...) */
    464 void
    465 )
    466{
    467 return "COIN-OR Linear Programming Solver developed by J. Forrest et.al. (projects.coin-or.org/Clp)";
    468}
    469
    470/** gets pointer for LP solver - use only with great care */
    472 SCIP_LPI* lpi /**< pointer to an LP interface structure */
    473 )
    474{
    475 assert(lpi != NULL);
    476 return (void*) lpi->clp;
    477}
    478
    479/** pass integrality information to LP solver */
    481 SCIP_LPI* lpi, /**< pointer to an LP interface structure */
    482 int ncols, /**< length of integrality array */
    483 int* intInfo /**< integrality array (0: continuous, 1: integer). May be NULL iff ncols is 0. */
    484 )
    485{
    486 assert(lpi != NULL);
    487
    488 SCIPerrorMessage("SCIPlpiSetIntegralityInformation() has not been implemented yet.\n");
    489
    490 return SCIP_LPERROR;
    491}
    492
    493/** informs about availability of a primal simplex solving method */
    495 void
    496 )
    497{
    498 return TRUE;
    499}
    500
    501/** informs about availability of a dual simplex solving method */
    503 void
    504 )
    505{
    506 return TRUE;
    507}
    508
    509/** informs about availability of a barrier solving method */
    511 void
    512 )
    513{
    514 return TRUE;
    515}
    516
    517
    518/**@} */
    519
    520
    521
    522
    523/*
    524 * LPI Creation and Destruction Methods
    525 */
    526
    527/**@name LPI Creation and Destruction Methods */
    528/**@{ */
    529
    530/** creates an LP problem object */
    532 SCIP_LPI** lpi, /**< pointer to an LP interface structure */
    533 SCIP_MESSAGEHDLR* messagehdlr, /**< message handler to use for printing messages, or NULL */
    534 const char* name, /**< problem name */
    535 SCIP_OBJSEN objsen /**< objective sense */
    536 )
    537{
    538 assert(lpi != NULL);
    539 assert(name != NULL);
    540
    541 SCIPdebugMessage("calling SCIPlpiCreate()\n");
    542
    543 // create lpi object
    545 (*lpi)->clp = new ClpSimplex();
    546 (*lpi)->cstat = 0;
    547 (*lpi)->rstat = 0;
    548 (*lpi)->cstatsize = 0;
    549 (*lpi)->rstatsize = 0;
    550 (*lpi)->startscratch = true;
    551 (*lpi)->pricing = SCIP_PRICING_LPIDEFAULT;
    552 (*lpi)->validFactorization = false;
    553 (*lpi)->setFactorizationFrequency = false;
    554 (*lpi)->fastmip = FALSE;
    555 (*lpi)->lastalgorithm = 0;
    556 invalidateSolution(*lpi);
    557
    558 // if you want to use saveModel()
    559 // (*lpi)->clp->setLengthNames(255);
    560
    561 // set pricing routines
    562
    563 // for primal:
    564 // 0 is exact devex,
    565 // 1 full steepest,
    566 // 2 is partial exact devex
    567 // 3 switches between 0 and 2 depending on factorization
    568 // 4 starts as partial dantzig/devex but then may switch between 0 and 2.
    569 // - currently (Clp 1.8stable) default is 3
    570 ClpPrimalColumnSteepest primalSteepest;
    571 (*lpi)->clp->setPrimalColumnPivotAlgorithm(primalSteepest);
    572
    573 // for dual:
    574 // 0 is uninitialized,
    575 // 1 full,
    576 // 2 is partial uninitialized,
    577 // 3 starts as 2 but may switch to 1.
    578 // - currently (Clp 1.8stable) default is 3
    579 ClpDualRowSteepest dualSteepest;
    580 (*lpi)->clp->setDualRowPivotAlgorithm(dualSteepest);
    581
    582 // set problem name
    583 (*lpi)->clp->setStrParam(ClpProbName, std::string(name) );
    584
    585 // set objective sense: SCIP values are the same as the ones for Clp
    586 (*lpi)->clp->setOptimizationDirection(objsen);
    587
    588 // turn off output by default
    589 (*lpi)->clp->setLogLevel(0);
    590
    591 // turn on auto scaling by default
    592 (*lpi)->clp->scaling(3);
    593
    594 // set default special options (similar to Cbc):
    595 // 32 - Create ray even in BAB
    596 // 64 - good idea to be fast
    597 // 128 - Assumes user will not create tiny or duplicate elements.
    598 // 1024 - In branch and bound.
    599 // 32768 - Just switches off some messages, e.g., empty problem.
    600 // 262144 - extra copy of scaled matrix
    601 // 2097152 - ray even if >2 pivots AND if problem is "crunched"
    602 // 0x2000000 - is in a different branch and bound
    603 (*lpi)->clp->setSpecialOptions(32|64|128|1024|32768|262144|2097152|0x2000000);
    604
    605 /* More special options:
    606 * 1 bit - if presolve says infeasible in ClpSolve return
    607 * 2 bit - if presolved problem infeasible return
    608 * 4 bit - keep arrays like upper_ around
    609 * 8 bit - no free or superBasic variables
    610 * 16 bit - if checking replaceColumn accuracy before updating
    611 * 32 bit - say optimal if primal feasible!
    612 * 64 bit - give up easily in dual (and say infeasible)
    613 * 128 bit - no objective, 0-1 and in B&B
    614 * 256 bit - in primal from dual or vice versa
    615 * 512 bit - alternative use of solveType_
    616 * 1024 bit - don't do row copy of factorization
    617 * 2048 bit - perturb in complete fathoming
    618 * 4096 bit - try more for complete fathoming
    619 * 8192 bit - don't even think of using primal if user asks for dual (and vv)
    620 * 16384 bit - in initialSolve so be more flexible
    621 * 32768 bit - don't swap algorithms from dual if small infeasibility
    622 * 65536 bit - perturb in postsolve cleanup (even if < 10000 rows)
    623 * 131072 bit - initial stateDualColumn
    624 * 524288 bit - stop when primal feasible
    625 * 1048576 bit - don't perturb even if long time
    626 * 2097152 bit - no primal in fastDual2 if feasible
    627 * 4194304 bit - tolerances have been changed by code
    628 * 8388608 bit - tolerances are dynamic (at first)
    629 * 16777216 bit - if factorization kept can still declare optimal at once
    630 */
    631
    632 // set default more special options:
    633 (*lpi)->clp->setMoreSpecialOptions(8192);
    634
    635 // set default pricing
    636 SCIP_CALL( SCIPlpiSetIntpar(*lpi, SCIP_LPPAR_PRICING, (int)(*lpi)->pricing) );
    637
    638 return SCIP_OKAY;
    639}
    640
    641
    642/** deletes an LP problem object */
    644 SCIP_LPI** lpi /**< pointer to an LP interface structure */
    645 )
    646{
    647 assert(lpi != NULL);
    648 assert(*lpi != 0);
    649 assert((*lpi)->clp != 0);
    650
    651 SCIPdebugMessage("calling SCIPlpiFree()\n");
    652
    653 /* free LP */
    654 delete (*lpi)->clp;
    655
    656 /* free memory */
    657 BMSfreeMemoryArrayNull(&(*lpi)->cstat);
    658 BMSfreeMemoryArrayNull(&(*lpi)->rstat);
    659 BMSfreeMemory(lpi);
    660
    661 return SCIP_OKAY;
    662}
    663
    664/**@} */
    665
    666
    667
    668
    669/*
    670 * Modification Methods
    671 */
    672
    673/**@name Modification Methods */
    674/**@{ */
    675
    676/** copies LP data with column matrix into LP solver */
    678 SCIP_LPI* lpi, /**< LP interface structure */
    679 SCIP_OBJSEN objsen, /**< objective sense */
    680 int ncols, /**< number of columns */
    681 const SCIP_Real* obj, /**< objective function values of columns */
    682 const SCIP_Real* lb, /**< lower bounds of columns */
    683 const SCIP_Real* ub, /**< upper bounds of columns */
    684 char** colnames, /**< column names, or NULL */
    685 int nrows, /**< number of rows */
    686 const SCIP_Real* lhs, /**< left hand sides of rows */
    687 const SCIP_Real* rhs, /**< right hand sides of rows */
    688 char** rownames, /**< row names, or NULL */
    689 int nnonz, /**< number of nonzero elements in the constraint matrix */
    690 const int* beg, /**< start index of each column in ind- and val-array */
    691 const int* ind, /**< row indices of constraint matrix entries */
    692 const SCIP_Real* val /**< values of constraint matrix entries */
    693 )
    694{
    695#ifndef NDEBUG
    696 {
    697 int j;
    698 for( j = 0; j < nnonz; j++ )
    699 assert( val[j] != 0 );
    700 }
    701#endif
    702
    703 SCIPdebugMessage("calling SCIPlpiLoadColLP()\n");
    704
    705 assert(lpi != NULL);
    706 assert(lpi->clp != NULL);
    707 assert(lhs != NULL);
    708 assert(rhs != NULL);
    709 assert(obj != NULL);
    710 assert(lb != NULL);
    711 assert(ub != NULL);
    712 assert(beg != NULL);
    713 assert(ind != NULL);
    714 assert(val != NULL);
    715
    716 assert( nnonz > beg[ncols-1] );
    717
    719
    720 ClpSimplex* clp = lpi->clp;
    721
    722 // copy beg-array
    723 int* mybeg = NULL;
    724 SCIP_ALLOC( BMSallocMemoryArray(&mybeg, ncols + 1) );
    725 BMScopyMemoryArray(mybeg, beg, ncols);
    726 mybeg[ncols] = nnonz; // add additional entry at end
    727
    728 // load problem
    729 clp->loadProblem(ncols, nrows, mybeg, ind, val, lb, ub, obj, lhs, rhs);
    730 BMSfreeMemoryArray( &mybeg );
    731
    732 // set objective sense
    733 clp->setOptimizationDirection(objsen);
    734
    735 // copy column and rownames if necessary
    736 if ( colnames || rownames )
    737 {
    738 std::vector<std::string> columnNames(ncols);
    739 std::vector<std::string> rowNames(nrows);
    740 if (colnames)
    741 {
    742 for (int j = 0; j < ncols; ++j)
    743 columnNames[j].assign(colnames[j]);
    744 }
    745 if (rownames)
    746 {
    747 for (int i = 0; i < ncols; ++i)
    748 rowNames[i].assign(rownames[i]);
    749 }
    750 clp->copyNames(rowNames, columnNames);
    751 }
    752
    753 return SCIP_OKAY;
    754}
    755
    756
    757/** adds columns to the LP */
    759 SCIP_LPI* lpi, /**< LP interface structure */
    760 int ncols, /**< number of columns to be added */
    761 const SCIP_Real* obj, /**< objective function values of new columns */
    762 const SCIP_Real* lb, /**< lower bounds of new columns */
    763 const SCIP_Real* ub, /**< upper bounds of new columns */
    764 char** colnames, /**< column names, or 0 */
    765 int nnonz, /**< number of nonzero elements to be added to the constraint matrix */
    766 const int* beg, /**< start index of each column in ind- and val-array, or 0 if nnonz == 0 */
    767 const int* ind, /**< row indices of constraint matrix entries, or 0 if nnonz == 0 */
    768 const SCIP_Real* val /**< values of constraint matrix entries, or 0 if nnonz == 0 */
    769 )
    770{
    771 SCIPdebugMessage("calling SCIPlpiAddCols()\n");
    772
    773 assert(lpi != NULL);
    774 assert(lpi->clp != NULL);
    775 assert(obj != NULL);
    776 assert(lb != NULL);
    777 assert(ub != NULL);
    778 assert(nnonz == 0 || beg != NULL);
    779 assert(nnonz == 0 || ind != NULL);
    780 assert(nnonz == 0 || val != NULL);
    781 assert(nnonz >= 0);
    782 assert(ncols >= 0);
    783
    785
    786 // store number of columns for later
    787 int numCols = lpi->clp->getNumCols();
    788
    789 // copy beg-array (if not 0)
    790 int* mybeg = NULL;
    791 SCIP_ALLOC( BMSallocMemoryArray(&mybeg, ncols + 1) );
    792
    793 // if columns are not empty
    794 if ( nnonz != 0 )
    795 {
    796#ifndef NDEBUG
    797 {
    798 int j;
    799 for( j = 0; j < nnonz; j++ )
    800 {
    801 assert( val[j] != 0.0 );
    802 /* perform check that no new rows are added - this is forbidden */
    803 assert( 0 <= ind[j] /*&& ind[j] < lpi->nrows*/ );
    804 }
    805 }
    806#endif
    807 BMScopyMemoryArray(mybeg, beg, ncols);
    808 mybeg[ncols] = nnonz; // add additional entry at end
    809
    810 // add columns
    811 lpi->clp->addColumns(ncols, lb, ub, obj, mybeg, ind, val);
    812 }
    813 else
    814 {
    815 for (int j = 0; j <= ncols; ++j)
    816 mybeg[j] = 0;
    817
    818 // add empty columns
    819 lpi->clp->addColumns(ncols, lb, ub, obj, mybeg, 0, 0);
    820 }
    821 BMSfreeMemoryArray(&mybeg);
    822
    823 // copy columnnames if necessary
    824 if ( colnames )
    825 {
    826 std::vector<std::string> columnNames(ncols);
    827 for (int j = 0; j < ncols; ++j)
    828 columnNames[j].assign(colnames[j]);
    829 lpi->clp->copyColumnNames(columnNames, numCols, numCols + ncols);
    830 }
    831
    832 return SCIP_OKAY;
    833}
    834
    835
    836/** deletes all columns in the given range from LP */
    838 SCIP_LPI* lpi, /**< LP interface structure */
    839 int firstcol, /**< first column to be deleted */
    840 int lastcol /**< last column to be deleted */
    841 )
    842{
    843 assert(lpi != NULL);
    844 assert(lpi->clp != NULL);
    845 assert(firstcol >= 0);
    846 assert(lastcol < lpi->clp->numberColumns());
    847 assert(firstcol <= lastcol + 1);
    848
    849 SCIPdebugMessage("calling SCIPlpiDelCols()\n");
    850
    851 // handle empty range
    852 if( firstcol > lastcol )
    853 return SCIP_OKAY;
    854
    856
    857 // Current Clp version (1.8) can't delete a range of columns; we have to use deleteColumns (see SCIPlpiDelColset)
    858 int num = lastcol-firstcol+1;
    859 int* which = NULL;
    860 SCIP_ALLOC( BMSallocMemoryArray( &which, num) );;
    861
    862 // fill array with interval
    863 for (int j = firstcol; j <= lastcol; ++j)
    864 which[j - firstcol] = j;
    865
    866 lpi->clp->deleteColumns(num, which);
    867 BMSfreeMemoryArray( &which );
    868
    869 return SCIP_OKAY;
    870}
    871
    872
    873/** deletes columns from SCIP_LPI; the new position of a column must not be greater that its old position */
    875 SCIP_LPI* lpi, /**< LP interface structure */
    876 int* dstat /**< deletion status of columns
    877 * input: 1 if column should be deleted, 0 if not
    878 * output: new position of column, -1 if column was deleted */
    879 )
    880{
    881 SCIPdebugMessage("calling SCIPlpiDelColset()\n");
    882
    883 assert(lpi != NULL);
    884 assert(lpi->clp != NULL);
    885 assert(dstat != NULL);
    886
    888
    889 // transform dstat information
    890 int ncols = lpi->clp->getNumCols();
    891 int* which = NULL;
    892 SCIP_ALLOC( BMSallocMemoryArray( &which, ncols) );
    893 int cnt = 0;
    894 for (int j = 0; j < ncols; ++j)
    895 {
    896 if ( dstat[j] == 1 )
    897 which[cnt++] = j;
    898 }
    899 lpi->clp->deleteColumns(cnt, which);
    900 BMSfreeMemoryArray(&which);
    901
    902 // update dstat
    903 cnt = 0;
    904 for (int j = 0; j < ncols; ++j)
    905 {
    906 if ( dstat[j] == 1 )
    907 {
    908 dstat[j] = -1;
    909 ++cnt;
    910 }
    911 else
    912 dstat[j] = j - cnt;
    913 }
    914
    915 return SCIP_OKAY;
    916}
    917
    918
    919/** adds rows to the LP */
    921 SCIP_LPI* lpi, /**< LP interface structure */
    922 int nrows, /**< number of rows to be added */
    923 const SCIP_Real* lhs, /**< left hand sides of new rows */
    924 const SCIP_Real* rhs, /**< right hand sides of new rows */
    925 char** rownames, /**< row names, or NULL */
    926 int nnonz, /**< number of nonzero elements to be added to the constraint matrix */
    927 const int* beg, /**< start index of each row in ind- and val-array, or NULL if nnonz == 0 */
    928 const int* ind, /**< column indices of constraint matrix entries, or NULL if nnonz == 0 */
    929 const SCIP_Real* val /**< values of constraint matrix entries, or NULL if nnonz == 0 */
    930 )
    931{
    932 SCIPdebugMessage("calling SCIPlpiAddRows()\n");
    933
    934 assert(lpi != NULL);
    935 assert(lpi->clp != NULL);
    936 assert(lhs != NULL);
    937 assert(rhs != NULL);
    938 assert(nnonz == 0 || beg != NULL);
    939 assert(nnonz == 0 || ind != NULL);
    940 assert(nnonz == 0 || val != NULL);
    941
    943
    944 // store number of rows for later use
    945 int numRows = lpi->clp->getNumRows();
    946
    947 int* mybeg = NULL;
    948 SCIP_ALLOC( BMSallocMemoryArray( &mybeg, nrows + 1) );
    949
    950 if ( nnonz > 0 )
    951 {
    952#ifndef NDEBUG
    953 /* perform check that no new columns are added - this is likely to be a mistake */
    954 int ncols = lpi->clp->getNumCols();
    955 for (int j = 0; j < nnonz; ++j)
    956 {
    957 assert( val[j] != 0.0 );
    958 assert( 0 <= ind[j] && ind[j] < ncols );
    959 }
    960#endif
    961
    962 // copy beg-array
    963 BMScopyMemoryArray( mybeg, beg, nrows);
    964 mybeg[nrows] = nnonz; // add additional entry at end
    965
    966 // add rows
    967 lpi->clp->addRows(nrows, lhs, rhs, mybeg, ind, val);
    968 }
    969 else
    970 {
    971 // add empty rows
    972 for (int i = 0; i <= nrows; ++i)
    973 mybeg[i] = 0;
    974 lpi->clp->addRows(nrows, lhs, rhs, mybeg, 0, 0);
    975 }
    976 BMSfreeMemoryArray( &mybeg );
    977
    978 // copy rownames if necessary
    979 if ( rownames )
    980 {
    981 std::vector<std::string> rowNames(nrows);
    982 for (int j = 0; j < nrows; ++j)
    983 rowNames[j].assign(rownames[j]);
    984 lpi->clp->copyRowNames(rowNames, numRows, numRows + nrows);
    985 }
    986
    987 return SCIP_OKAY;
    988}
    989
    990
    991/** deletes all rows in the given range from LP */
    993 SCIP_LPI* lpi, /**< LP interface structure */
    994 int firstrow, /**< first row to be deleted */
    995 int lastrow /**< last row to be deleted */
    996 )
    997{
    998 assert(lpi != NULL);
    999 assert(lpi->clp != NULL);
    1000 assert(firstrow >= 0);
    1001 assert(lastrow < lpi->clp->numberRows());
    1002 assert(firstrow <= lastrow + 1);
    1003
    1004 SCIPdebugMessage("calling SCIPlpiDelRows() (number: %d)\n", lastrow-firstrow+1);
    1005
    1006 // handle empty range
    1007 if( firstrow > lastrow )
    1008 return SCIP_OKAY;
    1009
    1010 invalidateSolution(lpi);
    1011
    1012 // Current Clp version (1.8) can't delete a range of rows; we have to use deleteRows (see SCIPlpiDelRowset)
    1013 int num = lastrow-firstrow+1;
    1014 int* which = NULL;
    1015 SCIP_ALLOC( BMSallocMemoryArray( &which, num) );
    1016
    1017 // fill array with interval
    1018 for (int i = firstrow; i <= lastrow; ++i)
    1019 which[i - firstrow] = i;
    1020
    1021 lpi->clp->deleteRows(num, which);
    1022
    1023 BMSfreeMemoryArray( &which );
    1024
    1025 return SCIP_OKAY;
    1026}
    1027
    1028
    1029/** deletes rows from SCIP_LP; the new position of a row must not be greater that its old position */
    1031 SCIP_LPI* lpi, /**< LP interface structure */
    1032 int* dstat /**< deletion status of rows
    1033 * input: 1 if row should be deleted, 0 if not
    1034 * output: new position of row, -1 if row was deleted */
    1035 )
    1036{
    1037 SCIPdebugMessage("calling SCIPlpiDelRowset()\n");
    1038
    1039 assert(lpi != NULL);
    1040 assert(lpi->clp != NULL);
    1041 assert(dstat != 0);
    1042
    1043 invalidateSolution(lpi);
    1044
    1045 // transform dstat information
    1046 int nrows = lpi->clp->getNumRows();
    1047 int* which = NULL;
    1048 SCIP_ALLOC( BMSallocMemoryArray( &which, nrows) );
    1049 int cnt = 0;
    1050 for (int i = 0; i < nrows; ++i)
    1051 {
    1052 if ( dstat[i] == 1 )
    1053 which[cnt++] = i;
    1054 }
    1055 lpi->clp->deleteRows(cnt, which);
    1056 BMSfreeMemoryArray( &which );
    1057
    1058 // update dstat
    1059 cnt = 0;
    1060 for (int i = 0; i < nrows; ++i)
    1061 {
    1062 if ( dstat[i] == 1 )
    1063 {
    1064 dstat[i] = -1;
    1065 ++cnt;
    1066 }
    1067 else
    1068 dstat[i] = i - cnt;
    1069 }
    1070
    1071 return SCIP_OKAY;
    1072}
    1073
    1074
    1075/** clears the whole LP */
    1077 SCIP_LPI* lpi /**< LP interface structure */
    1078 )
    1079{
    1080 SCIPdebugMessage("calling SCIPlpiClear()\n");
    1081
    1082 assert(lpi != NULL);
    1083 assert(lpi->clp != NULL);
    1084
    1085 invalidateSolution(lpi);
    1086 lpi->lastalgorithm = 0;
    1087
    1088 // We use the resize(0,0) to get rid of the model but keep all other settings
    1089 lpi->clp->resize(0,0);
    1090
    1091 return SCIP_OKAY;
    1092}
    1093
    1094
    1095/** changes lower and upper bounds of columns */
    1097 SCIP_LPI* lpi, /**< LP interface structure */
    1098 int ncols, /**< number of columns to change bounds for */
    1099 const int* ind, /**< column indices or NULL if ncols is zero */
    1100 const SCIP_Real* lb, /**< values for the new lower bounds or NULL if ncols is zero */
    1101 const SCIP_Real* ub /**< values for the new upper bounds or NULL if ncols is zero */
    1102 )
    1103{
    1104 assert(lpi != NULL);
    1105 assert(lpi->clp != NULL);
    1106 assert(ncols == 0 || (ind != NULL && lb != NULL && ub != NULL));
    1107
    1108 SCIPdebugMessage("calling SCIPlpiChgBounds()\n");
    1109 if( ncols <= 0 )
    1110 return SCIP_OKAY;
    1111
    1112 invalidateSolution(lpi);
    1113
    1114 ClpSimplex* clp = lpi->clp;
    1115
    1116#if SCIP_DISABLED_CODE
    1117 /* The following bugfix was necessary some time ago to avoid an error in Clp and can currently be disabled: the
    1118 * solution vector is modified to be set to the corresponding bounds. Remove if Clp versions have stabilized. */
    1119 double* sol = lpi->clp->primalColumnSolution();
    1120 const double* colLower = lpi->clp->getColLower();
    1121 const double* colUpper = lpi->clp->getColUpper();
    1122#endif
    1123
    1124 for (int j = 0; j < ncols; ++j)
    1125 {
    1126 if ( SCIPlpiIsInfinity(lpi, lb[j]) )
    1127 {
    1128 SCIPerrorMessage("LP Error: fixing lower bound for variable %d to infinity.\n", ind[j]);
    1129 return SCIP_LPERROR;
    1130 }
    1131 if ( SCIPlpiIsInfinity(lpi, -ub[j]) )
    1132 {
    1133 SCIPerrorMessage("LP Error: fixing upper bound for variable %d to -infinity.\n", ind[j]);
    1134 return SCIP_LPERROR;
    1135 }
    1136
    1137 clp->setColumnBounds(ind[j], lb[j], ub[j]);
    1138
    1139#if SCIP_DISABLED_CODE
    1140 /* Old bugfix, not currently needed - see above */
    1141 if ( sol != 0 )
    1142 {
    1143 if( clp->statusExists() )
    1144 {
    1145 assert( colLower != 0 );
    1146 assert( colUpper != 0 );
    1147 int k = ind[j];
    1148 switch ( clp->getColumnStatus(k) )
    1149 {
    1150 case ClpSimplex::isFree:
    1151 case ClpSimplex::superBasic:
    1152 sol[k] = 0.0;
    1153 break;
    1154 case ClpSimplex::atUpperBound:
    1155 sol[k] = colUpper[k];
    1156 assert( colUpper[k] == ub[j] );
    1157 break;
    1158 case ClpSimplex::isFixed:
    1159 case ClpSimplex::atLowerBound:
    1160 sol[k] = colLower[k];
    1161 assert( colLower[k] == lb[j] );
    1162 break;
    1163 default:;
    1164 }
    1165 }
    1166 else
    1167 { /* workaround: if there is no status, we assume something */
    1168 sol[ind[j]] = 0.0;
    1169 }
    1170 }
    1171#endif
    1172 }
    1173
    1174 return SCIP_OKAY;
    1175}
    1176
    1177
    1178/** changes left and right hand sides of rows */
    1180 SCIP_LPI* lpi, /**< LP interface structure */
    1181 int nrows, /**< number of rows to change sides for */
    1182 const int* ind, /**< row indices */
    1183 const SCIP_Real* lhs, /**< new values for left hand sides */
    1184 const SCIP_Real* rhs /**< new values for right hand sides */
    1185 )
    1186{
    1187 SCIPdebugMessage("calling SCIPlpiChgSides()\n");
    1188
    1189 assert(lpi != NULL);
    1190 assert(lpi->clp != NULL);
    1191 assert(ind != NULL);
    1192 assert(lhs != NULL);
    1193 assert(rhs != NULL);
    1194 if( nrows <= 0)
    1195 return SCIP_OKAY;
    1196
    1197 invalidateSolution(lpi);
    1198
    1199 ClpSimplex* clp = lpi->clp;
    1200
    1201 for (int i = 0; i < nrows; ++i)
    1202 clp->setRowBounds(ind[i], lhs[i], rhs[i]);
    1203
    1204 return SCIP_OKAY;
    1205}
    1206
    1207
    1208/** changes a single coefficient */
    1210 SCIP_LPI* lpi, /**< LP interface structure */
    1211 int row, /**< row number of coefficient to change */
    1212 int col, /**< column number of coefficient to change */
    1213 SCIP_Real newval /**< new value of coefficient */
    1214 )
    1215{
    1216 SCIPdebugMessage("calling SCIPlpiChgCoef()\n");
    1217
    1218 assert(lpi != NULL);
    1219 assert(lpi->clp != NULL);
    1220 assert(0 <= row && row < lpi->clp->numberRows());
    1221 assert(0 <= col && col < lpi->clp->numberColumns());
    1222
    1223 invalidateSolution(lpi);
    1224
    1225 lpi->clp->matrix()->modifyCoefficient(row, col, newval);
    1226
    1227 return SCIP_OKAY;
    1228}
    1229
    1230
    1231/** changes the objective sense */
    1233 SCIP_LPI* lpi, /**< LP interface structure */
    1234 SCIP_OBJSEN objsen /**< new objective sense */
    1235 )
    1236{
    1237 SCIPdebugMessage("calling SCIPlpiChgObjsen()\n");
    1238
    1239 assert(lpi != NULL);
    1240 assert(lpi->clp != NULL);
    1241
    1242 invalidateSolution(lpi);
    1243
    1244 // set objective sense: SCIP values are the same as the ones for Clp
    1245 lpi->clp->setOptimizationDirection(objsen);
    1246
    1247 return SCIP_OKAY;
    1248}
    1249
    1250
    1251/** changes objective values of columns in the LP */
    1253 SCIP_LPI* lpi, /**< LP interface structure */
    1254 int ncols, /**< number of columns to change objective value for */
    1255 const int* ind, /**< column indices to change objective value for */
    1256 const SCIP_Real* obj /**< new objective values for columns */
    1257 )
    1258{
    1259 SCIPdebugMessage("calling SCIPlpiChgObj()\n");
    1260
    1261 assert(lpi != NULL);
    1262 assert(lpi->clp != NULL);
    1263 assert(ind != NULL);
    1264 assert(obj != NULL);
    1265
    1266 invalidateSolution(lpi);
    1267
    1268 ClpSimplex* clp = lpi->clp;
    1269
    1270 // updates whatsChanged in Clp (bound checking in Clp)
    1271 for( int j = 0; j < ncols; ++j )
    1272 clp->setObjCoeff(ind[j], obj[j]); // inlined version of clp->setObjectiveCoefficient(ind[j], obj[j]);
    1273
    1274 return SCIP_OKAY;
    1275}
    1276
    1277
    1278/** multiplies a row with a non-zero scalar; for negative scalars, the row's sense is switched accordingly */
    1280 SCIP_LPI* lpi, /**< LP interface structure */
    1281 int row, /**< row number to scale */
    1282 SCIP_Real scaleval /**< scaling multiplier */
    1283 )
    1284{
    1285 SCIPdebugMessage("calling SCIPlpiScaleRow()\n");
    1286
    1287 assert(lpi != NULL);
    1288 assert(lpi->clp != NULL);
    1289 assert(scaleval != 0.0);
    1290 assert(0 <= row && row <= lpi->clp->numberRows() );
    1291
    1292 invalidateSolution(lpi);
    1293
    1294 // Note: if the scaling should be performed because of numerical stability,
    1295 // there are other more effective methods in Clp to adjust the scaling values
    1296 // for each row.
    1297
    1298 ClpSimplex* clp = lpi->clp;
    1299
    1300 // adjust the sides
    1301 double* lhs = clp->rowLower();
    1302 double* rhs = clp->rowUpper();
    1303
    1304 double lhsval = lhs[row];
    1305 if( lhsval > -COIN_DBL_MAX )
    1306 lhsval *= scaleval;
    1307 else if( scaleval < 0.0 )
    1308 lhsval = COIN_DBL_MAX;
    1309 double rhsval = rhs[row];
    1310 if( rhsval < COIN_DBL_MAX)
    1311 rhsval *= scaleval;
    1312 else if( scaleval < 0.0 )
    1313 rhsval = -COIN_DBL_MAX;
    1314 if( scaleval < 0.0 )
    1315 {
    1316 SCIP_Real oldlhs = lhsval;
    1317 lhsval = rhsval;
    1318 rhsval = oldlhs;
    1319 }
    1320 lhs[row] = lhsval; // change values directly into Clp data!
    1321 rhs[row] = rhsval;
    1322
    1323 // apply scaling ...
    1324
    1325 // WARNING: the following is quite expensive:
    1326 // We have to loop over the matrix to find the row entries.
    1327 // For columns we can do better, see @c SCIPlpiScaleCol.
    1328 CoinPackedMatrix* M = clp->matrix();
    1329 assert( M->getNumCols() == clp->numberColumns() );
    1330
    1331 const CoinBigIndex* beg = M->getVectorStarts();
    1332 const int* length = M->getVectorLengths();
    1333 const int* ind = M->getIndices();
    1334 double* val = M->getMutableElements();
    1335
    1336 for (int j = 0; j < M->getNumCols(); ++j)
    1337 {
    1338 for (CoinBigIndex k = beg[j]; k < beg[j] + length[j]; ++k)
    1339 {
    1340 if (ind[k] == row)
    1341 val[k] *= scaleval;
    1342 }
    1343 }
    1344
    1345 return SCIP_OKAY;
    1346}
    1347
    1348
    1349/** multiplies a column with a non-zero scalar; the objective value is multiplied with the scalar, and the bounds
    1350 * are divided by the scalar; for negative scalars, the column's bounds are switched
    1351 */
    1353 SCIP_LPI* lpi, /**< LP interface structure */
    1354 int col, /**< column number to scale */
    1355 SCIP_Real scaleval /**< scaling multiplier */
    1356 )
    1357{
    1358 SCIPdebugMessage("calling SCIPlpiScaleCol()\n");
    1359
    1360 assert(lpi != NULL);
    1361 assert(lpi->clp != NULL);
    1362 assert(scaleval != 0.0);
    1363 assert(0 <= col && col <= lpi->clp->numberColumns() );
    1364
    1365 invalidateSolution(lpi);
    1366
    1367 // Note: if the scaling should be performed because of numerical stability,
    1368 // there are other more effective methods in Clp to adjust the scaling values
    1369 // for each column.
    1370
    1371 ClpSimplex* clp = lpi->clp;
    1372
    1373 // adjust the objective coefficients
    1374 double* objvec = clp->objective(); // we have direct access to the data of Clp!
    1375 objvec[col] *= scaleval; // adjust the objective function value
    1376
    1377 // adjust the bounds
    1378 double* lb = clp->columnLower();
    1379 double* ub = clp->columnUpper();
    1380 double lbval = lb[col];
    1381 double ubval = ub[col];
    1382
    1383 if( lbval > -COIN_DBL_MAX )
    1384 lbval /= scaleval;
    1385 else if( scaleval < 0.0 )
    1386 lbval = COIN_DBL_MAX;
    1387 if( ubval < COIN_DBL_MAX )
    1388 ubval /= scaleval;
    1389 else if( scaleval < 0.0 )
    1390 ubval = -COIN_DBL_MAX;
    1391 if( scaleval < 0.0 )
    1392 {
    1393 SCIP_Real oldlb = lbval;
    1394 lbval = ubval;
    1395 ubval = oldlb;
    1396 }
    1397 lb[col] = lbval; // directly adjust values into Clp data
    1398 ub[col] = ubval;
    1399
    1400 // apply scaling directly to matrix (adapted from ClpPackedMatrix::reallyScale)
    1401 // See also ClpModel::gutsOfScaling ...
    1402 CoinPackedMatrix* M = clp->matrix();
    1403 assert( M->getNumCols() == clp->numberColumns() );
    1404
    1405 const CoinBigIndex* beg = M->getVectorStarts();
    1406 const int* length = M->getVectorLengths();
    1407 double* val = M->getMutableElements();
    1408 for (CoinBigIndex k = beg[col]; k < beg[col] + length[col]; ++k)
    1409 val[k] *= scaleval;
    1410
    1411 return SCIP_OKAY;
    1412}
    1413
    1414
    1415
    1416/**@} */
    1417
    1418
    1419
    1420
    1421/*
    1422 * Data Accessing Methods
    1423 */
    1424
    1425/**@name Data Accessing Methods */
    1426/**@{ */
    1427
    1428/** gets the number of rows in the LP */
    1430 SCIP_LPI* lpi, /**< LP interface structure */
    1431 int* nrows /**< pointer to store the number of rows */
    1432 )
    1433{
    1434 SCIPdebugMessage("calling SCIPlpiGetNRows()\n");
    1435
    1436 assert(lpi != NULL);
    1437 assert(lpi->clp != NULL);
    1438 assert(nrows != NULL);
    1439
    1440 *nrows = lpi->clp->numberRows();
    1441
    1442 return SCIP_OKAY;
    1443}
    1444
    1445
    1446/** gets the number of columns in the LP */
    1448 SCIP_LPI* lpi, /**< LP interface structure */
    1449 int* ncols /**< pointer to store the number of cols */
    1450 )
    1451{
    1452 SCIPdebugMessage("calling SCIPlpiGetNCols()\n");
    1453
    1454 assert(lpi != NULL);
    1455 assert(lpi->clp != NULL);
    1456 assert(ncols != NULL);
    1457
    1458 *ncols = lpi->clp->numberColumns();
    1459
    1460 return SCIP_OKAY;
    1461}
    1462
    1463
    1464/** gets the number of nonzero elements in the LP constraint matrix */
    1466 SCIP_LPI* lpi, /**< LP interface structure */
    1467 int* nnonz /**< pointer to store the number of nonzeros */
    1468 )
    1469{
    1470 SCIPdebugMessage("calling SCIPlpiGetNNonz()\n");
    1471
    1472 assert(lpi != NULL);
    1473 assert(lpi->clp != NULL);
    1474 assert(nnonz != NULL);
    1475
    1476 *nnonz = lpi->clp->getNumElements();
    1477
    1478 return SCIP_OKAY;
    1479}
    1480
    1481
    1482/** gets columns from LP problem object; the arrays have to be large enough to store all values
    1483 * Either both, lb and ub, have to be NULL, or both have to be non-NULL,
    1484 * either nnonz, beg, ind, and val have to be NULL, or all of them have to be non-NULL.
    1485 */
    1487 SCIP_LPI* lpi, /**< LP interface structure */
    1488 int firstcol, /**< first column to get from LP */
    1489 int lastcol, /**< last column to get from LP */
    1490 SCIP_Real* lb, /**< buffer to store the lower bound vector, or NULL */
    1491 SCIP_Real* ub, /**< buffer to store the upper bound vector, or NULL */
    1492 int* nnonz, /**< pointer to store the number of nonzero elements returned, or NULL */
    1493 int* beg, /**< buffer to store start index of each column in ind- and val-array, or NULL */
    1494 int* ind, /**< buffer to store row indices of constraint matrix entries, or NULL */
    1495 SCIP_Real* val /**< buffer to store values of constraint matrix entries, or NULL */
    1496 )
    1497{
    1498 assert(lpi != NULL);
    1499 assert(lpi->clp != NULL);
    1500 assert((lb != NULL && ub != NULL) || (lb == NULL && ub == NULL));
    1501 assert((nnonz != NULL && beg != NULL && ind != NULL && val != NULL) || (nnonz == NULL && beg == NULL && ind == NULL && val == NULL));
    1502 assert(firstcol >= 0);
    1503 assert(lastcol < lpi->clp->numberColumns());
    1504 assert(firstcol <= lastcol + 1);
    1505
    1506 SCIPdebugMessage("calling SCIPlpiGetCols()\n");
    1507
    1508 ClpSimplex* clp = lpi->clp;
    1509
    1510 // get lower and upper bounds for the variables
    1511 if ( lb != NULL )
    1512 {
    1513 const double* colLower = clp->getColLower(); // Here we can use the const versions (see SCIPchgBounds)
    1514 const double* colUpper = clp->getColUpper();
    1515
    1516 BMScopyMemoryArray( lb, colLower + firstcol, (lastcol - firstcol + 1));
    1517 BMScopyMemoryArray( ub, colUpper + firstcol, (lastcol - firstcol + 1));
    1518 }
    1519
    1520 if ( nnonz != NULL )
    1521 {
    1522 CoinPackedMatrix* M = clp->matrix();
    1523 assert( M != NULL );
    1524 assert( M->getNumCols() == clp->numberColumns() );
    1525
    1526 const CoinBigIndex* Mbeg = M->getVectorStarts(); // can use const versions
    1527 const int* Mlength = M->getVectorLengths();
    1528 const int* Mind = M->getIndices();
    1529 const double* Mval = M->getElements();
    1530
    1531 *nnonz = 0;
    1532 // can we use memcpy for the whole set (requires that columns are stored sequentially)
    1533 for (int j = firstcol; j <= lastcol; ++j)
    1534 {
    1535 beg[j-firstcol] = *nnonz;
    1536
    1537 BMScopyMemoryArray( (ind + (*nnonz)), Mind + Mbeg[j], Mlength[j]);
    1538 BMScopyMemoryArray( (val + (*nnonz)), Mval + Mbeg[j], Mlength[j]);
    1539
    1540 (*nnonz) += Mlength[j];
    1541 }
    1542 }
    1543
    1544 return SCIP_OKAY;
    1545}
    1546
    1547
    1548/** gets rows from LP problem object; the arrays have to be large enough to store all values.
    1549 * Either both, lhs and rhs, have to be NULL, or both have to be non-NULL,
    1550 * either nnonz, beg, ind, and val have to be NULL, or all of them have to be non-NULL.
    1551 */
    1553 SCIP_LPI* lpi, /**< LP interface structure */
    1554 int firstrow, /**< first row to get from LP */
    1555 int lastrow, /**< last row to get from LP */
    1556 SCIP_Real* lhs, /**< buffer to store left hand side vector, or NULL */
    1557 SCIP_Real* rhs, /**< buffer to store right hand side vector, or NULL */
    1558 int* nnonz, /**< pointer to store the number of nonzero elements returned, or NULL */
    1559 int* beg, /**< buffer to store start index of each row in ind- and val-array, or NULL */
    1560 int* ind, /**< buffer to store column indices of constraint matrix entries, or NULL */
    1561 SCIP_Real* val /**< buffer to store values of constraint matrix entries, or NULL */
    1562 )
    1563{
    1564 assert(lpi != NULL);
    1565 assert(lpi->clp != NULL);
    1566 assert((lhs != NULL && rhs != NULL) || (lhs == NULL && rhs == NULL));
    1567 assert((nnonz != NULL && beg != NULL && ind != NULL && val != NULL) || (nnonz == NULL && beg == NULL && ind == NULL && val == NULL));
    1568 assert(firstrow >= 0);
    1569 assert(lastrow < lpi->clp->numberRows());
    1570 assert(firstrow <= lastrow + 1);
    1571
    1572 SCIPdebugMessage("calling SCIPlpiGetRows()\n");
    1573
    1574 ClpSimplex* clp = lpi->clp;
    1575 if ( lhs != NULL )
    1576 {
    1577 const double* rowLower = clp->getRowLower(); // Here we can use the const versions (see SCIPchgSides)
    1578 const double* rowUpper = clp->getRowUpper();
    1579
    1580 BMScopyMemoryArray( lhs, rowLower + firstrow, (lastrow - firstrow + 1) );
    1581 BMScopyMemoryArray( rhs, rowUpper + firstrow, (lastrow - firstrow + 1) );
    1582 }
    1583
    1584 if ( nnonz != NULL )
    1585 {
    1586 ClpMatrixBase* M = clp->rowCopy(); // get row view on matrix
    1587 if ( M == NULL ) // can happen e.g. if no LP was solved yet ...
    1588 M = clp->clpMatrix()->reverseOrderedCopy();
    1589 assert( M != NULL );
    1590 assert( M->getNumRows() == clp->numberRows() );
    1591
    1592 const CoinBigIndex* Mbeg = M->getVectorStarts();
    1593 const int* Mlength = M->getVectorLengths();
    1594 const int* Mind = M->getIndices();
    1595 const double* Mval = M->getElements();
    1596
    1597 *nnonz = 0;
    1598 for( int i = firstrow; i <= lastrow; ++i )
    1599 {
    1600 beg[i-firstrow] = *nnonz;
    1601 for( CoinBigIndex k = Mbeg[i]; k < Mbeg[i] + Mlength[i]; ++k )
    1602 {
    1603 ind[*nnonz] = Mind[k];
    1604 val[*nnonz] = Mval[k];
    1605 (*nnonz)++;
    1606 }
    1607 }
    1608 }
    1609
    1610 return SCIP_OKAY;
    1611}
    1612
    1613
    1614/** gets column names */
    1616 SCIP_LPI* lpi, /**< LP interface structure */
    1617 int firstcol, /**< first column to get name from LP */
    1618 int lastcol, /**< last column to get name from LP */
    1619 char** colnames, /**< pointers to column names (of size at least lastcol-firstcol+1) or NULL if namestoragesize is zero */
    1620 char* namestorage, /**< storage for col names or NULL if namestoragesize is zero */
    1621 int namestoragesize, /**< size of namestorage (if 0, storageleft returns the storage needed) */
    1622 int* storageleft /**< amount of storage left (if < 0 the namestorage was not big enough) or NULL if namestoragesize is zero */
    1623 )
    1624{
    1625 assert(lpi != NULL);
    1626 assert(lpi->clp != NULL);
    1627 assert(colnames != NULL || namestoragesize == 0);
    1628 assert(namestorage != NULL || namestoragesize == 0);
    1629 assert(namestoragesize >= 0);
    1630 assert(storageleft != NULL);
    1631 assert(firstcol >= 0);
    1632 assert(lastcol < lpi->clp->numberColumns());
    1633 assert(firstcol <= lastcol + 1);
    1634
    1635 SCIPerrorMessage("SCIPlpiGetColNames() has not been implemented yet.\n");
    1636
    1637 return SCIP_LPERROR;
    1638}
    1639
    1640
    1641/** gets row names */
    1643 SCIP_LPI* lpi, /**< LP interface structure */
    1644 int firstrow, /**< first row to get name from LP */
    1645 int lastrow, /**< last row to get name from LP */
    1646 char** rownames, /**< pointers to row names (of size at least lastrow-firstrow+1) or NULL if namestoragesize is zero */
    1647 char* namestorage, /**< storage for row names or NULL if namestoragesize is zero */
    1648 int namestoragesize, /**< size of namestorage (if 0, -storageleft returns the storage needed) */
    1649 int* storageleft /**< amount of storage left (if < 0 the namestorage was not big enough) or NULL if namestoragesize is zero */
    1650 )
    1651{
    1652 assert(lpi != NULL);
    1653 assert(lpi->clp != NULL);
    1654 assert(rownames != NULL || namestoragesize == 0);
    1655 assert(namestorage != NULL || namestoragesize == 0);
    1656 assert(namestoragesize >= 0);
    1657 assert(storageleft != NULL);
    1658 assert(firstrow >= 0);
    1659 assert(lastrow < lpi->clp->numberRows());
    1660 assert(firstrow <= lastrow + 1);
    1661
    1662 SCIPerrorMessage("SCIPlpiGetRowNames() has not been implemented yet.\n");
    1663
    1664 return SCIP_LPERROR;
    1665}
    1666
    1667
    1668/** tries to reset the internal status of the LP solver in order to ignore an instability of the last solving call */
    1670 SCIP_LPI* lpi, /**< LP interface structure */
    1671 SCIP_Bool* success /**< pointer to store, whether the instability could be ignored */
    1672 )
    1673{
    1674 SCIPdebugMessage("calling SCIPlpiIgnoreInstability()\n");
    1675
    1676 assert(lpi != NULL);
    1677 assert(lpi->clp != NULL);
    1678 assert(success != NULL);
    1679
    1680 /* Unstable situations are currently not ignored. Could fix this similar to lpi_cpx by adjusting the solution status. */
    1681 *success = FALSE;
    1682
    1683 return SCIP_OKAY;
    1684}
    1685
    1686
    1687/** gets the objective sense of the LP */
    1689 SCIP_LPI* lpi, /**< LP interface structure */
    1690 SCIP_OBJSEN* objsen /**< pointer to store objective sense */
    1691 )
    1692{
    1693 assert( lpi != NULL );
    1694 assert( lpi->clp != NULL );
    1695 assert( objsen != NULL );
    1696
    1697 // Clp direction of optimization (1 - minimize, -1 - maximize, 0 - ignore)
    1698 if ( lpi->clp->getObjSense() < 0 )
    1699 *objsen = SCIP_OBJSEN_MAXIMIZE;
    1700 else
    1701 *objsen = SCIP_OBJSEN_MINIMIZE;
    1702
    1703 return SCIP_OKAY;
    1704}
    1705
    1706
    1707/** gets objective coefficients from LP problem object */
    1709 SCIP_LPI* lpi, /**< LP interface structure */
    1710 int firstcol, /**< first column to get objective coefficient for */
    1711 int lastcol, /**< last column to get objective coefficient for */
    1712 SCIP_Real* vals /**< array to store objective coefficients */
    1713 )
    1714{
    1715 assert(lpi != NULL);
    1716 assert(lpi->clp != NULL);
    1717 assert(vals != NULL);
    1718 assert(firstcol >= 0);
    1719 assert(lastcol < lpi->clp->numberColumns());
    1720 assert(firstcol <= lastcol + 1);
    1721
    1722 SCIPdebugMessage("calling SCIPlpiGetObj()\n");
    1723
    1724 const double* obj = lpi->clp->getObjCoefficients(); // Here we can use the const versions (see SCIPchgObj)
    1725
    1726 BMScopyMemoryArray(vals, obj + firstcol, (lastcol - firstcol + 1) );
    1727
    1728 return SCIP_OKAY;
    1729}
    1730
    1731
    1732/** gets current bounds from LP problem object */
    1734 SCIP_LPI* lpi, /**< LP interface structure */
    1735 int firstcol, /**< first column to get objective value for */
    1736 int lastcol, /**< last column to get objective value for */
    1737 SCIP_Real* lbs, /**< array to store lower bound values, or NULL */
    1738 SCIP_Real* ubs /**< array to store upper bound values, or NULL */
    1739 )
    1740{
    1741 assert(lpi != NULL);
    1742 assert(lpi->clp != NULL);
    1743 assert(firstcol >= 0);
    1744 assert(lastcol < lpi->clp->numberColumns());
    1745 assert(firstcol <= lastcol + 1);
    1746
    1747 SCIPdebugMessage("calling SCIPlpiGetBounds()\n");
    1748
    1749 if ( lbs != 0 )
    1750 {
    1751 const double* colLower = lpi->clp->getColLower(); // Here we can use the const versions (see SCIPchgBounds)
    1752 BMScopyMemoryArray( lbs, colLower + firstcol, (lastcol - firstcol + 1) );
    1753 }
    1754
    1755 if ( ubs != 0 )
    1756 {
    1757 const double* colUpper = lpi->clp->getColUpper();
    1758 BMScopyMemoryArray( ubs, colUpper + firstcol, (lastcol - firstcol + 1) );
    1759 }
    1760
    1761 return SCIP_OKAY;
    1762}
    1763
    1764
    1765/** gets current row sides from LP problem object */
    1767 SCIP_LPI* lpi, /**< LP interface structure */
    1768 int firstrow, /**< first row to get sides for */
    1769 int lastrow, /**< last row to get sides for */
    1770 SCIP_Real* lhss, /**< array to store left hand side values, or NULL */
    1771 SCIP_Real* rhss /**< array to store right hand side values, or NULL */
    1772 )
    1773{
    1774 assert(lpi != NULL);
    1775 assert(lpi->clp != NULL);
    1776 assert(firstrow >= 0);
    1777 assert(lastrow < lpi->clp->numberRows());
    1778 assert(firstrow <= lastrow + 1);
    1779
    1780 SCIPdebugMessage("calling SCIPlpiGetSides()\n");
    1781
    1782 if ( lhss != 0 )
    1783 {
    1784 const double* rowLower = lpi->clp->getRowLower(); // Here we can use the const versions (see SCIPchgSides)
    1785 BMScopyMemoryArray( lhss, rowLower + firstrow, (lastrow - firstrow + 1) );
    1786 }
    1787
    1788 if ( rhss != 0 )
    1789 {
    1790 const double* rowUpper = lpi->clp->getRowUpper();
    1791 BMScopyMemoryArray( rhss, rowUpper + firstrow, (lastrow - firstrow + 1) );
    1792 }
    1793
    1794 return SCIP_OKAY;
    1795}
    1796
    1797
    1798/** gets a single coefficient */
    1800 SCIP_LPI* lpi, /**< LP interface structure */
    1801 int row, /**< row number of coefficient */
    1802 int col, /**< column number of coefficient */
    1803 SCIP_Real* val /**< pointer to store the value of the coefficient */
    1804 )
    1805{
    1806 SCIPdebugMessage("calling SCIPlpiGetCoef()\n");
    1807
    1808 assert(lpi != NULL);
    1809 assert(lpi->clp != NULL);
    1810 assert(0 <= col && col < lpi->clp->numberColumns());
    1811 assert(0 <= row && row < lpi->clp->numberRows());
    1812 assert(val != NULL);
    1813
    1814 *val = lpi->clp->matrix()->getCoefficient(row, col);
    1815
    1816 return SCIP_OKAY;
    1817}
    1818
    1819/**@} */
    1820
    1821
    1822
    1823
    1824/*
    1825 * Solving Methods
    1826 */
    1827
    1828/**@name Solving Methods */
    1829/**@{ */
    1830
    1831
    1832/** calls primal simplex to solve the LP */
    1834 SCIP_LPI* lpi /**< LP interface structure */
    1835 )
    1836{
    1837 assert(lpi != NULL);
    1838 assert(lpi->clp != NULL);
    1839
    1840 SCIPdebugMessage("calling Clp primal(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
    1841
    1842#ifdef LPI_CLP_DEBUG_WRITE_FILES
    1843 char filename[255];
    1844 snprintf(filename, 255, "debug_p_%d.mps", fileNr);
    1845 fileNr = fileNr % 2;
    1846 SCIPlpiWriteLP(lpi, filename);
    1847 SCIPdebugMessage("Wrote file <%s>\n", filename);
    1848#endif
    1849
    1850 invalidateSolution(lpi);
    1851
    1852 // initialize factorization freq. depending on model size - applied only once
    1854
    1855 // if we want to construct a new basis
    1856 if ( lpi->startscratch )
    1857 {
    1858 lpi->clp->allSlackBasis(true); // reset basis
    1859 lpi->validFactorization = false;
    1860 }
    1861
    1862 /* startFinishOptions - bits
    1863 * 1 - do not delete work areas and factorization at end
    1864 * 2 - use old factorization if same number of rows
    1865 * 4 - skip as much initialization of work areas as possible (work in progress)
    1866 *
    1867 * 4 does not seem to work.
    1868 */
    1869 int startFinishOptions = 1;
    1870 if ( lpi->validFactorization )
    1871 startFinishOptions = startFinishOptions | 2;
    1872
    1873 /* Primal algorithm */
    1874 int status = lpi->clp->primal(0, startFinishOptions);
    1875
    1876#ifdef LPI_CLP_DEBUG_WRITE_FILES
    1877 char basisname[255];
    1878 snprintf(basisname, 255, "debug_p_%d.bas", fileNr);
    1879 SCIP_CALL( SCIPlpiWriteState(lpi, basisname) );
    1880 SCIPdebugMessage("Wrote basis file <%s>\n", basisname);
    1881 ++fileNr; /* not increased above! */
    1882 fileNr = fileNr % 2;
    1883#endif
    1884
    1885 lpi->lastalgorithm = 1;
    1886 lpi->validFactorization = true;
    1887 lpi->solved = TRUE;
    1888
    1889 // Unfortunately the status of Clp is hard coded ...
    1890 // -1 - did not run
    1891 // 0 - optimal
    1892 // 1 - primal infeasible
    1893 // 2 - dual infeasible
    1894 // 3 - stopped on iterations or time
    1895 // 4 - stopped due to errors
    1896 // 5 - stopped by event handler
    1897 assert( status != -1 ); // did not run should not occur
    1898 assert( status != 5 ); // begin stopped by event handler should not occur
    1899
    1900 if ( status == 4 || status == 5 || status == -1 )
    1901 return SCIP_LPERROR;
    1902
    1903 return SCIP_OKAY;
    1904}
    1905
    1906
    1907/** calls dual simplex to solve the LP */
    1909 SCIP_LPI* lpi /**< LP interface structure */
    1910 )
    1911{
    1912 assert(lpi != NULL);
    1913 assert(lpi->clp != NULL);
    1914
    1915 SCIPdebugMessage("calling Clp dual(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
    1916
    1917#ifdef LPI_CLP_DEBUG_WRITE_FILES
    1918 char filename[255];
    1919 snprintf(filename, 255, "debug_d_%d.mps", fileNr);
    1920 SCIPlpiWriteLP(lpi, filename);
    1921 SCIPdebugMessage("Wrote file <%s>\n", filename);
    1922 snprintf(filename, 255, "debug_d_%d.sav", fileNr);
    1923 // lpi->clp->saveModel(filename);
    1924 SCIPdebugMessage("Wrote file <%s>\n", filename);
    1925#endif
    1926
    1927 invalidateSolution(lpi);
    1928
    1929 // intialize factorization freq. depending on model size - applied only once
    1931
    1932 // if we want to construct a new basis
    1933 if( lpi->startscratch )
    1934 {
    1935 lpi->clp->allSlackBasis(true); // reset basis
    1936 lpi->validFactorization = false;
    1937 }
    1938
    1939 /* startFinishOptions - bits
    1940 * 1 - do not delete work areas and factorization at end
    1941 * 2 - use old factorization if same number of rows
    1942 * 4 - skip as much initialization of work areas as possible (work in progress)
    1943 *
    1944 * 4 does not seem to work.
    1945 */
    1946 int startFinishOptions = 1;
    1947 if ( lpi->validFactorization )
    1948 startFinishOptions = startFinishOptions | 2;
    1949
    1950 /* Dual algorithm */
    1951 int status = lpi->clp->dual(0, startFinishOptions);
    1952
    1953#ifdef LPI_CLP_DEBUG_WRITE_FILES
    1954 char basisname[255];
    1955 snprintf(basisname, 255, "debug_d_%d.bas", fileNr);
    1956 SCIP_CALL( SCIPlpiWriteState(lpi, basisname) );
    1957 SCIPdebugMessage("Wrote basis file <%s>\n", basisname);
    1958 ++fileNr; /* not increased above! */
    1959 fileNr = fileNr % 2;
    1960#endif
    1961
    1962 lpi->lastalgorithm = -1;
    1963 lpi->validFactorization = true;
    1964 lpi->solved = TRUE;
    1965
    1966 // Unfortunately the status of Clp is hard coded ...
    1967 // -1 - did not run
    1968 // 0 - optimal
    1969 // 1 - primal infeasible
    1970 // 2 - dual infeasible
    1971 // 3 - stopped on iterations or time
    1972 // 4 - stopped due to errors
    1973 // 5 - stopped by event handler
    1974 assert( status != -1 ); // did not run should not occur
    1975 assert( status != 5 ); // begin stopped by event handler should not occur
    1976
    1977 if ( status == 4 || status == 5 || status == -1 )
    1978 return SCIP_LPERROR;
    1979
    1980 return SCIP_OKAY;
    1981}
    1982
    1983
    1984/** calls barrier or interior point algorithm to solve the LP with crossover to simplex basis */
    1986 SCIP_LPI* lpi, /**< LP interface structure */
    1987 SCIP_Bool crossover /**< perform crossover */
    1988 )
    1989{
    1990 assert(lpi != NULL);
    1991 assert(lpi->clp != NULL);
    1992
    1993 SCIPdebugMessage("calling Clp barrier(): %d cols, %d rows; crossover: %u\n", lpi->clp->numberColumns(), lpi->clp->numberRows(), crossover);
    1994
    1995 invalidateSolution(lpi);
    1996
    1997 // Check whether we have a factorization, if yes destroy it (Clp doesn't like it ...)
    1998 /*
    1999 if (lpi->haveFactorization)
    2000 lpi->clp->finish();
    2001 */
    2002
    2003 // call barrier
    2004#if (CLP_VERSION_MAJOR >= 1 && CLP_VERSION_MINOR > 17) || CLP_VERSION_MAJOR >= 2
    2005 int startFinishOptions = 1;
    2006 int status = lpi->clp->barrier(crossover, startFinishOptions);
    2007#else
    2008 int status = lpi->clp->barrier(crossover);
    2009#endif
    2010
    2011 lpi->lastalgorithm = 2;
    2012 lpi->solved = TRUE;
    2013
    2014 // We may need to call ClpModel::status()
    2015
    2016 // Unfortunately the status of Clp is hard coded ...
    2017 // -1 - did not run
    2018 // 0 - optimal
    2019 // 1 - primal infeasible
    2020 // 2 - dual infeasible
    2021 // 3 - stopped on iterations or time
    2022 // 4 - stopped due to errors
    2023 // 5 - stopped by event handler
    2024 assert( status != -1 ); // did not run should not occur
    2025 assert( status != 5 ); // begin stopped by event handler should not occur
    2026
    2027 if ( status == 4 || status == 5 || status == -1 )
    2028 return SCIP_LPERROR;
    2029
    2030 return SCIP_OKAY;
    2031}
    2032
    2033/** start strong branching - call before any strongbranching */
    2035 SCIP_LPI* lpi /**< LP interface structure */
    2036 )
    2037{
    2038 assert(lpi != NULL);
    2039 assert(lpi->clp != NULL);
    2040
    2041 // currently do nothing; in the future: use code as in OSI
    2042 return SCIP_OKAY;
    2043}
    2044
    2045/** end strong branching - call after any strongbranching */
    2047 SCIP_LPI* lpi /**< LP interface structure */
    2048 )
    2049{
    2050 assert(lpi != NULL);
    2051 assert(lpi->clp != NULL);
    2052
    2053 // currently do nothing; in the future: use code as in OSI
    2054 return SCIP_OKAY;
    2055}
    2056
    2057/** performs strong branching iterations on one arbitrary candidate */
    2058static
    2060 SCIP_LPI* lpi, /**< LP interface structure */
    2061 int col, /**< column to apply strong branching on */
    2062 SCIP_Real psol, /**< current primal solution value of column */
    2063 int itlim, /**< iteration limit for strong branchings */
    2064 SCIP_Real* down, /**< stores dual bound after branching column down */
    2065 SCIP_Real* up, /**< stores dual bound after branching column up */
    2066 SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
    2067 * otherwise, it can only be used as an estimate value */
    2068 SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
    2069 * otherwise, it can only be used as an estimate value */
    2070 int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
    2071 )
    2072{
    2073 SCIPdebugMessage("calling SCIPlpiStrongbranch() on variable %d (%d iterations)\n", col, itlim);
    2074
    2075 assert(lpi != NULL);
    2076 assert(lpi->clp != NULL);
    2077 assert(down != NULL);
    2078 assert(up != NULL);
    2079 assert(downvalid != NULL);
    2080 assert(upvalid != NULL);
    2081
    2082 ClpSimplex* clp = lpi->clp;
    2083
    2084 // set up output arrays
    2085 int ncols = clp->numberColumns();
    2086 assert( 0 <= col && col < ncols );
    2087 double** outputSolution = NULL;
    2088 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution, 2) );
    2089 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution[0], ncols) );
    2090 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution[1], ncols) );
    2091
    2092 int* outputStatus = NULL;
    2093 SCIP_ALLOC( BMSallocMemoryArray( &outputStatus, 2) );
    2094
    2095 int* outputIterations = NULL;
    2096 SCIP_ALLOC( BMSallocMemoryArray( &outputIterations, 2) );
    2097
    2098 // set iteration limit
    2099 int iterlimit = clp->maximumIterations();
    2100 clp->setMaximumIterations(itlim);
    2101
    2102 // store objective value
    2103 double objval = clp->objectiveValue();
    2104
    2105 // store special options for later reset
    2106 int specialoptions = clp->specialOptions();
    2107
    2108 // lpi->clp->setSpecialOptions(64|128|512|1024|2048|4096|32768|262144|0x02000000);
    2109 // use default settings:
    2110 lpi->clp->setSpecialOptions(32|64|128|512|1024|2048|4096|32768|262144|2097152|0x2000000);
    2111
    2112 /* 'startfinish' options for strong branching:
    2113 * 1 - do not delete work areas and factorization at end
    2114 * 2 - use old factorization if same number of rows
    2115 * 4 - skip as much initialization of work areas as possible
    2116 * (based on whatsChanged in clpmodel.hpp) ** work in progress
    2117 *
    2118 * 4 does not seem to work in strong branching ...
    2119 */
    2120 int startFinishOptions = 1;
    2121 if ( lpi->validFactorization )
    2122 startFinishOptions = startFinishOptions | 2;
    2123
    2124 // set new lower and upper bounds for variable
    2125 *down = EPSCEIL(psol - 1.0, 1e-06);
    2126 *up = EPSFLOOR(psol + 1.0, 1e-06);
    2127
    2128 /* For strong branching. On input lower and upper are new bounds while
    2129 * on output they are change in objective function values (>1.0e50
    2130 * infeasible). Return code is
    2131 * 0 if nothing interesting,
    2132 * -1 if infeasible both ways and
    2133 * +1 if infeasible one way (check values to see which one(s))
    2134 * -2 if bad factorization
    2135 * Solutions are filled in as well - even down, odd up - also status and number of iterations
    2136 *
    2137 * The bools are:
    2138 * bool stopOnFirstInfeasible
    2139 * bool alwaysFinish
    2140 *
    2141 * At the moment: we need alwaysFinish to get correct bounds.
    2142 */
    2143 int res = clp->strongBranching(1, &col, up, down, outputSolution, outputStatus, outputIterations, false, true, startFinishOptions);
    2144
    2145 // reset special options
    2146 clp->setSpecialOptions(specialoptions);
    2147
    2148 lpi->validFactorization = true;
    2149
    2150 *down += objval;
    2151 *up += objval;
    2152
    2153 // The bounds returned by CLP seem to be valid using the above options
    2154 *downvalid = TRUE;
    2155 *upvalid = TRUE;
    2156
    2157 // correct iteration count
    2158 if (iter)
    2159 *iter = outputIterations[0] + outputIterations[1];
    2160
    2161 // reset iteration limit
    2162 clp->setMaximumIterations(iterlimit);
    2163
    2164 // free local memory
    2165 BMSfreeMemoryArray( &outputStatus );
    2166 BMSfreeMemoryArray( &outputIterations );
    2167 BMSfreeMemoryArray( &outputSolution[1] );
    2168 BMSfreeMemoryArray( &outputSolution[0] );
    2169 BMSfreeMemoryArray( &outputSolution );
    2170
    2171 if ( res == -2 )
    2172 return SCIP_LPERROR;
    2173
    2174 return SCIP_OKAY;
    2175}
    2176
    2177/** performs strong branching iterations on given arbitrary candidates */
    2178static
    2180 SCIP_LPI* lpi, /**< LP interface structure */
    2181 int* cols, /**< columns to apply strong branching on */
    2182 int ncols, /**< number of columns */
    2183 SCIP_Real* psols, /**< fractional current primal solution values of columns */
    2184 int itlim, /**< iteration limit for strong branchings */
    2185 SCIP_Real* down, /**< stores dual bounds after branching columns down */
    2186 SCIP_Real* up, /**< stores dual bounds after branching columns up */
    2187 SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
    2188 * otherwise, they can only be used as an estimate values */
    2189 SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
    2190 * otherwise, they can only be used as an estimate values */
    2191 int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
    2192 )
    2193{
    2194 SCIPdebugMessage("calling SCIPlpiStrongbranches() on %d variables (%d iterations)\n", ncols, itlim);
    2195
    2196 assert(lpi != NULL);
    2197 assert(lpi->clp != NULL);
    2198 assert( cols != NULL );
    2199 assert( psols != NULL );
    2200 assert( down != NULL );
    2201 assert( up != NULL );
    2202 assert( downvalid != NULL );
    2203 assert( upvalid != NULL );
    2204
    2205 ClpSimplex* clp = lpi->clp;
    2206
    2207 // set up output arrays
    2208 int n = clp->numberColumns();
    2209 assert( 0 < ncols && ncols <= n );
    2210 double** outputSolution = NULL;
    2211 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution, 2*ncols) );
    2212 for (int j = 0; j < 2*ncols; ++j)
    2213 {
    2214 SCIP_ALLOC( BMSallocMemoryArray( &(outputSolution[j]), n) );
    2215 }
    2216
    2217 int* outputStatus = NULL;
    2218 SCIP_ALLOC( BMSallocMemoryArray(&outputStatus, 2*ncols) );
    2219
    2220 int* outputIterations = NULL;
    2221 SCIP_ALLOC( BMSallocMemoryArray(&outputIterations, 2*ncols) );
    2222
    2223 // set iteration limit
    2224 int iterlimit = clp->maximumIterations();
    2225 clp->setMaximumIterations(itlim);
    2226
    2227 // store objective value
    2228 double objval = clp->objectiveValue();
    2229
    2230 // store special options for later reset
    2231 int specialoptions = clp->specialOptions();
    2232
    2233 // lpi->clp->setSpecialOptions(64|128|512|1024|2048|4096|32768|262144|0x02000000);
    2234 // use default settings:
    2235 lpi->clp->setSpecialOptions(32|64|128|512|1024|2048|4096|32768|262144|2097152|0x2000000);
    2236
    2237 /* 'startfinish' options for strong branching:
    2238 * 1 - do not delete work areas and factorization at end
    2239 * 2 - use old factorization if same number of rows
    2240 * 4 - skip as much initialization of work areas as possible
    2241 * (based on whatsChanged in clpmodel.hpp) ** work in progress
    2242 *
    2243 * 4 does not seem to work in strong branching ...
    2244 */
    2245 int startFinishOptions = 1;
    2246 if ( lpi->validFactorization )
    2247 startFinishOptions = startFinishOptions | 2;
    2248
    2249 // set new lower and upper bounds for variables
    2250 for (int j = 0; j < ncols; ++j)
    2251 {
    2252 assert( 0 <= cols[j] && cols[j] < n );
    2253 down[j] = EPSCEIL(psols[j] - 1.0, 1e-06);
    2254 up[j] = EPSFLOOR(psols[j] + 1.0, 1e-06);
    2255
    2256 // The bounds returned by CLP seem to be valid using the above options
    2257 downvalid[j] = TRUE;
    2258 upvalid[j] = TRUE;
    2259 }
    2260
    2261 /* For strong branching. On input lower and upper are new bounds while
    2262 * on output they are change in objective function values (>1.0e50
    2263 * infeasible). Return code is
    2264 * 0 if nothing interesting,
    2265 * -1 if infeasible both ways and
    2266 * +1 if infeasible one way (check values to see which one(s))
    2267 * -2 if bad factorization
    2268 * Solutions are filled in as well - even down, odd up - also status and number of iterations
    2269 *
    2270 * The bools are:
    2271 * bool stopOnFirstInfeasible
    2272 * bool alwaysFinish
    2273 *
    2274 * At the moment: we need alwaysFinish to get correct bounds.
    2275 */
    2276 int res = clp->strongBranching(ncols, cols, up, down, outputSolution, outputStatus, outputIterations, false, true, startFinishOptions);
    2277
    2278 // reset special options
    2279 clp->setSpecialOptions(specialoptions);
    2280
    2281 lpi->validFactorization = true;
    2282
    2283 for (int j = 0; j < ncols; ++j)
    2284 {
    2285 down[j] += objval;
    2286 up[j] += objval;
    2287
    2288 // correct iteration count
    2289 if (iter)
    2290 *iter += outputIterations[2*j] + outputIterations[2*j+1];
    2291
    2292 BMSfreeMemoryArray(&outputSolution[2*j]);
    2293 BMSfreeMemoryArray(&outputSolution[2*j+1]);
    2294 }
    2295
    2296 // reset iteration limit
    2297 clp->setMaximumIterations(iterlimit);
    2298
    2299 // free local memory
    2300 BMSfreeMemoryArray( &outputStatus );
    2301 BMSfreeMemoryArray( &outputIterations );
    2302 BMSfreeMemoryArray( &outputSolution );
    2303
    2304 if ( res == -2 )
    2305 return SCIP_LPERROR;
    2306
    2307 return SCIP_OKAY;
    2308}
    2309
    2310/** performs strong branching iterations on one @b fractional candidate */
    2312 SCIP_LPI* lpi, /**< LP interface structure */
    2313 int col, /**< column to apply strong branching on */
    2314 SCIP_Real psol, /**< current primal solution value of column */
    2315 int itlim, /**< iteration limit for strong branchings */
    2316 SCIP_Real* down, /**< stores dual bound after branching column down */
    2317 SCIP_Real* up, /**< stores dual bound after branching column up */
    2318 SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
    2319 * otherwise, it can only be used as an estimate value */
    2320 SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
    2321 * otherwise, it can only be used as an estimate value */
    2322 int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
    2323 )
    2324{
    2325 /* pass call on to lpiStrongbranch() */
    2326 SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
    2327
    2328 return SCIP_OKAY;
    2329}
    2330
    2331/** performs strong branching iterations on given @b fractional candidates */
    2333 SCIP_LPI* lpi, /**< LP interface structure */
    2334 int* cols, /**< columns to apply strong branching on */
    2335 int ncols, /**< number of columns */
    2336 SCIP_Real* psols, /**< fractional current primal solution values of columns */
    2337 int itlim, /**< iteration limit for strong branchings */
    2338 SCIP_Real* down, /**< stores dual bounds after branching columns down */
    2339 SCIP_Real* up, /**< stores dual bounds after branching columns up */
    2340 SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
    2341 * otherwise, they can only be used as an estimate values */
    2342 SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
    2343 * otherwise, they can only be used as an estimate values */
    2344 int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
    2345 )
    2346{
    2347 if ( iter != NULL )
    2348 *iter = 0;
    2349
    2350 /* pass call on to lpiStrongbranches() */
    2351 SCIP_CALL( lpiStrongbranches(lpi, cols, ncols, psols, itlim, down, up, downvalid, upvalid, iter) );
    2352
    2353 return SCIP_OKAY;
    2354}
    2355
    2356/** performs strong branching iterations on one candidate with @b integral value */
    2358 SCIP_LPI* lpi, /**< LP interface structure */
    2359 int col, /**< column to apply strong branching on */
    2360 SCIP_Real psol, /**< current integral primal solution value of column */
    2361 int itlim, /**< iteration limit for strong branchings */
    2362 SCIP_Real* down, /**< stores dual bound after branching column down */
    2363 SCIP_Real* up, /**< stores dual bound after branching column up */
    2364 SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
    2365 * otherwise, it can only be used as an estimate value */
    2366 SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
    2367 * otherwise, it can only be used as an estimate value */
    2368 int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
    2369 )
    2370{
    2371 /* pass call on to lpiStrongbranch() */
    2372 SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
    2373
    2374 return SCIP_OKAY;
    2375}
    2376
    2377/** performs strong branching iterations on given candidates with @b integral values */
    2379 SCIP_LPI* lpi, /**< LP interface structure */
    2380 int* cols, /**< columns to apply strong branching on */
    2381 int ncols, /**< number of columns */
    2382 SCIP_Real* psols, /**< current integral primal solution values of columns */
    2383 int itlim, /**< iteration limit for strong branchings */
    2384 SCIP_Real* down, /**< stores dual bounds after branching columns down */
    2385 SCIP_Real* up, /**< stores dual bounds after branching columns up */
    2386 SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
    2387 * otherwise, they can only be used as an estimate values */
    2388 SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
    2389 * otherwise, they can only be used as an estimate values */
    2390 int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
    2391 )
    2392{
    2393 if ( iter != NULL )
    2394 *iter = 0;
    2395
    2396 /* pass call on to lpiStrongbranches() */
    2397 SCIP_CALL( lpiStrongbranches(lpi, cols, ncols, psols, itlim, down, up, downvalid, upvalid, iter) );
    2398
    2399 return SCIP_OKAY;
    2400}
    2401
    2402/**@} */
    2403
    2404
    2405
    2406/*
    2407 * Solution Information Methods
    2408 */
    2409
    2410/**@name Solution Information Methods */
    2411/**@{ */
    2412
    2413/** returns whether a solve method was called after the last modification of the LP */
    2415 SCIP_LPI* lpi /**< LP interface structure */
    2416 )
    2417{
    2418 assert(lpi != NULL);
    2419
    2420 return lpi->solved;
    2421}
    2422
    2423/** gets information about primal and dual feasibility of the current LP solution
    2424 *
    2425 * The feasibility information is with respect to the last solving call and it is only relevant if SCIPlpiWasSolved()
    2426 * returns true. If the LP is changed, this information might be invalidated.
    2427 *
    2428 * Note that @a primalfeasible and @a dualfeasible should only return true if the solver has proved the respective LP to
    2429 * be feasible. Thus, the return values should be equal to the values of SCIPlpiIsPrimalFeasible() and
    2430 * SCIPlpiIsDualFeasible(), respectively. Note that if feasibility cannot be proved, they should return false (even if
    2431 * the problem might actually be feasible).
    2432 */
    2434 SCIP_LPI* lpi, /**< LP interface structure */
    2435 SCIP_Bool* primalfeasible, /**< pointer to store primal feasibility status */
    2436 SCIP_Bool* dualfeasible /**< pointer to store dual feasibility status */
    2437 )
    2438{
    2439 SCIPdebugMessage("calling SCIPlpiGetSolFeasibility()\n");
    2440
    2441 assert(lpi != NULL);
    2442 assert(lpi->clp != NULL);
    2443 assert(primalfeasible != NULL);
    2444 assert(dualfeasible != NULL);
    2445
    2446 if ( lpi->clp->primalFeasible() )
    2447 *primalfeasible = TRUE;
    2448 else
    2449 *primalfeasible = FALSE;
    2450
    2451 if ( lpi->clp->dualFeasible() )
    2452 *dualfeasible = TRUE;
    2453 else
    2454 *dualfeasible = FALSE;
    2455
    2456 // say feasible if deviation is small
    2457 if (lpi->clp->status()==0 && ( ! (*primalfeasible) || ! (*dualfeasible)) )
    2458 {
    2459 if ( !(*primalfeasible) && lpi->clp->sumPrimalInfeasibilities() < SUMINFEASBOUND )
    2460 {
    2461 lpi->clp->setNumberPrimalInfeasibilities(0);
    2462 *primalfeasible = TRUE;
    2463 }
    2464 if ( !(*dualfeasible) && lpi->clp->sumDualInfeasibilities() < SUMINFEASBOUND)
    2465 {
    2466 lpi->clp->setNumberDualInfeasibilities(0);
    2467 *dualfeasible = TRUE;
    2468 }
    2469 }
    2470
    2471 return SCIP_OKAY;
    2472}
    2473
    2474
    2475/** returns TRUE iff LP is proven to have a primal unbounded ray (but not necessary a primal feasible point);
    2476 * this does not necessarily mean, that the solver knows and can return the primal ray
    2477 */
    2479 SCIP_LPI* lpi /**< LP interface structure */
    2480 )
    2481{
    2482 SCIPdebugMessage("calling SCIPlpiExistsPrimalRay()\n");
    2483
    2484 assert(lpi != NULL);
    2485 assert(lpi->clp != NULL);
    2486
    2487 /* Clp usually has a primal ray whenever it concludes "dual infeasible" (status == 2)
    2488 * (but is not necessarily primal feasible), see ClpModel::unboundedRay(). */
    2489 return ( lpi->clp->status() == 2 );
    2490}
    2491
    2492
    2493/** returns TRUE iff LP is proven to have a primal unbounded ray (but not necessary a primal feasible point),
    2494 * and the solver knows and can return the primal ray
    2495 */
    2497 SCIP_LPI* lpi /**< LP interface structure */
    2498 )
    2499{
    2500 SCIPdebugMessage("calling SCIPlpiHasPrimalRay()\n");
    2501
    2502 assert(lpi != NULL);
    2503 assert(lpi->clp != NULL);
    2504
    2505 /* Clp usually has a primal ray whenever it concludes "dual infeasible" (status == 2)
    2506 * (but is not necessarily primal feasible), see ClpModel::unboundedRay(). */
    2507 if ( lpi->clp->rayExists() )
    2508 {
    2509 return ( lpi->clp->status() == 2 );
    2510 }
    2511 return FALSE;
    2512}
    2513
    2514
    2515/** returns TRUE iff LP is proven to be primal unbounded */
    2517 SCIP_LPI* lpi /**< LP interface structure */
    2518 )
    2519{
    2520 SCIPdebugMessage("calling SCIPlpiIsPrimalUnbounded()\n");
    2521
    2522 assert(lpi != NULL);
    2523 assert(lpi->clp != NULL);
    2524
    2525 return ( lpi->clp->isProvenDualInfeasible() && lpi->clp->primalFeasible() );
    2526}
    2527
    2528
    2529/** returns TRUE iff LP is proven to be primal infeasible */
    2531 SCIP_LPI* lpi /**< LP interface structure */
    2532 )
    2533{
    2534 SCIPdebugMessage("calling SCIPlpiIsPrimalInfeasible()\n");
    2535
    2536 assert(lpi != NULL);
    2537 assert(lpi->clp != NULL);
    2538
    2539 /* Should return ClpModel::isProvenPrimalInfeasible() (which returns "status == 1"), but the
    2540 * following is correct (Clp will not be changed). The secondaryStatus is 1 if the dual simplex
    2541 * detects an objective limit exceedence. The primal simplex has no such detection (will never
    2542 * stop with objective limit exceedence). Hence we are infeasible only if status == 1 and we have
    2543 * not stopped due to the objective limit. */
    2544 return ( lpi->clp->status() == 1 && (lpi->clp->secondaryStatus() == 0 || lpi->clp->secondaryStatus() == 6) );
    2545}
    2546
    2547
    2548/** returns TRUE iff LP is proven to be primal feasible */
    2550 SCIP_LPI* lpi /**< LP interface structure */
    2551 )
    2552{
    2553 SCIPdebugMessage("calling SCIPlpiIsPrimalFeasible()\n");
    2554
    2555 assert(lpi != NULL);
    2556 assert(lpi->clp != NULL);
    2557
    2558 return ( lpi->clp->primalFeasible() );
    2559}
    2560
    2561
    2562/** returns TRUE iff LP is proven to have a dual unbounded ray (but not necessary a dual feasible point);
    2563 * this does not necessarily mean, that the solver knows and can return the dual ray
    2564 */
    2566 SCIP_LPI* lpi /**< LP interface structure */
    2567 )
    2568{
    2569 SCIPdebugMessage("calling SCIPlpiExistsDualRay()\n");
    2570
    2571 assert(lpi != NULL);
    2572 assert(lpi->clp != NULL);
    2573
    2574 /* Clp usually has a dual ray whenever it concludes "primal infeasible" (but is not necessarily dual feasible), see
    2575 * ClpModel::infeasibilityRay. Additionally check whether ray exists in order to avoid situations in which Clp cannot
    2576 * provide a ray. SCIP often decides to resolve in such a case and the problem might go away. */
    2577 return ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->rayExists() );
    2578}
    2579
    2580
    2581/** returns TRUE iff LP is proven to have a dual unbounded ray (but not necessary a dual feasible point),
    2582 * and the solver knows and can return the dual ray
    2583 */
    2585 SCIP_LPI* lpi /**< LP interface structure */
    2586 )
    2587{
    2588 SCIPdebugMessage("calling SCIPlpiHasDualRay()\n");
    2589
    2590 assert(lpi != NULL);
    2591 assert(lpi->clp != NULL);
    2592
    2593 /* Clp usually has a dual ray whenever it concludes "primal infeasible" (but is not necessarily dual feasible),
    2594 * see ClpModel::infeasibilityRay. Additionally check whether ray exists. */
    2595 if ( lpi->clp->rayExists() )
    2596 {
    2597 if ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 )
    2598 return TRUE;
    2599 }
    2600
    2601 return FALSE;
    2602}
    2603
    2604
    2605/** returns TRUE iff LP is proven to be dual unbounded */
    2607 SCIP_LPI* lpi /**< LP interface structure */
    2608 )
    2609{
    2610 SCIPdebugMessage("calling SCIPlpiIsDualUnbounded()\n");
    2611
    2612 assert(lpi != NULL);
    2613 assert(lpi->clp != NULL);
    2614
    2615 /* The dual seems to be unbounded if the status is 1 (primal unbounded), the secondaryStatus is
    2616 * not 1 (i.e., the dual simplex has not stopped because of an objective limit exceedence), and
    2617 * the dual is feasible. */
    2618 return ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->dualFeasible() );
    2619}
    2620
    2621
    2622/** returns TRUE iff LP is proven to be dual infeasible */
    2624 SCIP_LPI* lpi /**< LP interface structure */
    2625 )
    2626{
    2627 SCIPdebugMessage("calling SCIPlpiIsDualInfeasible()\n");
    2628
    2629 assert(lpi != NULL);
    2630 assert(lpi->clp != NULL);
    2631
    2632 return ( lpi->clp->isProvenDualInfeasible() );
    2633}
    2634
    2635
    2636/** returns TRUE iff LP is proven to be dual feasible */
    2638 SCIP_LPI* lpi /**< LP interface structure */
    2639 )
    2640{
    2641 SCIPdebugMessage("calling SCIPlpiIsDualFeasible()\n");
    2642
    2643 assert(lpi != NULL);
    2644 assert(lpi->clp != NULL);
    2645
    2646 return ( lpi->clp->dualFeasible() );
    2647}
    2648
    2649
    2650/** returns TRUE iff LP was solved to optimality */
    2652 SCIP_LPI* lpi /**< LP interface structure */
    2653 )
    2654{
    2655 SCIPdebugMessage("calling SCIPlpiIsOptimal()\n");
    2656
    2657 assert(lpi != NULL);
    2658 assert(lpi->clp != NULL);
    2659
    2660 if ( SCIPlpiIsObjlimExc(lpi) )
    2661 return FALSE;
    2662
    2663 /* secondaryStatus == 6 means that the problem is empty */
    2664 return( lpi->clp->isProvenOptimal() && (lpi->clp->secondaryStatus() == 0 || lpi->clp->secondaryStatus() == 6));
    2665}
    2666
    2667
    2668/** returns TRUE iff current LP solution is stable
    2669 *
    2670 * This function should return true if the solution is reliable, i.e., feasible and optimal (or proven
    2671 * infeasible/unbounded) with respect to the original problem. The optimality status might be with respect to a scaled
    2672 * version of the problem, but the solution might not be feasible to the unscaled original problem; in this case,
    2673 * SCIPlpiIsStable() should return false.
    2674 */
    2676 SCIP_LPI* lpi /**< LP interface structure */
    2677 )
    2678{
    2679 SCIPdebugMessage("calling SCIPlpiIsStable()\n");
    2680
    2681 assert(lpi != NULL);
    2682 assert(lpi->clp != NULL);
    2683
    2684 /* Return false if infeasible, but dual ray is not present and the algorithm type has changed. This is one of the
    2685 * cases in which Clp cannot produce a ray and the hope is to get a ray by rerunning. */
    2686 if ( lpi->clp->status() == 1 && lpi->lastalgorithm != lpi->clp->algorithm() && ! lpi->clp->rayExists() )
    2687 return FALSE;
    2688
    2689 /* We first check if status is ok, i.e., is one of the following:
    2690 * 0 - optimal
    2691 * 1 - primal infeasible
    2692 * 2 - dual infeasible
    2693 * 3 - stopped on iterations or time
    2694 * 4 - stopped due to errors
    2695 * 5 - stopped by event handler (virtual int ClpEventHandler::event())
    2696 *
    2697 * Then we check the secondary status of Clp:
    2698 * 0 - none
    2699 * 1 - primal infeasible because dual limit reached OR (probably primal infeasible but can't prove it - main status was 4)
    2700 * 2 - scaled problem optimal - unscaled problem has primal infeasibilities
    2701 * 3 - scaled problem optimal - unscaled problem has dual infeasibilities
    2702 * 4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities
    2703 * 5 - giving up in primal with flagged variables
    2704 * 6 - failed due to empty problem check
    2705 * 7 - postSolve says not optimal
    2706 * 8 - failed due to bad element check
    2707 * 9 - status was 3 and stopped on time
    2708 * 100 up - translation of enum from ClpEventHandler
    2709 */
    2710 SCIPdebugMessage("status: %d secondary: %d\n", lpi->clp->status(), lpi->clp->secondaryStatus());
    2711 assert( 0 <= lpi->clp->status() && lpi->clp->status() <= 5 );
    2712
    2713 return( (lpi->clp->status() <= 3) && (lpi->clp->secondaryStatus() <= 1 || lpi->clp->secondaryStatus() == 6 || lpi->clp->secondaryStatus() == 9) );
    2714}
    2715
    2716
    2717/** returns TRUE iff the objective limit was reached */
    2719 SCIP_LPI* lpi /**< LP interface structure */
    2720 )
    2721{
    2722 SCIPdebugMessage("calling SCIPlpiIsObjlimExc()\n");
    2723
    2724 assert(lpi != NULL);
    2725 assert(lpi->clp != NULL);
    2726
    2727 /* if status == 1 (primal infeasible) and secondaryStatus == 1 then Clp hit the dual bound */
    2728 if ( lpi->clp->status() == 1 )
    2729 {
    2730 if ( lpi->clp->secondaryStatus() == 1 )
    2731 return TRUE;
    2732 else
    2733 return FALSE;
    2734 }
    2735
    2736 return ( lpi->clp->isObjectiveLimitTestValid() && lpi->clp->isDualObjectiveLimitReached() );
    2737
    2738 /* The above code is equivalent to the following:
    2739 if ( lpi->clp->status() == 0 || (lpi->clp->status() == 1 && lpi->clp->algorithm() < 0) || (lpi->clp->status() == 2 && lpi->clp->algorithm() > 0) )
    2740 {
    2741 return ( lpi->clp->isPrimalObjectiveLimitReached() || lpi->clp->isDualObjectiveLimitReached() );
    2742 }
    2743 */
    2744}
    2745
    2746
    2747/** returns TRUE iff the iteration limit was reached */
    2749 SCIP_LPI* lpi /**< LP interface structure */
    2750 )
    2751{
    2752 SCIPdebugMessage("calling SCIPlpiIsIterlimExc()\n");
    2753
    2754 assert(lpi != NULL);
    2755 assert(lpi->clp != NULL);
    2756
    2757 /* status == 3 means that Clp stopped on time or iteration limit
    2758 * secondary status == 9 means that status was 3 and Clp stopped on time */
    2759 return ( lpi->clp->status() == 3 && lpi->clp->secondaryStatus() != 9 );
    2760}
    2761
    2762
    2763/** returns TRUE iff the time limit was reached */
    2765 SCIP_LPI* lpi /**< LP interface structure */
    2766 )
    2767{
    2768 SCIPdebugMessage("calling SCIPlpiIsTimelimExc()\n");
    2769
    2770 assert(lpi != NULL);
    2771 assert(lpi->clp != NULL);
    2772
    2773 /* status == 3 means that Clp stopped on time or iteration limit
    2774 * secondary status == 9 means that status was 3 and Clp stopped on time */
    2775 return ( lpi->clp->status() == 3 && lpi->clp->secondaryStatus() == 9 );
    2776}
    2777
    2778
    2779/** returns the internal solution status of the solver */
    2781 SCIP_LPI* lpi /**< LP interface structure */
    2782 )
    2783{
    2784 SCIPdebugMessage("calling SCIPlpiGetInternalStatus()\n");
    2785
    2786 assert(lpi != NULL);
    2787 assert(lpi->clp != NULL);
    2788
    2789 return lpi->clp->status();
    2790}
    2791
    2792
    2793/** gets objective value of solution */
    2795 SCIP_LPI* lpi, /**< LP interface structure */
    2796 SCIP_Real* objval /**< stores the objective value */
    2797 )
    2798{
    2799 SCIPdebugMessage("calling SCIPlpiGetObjval()\n");
    2800
    2801 assert(lpi != NULL);
    2802 assert(lpi->clp != NULL);
    2803 assert(objval != NULL);
    2804
    2805 *objval = lpi->clp->objectiveValue();
    2806
    2807 return SCIP_OKAY;
    2808}
    2809
    2810
    2811/** gets primal and dual solution vectors for feasible LPs
    2812 *
    2813 * Before calling this function, the caller must ensure that the LP has been solved to optimality, i.e., that
    2814 * SCIPlpiIsOptimal() returns true.
    2815 */
    2817 SCIP_LPI* lpi, /**< LP interface structure */
    2818 SCIP_Real* objval, /**< stores the objective value, may be NULL if not needed */
    2819 SCIP_Real* primsol, /**< primal solution vector, may be NULL if not needed */
    2820 SCIP_Real* dualsol, /**< dual solution vector, may be NULL if not needed */
    2821 SCIP_Real* activity, /**< row activity vector, may be NULL if not needed */
    2822 SCIP_Real* redcost /**< reduced cost vector, may be NULL if not needed */
    2823 )
    2824{
    2825 SCIPdebugMessage("calling SCIPlpiGetSol()\n");
    2826
    2827 assert(lpi != NULL);
    2828 assert(lpi->clp != NULL);
    2829
    2830 ClpSimplex* clp = lpi->clp;
    2831 if( objval != NULL )
    2832 *objval = clp->objectiveValue();
    2833
    2834 if( primsol != NULL )
    2835 {
    2836 const double* sol = clp->getColSolution();
    2837 BMScopyMemoryArray( primsol, sol, clp->numberColumns() );
    2838 }
    2839 if( dualsol != NULL )
    2840 {
    2841 const double* dsol = clp->getRowPrice();
    2842 BMScopyMemoryArray( dualsol, dsol, clp->numberRows() );
    2843 }
    2844 if( activity != NULL )
    2845 {
    2846 const double* act = clp->getRowActivity();
    2847 BMScopyMemoryArray( activity, act, clp->numberRows() );
    2848 }
    2849 if( redcost != NULL )
    2850 {
    2851 const double* red = clp->getReducedCost();
    2852 BMScopyMemoryArray( redcost, red, clp->numberColumns() );
    2853 }
    2854
    2855 return SCIP_OKAY;
    2856}
    2857
    2858
    2859/** gets primal ray for unbounded LPs */
    2861 SCIP_LPI* lpi, /**< LP interface structure */
    2862 SCIP_Real* ray /**< primal ray */
    2863 )
    2864{
    2865 SCIPdebugMessage("calling SCIPlpiGetPrimalRay()\n");
    2866
    2867 assert(lpi != NULL);
    2868 assert(lpi->clp != NULL);
    2869 assert(ray != NULL);
    2870
    2871 /* Unbounded ray (NULL returned if none/wrong). Up to user to use delete [] on these arrays. */
    2872 const double* clpray = lpi->clp->unboundedRay();
    2873
    2874 if ( clpray == NULL )
    2875 return SCIP_LPERROR;
    2876
    2877 BMScopyMemoryArray(ray, clpray, lpi->clp->numberColumns());
    2878
    2879 delete [] clpray;
    2880
    2881 return SCIP_OKAY;
    2882}
    2883
    2884/** gets dual farkas proof for infeasibility */
    2886 SCIP_LPI* lpi, /**< LP interface structure */
    2887 SCIP_Real* dualfarkas /**< dual farkas row multipliers */
    2888 )
    2889{
    2890 SCIPdebugMessage("calling SCIPlpiGetDualfarkas()\n");
    2891
    2892 assert(lpi != NULL);
    2893 assert(lpi->clp != NULL);
    2894 assert(dualfarkas != NULL);
    2895
    2896 /* Infeasibility ray (NULL returned if none/wrong). Up to user to use delete [] on these arrays. */
    2897 const double* dualray = lpi->clp->infeasibilityRay();
    2898
    2899 if ( dualray == NULL )
    2900 return SCIP_LPERROR;
    2901
    2902 /* The dual ray returned by Clp sometimes contains large numbers. We try to scale the vector. First compute maximal
    2903 * and minimal absolute values. */
    2904 double minabsvalue = SCIPlpiInfinity(lpi);
    2905 double maxabsvalue = 0.0;
    2906 double feastol = lpi->clp->primalTolerance();
    2907 for (int j = 0; j < lpi->clp->numberRows(); ++j)
    2908 {
    2909 double val = fabs(dualray[j]);
    2910
    2911 /* only consider nonzero entries */
    2912 if ( val >= feastol )
    2913 {
    2914 if ( val > maxabsvalue )
    2915 maxabsvalue = val;
    2916 if ( val < minabsvalue )
    2917 minabsvalue = val;
    2918 }
    2919 }
    2920
    2921 /* Possibly scale and also convert sign. */
    2922 if ( maxabsvalue > 0.0 )
    2923 {
    2924 assert( 0.0 < minabsvalue && minabsvalue <= maxabsvalue );
    2925
    2926 /* We try to make the maximum absolute value to be 1.0, but if the minimal absolute value would be less than the
    2927 * feasibility tolerance, we adjust the factor such that it will be equal to the feasibility tolerance. */
    2928 double scalingfactor = maxabsvalue;
    2929 if ( minabsvalue / scalingfactor < feastol )
    2930 scalingfactor = minabsvalue / feastol;
    2931
    2932 for (int j = 0; j < lpi->clp->numberRows(); ++j)
    2933 dualfarkas[j] = -dualray[j]/scalingfactor;
    2934 }
    2935 else
    2936 {
    2937 /* convert sign */
    2938 for (int j = 0; j < lpi->clp->numberRows(); ++j)
    2939 dualfarkas[j] = -dualray[j];
    2940 }
    2941
    2942 delete [] dualray;
    2943
    2944 return SCIP_OKAY;
    2945}
    2946
    2947
    2948/** gets the number of LP iterations of the last solve call */
    2950 SCIP_LPI* lpi, /**< LP interface structure */
    2951 int* iterations /**< pointer to store the number of iterations of the last solve call */
    2952 )
    2953{
    2954 assert(lpi != NULL);
    2955 assert(lpi->clp != NULL);
    2956 assert(iterations != NULL);
    2957
    2958 *iterations = lpi->clp->numberIterations();
    2959
    2960 return SCIP_OKAY;
    2961}
    2962
    2963/** gets information about the quality of an LP solution
    2964 *
    2965 * Such information is usually only available, if also a (maybe not optimal) solution is available.
    2966 * The LPI should return SCIP_INVALID for @p quality, if the requested quantity is not available.
    2967 */
    2969 SCIP_LPI* lpi, /**< LP interface structure */
    2970 SCIP_LPSOLQUALITY qualityindicator, /**< indicates which quality should be returned */
    2971 SCIP_Real* quality /**< pointer to store quality number */
    2972 )
    2973{
    2974 assert(lpi != NULL);
    2975 assert(quality != NULL);
    2976
    2977 *quality = SCIP_INVALID;
    2978
    2979 return SCIP_OKAY;
    2980}
    2981
    2982/**@} */
    2983
    2984
    2985
    2986
    2987/*
    2988 * LP Basis Methods
    2989 */
    2990
    2991/**@name LP Basis Methods */
    2992/**@{ */
    2993
    2994/** gets current basis status for columns and rows; arrays must be large enough to store the basis status */
    2996 SCIP_LPI* lpi, /**< LP interface structure */
    2997 int* cstat, /**< array to store column basis status, or NULL */
    2998 int* rstat /**< array to store row basis status, or NULL */
    2999 )
    3000{
    3001 SCIPdebugMessage("calling SCIPlpiGetBase()\n");
    3002
    3003 assert(lpi != NULL);
    3004 assert(lpi->clp != NULL);
    3005
    3006 ClpSimplex* clp = lpi->clp;
    3007
    3008 if( rstat != NULL )
    3009 {
    3010 for( int i = 0; i < clp->numberRows(); ++i )
    3011 {
    3012 switch ( clp->getRowStatus(i) )
    3013 {
    3014 case ClpSimplex::isFree:
    3015 rstat[i] = SCIP_BASESTAT_ZERO;
    3016 break;
    3017 case ClpSimplex::basic:
    3018 rstat[i] = SCIP_BASESTAT_BASIC;
    3019 break;
    3020 case ClpSimplex::atUpperBound:
    3021 rstat[i] = SCIP_BASESTAT_UPPER;
    3022 break;
    3023 case ClpSimplex::atLowerBound:
    3024 rstat[i] = SCIP_BASESTAT_LOWER;
    3025 break;
    3026 case ClpSimplex::superBasic:
    3027 rstat[i] = SCIP_BASESTAT_ZERO;
    3028 break;
    3029 case ClpSimplex::isFixed:
    3030 if (clp->getRowPrice()[i] > 0.0)
    3031 rstat[i] = SCIP_BASESTAT_LOWER;
    3032 else
    3033 rstat[i] = SCIP_BASESTAT_UPPER;
    3034 break;
    3035 default:
    3036 SCIPerrorMessage("invalid basis status\n");
    3037 SCIPABORT();
    3038 return SCIP_INVALIDDATA; /*lint !e527*/
    3039 }
    3040 }
    3041 }
    3042
    3043 if( cstat != NULL )
    3044 {
    3045#ifndef NDEBUG
    3046 const double* lb = clp->getColLower();
    3047 const double* ub = clp->getColUpper();
    3048#endif
    3049
    3050 for( int j = 0; j < clp->numberColumns(); ++j )
    3051 {
    3052 switch ( clp->getColumnStatus(j) )
    3053 {
    3054 case ClpSimplex::isFree:
    3055 cstat[j] = SCIP_BASESTAT_ZERO;
    3056 break;
    3057 case ClpSimplex::basic:
    3058 cstat[j] = SCIP_BASESTAT_BASIC;
    3059 break;
    3060 case ClpSimplex::atUpperBound:
    3061 cstat[j] = SCIP_BASESTAT_UPPER;
    3062 assert( ub[j] < COIN_DBL_MAX );
    3063 break;
    3064 case ClpSimplex::atLowerBound:
    3065 cstat[j] = SCIP_BASESTAT_LOWER;
    3066 assert( lb[j] > -COIN_DBL_MAX );
    3067 break;
    3068 case ClpSimplex::superBasic:
    3069 cstat[j] = SCIP_BASESTAT_ZERO;
    3070 break;
    3071 case ClpSimplex::isFixed:
    3072 if (clp->getReducedCost()[j] > 0.0)
    3073 {
    3074 cstat[j] = SCIP_BASESTAT_LOWER;
    3075 assert( lb[j] > -COIN_DBL_MAX );
    3076 }
    3077 else
    3078 {
    3079 cstat[j] = SCIP_BASESTAT_UPPER;
    3080 assert( ub[j] < COIN_DBL_MAX );
    3081 }
    3082 break;
    3083 default: SCIPerrorMessage("invalid basis status\n");
    3084 SCIPABORT();
    3085 return SCIP_INVALIDDATA; /*lint !e527*/
    3086 }
    3087 }
    3088 }
    3089
    3090 return SCIP_OKAY;
    3091}
    3092
    3093
    3094/** sets current basis status for columns and rows */
    3096 SCIP_LPI* lpi, /**< LP interface structure */
    3097 const int* cstat, /**< array with column basis status */
    3098 const int* rstat /**< array with row basis status */
    3099 )
    3100{
    3101 int ncols;
    3102 int nrows;
    3103
    3104 SCIPdebugMessage("calling SCIPlpiSetBase()\n");
    3105
    3106 assert(lpi != NULL);
    3107 assert(lpi->clp != NULL);
    3108
    3109 SCIP_CALL( SCIPlpiGetNCols(lpi, &ncols) );
    3110 SCIP_CALL( SCIPlpiGetNRows(lpi, &nrows) );
    3111
    3112 assert(rstat != NULL || lpi->clp->numberRows() == 0);
    3113 assert(cstat != NULL || lpi->clp->numberColumns() == 0);
    3114
    3115 invalidateSolution(lpi);
    3116
    3117 // Adapted from OsiClpSolverInterface::setBasisStatus
    3118
    3119 ClpSimplex* clp = lpi->clp;
    3120 clp->createStatus();
    3121
    3122 const double* lhs = clp->getRowLower();
    3123 const double* rhs = clp->getRowUpper();
    3124
    3125 for( int i = 0; i < clp->numberRows(); ++i )
    3126 {
    3127 int status = rstat[i];
    3128 assert( 0 <= status && status <= 3 );
    3129 assert( lhs[i] > -COIN_DBL_MAX || status != SCIP_BASESTAT_LOWER); // can't be at lower bound
    3130 assert( rhs[i] < COIN_DBL_MAX || status != SCIP_BASESTAT_UPPER); // can't be at upper bound
    3131
    3132 switch ( status )
    3133 {
    3134 case SCIP_BASESTAT_ZERO:
    3135 if ( lhs[i] <= -COIN_DBL_MAX && rhs[i] >= COIN_DBL_MAX )
    3136 clp->setRowStatus(i, ClpSimplex::isFree);
    3137 else
    3138 clp->setRowStatus(i, ClpSimplex::superBasic);
    3139 break;
    3141 clp->setRowStatus(i, ClpSimplex::basic);
    3142 break;
    3144 clp->setRowStatus(i, ClpSimplex::atUpperBound);
    3145 break;
    3147 if ( EPSEQ(rhs[i], lhs[i], 1e-6) ) // if bounds are equal
    3148 clp->setRowStatus(i, ClpSimplex::isFixed);
    3149 else
    3150 clp->setRowStatus(i, ClpSimplex::atLowerBound);
    3151 break;
    3152 default:
    3153 SCIPerrorMessage("invalid basis status\n");
    3154 SCIPABORT();
    3155 return SCIP_INVALIDDATA; /*lint !e527*/
    3156 }
    3157 }
    3158
    3159 const double* lb = clp->getColLower();
    3160 const double* ub = clp->getColUpper();
    3161
    3162 for( int j = 0; j < clp->numberColumns(); ++j )
    3163 {
    3164 int status = cstat[j];
    3165 assert( 0 <= status && status <= 3 );
    3166 assert( lb[j] > -COIN_DBL_MAX || status != SCIP_BASESTAT_LOWER); // can't be at lower bound
    3167 assert( ub[j] < COIN_DBL_MAX || status != SCIP_BASESTAT_UPPER); // can't be at upper bound
    3168
    3169 switch ( status )
    3170 {
    3171 case SCIP_BASESTAT_ZERO:
    3172 if ( lb[j] <= -COIN_DBL_MAX && ub[j] >= COIN_DBL_MAX )
    3173 clp->setColumnStatus(j, ClpSimplex::isFree);
    3174 else
    3175 clp->setColumnStatus(j, ClpSimplex::superBasic);
    3176 break;
    3178 clp->setColumnStatus(j, ClpSimplex::basic);
    3179 break;
    3181 clp->setColumnStatus(j, ClpSimplex::atUpperBound);
    3182 break;
    3184 if ( EPSEQ(ub[j], lb[j], 1e-6) )
    3185 clp->setColumnStatus(j, ClpSimplex::isFixed);
    3186 else
    3187 clp->setColumnStatus(j, ClpSimplex::atLowerBound);
    3188 break;
    3189 default:
    3190 SCIPerrorMessage("invalid basis status\n");
    3191 SCIPABORT();
    3192 return SCIP_INVALIDDATA; /*lint !e527*/
    3193 }
    3194 }
    3195
    3196 /* Whats changed since last solve.
    3197 * Is only used when startFinishOptions used in dual or primal.
    3198 * Bit 1 - number of rows/columns has not changed (so work arrays valid)
    3199 * 2 - matrix has not changed
    3200 * 4 - if matrix has changed only by adding rows
    3201 * 8 - if matrix has changed only by adding columns
    3202 * 16 - row lbs not changed
    3203 * 32 - row ubs not changed
    3204 * 64 - column objective not changed
    3205 * 128 - column lbs not changed
    3206 * 256 - column ubs not changed
    3207 * 512 - basis not changed (up to user to set this to 0)
    3208 * top bits may be used internally
    3209 */
    3210 clp->setWhatsChanged(clp->whatsChanged() & (~512));
    3211
    3212 return SCIP_OKAY;
    3213}
    3214
    3215
    3216/** returns the indices of the basic columns and rows; basic column n gives value n, basic row m gives value -1-m */
    3218 SCIP_LPI* lpi, /**< LP interface structure */
    3219 int* bind /**< pointer to store basis indices ready to keep number of rows entries */
    3220 )
    3221{
    3222 SCIPdebugMessage("calling SCIPlpiGetBasisInd()\n");
    3223
    3224 assert(lpi != NULL);
    3225 assert(lpi->clp != NULL);
    3226 assert(bind != 0);
    3227
    3228 ClpSimplex* clp = lpi->clp;
    3229 int nrows = clp->numberRows();
    3230 int ncols = clp->numberColumns();
    3231
    3232 int* idx = NULL;
    3233 SCIP_ALLOC( BMSallocMemoryArray(&idx, nrows) );
    3234
    3235 /* If secondaryStatus == 6, clp says the LP is empty. Mose likely this happened, because the
    3236 * matrix is empty, i.e., all rows were redundant/empty. In this case, we construct a basis
    3237 * consisting of slack variables. */
    3238 if ( clp->secondaryStatus() == 6 )
    3239 {
    3240 assert( clp->getNumElements() == 0 );
    3241 for (int i = 0; i < nrows; ++i)
    3242 idx[i] = ncols + i;
    3243 }
    3244 else
    3245 clp->getBasics(idx);
    3246
    3247 for (int i = 0; i < nrows; ++i)
    3248 {
    3249 if ( idx[i] < ncols )
    3250 bind[i] = idx[i];
    3251 else
    3252 bind[i] = -1 - (idx[i] - ncols);
    3253 }
    3254
    3255 BMSfreeMemoryArray(&idx);
    3256
    3257 return SCIP_OKAY;
    3258}
    3259
    3260
    3261/** get row of inverse basis matrix B^-1
    3262 *
    3263 * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
    3264 * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
    3265 * see also the explanation in lpi.h.
    3266 *
    3267 * @todo check that the result is in terms of the LP interface definition
    3268 */
    3270 SCIP_LPI* lpi, /**< LP interface structure */
    3271 int r, /**< row number */
    3272 SCIP_Real* coef, /**< pointer to store the coefficients of the row */
    3273 int* inds, /**< array to store the non-zero indices, or NULL */
    3274 int* ninds /**< pointer to store the number of non-zero indices, or NULL
    3275 * (-1: if we do not store sparsity information) */
    3276 )
    3277{
    3278 SCIPdebugMessage("calling SCIPlpiGetBInvRow()\n");
    3279
    3280 assert(lpi != NULL);
    3281 assert(lpi->clp != NULL);
    3282 assert(coef != NULL);
    3283 assert( 0 <= r && r <= lpi->clp->numberRows() );
    3284
    3285 /* can only return dense result */
    3286 if ( ninds != NULL )
    3287 *ninds = -1;
    3288
    3289 ClpSimplex* clp = lpi->clp;
    3290 clp->getBInvRow(r, coef);
    3291
    3292 return SCIP_OKAY;
    3293}
    3294
    3295
    3296/** get column of inverse basis matrix B^-1
    3297 *
    3298 * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
    3299 * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
    3300 * see also the explanation in lpi.h.
    3301 *
    3302 * @todo check that the result is in terms of the LP interface definition
    3303 */
    3305 SCIP_LPI* lpi, /**< LP interface structure */
    3306 int c, /**< column number of B^-1; this is NOT the number of the column in the LP;
    3307 * you have to call SCIPlpiGetBasisInd() to get the array which links the
    3308 * B^-1 column numbers to the row and column numbers of the LP!
    3309 * c must be between 0 and nrows-1, since the basis has the size
    3310 * nrows * nrows */
    3311 SCIP_Real* coef, /**< pointer to store the coefficients of the column */
    3312 int* inds, /**< array to store the non-zero indices, or NULL */
    3313 int* ninds /**< pointer to store the number of non-zero indices, or NULL
    3314 * (-1: if we do not store sparsity information) */
    3315 )
    3316{
    3317 SCIPdebugMessage("calling SCIPlpiGetBInvCol()\n");
    3318
    3319 assert(lpi != NULL);
    3320 assert(lpi->clp != NULL);
    3321 assert(coef != NULL);
    3322 assert( 0 <= c && c <= lpi->clp->numberRows() ); /* basis matrix is nrows * nrows */
    3323
    3324 /* can only return dense result */
    3325 if ( ninds != NULL )
    3326 *ninds = -1;
    3327
    3328 ClpSimplex* clp = lpi->clp;
    3329 clp->getBInvCol(c, coef);
    3330
    3331 return SCIP_OKAY;
    3332}
    3333
    3334/** get row of inverse basis matrix times constraint matrix B^-1 * A
    3335 *
    3336 * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
    3337 * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
    3338 * see also the explanation in lpi.h.
    3339 *
    3340 * @todo check that the result is in terms of the LP interface definition
    3341 */
    3343 SCIP_LPI* lpi, /**< LP interface structure */
    3344 int r, /**< row number */
    3345 const SCIP_Real* binvrow, /**< row in (A_B)^-1 from prior call to SCIPlpiGetBInvRow(), or NULL */
    3346 SCIP_Real* coef, /**< vector to return coefficients of the row */
    3347 int* inds, /**< array to store the non-zero indices, or NULL */
    3348 int* ninds /**< pointer to store the number of non-zero indices, or NULL
    3349 * (-1: if we do not store sparsity information) */
    3350 )
    3351{
    3352 SCIPdebugMessage("calling SCIPlpiGetBInvARow()\n");
    3353
    3354 assert(lpi != NULL);
    3355 assert(lpi->clp != NULL);
    3356 assert(coef != NULL);
    3357 assert( 0 <= r && r <= lpi->clp->numberRows() );
    3358
    3359 /* can only return dense result */
    3360 if ( ninds != NULL )
    3361 *ninds = -1;
    3362
    3363 ClpSimplex* clp = lpi->clp;
    3364 clp->getBInvARow(r, coef, 0);
    3365
    3366 return SCIP_OKAY;
    3367}
    3368
    3369/** get column of inverse basis matrix times constraint matrix B^-1 * A
    3370 *
    3371 * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
    3372 * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
    3373 * see also the explanation in lpi.h.
    3374 *
    3375 * @todo check that the result is in terms of the LP interface definition
    3376 */
    3378 SCIP_LPI* lpi, /**< LP interface structure */
    3379 int c, /**< column number */
    3380 SCIP_Real* coef, /**< vector to return coefficients of the column */
    3381 int* inds, /**< array to store the non-zero indices, or NULL */
    3382 int* ninds /**< pointer to store the number of non-zero indices, or NULL
    3383 * (-1: if we do not store sparsity information) */
    3384 )
    3385{
    3386 SCIPdebugMessage("calling SCIPlpiGetBInvACol()\n");
    3387
    3388 assert(lpi != NULL);
    3389 assert(lpi->clp != NULL);
    3390 assert( coef != 0 );
    3391 assert( 0 <= c && c <= lpi->clp->numberColumns() );
    3392
    3393 /* can only return dense result */
    3394 if ( ninds != NULL )
    3395 *ninds = -1;
    3396
    3397 ClpSimplex* clp = lpi->clp;
    3398 clp->getBInvACol(c, coef);
    3399
    3400 return SCIP_OKAY;
    3401}
    3402
    3403
    3404/**@} */
    3405
    3406
    3407
    3408
    3409/*
    3410 * LP State Methods
    3411 */
    3412
    3413/**@name LP State Methods */
    3414/**@{ */
    3415
    3416/** stores LPi state (like basis information) into lpistate object */
    3418 SCIP_LPI* lpi, /**< LP interface structure */
    3419 BMS_BLKMEM* blkmem, /**< block memory */
    3420 SCIP_LPISTATE** lpistate /**< pointer to LPi state information (like basis information) */
    3421 )
    3422{
    3423 SCIPdebugMessage("calling SCIPlpiGetState()\n");
    3424
    3425 assert(blkmem != NULL);
    3426 assert(lpi != NULL);
    3427 assert(lpi->clp != NULL);
    3428 assert(lpistate != NULL);
    3429
    3430 int ncols = lpi->clp->numberColumns();
    3431 int nrows = lpi->clp->numberRows();
    3432 assert(ncols >= 0);
    3433 assert(nrows >= 0);
    3434
    3435 /* allocate lpistate data */
    3436 SCIP_CALL( lpistateCreate(lpistate, blkmem, ncols, nrows) );
    3437
    3438 /* allocate enough memory for storing uncompressed basis information */
    3439 SCIP_CALL( ensureCstatMem(lpi, ncols) );
    3440 SCIP_CALL( ensureRstatMem(lpi, nrows) );
    3441
    3442 /* get unpacked basis information */
    3443 SCIP_CALL( SCIPlpiGetBase(lpi, lpi->cstat, lpi->rstat) );
    3444
    3445 /* pack LPi state data */
    3446 (*lpistate)->ncols = ncols;
    3447 (*lpistate)->nrows = nrows;
    3448 lpistatePack(*lpistate, lpi->cstat, lpi->rstat);
    3449
    3450 return SCIP_OKAY;
    3451}
    3452
    3453
    3454/** loads LPi state (like basis information) into solver; note that the LP might have been extended with additional
    3455 * columns and rows since the state was stored with SCIPlpiGetState()
    3456 */
    3458 SCIP_LPI* lpi, /**< LP interface structure */
    3459 BMS_BLKMEM* blkmem, /**< block memory */
    3460 const SCIP_LPISTATE* lpistate /**< LPi state information (like basis information), or NULL */
    3461 )
    3462{ /* lint --e{715} */
    3463 int lpncols;
    3464 int lpnrows;
    3465 int i;
    3466
    3467 SCIPdebugMessage("calling SCIPlpiSetState()\n");
    3468
    3469 assert(lpi != NULL);
    3470 assert(lpi->clp != NULL);
    3471 assert(blkmem != NULL);
    3472
    3473 /* if there was no basis information available, the LPI state was not stored */
    3474 if( lpistate == NULL )
    3475 return SCIP_OKAY;
    3476
    3477 lpncols = lpi->clp->numberColumns();
    3478 lpnrows = lpi->clp->numberRows();
    3479 assert(lpistate->ncols <= lpncols);
    3480 assert(lpistate->nrows <= lpnrows);
    3481
    3482 /* allocate enough memory for storing uncompressed basis information */
    3483 SCIP_CALL( ensureCstatMem(lpi, lpncols) );
    3484 SCIP_CALL( ensureRstatMem(lpi, lpnrows) );
    3485
    3486 /* unpack LPi state data */
    3487 lpistateUnpack(lpistate, lpi->cstat, lpi->rstat);
    3488
    3489 /* extend the basis to the current LP beyond the previously existing columns */
    3490 for( i = lpistate->ncols; i < lpncols; ++i )
    3491 {
    3492 SCIP_Real bnd = (lpi->clp->getColLower())[i];
    3493 if ( SCIPlpiIsInfinity(lpi, REALABS(bnd)) )
    3494 {
    3495 /* if lower bound is +/- infinity -> try upper bound */
    3496 bnd = (lpi->clp->getColUpper())[i];
    3497 if ( SCIPlpiIsInfinity(lpi, REALABS(bnd)) )
    3498 lpi->cstat[i] = SCIP_BASESTAT_ZERO; /* variable is free */
    3499 else
    3500 lpi->cstat[i] = SCIP_BASESTAT_UPPER; /* use finite upper bound */
    3501 }
    3502 else
    3503 lpi->cstat[i] = SCIP_BASESTAT_LOWER; /* use finite lower bound */
    3504 }
    3505 for( i = lpistate->nrows; i < lpnrows; ++i )
    3506 lpi->rstat[i] = SCIP_BASESTAT_BASIC;
    3507
    3508 /* load basis information */
    3509 SCIP_CALL( SCIPlpiSetBase(lpi, lpi->cstat, lpi->rstat) );
    3510
    3511 return SCIP_OKAY;
    3512}
    3513
    3514/** clears current LPi state (like basis information) of the solver */
    3516 SCIP_LPI* lpi /**< LP interface structure */
    3517 )
    3518{
    3519 SCIPdebugMessage("calling SCIPlpiClearState()\n");
    3520
    3521 assert(lpi != NULL);
    3522 assert(lpi->clp != NULL);
    3523
    3524 lpi->clp->allSlackBasis(true);
    3525 lpi->validFactorization = false;
    3526
    3527 return SCIP_OKAY;
    3528}
    3529
    3530/** frees LPi state information */
    3532 SCIP_LPI* lpi, /**< LP interface structure */
    3533 BMS_BLKMEM* blkmem, /**< block memory */
    3534 SCIP_LPISTATE** lpistate /**< pointer to LPi state information (like basis information) */
    3535 )
    3536{
    3537 SCIPdebugMessage("calling SCIPlpiFreeState()\n");
    3538
    3539 assert(lpi != NULL);
    3540 assert(lpistate != NULL);
    3541 assert(blkmem != NULL);
    3542
    3543 if ( *lpistate != NULL )
    3544 lpistateFree(lpistate, blkmem);
    3545
    3546 return SCIP_OKAY;
    3547}
    3548
    3549/** checks whether the given LP state contains simplex basis information */
    3551 SCIP_LPI* lpi, /**< LP interface structure */
    3552 SCIP_LPISTATE* lpistate /**< LP state information (like basis information), or NULL*/
    3553 )
    3554{
    3555 assert(lpi != NULL);
    3556 return (lpistate != NULL);
    3557}
    3558
    3559/** reads LP state (like basis information) from a file */
    3561 SCIP_LPI* lpi, /**< LP interface structure */
    3562 const char* fname /**< file name */
    3563 )
    3564{
    3565 SCIPdebugMessage("calling SCIPlpiReadState()\n");
    3566 assert(lpi != NULL);
    3567 assert(lpi->clp != NULL);
    3568 assert(fname != NULL);
    3569
    3570 /* Read a basis from the given filename,
    3571 * returns -1 on file error, 0 if no values, 1 if values
    3572 */
    3573 if ( lpi->clp->readBasis(fname) < 0 )
    3574 return SCIP_READERROR;
    3575
    3576 return SCIP_OKAY;
    3577}
    3578
    3579/** writes LPi state (i.e. basis information) to a file */
    3581 SCIP_LPI* lpi, /**< LP interface structure */
    3582 const char* fname /**< file name */
    3583 )
    3584{
    3585 SCIPdebugMessage("calling SCIPlpiWriteState()\n");
    3586 assert(lpi != NULL);
    3587 assert(lpi->clp != NULL);
    3588 assert(fname != NULL);
    3589
    3590 /* Write the basis in MPS format to the specified file.
    3591 * If writeValues true, writes values of structurals
    3592 * (and adds VALUES to end of NAME card)
    3593 *
    3594 * parameters:
    3595 * - filename
    3596 * - bool writeValues
    3597 * - int formatType (0 - normal, 1 - extra accuracy, 2 - IEEE hex)
    3598 */
    3599 if ( lpi->clp->writeBasis(fname, false, 0) )
    3600 return SCIP_WRITEERROR;
    3601
    3602 return SCIP_OKAY;
    3603}
    3604
    3605/**@} */
    3606
    3607
    3608
    3609
    3610/*
    3611 * LP Pricing Norms Methods
    3612 */
    3613
    3614/**@name LP Pricing Norms Methods */
    3615/**@{ */
    3616
    3617/** stores LPi pricing norms information
    3618 * @todo should we store norm information?
    3619 */
    3621 SCIP_LPI* lpi, /**< LP interface structure */
    3622 BMS_BLKMEM* blkmem, /**< block memory */
    3623 SCIP_LPINORMS** lpinorms /**< pointer to LPi pricing norms information */
    3624 )
    3625{
    3626 assert(blkmem != NULL);
    3627 assert(lpi != NULL);
    3628 assert(lpinorms != NULL);
    3629
    3630 (*lpinorms) = NULL;
    3631
    3632 return SCIP_OKAY;
    3633}
    3634
    3635/** loads LPi pricing norms into solver; note that the LP might have been extended with additional
    3636 * columns and rows since the state was stored with SCIPlpiGetNorms()
    3637 */
    3639 SCIP_LPI* lpi, /**< LP interface structure */
    3640 BMS_BLKMEM* blkmem, /**< block memory */
    3641 const SCIP_LPINORMS* lpinorms /**< LPi pricing norms information, or NULL */
    3642 )
    3643{
    3644 assert(lpinorms == NULL);
    3645
    3646 /* no work necessary */
    3647 return SCIP_OKAY;
    3648}
    3649
    3650/** frees pricing norms information */
    3652 SCIP_LPI* lpi, /**< LP interface structure */
    3653 BMS_BLKMEM* blkmem, /**< block memory */
    3654 SCIP_LPINORMS** lpinorms /**< pointer to LPi pricing norms information, or NULL */
    3655 )
    3656{
    3657 assert(lpinorms == NULL);
    3658
    3659 /* no work necessary */
    3660 return SCIP_OKAY;
    3661}
    3662
    3663/**@} */
    3664
    3665
    3666
    3667
    3668/*
    3669 * Parameter Methods
    3670 */
    3671
    3672/**@name Parameter Methods */
    3673/**@{ */
    3674
    3675/** gets integer parameter of LP */
    3677 SCIP_LPI* lpi, /**< LP interface structure */
    3678 SCIP_LPPARAM type, /**< parameter number */
    3679 int* ival /**< buffer to store the parameter value */
    3680 )
    3681{
    3682 SCIPdebugMessage("calling SCIPlpiGetIntpar()\n");
    3683
    3684 assert(lpi != NULL);
    3685 assert(lpi->clp != NULL);
    3686 assert(ival != 0);
    3687
    3688 switch( type )
    3689 {
    3691 *ival = lpi->startscratch;
    3692 break;
    3693 case SCIP_LPPAR_SCALING:
    3694 if( lpi->clp->scalingFlag() != 0 ) // 0 -off, 1 equilibrium, 2 geometric, 3 auto, 4 dynamic(later)
    3695 *ival = TRUE;
    3696 else
    3697 *ival = FALSE;
    3698 break;
    3699 case SCIP_LPPAR_PRICING:
    3700 *ival = (int)lpi->pricing; // store pricing method in LPI struct
    3701 break;
    3702 case SCIP_LPPAR_LPINFO:
    3703 *ival = lpi->clp->logLevel() > 0 ? TRUE : FALSE;
    3704 break;
    3705 case SCIP_LPPAR_LPITLIM:
    3706 *ival = lpi->clp->maximumIterations();
    3707 break;
    3708 case SCIP_LPPAR_FASTMIP:
    3709 *ival = lpi->fastmip;
    3710 break;
    3711 default:
    3712 return SCIP_PARAMETERUNKNOWN;
    3713 }
    3714
    3715 return SCIP_OKAY;
    3716}
    3717
    3718
    3719/** sets integer parameter of LP */
    3721 SCIP_LPI* lpi, /**< LP interface structure */
    3722 SCIP_LPPARAM type, /**< parameter number */
    3723 int ival /**< parameter value */
    3724 )
    3725{
    3726 SCIPdebugMessage("calling SCIPlpiSetIntpar()\n");
    3727
    3728 assert(lpi != NULL);
    3729 assert(lpi->clp != NULL);
    3730
    3731 // Handle pricing separately ...
    3732 if( type == SCIP_LPPAR_PRICING )
    3733 {
    3734 // for primal:
    3735 // 0 is exact devex,
    3736 // 1 full steepest,
    3737 // 2 is partial exact devex
    3738 // 3 switches between 0 and 2 depending on factorization
    3739 // 4 starts as partial dantzig/devex but then may switch between 0 and 2.
    3740 // - currently (Clp 1.8) default is 3
    3741
    3742 // for dual:
    3743 // 0 is uninitialized,
    3744 // 1 full,
    3745 // 2 is partial uninitialized,
    3746 // 3 starts as 2 but may switch to 1.
    3747 // - currently (Clp 1.8) default is 3
    3748 lpi->pricing = (SCIP_PRICING)ival;
    3749 int primalmode = 0;
    3750 int dualmode = 0;
    3751 switch( (SCIP_PRICING)ival )
    3752 {
    3753 case SCIP_PRICING_AUTO:
    3754 primalmode = 3; dualmode = 3; break;
    3755 case SCIP_PRICING_FULL:
    3756 primalmode = 0; dualmode = 1; break;
    3758 case SCIP_PRICING_STEEP:
    3759 primalmode = 1; dualmode = 0; break;
    3761 primalmode = 1; dualmode = 2; break;
    3762 case SCIP_PRICING_DEVEX:
    3763 primalmode = 2; dualmode = 3; break;
    3764 default:
    3765 SCIPerrorMessage("unkown pricing parameter %d!\n", ival);
    3766 SCIPABORT();
    3767 return SCIP_INVALIDDATA; /*lint !e527*/
    3768 }
    3769 ClpPrimalColumnSteepest primalpivot(primalmode);
    3770 lpi->clp->setPrimalColumnPivotAlgorithm(primalpivot);
    3771 ClpDualRowSteepest dualpivot(dualmode);
    3772 lpi->clp->setDualRowPivotAlgorithm(dualpivot);
    3773 return SCIP_OKAY;
    3774 }
    3775
    3776 switch( type )
    3777 {
    3779 lpi->startscratch = ival;
    3780 break;
    3781 case SCIP_LPPAR_SCALING:
    3782 lpi->clp->scaling((ival > 0) ? 3 : 0); // 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later));
    3783 break;
    3784 case SCIP_LPPAR_PRICING:
    3785 /* should not happen - see above */
    3786 SCIPABORT();
    3787 return SCIP_LPERROR; /*lint !e527*/
    3788 case SCIP_LPPAR_LPINFO:
    3789 assert(ival == TRUE || ival == FALSE);
    3790 /* Amount of print out:
    3791 * 0 - none
    3792 * 1 - just final
    3793 * 2 - just factorizations
    3794 * 3 - as 2 plus a bit more
    3795 * 4 - verbose
    3796 * above that 8,16,32 etc just for selective SCIPdebug
    3797 */
    3798 if ( ival )
    3799 lpi->clp->setLogLevel(2); // lpi->clp->setLogLevel(63);
    3800 else
    3801 lpi->clp->setLogLevel(0);
    3802 break;
    3803 case SCIP_LPPAR_LPITLIM:
    3804 /* ival >= 0, 0 stop immediately */
    3805 assert( ival >= 0 );
    3806 lpi->clp->setMaximumIterations(ival);
    3807 break;
    3808 case SCIP_LPPAR_FASTMIP:
    3809 assert(ival == TRUE || ival == FALSE);
    3810 if( ival )
    3812 else
    3814 break;
    3815 default:
    3816 return SCIP_PARAMETERUNKNOWN;
    3817 }
    3818
    3819 return SCIP_OKAY;
    3820}
    3821
    3822
    3823/** gets floating point parameter of LP */
    3825 SCIP_LPI* lpi, /**< LP interface structure */
    3826 SCIP_LPPARAM type, /**< parameter number */
    3827 SCIP_Real* dval /**< buffer to store the parameter value */
    3828 )
    3829{
    3830 SCIPdebugMessage("calling SCIPlpiGetRealpar()\n");
    3831
    3832 assert(lpi != NULL);
    3833 assert(lpi->clp != NULL);
    3834 assert(dval != 0);
    3835
    3836 switch( type )
    3837 {
    3838 case SCIP_LPPAR_FEASTOL:
    3839 *dval = lpi->clp->primalTolerance();
    3840 break;
    3842 *dval = lpi->clp->dualTolerance();
    3843 break;
    3845 /* @todo add BARRIERCONVTOL parameter */
    3846 return SCIP_PARAMETERUNKNOWN;
    3847 case SCIP_LPPAR_OBJLIM:
    3848 *dval = lpi->clp->dualObjectiveLimit();
    3849 break;
    3850 case SCIP_LPPAR_LPTILIM:
    3851 *dval = lpi->clp->maximumSeconds();
    3852 break;
    3853 default:
    3854 return SCIP_PARAMETERUNKNOWN;
    3855 }
    3856
    3857 return SCIP_OKAY;
    3858}
    3859
    3860/** sets floating point parameter of LP */
    3862 SCIP_LPI* lpi, /**< LP interface structure */
    3863 SCIP_LPPARAM type, /**< parameter number */
    3864 SCIP_Real dval /**< parameter value */
    3865 )
    3866{
    3867 SCIPdebugMessage("calling SCIPlpiSetRealpar()\n");
    3868 SCIPdebugMessage("setting parameter %d to value %g.\n", type, dval);
    3869
    3870 assert(lpi != NULL);
    3871 assert(lpi->clp != NULL);
    3872
    3873 switch( type )
    3874 {
    3875 case SCIP_LPPAR_FEASTOL:
    3876 assert( dval > 0.0 );
    3877 /* 0 < dval < 1e10 */
    3878 if( dval > 1e+10 )
    3879 {
    3880 /* however dval is required to be strictly less than 1e+10 */
    3881 dval = 9e+9;
    3882 }
    3883
    3884 lpi->clp->setPrimalTolerance(dval);
    3885 break;
    3887 assert( dval > 0.0 );
    3888 /* 0 < dval < 1e10 */
    3889 if( dval > 1e+10 )
    3890 {
    3891 /* however dval is required to be strictly less than 1e+10 */
    3892 dval = 9e+9;
    3893 }
    3894
    3895 lpi->clp->setDualTolerance(dval);
    3896 break;
    3898 /* @todo add BARRIERCONVTOL parameter */
    3899 return SCIP_PARAMETERUNKNOWN;
    3900 case SCIP_LPPAR_OBJLIM:
    3901 /* no restriction on dval */
    3902
    3903 lpi->clp->setDualObjectiveLimit(dval);
    3904 break;
    3905 case SCIP_LPPAR_LPTILIM:
    3906 assert( dval > 0.0 );
    3907 /* clp poses no restrictions on dval
    3908 * (it handles the case dval < 0 internally and sets param to -1 meaning no time limit.)
    3909 *
    3910 * However for consistency we assert the timelimit to be strictly positive.
    3911 */
    3912
    3913 lpi->clp->setMaximumSeconds(dval);
    3914 break;
    3915 default:
    3916 return SCIP_PARAMETERUNKNOWN;
    3917 }
    3918
    3919 return SCIP_OKAY;
    3920}
    3921
    3922/** interrupts the currently ongoing lp solve or disables the interrupt */
    3924 SCIP_LPI* lpi, /**< LP interface structure */
    3925 SCIP_Bool interrupt /**< TRUE if interrupt should be set, FALSE if it should be disabled */
    3926 )
    3927{
    3928 /*lint --e{715}*/
    3929 assert(lpi != NULL);
    3930
    3931 return SCIP_OKAY;
    3932}
    3933
    3934/**@} */
    3935
    3936
    3937
    3938
    3939/*
    3940 * Numerical Methods
    3941 */
    3942
    3943/**@name Numerical Methods */
    3944/**@{ */
    3945
    3946/** returns value treated as infinity in the LP solver */
    3948 SCIP_LPI* lpi /**< LP interface structure */
    3949 )
    3950{ /* lint --e{715} */
    3951 assert(lpi != NULL);
    3952 SCIPdebugMessage("calling SCIPlpiInfinity()\n");
    3953
    3954 return COIN_DBL_MAX;
    3955}
    3956
    3957
    3958/** checks if given value is treated as infinity in the LP solver */
    3960 SCIP_LPI* lpi, /**< LP interface structure */
    3961 SCIP_Real val /**< value to check */
    3962 )
    3963{ /* lint --e{715} */
    3964 assert(lpi != NULL);
    3965 SCIPdebugMessage("calling SCIPlpiIsInfinity()\n");
    3966
    3967 return (val >= COIN_DBL_MAX);
    3968}
    3969
    3970/**@} */
    3971
    3972
    3973
    3974
    3975/*
    3976 * File Interface Methods
    3977 */
    3978
    3979/**@name File Interface Methods */
    3980/**@{ */
    3981
    3982/** returns whether the given file exists */
    3983static
    3985 const char* filename /**< file name */
    3986 )
    3987{
    3988 FILE* f;
    3989
    3990 f = fopen(filename, "r");
    3991 if( f == 0 )
    3992 return FALSE;
    3993
    3994 fclose(f);
    3995
    3996 return TRUE;
    3997}
    3998
    3999/** reads LP from a file */
    4001 SCIP_LPI* lpi, /**< LP interface structure */
    4002 const char* fname /**< file name */
    4003 )
    4004{
    4005 SCIPdebugMessage("calling SCIPlpiReadLP()\n");
    4006
    4007 assert(lpi != NULL);
    4008 assert(lpi->clp != NULL);
    4009 assert(fname != NULL);
    4010
    4011 // WARNING: can only read mps files
    4012
    4013 if ( !fileExists(fname) )
    4014 return SCIP_NOFILE;
    4015
    4016 /* read file in MPS format
    4017 * parameters:
    4018 * filename
    4019 * bool keepNames
    4020 * bool ignoreErrors
    4021 */
    4022 if ( lpi->clp->readMps(fname, true, false) )
    4023 return SCIP_READERROR;
    4024
    4025 return SCIP_OKAY;
    4026}
    4027
    4028/** writes LP to a file */
    4030 SCIP_LPI* lpi, /**< LP interface structure */
    4031 const char* fname /**< file name */
    4032 )
    4033{
    4034 SCIPdebugMessage("calling SCIPlpiWriteLP() - %s\n", fname);
    4035
    4036 assert(lpi != NULL);
    4037 assert(lpi->clp != NULL);
    4038 assert(fname != NULL);
    4039
    4040 /* write file in MPS format
    4041 * parameters:
    4042 * filename
    4043 * int formatType (0 - normal, 1 - extra accuracy, 2 - IEEE hex)
    4044 * int numberAcross (1 or 2 values should be specified on every data line in the MPS file)
    4045 * double objSense
    4046 */
    4047 if ( lpi->clp->writeMps(fname, 0, 2, lpi->clp->optimizationDirection()) )
    4048 return SCIP_WRITEERROR;
    4049
    4050 return SCIP_OKAY;
    4051}
    4052
    4053/**@} */
    void SCIPdecodeDualBit(const SCIP_DUALPACKET *inp, int *out, int count)
    Definition: bitencode.c:308
    void SCIPencodeDualBit(const int *inp, SCIP_DUALPACKET *out, int count)
    Definition: bitencode.c:238
    packing single and dual bit values
    unsigned int SCIP_DUALPACKET
    Definition: bitencode.h:42
    SCIP_Real * r
    Definition: circlepacking.c:59
    #define NULL
    Definition: def.h:248
    #define SCIP_INVALID
    Definition: def.h:178
    #define SCIP_Bool
    Definition: def.h:91
    #define SCIP_ALLOC(x)
    Definition: def.h:366
    #define SCIP_Real
    Definition: def.h:156
    #define EPSEQ(x, y, eps)
    Definition: def.h:183
    #define TRUE
    Definition: def.h:93
    #define FALSE
    Definition: def.h:94
    #define MAX(x, y)
    Definition: def.h:220
    #define EPSCEIL(x, eps)
    Definition: def.h:192
    #define SCIPABORT()
    Definition: def.h:327
    #define EPSFLOOR(x, eps)
    Definition: def.h:191
    #define REALABS(x)
    Definition: def.h:182
    #define SCIP_CALL(x)
    Definition: def.h:355
    static SCIP_RETCODE lpiStrongbranches(SCIP_LPI *lpi, int *cols, int ncols, SCIP_Real *psols, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
    Definition: lpi_clp.cpp:2179
    SCIP_RETCODE SCIPlpiChgSides(SCIP_LPI *lpi, int nrows, const int *ind, const SCIP_Real *lhs, const SCIP_Real *rhs)
    Definition: lpi_clp.cpp:1179
    SCIP_RETCODE SCIPlpiSetState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, const SCIP_LPISTATE *lpistate)
    Definition: lpi_clp.cpp:3457
    SCIP_RETCODE SCIPlpiGetBInvACol(SCIP_LPI *lpi, int c, SCIP_Real *coef, int *inds, int *ninds)
    Definition: lpi_clp.cpp:3377
    SCIP_RETCODE SCIPlpiGetRealpar(SCIP_LPI *lpi, SCIP_LPPARAM type, SCIP_Real *dval)
    Definition: lpi_clp.cpp:3824
    SCIP_Real SCIPlpiInfinity(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:3947
    SCIP_Bool SCIPlpiIsObjlimExc(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2718
    SCIP_RETCODE SCIPlpiChgObjsen(SCIP_LPI *lpi, SCIP_OBJSEN objsen)
    Definition: lpi_clp.cpp:1232
    SCIP_Bool SCIPlpiIsInfinity(SCIP_LPI *lpi, SCIP_Real val)
    Definition: lpi_clp.cpp:3959
    SCIP_RETCODE SCIPlpiClear(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:1076
    SCIP_RETCODE SCIPlpiClearState(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:3515
    SCIP_Bool SCIPlpiExistsDualRay(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2565
    SCIP_Bool SCIPlpiExistsPrimalRay(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2478
    SCIP_RETCODE SCIPlpiGetBase(SCIP_LPI *lpi, int *cstat, int *rstat)
    Definition: lpi_clp.cpp:2995
    SCIP_RETCODE SCIPlpiReadState(SCIP_LPI *lpi, const char *fname)
    Definition: lpi_clp.cpp:3560
    SCIP_RETCODE SCIPlpiAddRows(SCIP_LPI *lpi, int nrows, const SCIP_Real *lhs, const SCIP_Real *rhs, char **rownames, int nnonz, const int *beg, const int *ind, const SCIP_Real *val)
    Definition: lpi_clp.cpp:920
    SCIP_RETCODE SCIPlpiGetPrimalRay(SCIP_LPI *lpi, SCIP_Real *ray)
    Definition: lpi_clp.cpp:2860
    SCIP_RETCODE SCIPlpiGetIntpar(SCIP_LPI *lpi, SCIP_LPPARAM type, int *ival)
    Definition: lpi_clp.cpp:3676
    SCIP_RETCODE SCIPlpiWriteLP(SCIP_LPI *lpi, const char *fname)
    Definition: lpi_clp.cpp:4029
    SCIP_RETCODE SCIPlpiSetIntegralityInformation(SCIP_LPI *lpi, int ncols, int *intInfo)
    Definition: lpi_clp.cpp:480
    SCIP_Bool SCIPlpiIsDualInfeasible(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2623
    SCIP_RETCODE SCIPlpiSetRealpar(SCIP_LPI *lpi, SCIP_LPPARAM type, SCIP_Real dval)
    Definition: lpi_clp.cpp:3861
    SCIP_RETCODE SCIPlpiStrongbranchFrac(SCIP_LPI *lpi, int col, SCIP_Real psol, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
    Definition: lpi_clp.cpp:2311
    SCIP_RETCODE SCIPlpiSetNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, const SCIP_LPINORMS *lpinorms)
    Definition: lpi_clp.cpp:3638
    SCIP_RETCODE SCIPlpiGetNNonz(SCIP_LPI *lpi, int *nnonz)
    Definition: lpi_clp.cpp:1465
    SCIP_Bool SCIPlpiHasPrimalSolve(void)
    Definition: lpi_clp.cpp:494
    SCIP_RETCODE SCIPlpiStrongbranchInt(SCIP_LPI *lpi, int col, SCIP_Real psol, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
    Definition: lpi_clp.cpp:2357
    SCIP_RETCODE SCIPlpiGetBounds(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *lbs, SCIP_Real *ubs)
    Definition: lpi_clp.cpp:1733
    SCIP_Bool SCIPlpiHasBarrierSolve(void)
    Definition: lpi_clp.cpp:510
    SCIP_RETCODE SCIPlpiGetDualfarkas(SCIP_LPI *lpi, SCIP_Real *dualfarkas)
    Definition: lpi_clp.cpp:2885
    SCIP_RETCODE SCIPlpiGetObjval(SCIP_LPI *lpi, SCIP_Real *objval)
    Definition: lpi_clp.cpp:2794
    SCIP_RETCODE SCIPlpiScaleCol(SCIP_LPI *lpi, int col, SCIP_Real scaleval)
    Definition: lpi_clp.cpp:1352
    int SCIPlpiGetInternalStatus(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2780
    SCIP_RETCODE SCIPlpiStartStrongbranch(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2034
    SCIP_RETCODE SCIPlpiGetSolFeasibility(SCIP_LPI *lpi, SCIP_Bool *primalfeasible, SCIP_Bool *dualfeasible)
    Definition: lpi_clp.cpp:2433
    SCIP_RETCODE SCIPlpiFreeNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS **lpinorms)
    Definition: lpi_clp.cpp:3651
    SCIP_Bool SCIPlpiIsIterlimExc(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2748
    SCIP_RETCODE SCIPlpiChgBounds(SCIP_LPI *lpi, int ncols, const int *ind, const SCIP_Real *lb, const SCIP_Real *ub)
    Definition: lpi_clp.cpp:1096
    SCIP_Bool SCIPlpiIsPrimalUnbounded(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2516
    SCIP_RETCODE SCIPlpiIgnoreInstability(SCIP_LPI *lpi, SCIP_Bool *success)
    Definition: lpi_clp.cpp:1669
    SCIP_RETCODE SCIPlpiWriteState(SCIP_LPI *lpi, const char *fname)
    Definition: lpi_clp.cpp:3580
    SCIP_RETCODE SCIPlpiFree(SCIP_LPI **lpi)
    Definition: lpi_clp.cpp:643
    SCIP_RETCODE SCIPlpiStrongbranchesFrac(SCIP_LPI *lpi, int *cols, int ncols, SCIP_Real *psols, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
    Definition: lpi_clp.cpp:2332
    SCIP_RETCODE SCIPlpiGetCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real *val)
    Definition: lpi_clp.cpp:1799
    SCIP_Bool SCIPlpiIsPrimalFeasible(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2549
    SCIP_RETCODE SCIPlpiReadLP(SCIP_LPI *lpi, const char *fname)
    Definition: lpi_clp.cpp:4000
    SCIP_RETCODE SCIPlpiGetRealSolQuality(SCIP_LPI *lpi, SCIP_LPSOLQUALITY qualityindicator, SCIP_Real *quality)
    Definition: lpi_clp.cpp:2968
    SCIP_Bool SCIPlpiIsDualFeasible(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2637
    static SCIP_RETCODE lpiStrongbranch(SCIP_LPI *lpi, int col, SCIP_Real psol, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
    Definition: lpi_clp.cpp:2059
    SCIP_RETCODE SCIPlpiGetNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS **lpinorms)
    Definition: lpi_clp.cpp:3620
    SCIP_Bool SCIPlpiIsTimelimExc(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2764
    SCIP_Bool SCIPlpiHasStateBasis(SCIP_LPI *lpi, SCIP_LPISTATE *lpistate)
    Definition: lpi_clp.cpp:3550
    SCIP_RETCODE SCIPlpiSetIntpar(SCIP_LPI *lpi, SCIP_LPPARAM type, int ival)
    Definition: lpi_clp.cpp:3720
    const char * SCIPlpiGetSolverName(void)
    Definition: lpi_clp.cpp:454
    SCIP_RETCODE SCIPlpiSetBase(SCIP_LPI *lpi, const int *cstat, const int *rstat)
    Definition: lpi_clp.cpp:3095
    SCIP_Bool SCIPlpiHasPrimalRay(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2496
    SCIP_RETCODE SCIPlpiGetBInvRow(SCIP_LPI *lpi, int r, SCIP_Real *coef, int *inds, int *ninds)
    Definition: lpi_clp.cpp:3269
    SCIP_RETCODE SCIPlpiDelRows(SCIP_LPI *lpi, int firstrow, int lastrow)
    Definition: lpi_clp.cpp:992
    SCIP_RETCODE SCIPlpiGetCols(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *lb, SCIP_Real *ub, int *nnonz, int *beg, int *ind, SCIP_Real *val)
    Definition: lpi_clp.cpp:1486
    SCIP_RETCODE SCIPlpiGetBInvCol(SCIP_LPI *lpi, int c, SCIP_Real *coef, int *inds, int *ninds)
    Definition: lpi_clp.cpp:3304
    SCIP_RETCODE SCIPlpiGetColNames(SCIP_LPI *lpi, int firstcol, int lastcol, char **colnames, char *namestorage, int namestoragesize, int *storageleft)
    Definition: lpi_clp.cpp:1615
    SCIP_RETCODE SCIPlpiGetBInvARow(SCIP_LPI *lpi, int r, const SCIP_Real *binvrow, SCIP_Real *coef, int *inds, int *ninds)
    Definition: lpi_clp.cpp:3342
    SCIP_RETCODE SCIPlpiGetRows(SCIP_LPI *lpi, int firstrow, int lastrow, SCIP_Real *lhs, SCIP_Real *rhs, int *nnonz, int *beg, int *ind, SCIP_Real *val)
    Definition: lpi_clp.cpp:1552
    SCIP_Bool SCIPlpiWasSolved(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2414
    const char * SCIPlpiGetSolverDesc(void)
    Definition: lpi_clp.cpp:463
    SCIP_RETCODE SCIPlpiSolveBarrier(SCIP_LPI *lpi, SCIP_Bool crossover)
    Definition: lpi_clp.cpp:1985
    SCIP_Bool SCIPlpiIsOptimal(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2651
    SCIP_RETCODE SCIPlpiGetRowNames(SCIP_LPI *lpi, int firstrow, int lastrow, char **rownames, char *namestorage, int namestoragesize, int *storageleft)
    Definition: lpi_clp.cpp:1642
    SCIP_Bool SCIPlpiHasDualSolve(void)
    Definition: lpi_clp.cpp:502
    SCIP_RETCODE SCIPlpiEndStrongbranch(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2046
    SCIP_RETCODE SCIPlpiGetSides(SCIP_LPI *lpi, int firstrow, int lastrow, SCIP_Real *lhss, SCIP_Real *rhss)
    Definition: lpi_clp.cpp:1766
    SCIP_RETCODE SCIPlpiStrongbranchesInt(SCIP_LPI *lpi, int *cols, int ncols, SCIP_Real *psols, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
    Definition: lpi_clp.cpp:2378
    SCIP_RETCODE SCIPlpiGetSol(SCIP_LPI *lpi, SCIP_Real *objval, SCIP_Real *primsol, SCIP_Real *dualsol, SCIP_Real *activity, SCIP_Real *redcost)
    Definition: lpi_clp.cpp:2816
    SCIP_Bool SCIPlpiHasDualRay(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2584
    SCIP_RETCODE SCIPlpiDelColset(SCIP_LPI *lpi, int *dstat)
    Definition: lpi_clp.cpp:874
    SCIP_RETCODE SCIPlpiGetObj(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *vals)
    Definition: lpi_clp.cpp:1708
    SCIP_RETCODE SCIPlpiFreeState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPISTATE **lpistate)
    Definition: lpi_clp.cpp:3531
    SCIP_Bool SCIPlpiIsPrimalInfeasible(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2530
    SCIP_RETCODE SCIPlpiSolveDual(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:1908
    SCIP_RETCODE SCIPlpiAddCols(SCIP_LPI *lpi, int ncols, const SCIP_Real *obj, const SCIP_Real *lb, const SCIP_Real *ub, char **colnames, int nnonz, const int *beg, const int *ind, const SCIP_Real *val)
    Definition: lpi_clp.cpp:758
    SCIP_RETCODE SCIPlpiSolvePrimal(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:1833
    SCIP_RETCODE SCIPlpiLoadColLP(SCIP_LPI *lpi, SCIP_OBJSEN objsen, int ncols, const SCIP_Real *obj, const SCIP_Real *lb, const SCIP_Real *ub, char **colnames, int nrows, const SCIP_Real *lhs, const SCIP_Real *rhs, char **rownames, int nnonz, const int *beg, const int *ind, const SCIP_Real *val)
    Definition: lpi_clp.cpp:677
    SCIP_Bool SCIPlpiIsDualUnbounded(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2606
    SCIP_RETCODE SCIPlpiGetIterations(SCIP_LPI *lpi, int *iterations)
    Definition: lpi_clp.cpp:2949
    SCIP_RETCODE SCIPlpiGetBasisInd(SCIP_LPI *lpi, int *bind)
    Definition: lpi_clp.cpp:3217
    SCIP_RETCODE SCIPlpiCreate(SCIP_LPI **lpi, SCIP_MESSAGEHDLR *messagehdlr, const char *name, SCIP_OBJSEN objsen)
    Definition: lpi_clp.cpp:531
    void * SCIPlpiGetSolverPointer(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:471
    SCIP_RETCODE SCIPlpiChgObj(SCIP_LPI *lpi, int ncols, const int *ind, const SCIP_Real *obj)
    Definition: lpi_clp.cpp:1252
    SCIP_RETCODE SCIPlpiGetObjsen(SCIP_LPI *lpi, SCIP_OBJSEN *objsen)
    Definition: lpi_clp.cpp:1688
    SCIP_Bool SCIPlpiIsStable(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:2675
    SCIP_RETCODE SCIPlpiGetNCols(SCIP_LPI *lpi, int *ncols)
    Definition: lpi_clp.cpp:1447
    SCIP_RETCODE SCIPlpiInterrupt(SCIP_LPI *lpi, SCIP_Bool interrupt)
    Definition: lpi_clp.cpp:3923
    SCIP_RETCODE SCIPlpiDelCols(SCIP_LPI *lpi, int firstcol, int lastcol)
    Definition: lpi_clp.cpp:837
    SCIP_RETCODE SCIPlpiDelRowset(SCIP_LPI *lpi, int *dstat)
    Definition: lpi_clp.cpp:1030
    SCIP_RETCODE SCIPlpiScaleRow(SCIP_LPI *lpi, int row, SCIP_Real scaleval)
    Definition: lpi_clp.cpp:1279
    SCIP_RETCODE SCIPlpiGetNRows(SCIP_LPI *lpi, int *nrows)
    Definition: lpi_clp.cpp:1429
    SCIP_RETCODE SCIPlpiGetState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPISTATE **lpistate)
    Definition: lpi_clp.cpp:3417
    SCIP_RETCODE SCIPlpiChgCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real newval)
    Definition: lpi_clp.cpp:1209
    interface methods for specific LP solvers
    static void lpistatePack(SCIP_LPISTATE *lpistate, const int *cstat, const int *rstat)
    Definition: lpi_clp.cpp:218
    static void lpistateUnpack(const SCIP_LPISTATE *lpistate, int *cstat, int *rstat)
    Definition: lpi_clp.cpp:234
    static SCIP_Bool fileExists(const char *filename)
    Definition: lpi_clp.cpp:3984
    #define CLP_VERSION
    Definition: lpi_clp.cpp:77
    static int rowpacketNum(int nrows)
    Definition: lpi_clp.cpp:209
    SCIP_DUALPACKET ROWPACKET
    Definition: lpi_clp.cpp:128
    static SCIP_RETCODE ensureCstatMem(SCIP_LPI *lpi, int num)
    Definition: lpi_clp.cpp:149
    #define SUMINFEASBOUND
    Definition: lpi_clp.cpp:101
    #define COLS_PER_PACKET
    Definition: lpi_clp.cpp:127
    static void lpistateFree(SCIP_LPISTATE **lpistate, BMS_BLKMEM *blkmem)
    Definition: lpi_clp.cpp:271
    SCIP_DUALPACKET COLPACKET
    Definition: lpi_clp.cpp:126
    static void unsetFastmipClpParameters(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:419
    static void setFactorizationFrequency(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:305
    static SCIP_RETCODE ensureRstatMem(SCIP_LPI *lpi, int num)
    Definition: lpi_clp.cpp:171
    static int colpacketNum(int ncols)
    Definition: lpi_clp.cpp:200
    static void setFastmipClpParameters(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:321
    static SCIP_RETCODE lpistateCreate(SCIP_LPISTATE **lpistate, BMS_BLKMEM *blkmem, int ncols, int nrows)
    Definition: lpi_clp.cpp:250
    #define ROWS_PER_PACKET
    Definition: lpi_clp.cpp:129
    static void invalidateSolution(SCIP_LPI *lpi)
    Definition: lpi_clp.cpp:295
    #define BMSfreeMemory(ptr)
    Definition: memory.h:145
    #define BMSfreeBlockMemory(mem, ptr)
    Definition: memory.h:465
    #define BMSallocBlockMemory(mem, ptr)
    Definition: memory.h:451
    #define BMSreallocMemoryArray(ptr, num)
    Definition: memory.h:127
    #define BMSallocMemoryArray(ptr, num)
    Definition: memory.h:123
    #define BMSfreeMemoryArray(ptr)
    Definition: memory.h:147
    #define BMSallocBlockMemoryArray(mem, ptr, num)
    Definition: memory.h:454
    #define BMScopyMemoryArray(ptr, source, num)
    Definition: memory.h:134
    #define BMSfreeBlockMemoryArray(mem, ptr, num)
    Definition: memory.h:467
    struct BMS_BlkMem BMS_BLKMEM
    Definition: memory.h:437
    #define BMSfreeMemoryArrayNull(ptr)
    Definition: memory.h:148
    #define BMSallocMemory(ptr)
    Definition: memory.h:118
    public methods for message output
    #define SCIPerrorMessage
    Definition: pub_message.h:64
    #define SCIPdebugMessage
    Definition: pub_message.h:96
    COLPACKET * packcstat
    Definition: lpi_clp.cpp:136
    ROWPACKET * packrstat
    Definition: lpi_clp.cpp:137
    SCIP_Bool solved
    Definition: lpi_clp.cpp:114
    int lastalgorithm
    Definition: lpi_clp.cpp:117
    bool startscratch
    Definition: lpi_clp.cpp:111
    SCIP_Bool fastmip
    Definition: lpi_clp.cpp:116
    int * cstat
    Definition: lpi_clp.cpp:107
    int rstatsize
    Definition: lpi_clp.cpp:110
    int * rstat
    Definition: lpi_clp.cpp:108
    SCIP_PRICING pricing
    Definition: lpi_clp.cpp:112
    int cstatsize
    Definition: lpi_clp.cpp:109
    bool setFactorizationFrequency
    Definition: lpi_clp.cpp:115
    bool validFactorization
    Definition: lpi_clp.cpp:113
    ClpSimplex * clp
    Definition: lpi_clp.cpp:106
    @ SCIP_PRICING_STEEPQSTART
    Definition: type_lpi.h:83
    @ SCIP_PRICING_AUTO
    Definition: type_lpi.h:79
    @ SCIP_PRICING_DEVEX
    Definition: type_lpi.h:84
    @ SCIP_PRICING_STEEP
    Definition: type_lpi.h:82
    @ SCIP_PRICING_FULL
    Definition: type_lpi.h:80
    @ SCIP_PRICING_LPIDEFAULT
    Definition: type_lpi.h:78
    enum SCIP_Pricing SCIP_PRICING
    Definition: type_lpi.h:86
    enum SCIP_LPParam SCIP_LPPARAM
    Definition: type_lpi.h:73
    @ SCIP_LPPAR_PRICING
    Definition: type_lpi.h:54
    @ SCIP_LPPAR_LPINFO
    Definition: type_lpi.h:55
    @ SCIP_LPPAR_SCALING
    Definition: type_lpi.h:52
    @ SCIP_LPPAR_LPTILIM
    Definition: type_lpi.h:61
    @ SCIP_LPPAR_BARRIERCONVTOL
    Definition: type_lpi.h:58
    @ SCIP_LPPAR_FASTMIP
    Definition: type_lpi.h:51
    @ SCIP_LPPAR_DUALFEASTOL
    Definition: type_lpi.h:57
    @ SCIP_LPPAR_FROMSCRATCH
    Definition: type_lpi.h:50
    @ SCIP_LPPAR_FEASTOL
    Definition: type_lpi.h:56
    @ SCIP_LPPAR_LPITLIM
    Definition: type_lpi.h:60
    @ SCIP_LPPAR_OBJLIM
    Definition: type_lpi.h:59
    @ SCIP_BASESTAT_BASIC
    Definition: type_lpi.h:92
    @ SCIP_BASESTAT_UPPER
    Definition: type_lpi.h:93
    @ SCIP_BASESTAT_LOWER
    Definition: type_lpi.h:91
    @ SCIP_BASESTAT_ZERO
    Definition: type_lpi.h:94
    enum SCIP_LPSolQuality SCIP_LPSOLQUALITY
    Definition: type_lpi.h:104
    @ SCIP_OBJSEN_MAXIMIZE
    Definition: type_lpi.h:42
    @ SCIP_OBJSEN_MINIMIZE
    Definition: type_lpi.h:43
    enum SCIP_ObjSen SCIP_OBJSEN
    Definition: type_lpi.h:45
    @ SCIP_LPERROR
    Definition: type_retcode.h:49
    @ SCIP_NOFILE
    Definition: type_retcode.h:47
    @ SCIP_READERROR
    Definition: type_retcode.h:45
    @ SCIP_INVALIDDATA
    Definition: type_retcode.h:52
    @ SCIP_PARAMETERUNKNOWN
    Definition: type_retcode.h:55
    @ SCIP_WRITEERROR
    Definition: type_retcode.h:46
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63