@@ -61,102 +61,23 @@ void change_features(const std::string initial_graph_file, const std::string rep
6161void remove_non_mrng_edges_2 (const std::string initial_graph_file, const std::string graph_file) {
6262 fmt::print (" Load graph {} \n " , initial_graph_file);
6363 auto graph = deglib::graph::load_sizebounded_graph (initial_graph_file.c_str ());
64- fmt::print (" Graph with {} vertices and containing {} non-RNG edges\n " , graph.size (), deglib::analysis::calc_non_rng_edges (graph));
64+ fmt::print (" Graph with {} vertices and containing {} non-RNG edges \n " , graph.size (), deglib::analysis::calc_non_rng_edges (graph));
6565
66- const auto vertex_count = graph.size ();
67- const auto edge_per_vertex = graph.getEdgesPerVertex ();
68-
69- const auto start = std::chrono::steady_clock::now ();
70- std::vector<deglib::builder::GraphEdge> nonMRNG_edges;
71- for (uint32_t i = 0 ; i < vertex_count; i++) {
72- const auto vertex_index = i;
73- const auto neighbor_indices = graph.getNeighborIndices (vertex_index);
74- const auto neighbor_weights = graph.getNeighborWeights (vertex_index);
75-
76- // find all none rng conform neighbors
77- for (uint32_t n = 0 ; n < edge_per_vertex; n++) {
78- const auto neighbor_index = neighbor_indices[n];
79- const auto neighbor_weight = neighbor_weights[n];
80- if (deglib::analysis::checkRNG (graph, edge_per_vertex, vertex_index, neighbor_index, neighbor_weight) == false )
81- nonMRNG_edges.emplace_back (vertex_index, neighbor_index, neighbor_weight);
82- }
83- }
84- std::sort (nonMRNG_edges.begin (), nonMRNG_edges.end (), [](const auto & x, const auto & y){return x.weight < y.weight ;});
85-
86- size_t removed_rng_edges = 0 ;
87- for (size_t i = 0 ; i < nonMRNG_edges.size (); i++) {
88- const deglib::builder::GraphEdge& edge = nonMRNG_edges[i];
89- if (deglib::analysis::checkRNG (graph, edge_per_vertex, edge.from_vertex , edge.to_vertex , edge.weight ) == false ) {
90- graph.changeEdge (edge.from_vertex , edge.to_vertex , edge.from_vertex , 0 );
91- removed_rng_edges++;
92- }
93- }
94- const auto duration_ms = uint32_t (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now () - start).count ());
66+ deglib::optimization::remove_non_mrng_edges_weight_sorted (graph);
9567
9668 // store the graph
9769 graph.saveGraph (graph_file.c_str ());
98-
99- fmt::print (" Removed {} edges in {} ms. Final graph contains {} non-RNG edges\n " , removed_rng_edges, duration_ms, deglib::analysis::calc_non_rng_edges (graph));
10070}
10171
10272void remove_non_mrng_edges_1 (const std::string initial_graph_file, const std::string graph_file) {
10373 fmt::print (" Load graph {} \n " , initial_graph_file);
10474 auto graph = deglib::graph::load_sizebounded_graph (initial_graph_file.c_str ());
105- fmt::print (" Graph with {} vertices and containing {} non-RNG edges\n " , graph.size (), deglib::analysis::calc_non_rng_edges (graph));
75+ fmt::print (" Graph with {} vertices and containing {} non-RNG edges \n " , graph.size (), deglib::analysis::calc_non_rng_edges (graph));
10676
107- const auto vertex_count = graph.size ();
108- const auto edge_per_vertex = graph.getEdgesPerVertex ();
109-
110- const auto start = std::chrono::steady_clock::now ();
111- size_t removed_rng_edges = 0 ;
112- for (uint32_t i = 0 ; i < vertex_count; i++) {
113- const auto vertex_index = i;
114-
115- // sort neighbors by their weight (highest to lowest)
116- std::vector<std::pair<uint32_t , float >> neighbors;
117- {
118- const auto neighbor_indices = graph.getNeighborIndices (vertex_index);
119- const auto neighbor_weights = graph.getNeighborWeights (vertex_index);
120- for (uint32_t n = 0 ; n < edge_per_vertex; n++) {
121- const auto neighbor_index = neighbor_indices[n];
122- const auto neighbor_weight = neighbor_weights[n];
123- neighbors.emplace_back (neighbor_index, neighbor_weight);
124- }
125- std::sort (neighbors.begin (), neighbors.end (), [](const auto & x, const auto & y){return x.second < y.second ;});
126- }
127-
128- // find all none rng conform neighbors
129- std::vector<uint32_t > nonMRNG_edges;
130- for (uint32_t n = 0 ; n < neighbors.size (); n++) {
131- const auto neighbor_index = neighbors[n].first ;
132- const auto neighbor_weight = neighbors[n].second ;
133- if (deglib::analysis::checkRNG (graph, edge_per_vertex, vertex_index, neighbor_index, neighbor_weight) == false )
134- nonMRNG_edges.emplace_back (n);
135- }
136-
137- bool removed_edge = false ;
138- do {
139- removed_edge = false ;
140- for (uint32_t n = 0 ; n < nonMRNG_edges.size (); n++) {
141- const auto neighbor_index = neighbors[nonMRNG_edges[n]].first ;
142- const auto neighbor_weight = neighbors[nonMRNG_edges[n]].second ;
143-
144- if (deglib::analysis::checkRNG (graph, edge_per_vertex, vertex_index, neighbor_index, neighbor_weight) == false ) {
145- nonMRNG_edges.erase (nonMRNG_edges.begin () + n);
146- graph.changeEdge (vertex_index, neighbor_index, vertex_index, 0 );
147- removed_rng_edges++;
148- removed_edge = true ;
149- break ;
150- }
151- }
152- } while (removed_edge);
153- }
154- const auto duration_ms = uint32_t (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now () - start).count ());
77+ deglib::optimization::remove_non_mrng_edges_iterative (graph);
15578
15679 // store the graph
15780 graph.saveGraph (graph_file.c_str ());
158-
159- fmt::print (" Removed {} edges in {} ms. Final graph contains {} non-RNG edges\n " , removed_rng_edges, duration_ms, deglib::analysis::calc_non_rng_edges (graph));
16081}
16182
16283
@@ -168,7 +89,7 @@ void remove_non_mrng_edges(const std::string initial_graph_file, const std::stri
16889 auto graph = deglib::graph::load_sizebounded_graph (initial_graph_file.c_str ());
16990 fmt::print (" Graph with {} vertices and containing {} non-RNG edges\n " , graph.size (), deglib::analysis::calc_non_rng_edges (graph));
17091
171- deglib::builder ::remove_non_mrng_edges (graph);
92+ deglib::optimization ::remove_non_mrng_edges (graph);
17293
17394 // store the graph
17495 graph.saveGraph (graph_file.c_str ());
@@ -186,7 +107,7 @@ void optimize_graph(const std::string initial_graph_file, const std::string grap
186107 auto graph = deglib::graph::load_sizebounded_graph (initial_graph_file.c_str ());
187108 fmt::print (" Graph with {} vertices and an avg edge weight of {} \n " , graph.size (), deglib::analysis::calc_avg_edge_weight (graph, 100 ));
188109
189- deglib::builder ::optimize_edges (graph, k_opt, eps_opt, i_opt, iterations);
110+ deglib::optimization ::optimize_edges (graph, k_opt, eps_opt, i_opt, iterations);
190111
191112 // store the graph
192113 graph.saveGraph (graph_file.c_str ());
0 commit comments