| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "krasnopevtseva_v_monte_carlo_integration/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <random> | ||
| 6 | #include <tuple> | ||
| 7 | |||
| 8 | #include "krasnopevtseva_v_monte_carlo_integration/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace krasnopevtseva_v_monte_carlo_integration { | ||
| 11 | |||
| 12 | 160 | KrasnopevtsevaVMCIntegrationSEQ::KrasnopevtsevaVMCIntegrationSEQ(const InType &in) { | |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | GetOutput() = 0; | ||
| 16 | 160 | } | |
| 17 | |||
| 18 | 160 | bool KrasnopevtsevaVMCIntegrationSEQ::ValidationImpl() { | |
| 19 | const auto &input = GetInput(); | ||
| 20 | 160 | double a = std::get<0>(input); | |
| 21 | 160 | double b = std::get<1>(input); | |
| 22 | 160 | int num_points = std::get<2>(input); | |
| 23 | 160 | std::uint8_t func = std::get<3>(input); | |
| 24 | |||
| 25 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | return (a <= b) && (num_points > 0) && (func <= 3); |
| 26 | } | ||
| 27 | |||
| 28 | 160 | bool KrasnopevtsevaVMCIntegrationSEQ::PreProcessingImpl() { | |
| 29 | 160 | GetOutput() = 0.0; | |
| 30 | 160 | return true; | |
| 31 | } | ||
| 32 | |||
| 33 | 160 | bool KrasnopevtsevaVMCIntegrationSEQ::RunImpl() { | |
| 34 | const auto &input = GetInput(); | ||
| 35 | 160 | double a = std::get<0>(input); | |
| 36 | 160 | double b = std::get<1>(input); | |
| 37 | 160 | int num_points = std::get<2>(input); | |
| 38 | 160 | std::uint8_t func = std::get<3>(input); | |
| 39 | |||
| 40 | double sum = 0.0; | ||
| 41 | |||
| 42 | // генератор вихрь Мерсенна | ||
| 43 | 160 | std::random_device rd; | |
| 44 | 160 | std::mt19937 gen(rd()); | |
| 45 | std::uniform_real_distribution<double> dis(a, b); | ||
| 46 | |||
| 47 | // cos(x)*x^3 | ||
| 48 |
2/2✓ Branch 0 taken 5765552 times.
✓ Branch 1 taken 160 times.
|
5765712 | for (int i = 0; i < num_points; i++) { |
| 49 | double x = dis(gen); | ||
| 50 | 5765552 | double fx = FuncSystem::GetFunc(func, x); | |
| 51 | 5765552 | sum += fx; | |
| 52 | } | ||
| 53 | |||
| 54 | 160 | double integral = (b - a) * sum / num_points; | |
| 55 | 160 | GetOutput() = integral; | |
| 56 | |||
| 57 | 160 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 | 160 | bool KrasnopevtsevaVMCIntegrationSEQ::PostProcessingImpl() { | |
| 61 | 160 | return true; | |
| 62 | } | ||
| 63 | |||
| 64 | } // namespace krasnopevtseva_v_monte_carlo_integration | ||
| 65 |