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.

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