Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename _TVertexValue, typename _TEdgeWeight>
- void GraphGenerationAPI<_TVertexValue, _TEdgeWeight>::R_MAT(EdgesListGraph<_TVertexValue, _TEdgeWeight> &_graph,
- int _vertices_count, long long _edges_count,
- int _a_prob, int _b_prob, int _c_prob,
- int _d_prob, DirectionType _direction_type)
- {
- int n = (int)log2(_vertices_count);
- int vertices_count = _vertices_count;
- long long edges_count = _edges_count;
- int step = 1;
- if(_direction_type)
- {
- _graph.resize(vertices_count, edges_count);
- }
- else
- {
- step = 2;
- _graph.resize(vertices_count, 2*edges_count);
- }
- int *src_ids = _graph.get_src_ids();
- int *dst_ids = _graph.get_dst_ids();
- _TEdgeWeight *weights = _graph.get_weights();
- RandomGenerationAPI rng_api;
- rng_api.generate_array_of_random_values<_TVertexValue>(_graph.get_vertex_values(), vertices_count, 1000);
- int threads_count = omp_get_max_threads();
- // generate and add edges to graph
- unsigned int seed = 0;
- #pragma omp parallel private(seed) num_threads(threads_count)
- {
- seed = int(time(NULL)) * omp_get_thread_num();
- #pragma omp for schedule(static)
- for (long long cur_edge = 0; cur_edge < edges_count; cur_edge += step)
- {
- int x_middle = _vertices_count / 2, y_middle = _vertices_count / 2;
- for (long long i = 1; i < n; i++)
- {
- int a_beg = 0, a_end = _a_prob;
- int b_beg = _a_prob, b_end = b_beg + _b_prob;
- int c_beg = _a_prob + _b_prob, c_end = c_beg + _c_prob;
- int d_beg = _a_prob + _b_prob + _c_prob, d_end = d_beg + _d_prob;
- int step = (int)pow(2, n - (i + 1));
- int probability = rand_r(&seed) % 100;
- if (a_beg <= probability && probability < a_end)
- {
- x_middle -= step, y_middle -= step;
- }
- else if (b_beg <= probability && probability < b_end)
- {
- x_middle -= step, y_middle += step;
- }
- else if (c_beg <= probability && probability < c_end)
- {
- x_middle += step, y_middle -= step;
- }
- else if (d_beg <= probability && probability < d_end)
- {
- x_middle += step, y_middle += step;
- }
- }
- if (rand_r(&seed) % 2 == 0)
- x_middle--;
- if (rand_r(&seed) % 2 == 0)
- y_middle--;
- int from = x_middle;
- int to = y_middle;
- _TEdgeWeight edge_weight = (rand_r(&seed) % 10) + static_cast <float> (rand_r(&seed)) / static_cast <float> (RAND_MAX);
- src_ids[cur_edge] = from;
- dst_ids[cur_edge] = to;
- weights[cur_edge] = edge_weight;
- if(!_direction_type)
- {
- src_ids[cur_edge + 1] = to;
- dst_ids[cur_edge + 1] = from;
- weights[cur_edge + 1] = edge_weight;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement