| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gutyansky_a_monte_carlo_multi_dimension/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <random> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "gutyansky_a_monte_carlo_multi_dimension/common/include/common.hpp" | ||
| 8 | #include "gutyansky_a_monte_carlo_multi_dimension/common/include/function_registry.hpp" | ||
| 9 | |||
| 10 | namespace gutyansky_a_monte_carlo_multi_dimension { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | GutyanskyAMonteCarloMultiDimensionSEQ::GutyanskyAMonteCarloMultiDimensionSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | |||
| 15 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | GetInput() = in; |
| 16 | 64 | GetOutput() = 0.0; | |
| 17 | 64 | } | |
| 18 | |||
| 19 | 64 | bool GutyanskyAMonteCarloMultiDimensionSEQ::ValidationImpl() { | |
| 20 | 64 | return GetInput().IsValid(); | |
| 21 | } | ||
| 22 | |||
| 23 | 64 | bool GutyanskyAMonteCarloMultiDimensionSEQ::PreProcessingImpl() { | |
| 24 | 64 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | 64 | bool GutyanskyAMonteCarloMultiDimensionSEQ::RunImpl() { | |
| 28 | 64 | std::random_device rd; | |
| 29 | 64 | std::mt19937 gen(rd()); | |
| 30 | std::uniform_real_distribution<double> distr(0.0, 1.0); | ||
| 31 | |||
| 32 | 64 | size_t n_points = GetInput().n_points; | |
| 33 | 64 | size_t n_dims = GetInput().n_dims; | |
| 34 | |||
| 35 | double volume = 1.0; | ||
| 36 | |||
| 37 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 64 times.
|
248 | for (size_t i = 0; i < n_dims; i++) { |
| 38 | 184 | volume *= GetInput().upper_bounds[i] - GetInput().lower_bounds[i]; | |
| 39 | } | ||
| 40 | |||
| 41 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | FunctionRegistry::IntegralFunction function = GetInput().GetFunction(); |
| 42 | |||
| 43 |
1/4✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
64 | std::vector<double> random_point(n_dims); |
| 44 | |||
| 45 | double sum = 0.0; | ||
| 46 | |||
| 47 |
2/2✓ Branch 0 taken 32000000 times.
✓ Branch 1 taken 64 times.
|
32000064 | for (size_t i = 0; i < n_points; i++) { |
| 48 |
2/2✓ Branch 0 taken 92000000 times.
✓ Branch 1 taken 32000000 times.
|
124000000 | for (size_t j = 0; j < n_dims; j++) { |
| 49 | 92000000 | double lb = GetInput().lower_bounds[j]; | |
| 50 | 92000000 | double rb = GetInput().upper_bounds[j]; | |
| 51 | |||
| 52 | 92000000 | random_point[j] = lb + (distr(gen) * (rb - lb)); | |
| 53 | } | ||
| 54 | |||
| 55 | 32000000 | sum += function(random_point); | |
| 56 | } | ||
| 57 | |||
| 58 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | GetOutput() = volume * (sum / static_cast<double>(n_points)); |
| 59 | |||
| 60 | 64 | return true; | |
| 61 | } | ||
| 62 | |||
| 63 | 64 | bool GutyanskyAMonteCarloMultiDimensionSEQ::PostProcessingImpl() { | |
| 64 | 64 | return true; | |
| 65 | } | ||
| 66 | |||
| 67 | } // namespace gutyansky_a_monte_carlo_multi_dimension | ||
| 68 |