diff --git a/src/storm/solver/GlpkLpSolver.cpp b/src/storm/solver/GlpkLpSolver.cpp index 170d55a78..837d3666a 100644 --- a/src/storm/solver/GlpkLpSolver.cpp +++ b/src/storm/solver/GlpkLpSolver.cpp @@ -67,6 +67,7 @@ namespace storm { template storm::expressions::Variable GlpkLpSolver::addBoundedContinuousVariable(std::string const& name, ValueType lowerBound, ValueType upperBound, ValueType objectiveFunctionCoefficient) { + STORM_LOG_ASSERT(lowerBound != upperBound, "GLPK does not support variable bounds of the form [x,x]."); storm::expressions::Variable newVariable = this->manager->declareOrGetVariable(name, this->manager->getRationalType()); this->addVariable(newVariable, GLP_CV, GLP_DB, lowerBound, upperBound, objectiveFunctionCoefficient); return newVariable; @@ -95,6 +96,7 @@ namespace storm { template storm::expressions::Variable GlpkLpSolver::addBoundedIntegerVariable(std::string const& name, ValueType lowerBound, ValueType upperBound, ValueType objectiveFunctionCoefficient) { + STORM_LOG_ASSERT(lowerBound != upperBound, "GLPK does not support variable bounds of the form [x,x]."); storm::expressions::Variable newVariable = this->manager->declareOrGetVariable(name, this->manager->getIntegerType()); this->addVariable(newVariable, GLP_IV, GLP_DB, lowerBound, upperBound, objectiveFunctionCoefficient); this->modelContainsIntegerVariables = true; @@ -362,10 +364,10 @@ namespace storm { value = glp_get_col_prim(this->lp, static_cast(variableIndexPair->second)); } - // Now check the desired precision was actually achieved. - STORM_LOG_THROW(std::fabs(static_cast(value) - value) <= storm::settings::getModule().getIntegerTolerance(), storm::exceptions::InvalidStateException, "Illegal value for integer variable in glpk solution (" << value << ")."); - - return static_cast(value); + double roundedValue = std::round(value); + double diff = std::abs(roundedValue - value); + STORM_LOG_ERROR_COND(diff <= storm::settings::getModule().getIntegerTolerance(), "Illegal value for integer variable in GLPK solution (" << value << "). Difference to nearest int is " << diff); + return static_cast(roundedValue); } template @@ -386,7 +388,13 @@ namespace storm { value = glp_get_col_prim(this->lp, static_cast(variableIndexPair->second)); } - STORM_LOG_THROW(std::fabs(static_cast(value) - value) <= storm::settings::getModule().getIntegerTolerance(), storm::exceptions::InvalidStateException, "Illegal value for binary variable in glpk solution (" << value << ")."); + if (value > 0.5) { + STORM_LOG_ERROR_COND(std::abs(value - 1.0) <= storm::settings::getModule().getIntegerTolerance(), "Illegal value for binary variable in GLPK solution (" << value << ")."); + return true; + } else { + STORM_LOG_ERROR_COND(std::abs(value) <= storm::settings::getModule().getIntegerTolerance(), "Illegal value for binary variable in GLPK solution (" << value << ")."); + return false; + } return static_cast(value); } diff --git a/src/storm/solver/GurobiLpSolver.cpp b/src/storm/solver/GurobiLpSolver.cpp index 43eda0eeb..c6d293a26 100644 --- a/src/storm/solver/GurobiLpSolver.cpp +++ b/src/storm/solver/GurobiLpSolver.cpp @@ -367,10 +367,10 @@ namespace storm { STORM_LOG_THROW(error == 0, storm::exceptions::InvalidStateException, "Unable to get Gurobi solution (" << GRBgeterrormsg(env) << ", error code " << error << ")."); if (value > 0.5) { - STORM_LOG_ERROR_COND(std::abs(value - 1.0) <= storm::settings::getModule().getIntegerTolerance(), "Illegal value for integer variable in Gurobi solution (" << value << ")."); + STORM_LOG_ERROR_COND(std::abs(value - 1.0) <= storm::settings::getModule().getIntegerTolerance(), "Illegal value for binary variable in Gurobi solution (" << value << ")."); return true; } else { - STORM_LOG_ERROR_COND(std::abs(value) <= storm::settings::getModule().getIntegerTolerance(), "Illegal value for integer variable in Gurobi solution (" << value << ")."); + STORM_LOG_ERROR_COND(std::abs(value) <= storm::settings::getModule().getIntegerTolerance(), "Illegal value for binary variable in Gurobi solution (" << value << ")."); return false; } }