Browse Source

Replaced calls to std::abs with calls to std::fabs and included cmath.

Former-commit-id: 40fb587e2f
tempestpy_adaptions
PBerger 9 years ago
parent
commit
b99a063cce
  1. 26
      test/functional/solver/GlpkLpSolverTest.cpp

26
test/functional/solver/GlpkLpSolverTest.cpp

@ -13,6 +13,8 @@
#include "src/storage/expressions/Expressions.h" #include "src/storage/expressions/Expressions.h"
#include "src/solver/OptimizationDirection.h" #include "src/solver/OptimizationDirection.h"
#include <cmath>
TEST(GlpkLpSolver, LPOptimizeMax) { TEST(GlpkLpSolver, LPOptimizeMax) {
storm::solver::GlpkLpSolver solver(storm::OptimizationDirection::Maximize); storm::solver::GlpkLpSolver solver(storm::OptimizationDirection::Maximize);
storm::expressions::Variable x; storm::expressions::Variable x;
@ -34,16 +36,16 @@ TEST(GlpkLpSolver, LPOptimizeMax) {
ASSERT_FALSE(solver.isInfeasible()); ASSERT_FALSE(solver.isInfeasible());
double xValue = 0; double xValue = 0;
ASSERT_NO_THROW(xValue = solver.getContinuousValue(x)); ASSERT_NO_THROW(xValue = solver.getContinuousValue(x));
ASSERT_LT(std::abs(xValue - 1), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(xValue - 1), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double yValue = 0; double yValue = 0;
ASSERT_NO_THROW(yValue = solver.getContinuousValue(y)); ASSERT_NO_THROW(yValue = solver.getContinuousValue(y));
ASSERT_LT(std::abs(yValue - 6.5), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(yValue - 6.5), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double zValue = 0; double zValue = 0;
ASSERT_NO_THROW(zValue = solver.getContinuousValue(z)); ASSERT_NO_THROW(zValue = solver.getContinuousValue(z));
ASSERT_LT(std::abs(zValue - 2.75), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(zValue - 2.75), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double objectiveValue = 0; double objectiveValue = 0;
ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue()); ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue());
ASSERT_LT(std::abs(objectiveValue - 14.75), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(objectiveValue - 14.75), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
} }
TEST(GlpkLpSolver, LPOptimizeMin) { TEST(GlpkLpSolver, LPOptimizeMin) {
@ -67,16 +69,16 @@ TEST(GlpkLpSolver, LPOptimizeMin) {
ASSERT_FALSE(solver.isInfeasible()); ASSERT_FALSE(solver.isInfeasible());
double xValue = 0; double xValue = 0;
ASSERT_NO_THROW(xValue = solver.getContinuousValue(x)); ASSERT_NO_THROW(xValue = solver.getContinuousValue(x));
ASSERT_LT(std::abs(xValue - 1), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(xValue - 1), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double yValue = 0; double yValue = 0;
ASSERT_NO_THROW(yValue = solver.getContinuousValue(y)); ASSERT_NO_THROW(yValue = solver.getContinuousValue(y));
ASSERT_LT(std::abs(yValue - 0), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(yValue - 0), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double zValue = 0; double zValue = 0;
ASSERT_NO_THROW(zValue = solver.getContinuousValue(z)); ASSERT_NO_THROW(zValue = solver.getContinuousValue(z));
ASSERT_LT(std::abs(zValue - 5.7), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(zValue - 5.7), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double objectiveValue = 0; double objectiveValue = 0;
ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue()); ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue());
ASSERT_LT(std::abs(objectiveValue - (-6.7)), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(objectiveValue - (-6.7)), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
} }
TEST(GlpkLpSolver, MILPOptimizeMax) { TEST(GlpkLpSolver, MILPOptimizeMax) {
@ -106,10 +108,10 @@ TEST(GlpkLpSolver, MILPOptimizeMax) {
ASSERT_EQ(6, yValue); ASSERT_EQ(6, yValue);
double zValue = 0; double zValue = 0;
ASSERT_NO_THROW(zValue = solver.getContinuousValue(z)); ASSERT_NO_THROW(zValue = solver.getContinuousValue(z));
ASSERT_LT(std::abs(zValue - 3), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(zValue - 3), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double objectiveValue = 0; double objectiveValue = 0;
ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue()); ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue());
ASSERT_LT(std::abs(objectiveValue - 14), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(objectiveValue - 14), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
} }
TEST(GlpkLpSolver, MILPOptimizeMin) { TEST(GlpkLpSolver, MILPOptimizeMin) {
@ -139,10 +141,10 @@ TEST(GlpkLpSolver, MILPOptimizeMin) {
ASSERT_EQ(0, yValue); ASSERT_EQ(0, yValue);
double zValue = 0; double zValue = 0;
ASSERT_NO_THROW(zValue = solver.getContinuousValue(z)); ASSERT_NO_THROW(zValue = solver.getContinuousValue(z));
ASSERT_LT(std::abs(zValue - 5), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(zValue - 5), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
double objectiveValue = 0; double objectiveValue = 0;
ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue()); ASSERT_NO_THROW(objectiveValue = solver.getObjectiveValue());
ASSERT_LT(std::abs(objectiveValue - (-6)), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
ASSERT_LT(std::fabs(objectiveValue - (-6)), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
} }
TEST(GlpkLpSolver, LPInfeasible) { TEST(GlpkLpSolver, LPInfeasible) {

Loading…
Cancel
Save