Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v9-minor'
Browse files Browse the repository at this point in the history
  • Loading branch information
scip-ci committed Feb 5, 2025
2 parents bb21ca9 + 171536b commit 8605347
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ Miscellaneous
Fixed bugs
----------

- fixed definition of slack variables of >= constraints and ranged rows in LP interface to Gurobi (lpi_grb.c)

Build system
------------

Expand Down
18 changes: 9 additions & 9 deletions src/lpi/lpi_cpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -4544,30 +4544,30 @@ SCIP_RETCODE SCIPlpiSetRealpar(
{
case SCIP_LPPAR_FEASTOL:
assert( dval > 0.0 );
/* 1e-09 <= dval <= 1e-04 */
/* 1e-09 <= dval <= 1e-01 */
if( dval < 1e-09 )
dval = 1e-09;
else if( dval > 1e-04 )
dval = 1e-04;
else if( dval > 1e-01 )
dval = 1e-01;

setDblParam(lpi, CPX_PARAM_EPRHS, dval);
lpi->feastol = dval;
break;
case SCIP_LPPAR_DUALFEASTOL:
assert( dval > 0.0 );
/* 1e-09 <= dval <= 1e-04 */
/* 1e-09 <= dval <= 1e-01 */
if( dval < 1e-09 )
dval = 1e-09;
else if( dval > 1e-04 )
dval = 1e-04;
else if( dval > 1e-01 )
dval = 1e-01;

setDblParam(lpi, CPX_PARAM_EPOPT, dval);
break;
case SCIP_LPPAR_BARRIERCONVTOL:
/* 1e-10 <= dval */
/* 1e-12 <= dval */
assert( dval >= 0.0 );
if( dval < 1e-10 )
dval = 1e-10;
if( dval < 1e-12 )
dval = 1e-12;

setDblParam(lpi, CPX_PARAM_BAREPCOMP, dval);
break;
Expand Down
51 changes: 39 additions & 12 deletions src/lpi/lpi_grb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4764,6 +4764,8 @@ SCIP_RETCODE SCIPlpiGetBInvRow(
double val;
int ind;
int status;
int ncols;
int ngrbcols;

assert(lpi != NULL);
assert(lpi->grbmodel != NULL);
Expand All @@ -4779,19 +4781,34 @@ SCIP_RETCODE SCIPlpiGetBInvRow(
}

SCIP_CALL( SCIPlpiGetNRows(lpi, &nrows) );
SCIP_CALL( SCIPlpiGetNCols(lpi, &ncols) );
CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ngrbcols) );

/* set up solution vector */
x.len = 0;
SCIP_ALLOC( BMSallocMemoryArray(&(x.ind), nrows) );
SCIP_ALLOC( BMSallocMemoryArray(&(x.val), nrows) );

/* get basis indices, temporarily using memory of x.ind */
SCIP_CALL( SCIPlpiGetBasisInd(lpi, x.ind) );
CHECK_ZERO( lpi->messagehdlr, GRBgetBasisHead(lpi->grbmodel, x.ind) );

/* set up rhs */
b.len = 1;
ind = r;
val = (x.ind)[r] >= 0 ? 1.0 : -1.0;
val = 1.0;
if ( x.ind[r] > ncols )
{
/* the sign of the slack variables seems to be 1 for <= inequalities, equations, but -1 for >= inequalities and ranged rows */
if ( x.ind[r] < ngrbcols )
val = -1.0;
else
{
char sense;
CHECK_ZERO( lpi->messagehdlr, GRBgetcharattrarray(lpi->grbmodel, GRB_CHAR_ATTR_SENSE, x.ind[r] - ngrbcols, 1, &sense) );
if ( sense == '>' )
val = -1.0;
}
}
b.ind = &ind;
b.val = &val;

Expand Down Expand Up @@ -4862,11 +4879,12 @@ SCIP_RETCODE SCIPlpiGetBInvCol(
{
SVECTOR x;
SVECTOR b;
int* bind;
int nrows;
double val;
int ind;
int status;
int ncols;
int ngrbcols;

assert(lpi != NULL);
assert(lpi->grbmodel != NULL);
Expand All @@ -4882,16 +4900,34 @@ SCIP_RETCODE SCIPlpiGetBInvCol(
}

SCIP_CALL( SCIPlpiGetNRows(lpi, &nrows) );
SCIP_CALL( SCIPlpiGetNCols(lpi, &ncols) );
CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ngrbcols) );

/* set up solution vector */
x.len = 0;
SCIP_ALLOC( BMSallocMemoryArray(&(x.ind), nrows) );
SCIP_ALLOC( BMSallocMemoryArray(&(x.val), nrows) );

/* get basis indices, temporarily using memory of x.ind */
CHECK_ZERO( lpi->messagehdlr, GRBgetBasisHead(lpi->grbmodel, x.ind) );

/* set up rhs */
b.len = 1;
ind = c;
val = 1.0;
if ( x.ind[c] > ncols )
{
/* the sign of the slack variables seems to be 1 for <= inequalities, equations, but -1 for >= inequalities and ranged rows */
if ( x.ind[c] < ngrbcols )
val = -1.0;
else
{
char sense;
CHECK_ZERO( lpi->messagehdlr, GRBgetcharattrarray(lpi->grbmodel, GRB_CHAR_ATTR_SENSE, x.ind[c] - ngrbcols, 1, &sense) );
if ( sense == '>' )
val = -1.0;
}
}
b.ind = &ind;
b.val = &val;

Expand All @@ -4901,10 +4937,6 @@ SCIP_RETCODE SCIPlpiGetBInvCol(
/* size should be at most the number of rows */
assert( x.len <= nrows );

/* get basis indices: entries that correspond to slack variables with coefficient -1 must be negated */
SCIP_ALLOC( BMSallocMemoryArray(&bind, nrows) );
SCIP_CALL( SCIPlpiGetBasisInd(lpi, bind) );

/* check whether we require a dense or sparse result vector */
if ( ninds != NULL && inds != NULL )
{
Expand All @@ -4918,8 +4950,6 @@ SCIP_RETCODE SCIPlpiGetBInvCol(
assert( idx >= 0 && idx < nrows );
inds[i] = idx;
coef[idx] = (x.val)[i];
if( bind[idx] < 0 )
coef[idx] *= -1.0;
}
*ninds = x.len;
}
Expand All @@ -4935,13 +4965,10 @@ SCIP_RETCODE SCIPlpiGetBInvCol(
idx = (x.ind)[i];
assert( idx >= 0 && idx < nrows );
coef[idx] = (x.val)[i];
if( bind[idx] < 0 )
coef[idx] *= -1.0;
}
}

/* free solution space and basis index array */
BMSfreeMemoryArray(&bind);
BMSfreeMemoryArray(&(x.val));
BMSfreeMemoryArray(&(x.ind));

Expand Down
Loading

0 comments on commit 8605347

Please sign in to comment.