Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into doc_typos
Browse files Browse the repository at this point in the history
  • Loading branch information
bobluppes committed Jun 18, 2024
2 parents 8f10104 + d1a7873 commit 743ee8a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build/
cmake-modules/
venv
cmake-build-debug

# IDE
.vscode/
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ project(Graaf
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# The target name of the Library, what name you give to the Interface
set(GRAAF_LIB_TARGET_NAME ${PROJECT_NAME})

# Example usages of the library
option(SKIP_EXAMPLES "Skip building the examples" OFF)
if(NOT SKIP_EXAMPLES)
Expand All @@ -29,3 +32,8 @@ if(NOT SKIP_BENCHMARKS)
add_subdirectory(perf)
endif()

#Adding Interface to enable use of FetchContent
add_library(${GRAAF_LIB_TARGET_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${GRAAF_LIB_TARGET_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${GRAAF_LIB_TARGET_NAME} INTERFACE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include/")
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gtest/gtest.h>
#include <utils/fixtures/fixtures.h>

#include <algorithm>
#include <vector>

namespace graaf::algorithm {
Expand Down Expand Up @@ -299,4 +300,4 @@ TYPED_TEST(TarjansStronglyConnectedComponentsTest, TarjansComplexGraphTest) {
ASSERT_TRUE(are_set_vectors_equal(sccs, expected_sccs));
}

} // namespace graaf::algorithm
} // namespace graaf::algorithm

0 comments on commit 743ee8a

Please sign in to comment.