Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v80-bugfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
scip-ci committed Aug 1, 2023
2 parents 8c222e4 + c1eabc8 commit ca0c6e1
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ Fixed bugs
- fixed that scaling of rows in Gurobi interface (SCIPlpiScaleRow()) changed infinite sides to large finite ones (1e20) when scale factor is negative
- check whether objective limit is truly reached in SCIPlpiIsStable()
- if an objective limit is set and Mosek claims that it is exceeded, check that this is indeed the case in SCIPlpiIsStable()
- The .mps file reader was extended to additionally accept .mps files with the objective sense section on one line.

Miscellaneous
-------------
Expand Down
16 changes: 11 additions & 5 deletions src/scip/reader_mps.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,18 @@ SCIP_RETCODE readObjsen(

SCIPdebugMsg(scip, "read objective sense\n");

/* This has to be the Line with MIN or MAX. */
if( !mpsinputReadLine(mpsi) || (mpsinputField1(mpsi) == NULL) )
{
mpsinputSyntaxerror(mpsi);
return SCIP_OKAY;
/* Although this is not explicitly in the MPS extensions as provided by CPLEX, some other MIP solvers
* (in particular gurobi), put 'MIN' or 'MAX' as the input field on the same line as the section declaration */
if( mpsinputField1(mpsi) == NULL){
/* Normal Cplex extension; info should be on the next line, in field 1 */
/* This has to be the Line with MIN or MAX. */
if( !mpsinputReadLine(mpsi) || (mpsinputField1(mpsi) == NULL) )
{
mpsinputSyntaxerror(mpsi);
return SCIP_OKAY;
}
}
/* Otherwise, the input should read e.g. "OBJSENSE MAX" so that MAX is also the first field */

if( !strncmp(mpsinputField1(mpsi), "MIN", 3) )
mpsinputSetObjsense(mpsi, SCIP_OBJSENSE_MINIMIZE);
Expand Down
81 changes: 81 additions & 0 deletions tests/src/reader/mps.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the program and library */
/* SCIP --- Solving Constraint Integer Programs */
/* */
/* Copyright (c) 2002-2023 Zuse Institute Berlin (ZIB) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* */
/* You should have received a copy of the Apache-2.0 license */
/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/**@file mps.c
* @brief Unittest for MPS reader
* @author Mathieu Besançon, Rolf van der Hulst
*/

/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/

#include <assert.h>

#include "scip/scip.h"
#include "scip/reader_mps.h"
#include "scip/scipdefplugins.h"

#include "include/scip_test.h"

static SCIP* scip;

static
void setup(void)
{
/* create SCIP instance */
SCIP_CALL( SCIPcreate(&scip) );

/* include reader */
SCIP_CALL( SCIPincludeDefaultPlugins(scip) );

}

static
void teardown(void)
{
/* free variable and SCIP */
SCIP_CALL( SCIPfree(&scip) );
}

/* TEST SUITE */
TestSuite(readermps, .init = setup, .fini = teardown);

Test(readermps, read1, .description = "check the function for reading a *.mps file")
{
/*The file tested below originally failed because 'OBJSENSE MAX' is on one line. */
char filename[SCIP_MAXSTRLEN];
TESTsetTestfilename(filename, __FILE__, "oc5.mps");

SCIP_CALL( SCIPreadProb(scip, filename, NULL) );
cr_expect( SCIPgetNVars(scip) == 5 );
}

Test(readermps, read2, .description = "check the function for reading a *.mps file")
{
/*A 'normal' mps file with OBJSENSE MAX on two lines */
char filename[SCIP_MAXSTRLEN];
TESTsetTestfilename(filename, __FILE__, "oc5_1.mps");

SCIP_CALL( SCIPreadProb(scip, filename, NULL) );
cr_expect( SCIPgetNVars(scip) == 5 );
}
40 changes: 40 additions & 0 deletions tests/src/reader/oc5.mps
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
NAME oc5
OBJSENSE MAX
ROWS
N OBJ
L R0
L R1
L R2
L R3
L R4
COLUMNS
MARKER 'MARKER' 'INTORG'
C0 OBJ 1
C0 R0 1
C0 R4 1
C1 R0 1
C1 R1 1
C1 OBJ 1
C2 R1 1
C2 R2 1
C2 OBJ 1
C3 R2 1
C3 R3 1
C3 OBJ 1
C4 R3 1
C4 R4 1
C4 OBJ 1
MARKER 'MARKER' 'INTEND'
RHS
RHS1 R0 1
RHS1 R1 1
RHS1 R2 1
RHS1 R3 1
RHS1 R4 1
BOUNDS
BV BND1 C0
BV BND1 C1
BV BND1 C2
BV BND1 C3
BV BND1 C4
ENDATA
41 changes: 41 additions & 0 deletions tests/src/reader/oc5_1.mps
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
NAME oc5
OBJSENSE
MAX
ROWS
N OBJ
L R0
L R1
L R2
L R3
L R4
COLUMNS
MARKER 'MARKER' 'INTORG'
C0 OBJ 1
C0 R0 1
C0 R4 1
C1 R0 1
C1 R1 1
C1 OBJ 1
C2 R1 1
C2 R2 1
C2 OBJ 1
C3 R2 1
C3 R3 1
C3 OBJ 1
C4 R3 1
C4 R4 1
C4 OBJ 1
MARKER 'MARKER' 'INTEND'
RHS
RHS1 R0 1
RHS1 R1 1
RHS1 R2 1
RHS1 R3 1
RHS1 R4 1
BOUNDS
BV BND1 C0
BV BND1 C1
BV BND1 C2
BV BND1 C3
BV BND1 C4
ENDATA

0 comments on commit ca0c6e1

Please sign in to comment.