diff --git a/include/graaflib/algorithm/coloring/welsh_powell.tpp b/include/graaflib/algorithm/coloring/welsh_powell.tpp index 8f155117..c3a3287a 100644 --- a/include/graaflib/algorithm/coloring/welsh_powell.tpp +++ b/include/graaflib/algorithm/coloring/welsh_powell.tpp @@ -1,49 +1,46 @@ #pragma once #include #include -#include -#include + #include #include +#include +#include namespace graaf::algorithm { template std::unordered_map welsh_powell_coloring(const GRAPH& graph) { - - using degree_vertex_pair = std::pair; - - // Step 1: Sort vertices by degree in descending order - std::vector degree_vertex_pairs; - for (const auto& [vertex_id, _] : graph.get_vertices()) { - - int degree = properties::vertex_degree(graph, vertex_id); - degree_vertex_pairs.emplace_back(degree, vertex_id); - - } + using degree_vertex_pair = std::pair; - std::sort(degree_vertex_pairs.rbegin(), degree_vertex_pairs.rend()); + // Step 1: Sort vertices by degree in descending order + std::vector degree_vertex_pairs; + for (const auto& [vertex_id, _] : graph.get_vertices()) { + int degree = properties::vertex_degree(graph, vertex_id); + degree_vertex_pairs.emplace_back(degree, vertex_id); + } - // Step 2: Assign colors to vertices - std::unordered_map color_map; + std::sort(degree_vertex_pairs.rbegin(), degree_vertex_pairs.rend()); - for (const auto [_, current_vertex] : degree_vertex_pairs) { + // Step 2: Assign colors to vertices + std::unordered_map color_map; - int color = 0; // Start with color 0 + for (const auto [_, current_vertex] : degree_vertex_pairs) { + int color = 0; // Start with color 0 - // Check colors of adjacent vertices - for (const auto& neighbor : graph.get_neighbors(current_vertex)) { - // If neighbor is already colored with this color, increment the color - if (color_map.contains(neighbor) && color_map[neighbor] == color) { - color++; - } - } - - // Assign the color to the current vertex - color_map[current_vertex] = color; + // Check colors of adjacent vertices + for (const auto& neighbor : graph.get_neighbors(current_vertex)) { + // If neighbor is already colored with this color, increment the color + if (color_map.contains(neighbor) && color_map[neighbor] == color) { + color++; + } } - return color_map; + // Assign the color to the current vertex + color_map[current_vertex] = color; + } + + return color_map; } } // namespace graaf::algorithm diff --git a/include/graaflib/algorithm/strongly_connected_components/tarjan.tpp b/include/graaflib/algorithm/strongly_connected_components/tarjan.tpp index 1724f7bf..f4f25eb5 100644 --- a/include/graaflib/algorithm/strongly_connected_components/tarjan.tpp +++ b/include/graaflib/algorithm/strongly_connected_components/tarjan.tpp @@ -10,8 +10,7 @@ namespace graaf::algorithm { template -[[nodiscard]] sccs_t -tarjans_strongly_connected_components( +[[nodiscard]] sccs_t tarjans_strongly_connected_components( const graph& graph) { // Vector to store strongly connected components sccs_t sccs{};