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.

414 lines
22 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/EigenLinearEquationSolver.h"
  4. #include "src/settings/SettingsManager.h"
  5. #include "src/utility/constants.h"
  6. #include "src/settings/modules/EigenEquationSolverSettings.h"
  7. TEST(EigenLinearEquationSolver, SolveWithStandardOptions) {
  8. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  9. storm::storage::SparseMatrixBuilder<double> builder;
  10. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  11. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  12. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  13. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  14. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  15. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  16. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  17. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  18. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  19. storm::storage::SparseMatrix<double> A;
  20. ASSERT_NO_THROW(A = builder.build());
  21. std::vector<double> x(3);
  22. std::vector<double> b = {16, -4, -7};
  23. ASSERT_NO_THROW(storm::solver::EigenLinearEquationSolver<double> solver(A));
  24. storm::solver::EigenLinearEquationSolver<double> solver(A);
  25. ASSERT_NO_THROW(solver.solveEquations(x, b));
  26. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  27. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  28. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  29. }
  30. TEST(EigenLinearEquationSolver, SparseLU) {
  31. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  32. storm::storage::SparseMatrixBuilder<double> builder;
  33. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  34. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  35. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  36. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  37. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  38. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  39. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  40. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  41. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  42. storm::storage::SparseMatrix<double> A;
  43. ASSERT_NO_THROW(A = builder.build());
  44. std::vector<double> x(3);
  45. std::vector<double> b = {16, -4, -7};
  46. storm::solver::EigenLinearEquationSolver<double> solver(A);
  47. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::SparseLU);
  48. solver.getSettings().setMaximalNumberOfIterations(10000);
  49. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None);
  50. ASSERT_NO_THROW(solver.solveEquations(x, b));
  51. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  52. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  53. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  54. }
  55. TEST(EigenLinearEquationSolver, SparseLU_RationalNumber) {
  56. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<storm::RationalNumber> builder);
  57. storm::storage::SparseMatrixBuilder<storm::RationalNumber> builder;
  58. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  59. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  60. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  61. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  62. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  63. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  64. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  65. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  66. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  67. storm::storage::SparseMatrix<storm::RationalNumber> A;
  68. ASSERT_NO_THROW(A = builder.build());
  69. std::vector<storm::RationalNumber> x(3);
  70. std::vector<storm::RationalNumber> b = {16, -4, -7};
  71. storm::solver::EigenLinearEquationSolver<storm::RationalNumber> solver(A);
  72. ASSERT_NO_THROW(solver.solveEquations(x, b));
  73. ASSERT_TRUE(storm::utility::isOne(x[0]));
  74. ASSERT_TRUE(x[1] == 3);
  75. ASSERT_TRUE(x[2] == -1);
  76. }
  77. TEST(EigenLinearEquationSolver, SparseLU_RationalFunction) {
  78. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<storm::RationalFunction> builder);
  79. storm::storage::SparseMatrixBuilder<storm::RationalFunction> builder;
  80. ASSERT_NO_THROW(builder.addNextValue(0, 0, storm::RationalFunction(2)));
  81. ASSERT_NO_THROW(builder.addNextValue(0, 1, storm::RationalFunction(4)));
  82. ASSERT_NO_THROW(builder.addNextValue(0, 2, storm::RationalFunction(-2)));
  83. ASSERT_NO_THROW(builder.addNextValue(1, 0, storm::RationalFunction(4)));
  84. ASSERT_NO_THROW(builder.addNextValue(1, 1, storm::RationalFunction(-1)));
  85. ASSERT_NO_THROW(builder.addNextValue(1, 2, storm::RationalFunction(5)));
  86. ASSERT_NO_THROW(builder.addNextValue(2, 0, storm::RationalFunction(-1)));
  87. ASSERT_NO_THROW(builder.addNextValue(2, 1, storm::RationalFunction(-1)));
  88. ASSERT_NO_THROW(builder.addNextValue(2, 2, storm::RationalFunction(3)));
  89. storm::storage::SparseMatrix<storm::RationalFunction> A;
  90. ASSERT_NO_THROW(A = builder.build());
  91. std::vector<storm::RationalFunction> x(3);
  92. std::vector<storm::RationalFunction> b = {storm::RationalFunction(16), storm::RationalFunction(-4), storm::RationalFunction(-7)};
  93. storm::solver::EigenLinearEquationSolver<storm::RationalFunction> solver(A);
  94. ASSERT_NO_THROW(solver.solveEquations(x, b));
  95. ASSERT_TRUE(storm::utility::isOne(x[0]));
  96. ASSERT_TRUE(x[1] == storm::RationalFunction(3));
  97. ASSERT_TRUE(x[2] == storm::RationalFunction(-1));
  98. }
  99. TEST(EigenLinearEquationSolver, DGMRES) {
  100. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  101. storm::storage::SparseMatrixBuilder<double> builder;
  102. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  103. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  104. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  105. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  106. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  107. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  108. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  109. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  110. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  111. storm::storage::SparseMatrix<double> A;
  112. ASSERT_NO_THROW(A = builder.build());
  113. std::vector<double> x(3);
  114. std::vector<double> b = {16, -4, -7};
  115. storm::solver::EigenLinearEquationSolver<double> solver(A);
  116. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::DGMRES);
  117. solver.getSettings().setPrecision(1e-6);
  118. solver.getSettings().setMaximalNumberOfIterations(10000);
  119. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None);
  120. solver.getSettings().setNumberOfIterationsUntilRestart(50);
  121. ASSERT_NO_THROW(solver.solveEquations(x, b));
  122. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  123. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  124. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  125. }
  126. TEST(EigenLinearEquationSolver, DGMRES_Ilu) {
  127. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  128. storm::storage::SparseMatrixBuilder<double> builder;
  129. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  130. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  131. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  132. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  133. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  134. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  135. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  136. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  137. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  138. storm::storage::SparseMatrix<double> A;
  139. ASSERT_NO_THROW(A = builder.build());
  140. std::vector<double> x(3);
  141. std::vector<double> b = {16, -4, -7};
  142. storm::solver::EigenLinearEquationSolver<double> solver(A);
  143. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::DGMRES);
  144. solver.getSettings().setPrecision(1e-6);
  145. solver.getSettings().setMaximalNumberOfIterations(10000);
  146. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Ilu);
  147. ASSERT_NO_THROW(solver.solveEquations(x, b));
  148. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  149. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  150. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  151. }
  152. TEST(EigenLinearEquationSolver, DGMRES_Diagonal) {
  153. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  154. storm::storage::SparseMatrixBuilder<double> builder;
  155. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  156. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  157. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  158. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  159. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  160. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  161. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  162. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  163. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  164. storm::storage::SparseMatrix<double> A;
  165. ASSERT_NO_THROW(A = builder.build());
  166. std::vector<double> x(3);
  167. std::vector<double> b = {16, -4, -7};
  168. storm::solver::EigenLinearEquationSolver<double> solver(A);
  169. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::DGMRES);
  170. solver.getSettings().setPrecision(1e-6);
  171. solver.getSettings().setMaximalNumberOfIterations(10000);
  172. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Diagonal);
  173. ASSERT_NO_THROW(solver.solveEquations(x, b));
  174. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  175. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  176. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  177. }
  178. TEST(EigenLinearEquationSolver, GMRES) {
  179. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  180. storm::storage::SparseMatrixBuilder<double> builder;
  181. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  182. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  183. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  184. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  185. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  186. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  187. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  188. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  189. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  190. storm::storage::SparseMatrix<double> A;
  191. ASSERT_NO_THROW(A = builder.build());
  192. std::vector<double> x(3);
  193. std::vector<double> b = {16, -4, -7};
  194. storm::solver::EigenLinearEquationSolver<double> solver(A);
  195. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::GMRES);
  196. solver.getSettings().setPrecision(1e-6);
  197. solver.getSettings().setMaximalNumberOfIterations(10000);
  198. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None);
  199. solver.getSettings().setNumberOfIterationsUntilRestart(50);
  200. ASSERT_NO_THROW(solver.solveEquations(x, b));
  201. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  202. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  203. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  204. }
  205. TEST(EigenLinearEquationSolver, GMRES_Ilu) {
  206. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  207. storm::storage::SparseMatrixBuilder<double> builder;
  208. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  209. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  210. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  211. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  212. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  213. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  214. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  215. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  216. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  217. storm::storage::SparseMatrix<double> A;
  218. ASSERT_NO_THROW(A = builder.build());
  219. std::vector<double> x(3);
  220. std::vector<double> b = {16, -4, -7};
  221. storm::solver::EigenLinearEquationSolver<double> solver(A);
  222. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::GMRES);
  223. solver.getSettings().setPrecision(1e-6);
  224. solver.getSettings().setMaximalNumberOfIterations(10000);
  225. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Ilu);
  226. ASSERT_NO_THROW(solver.solveEquations(x, b));
  227. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  228. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  229. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  230. }
  231. TEST(EigenLinearEquationSolver, GMRES_Diagonal) {
  232. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  233. storm::storage::SparseMatrixBuilder<double> builder;
  234. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  235. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  236. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  237. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  238. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  239. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  240. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  241. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  242. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  243. storm::storage::SparseMatrix<double> A;
  244. ASSERT_NO_THROW(A = builder.build());
  245. std::vector<double> x(3);
  246. std::vector<double> b = {16, -4, -7};
  247. storm::solver::EigenLinearEquationSolver<double> solver(A);
  248. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::GMRES);
  249. solver.getSettings().setPrecision(1e-6);
  250. solver.getSettings().setMaximalNumberOfIterations(10000);
  251. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Diagonal);
  252. ASSERT_NO_THROW(solver.solveEquations(x, b));
  253. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  254. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  255. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  256. }
  257. TEST(EigenLinearEquationSolver, BiCGSTAB) {
  258. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  259. storm::storage::SparseMatrixBuilder<double> builder;
  260. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  261. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  262. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  263. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  264. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  265. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  266. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  267. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  268. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  269. storm::storage::SparseMatrix<double> A;
  270. ASSERT_NO_THROW(A = builder.build());
  271. std::vector<double> x(3);
  272. std::vector<double> b = {16, -4, -7};
  273. storm::solver::EigenLinearEquationSolver<double> solver(A);
  274. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::BiCGSTAB);
  275. solver.getSettings().setPrecision(1e-6);
  276. solver.getSettings().setMaximalNumberOfIterations(10000);
  277. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None);
  278. ASSERT_NO_THROW(solver.solveEquations(x, b));
  279. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  280. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  281. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  282. }
  283. TEST(EigenLinearEquationSolver, BiCGSTAB_Ilu) {
  284. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  285. storm::storage::SparseMatrixBuilder<double> builder;
  286. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  287. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  288. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  289. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  290. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  291. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  292. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  293. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  294. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  295. storm::storage::SparseMatrix<double> A;
  296. ASSERT_NO_THROW(A = builder.build());
  297. std::vector<double> x(3);
  298. std::vector<double> b = {16, -4, -7};
  299. storm::solver::EigenLinearEquationSolver<double> solver(A);
  300. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::BiCGSTAB);
  301. solver.getSettings().setPrecision(1e-6);
  302. solver.getSettings().setMaximalNumberOfIterations(10000);
  303. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Ilu);
  304. ASSERT_NO_THROW(solver.solveEquations(x, b));
  305. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  306. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  307. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  308. }
  309. TEST(EigenLinearEquationSolver, BiCGSTAB_Diagonal) {
  310. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  311. storm::storage::SparseMatrixBuilder<double> builder;
  312. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  313. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  314. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  315. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  316. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  317. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  318. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  319. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  320. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  321. storm::storage::SparseMatrix<double> A;
  322. ASSERT_NO_THROW(A = builder.build());
  323. std::vector<double> x(3);
  324. std::vector<double> b = {16, -4, -7};
  325. storm::solver::EigenLinearEquationSolver<double> solver(A);
  326. solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::BiCGSTAB);
  327. solver.getSettings().setPrecision(1e-6);
  328. solver.getSettings().setMaximalNumberOfIterations(10000);
  329. solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Diagonal);
  330. ASSERT_NO_THROW(solver.solveEquations(x, b));
  331. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  332. ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  333. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  334. }
  335. TEST(EigenLinearEquationSolver, MatrixVectorMultiplication) {
  336. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  337. storm::storage::SparseMatrixBuilder<double> builder;
  338. ASSERT_NO_THROW(builder.addNextValue(0, 1, 0.5));
  339. ASSERT_NO_THROW(builder.addNextValue(0, 4, 0.5));
  340. ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.5));
  341. ASSERT_NO_THROW(builder.addNextValue(1, 4, 0.5));
  342. ASSERT_NO_THROW(builder.addNextValue(2, 3, 0.5));
  343. ASSERT_NO_THROW(builder.addNextValue(2, 4, 0.5));
  344. ASSERT_NO_THROW(builder.addNextValue(3, 4, 1));
  345. ASSERT_NO_THROW(builder.addNextValue(4, 4, 1));
  346. storm::storage::SparseMatrix<double> A;
  347. ASSERT_NO_THROW(A = builder.build());
  348. std::vector<double> x(5);
  349. x[4] = 1;
  350. storm::solver::EigenLinearEquationSolver<double> solver(A);
  351. ASSERT_NO_THROW(solver.repeatedMultiply(x, nullptr, 4));
  352. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  353. }