Skip to content

Commit

Permalink
Merge branch 'fix-sol-checker' into 'v92-bugfix'
Browse files Browse the repository at this point in the history
Fix sol checker

See merge request integer/scip!3634
  • Loading branch information
svigerske committed Jan 10, 2025
2 parents 27d527d + d14638f commit 668cee7
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 70 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ Build system

### Makefile

- the check/solchecker build now finds a GMP installation by Homebrew on macOS/arm64

Miscellaneous
-------------

- The output precision for writing CIP/POB files has been increased at several places for nonlinear constraints.
- the output precision for writing CIP/OPB files has been increased at several places for nonlinear constraints
- the solchecker tool now also supports SCIP solution format

Known bugs
----------
Expand Down
4 changes: 2 additions & 2 deletions check/solchecker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LINKCXX_l = -l
LINKCXX_o = -o # the trailing space is important
FLAGS =
OFLAGS =
CXXFLAGS = -I/usr/local/include
LDFLAGS = -L/usr/local/lib
CXXFLAGS = -I/usr/local/include -I/opt/homebrew/include
LDFLAGS = -L/usr/local/lib -L/opt/homebrew/lib

DOXY = doxygen

Expand Down
2 changes: 1 addition & 1 deletion check/solchecker/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Solution Checker

This code implements a solution checker for MIP models.
It reads a MIP model from a (gzipped) MPS file and a
solution from a SOL file and checks the feasibility of this
solution from a non-gzipped SOL file and checks the feasibility of this
solution. All input is internally stored as arbitrary precision
numbers (thanks to GNU GMP) and all calculations are done
in arbitrary precision. The code checks the integrality, the
Expand Down
39 changes: 20 additions & 19 deletions check/solchecker/src/gmputils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file gmputils.cpp
* @brief Basic classes to for rational arithmetic
* @brief Basic classes for rational arithmetic
*
* @author Domenico Salvagnin
* @author Thorsten Koch
Expand All @@ -11,6 +11,7 @@
#include <stdlib.h>
#include <assert.h>


char Rational::buffer[] = {'\0'};

Rational::Rational(int num, int den)
Expand Down Expand Up @@ -40,7 +41,7 @@ Rational::~Rational()

Rational& Rational::operator=(const Rational& rhs)
{
if (this != &rhs)
if( this != &rhs )
mpq_set(number, rhs.number);
return *this;
}
Expand Down Expand Up @@ -116,7 +117,7 @@ void Rational::integralityViolation(Rational& violation) const
}
// otherwise, we must check w.r.t. the given tolerance
// first calculate the fractional part
violation = (*this);
violation = *this;
violation.abs();
mpz_t r;
mpz_init(r);
Expand All @@ -136,7 +137,8 @@ void Rational::toZero()
bool Rational::isInteger(const Rational& tolerance) const
{
// if denominator is 1, then it is an integer for sure
if (mpz_cmp_ui(mpq_denref(number), 1) == 0) return true;
if( mpz_cmp_ui(mpq_denref(number), 1) == 0 )
return true;
// otherwise, we must check w.r.t. the given tolerance
// first calculate the fractional part
Rational viol(*this);
Expand Down Expand Up @@ -170,47 +172,46 @@ bool Rational::isZero() const
void Rational::fromString(const char* num)
{
char* tmp = &buffer[0];
int k = 0;
int exponent = 0;
int fraction = 0;
int exponent = 0;
int fraction = 0;
int k = 0;

assert(num != NULL);
assert(strlen(num) < 32);

// Skip initial whitespace
while(isspace(*num))
// skip initial whitespaces
while( isspace(*num) )
num++;

// Skip initial +/-
if (*num == '+')
// skip initial sign
if( *num == '+' )
num++;
else if (*num == '-')
else if( *num == '-' )
tmp[k++] = *num++;

for(int i = 0; num[i] != '\0'; i++)
for( int i = 0; num[i] != '\0'; ++i )
{
if (isdigit(num[i]))
if( isdigit(num[i]) )
{
tmp[k++] = num[i];
exponent -= fraction;
}
else if (num[i] == '.')
else if( num[i] == '.' )
fraction = 1;
else if (tolower(num[i]) == 'e')
else if( tolower(num[i]) == 'e' )
{
exponent += atoi(&num[i + 1]);
break;
}
}
while(exponent > 0)
while( exponent > 0 )
{
tmp[k++] = '0';
exponent--;
}
tmp[k++] = '/';
tmp[k++] = '1';

while(exponent < 0)
while( exponent < 0 )
{
tmp[k++] = '0';
exponent++;
Expand Down
3 changes: 2 additions & 1 deletion check/solchecker/src/gmputils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file gmputils.h
* @brief Basic classes to for rational arithmetic
* @brief Basic classes for rational arithmetic
*
* @author Domenico Salvagnin
*/
Expand All @@ -11,6 +11,7 @@
#include <gmp.h>
#include <string>


/**
* @brief Simple wrapper class around GMP mpq_t.
* Not a full-blown wrapper such as the ones in GMP++, but should be enough for the job.
Expand Down
Loading

0 comments on commit 668cee7

Please sign in to comment.