Skip to content

Commit

Permalink
clang-format (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobluppes committed Jun 16, 2024
1 parent e6e0a93 commit c096baf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
55 changes: 26 additions & 29 deletions include/graaflib/algorithm/coloring/welsh_powell.tpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
#pragma once
#include <graaflib/algorithm/coloring/welsh_powell.h>
#include <graaflib/properties/vertex_properties.h>
#include <unordered_map>
#include <vector>

#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

namespace graaf::algorithm {

template <typename GRAPH>
std::unordered_map<vertex_id_t, int> welsh_powell_coloring(const GRAPH& graph) {

using degree_vertex_pair = std::pair<int, vertex_id_t>;

// Step 1: Sort vertices by degree in descending order
std::vector<degree_vertex_pair> 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<int, vertex_id_t>;

std::sort(degree_vertex_pairs.rbegin(), degree_vertex_pairs.rend());
// Step 1: Sort vertices by degree in descending order
std::vector<degree_vertex_pair> 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<vertex_id_t, int> 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<vertex_id_t, int> 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
namespace graaf::algorithm {

template <typename V, typename E>
[[nodiscard]] sccs_t
tarjans_strongly_connected_components(
[[nodiscard]] sccs_t tarjans_strongly_connected_components(
const graph<V, E, graph_type::DIRECTED>& graph) {
// Vector to store strongly connected components
sccs_t sccs{};
Expand Down

0 comments on commit c096baf

Please sign in to comment.