You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
3.7 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/NativeNondeterministicLinearEquationSolver.h"
  4. #include "src/settings/Settings.h"
  5. TEST(NativeNondeterministicLinearEquationSolver, SolveWithStandardOptions) {
  6. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  7. storm::storage::SparseMatrixBuilder<double> builder;
  8. ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9));
  9. storm::storage::SparseMatrix<double> A;
  10. ASSERT_NO_THROW(A = builder.build(2));
  11. std::vector<uint_fast64_t> nondeterministicChoiceIndices = {0, 2};
  12. std::vector<double> x(1);
  13. std::vector<double> b = {0.099, 0.5};
  14. ASSERT_NO_THROW(storm::solver::NativeNondeterministicLinearEquationSolver<double> solver);
  15. storm::solver::NativeNondeterministicLinearEquationSolver<double> solver;
  16. ASSERT_NO_THROW(solver.solveEquationSystem(true, A, x, b, nondeterministicChoiceIndices));
  17. ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::Settings::getInstance()->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  18. ASSERT_NO_THROW(solver.solveEquationSystem(false, A, x, b, nondeterministicChoiceIndices));
  19. ASSERT_LT(std::abs(x[0] - 0.989991), storm::settings::Settings::getInstance()->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  20. }
  21. TEST(NativeNondeterministicLinearEquationSolver, MatrixVectorMultiplication) {
  22. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  23. storm::storage::SparseMatrixBuilder<double> builder;
  24. ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9));
  25. ASSERT_NO_THROW(builder.addNextValue(0, 1, 0.099));
  26. ASSERT_NO_THROW(builder.addNextValue(0, 2, 0.001));
  27. ASSERT_NO_THROW(builder.addNextValue(1, 1, 0.5));
  28. ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.5));
  29. ASSERT_NO_THROW(builder.addNextValue(2, 1, 1));
  30. ASSERT_NO_THROW(builder.addNextValue(3, 2, 1));
  31. storm::storage::SparseMatrix<double> A;
  32. ASSERT_NO_THROW(A = builder.build());
  33. std::vector<uint_fast64_t> nondeterministicChoiceIndices = {0, 2, 3, 4};
  34. std::vector<double> x = {0, 1, 0};
  35. ASSERT_NO_THROW(storm::solver::NativeNondeterministicLinearEquationSolver<double> solver);
  36. storm::solver::NativeNondeterministicLinearEquationSolver<double> solver;
  37. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(true, A, x, nondeterministicChoiceIndices, nullptr, 1));
  38. ASSERT_LT(std::abs(x[0] - 0.099), storm::settings::Settings::getInstance()->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  39. x = {0, 1, 0};
  40. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(true, A, x, nondeterministicChoiceIndices, nullptr, 2));
  41. ASSERT_LT(std::abs(x[0] - 0.1881), storm::settings::Settings::getInstance()->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  42. x = {0, 1, 0};
  43. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(true, A, x, nondeterministicChoiceIndices, nullptr, 20));
  44. ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::Settings::getInstance()->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  45. x = {0, 1, 0};
  46. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(false, A, x, nondeterministicChoiceIndices, nullptr, 1));
  47. ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::Settings::getInstance()->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  48. x = {0, 1, 0};
  49. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(false, A, x, nondeterministicChoiceIndices, nullptr, 20));
  50. ASSERT_LT(std::abs(x[0] - 0.9238082658), storm::settings::Settings::getInstance()->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  51. }