From 1f0cc863cfe7b6773bea11473a775ab507140bd3 Mon Sep 17 00:00:00 2001 From: Jonas Weich Date: Sun, 1 Oct 2023 11:38:04 +0200 Subject: [PATCH 1/2] Fully connected graph scenario --- test/utils/scenarios/scenarios.h | 47 ++++++++++++++++++++++++++++++ test/utils/scenarios/scenarios.tpp | 27 +++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/test/utils/scenarios/scenarios.h b/test/utils/scenarios/scenarios.h index 1c329dc3..3c5e676e 100644 --- a/test/utils/scenarios/scenarios.h +++ b/test/utils/scenarios/scenarios.h @@ -90,6 +90,53 @@ template template [[nodiscard]] scenario create_simple_graph_scenario(); +/** + * Creates a scenario containing a fully connected graph structure. In the + * visualization below, vertices and edge values are shown. Vertex IDs are given + * between parentheses. + * + * The direction of the edges is visualized. However, undirected edges are + * supported as well if an undirected graph is passed as a template parameter. + * + * + * ┌─────────────────┐ + * │ │ + * ┌────────┐ │ + * ┌──── │ 10 (0) │ ─┐ │ + * │ └────────┘ │ │ + * │ │ │ │ + * │ │ 100 │ │ + * │ ▼ │ │ + * │ ┌────────┐ │ │ + * ┌────┼──── │ 20 (1) │ ─┼───────┼────────────┐ + * │ │ └────────┘ │ │ │ + * │ │ │ │ │ │ + * │ │ │ 500 │ 200 │ │ + * │ │ ▼ │ │ │ + * │ │ ┌────────┐ │ │ │ + * ┌────┼────┼──── │ 30 (2) │ ◀┘ │ │ + * │ │ │ └────────┘ │ │ + * │ │ │ │ │ │ + * │ │ │ 300 │ 800 │ │ 700 + * │ │ │ ▼ │ │ + * │ │ │ ┌────────┐ 600 │ │ + * │ │ └───▶ │ 40 (3) │ ◀────────┼───────┐ │ + * │ │ └────────┘ │ │ │ + * │ │ │ │ │ │ + * │ │ │ 1000 │ 400 │ │ + * │ │ ▼ ▼ │ │ + * │ │ 900 ┌────────────────────────┐ │ │ + * └────┼────────▶ │ 50 (4) │ ◀┼────┘ + * │ └────────────────────────┘ │ + * │ │ + * └──────────────────────────────────────┘ + * + * @tparam GRAPH_T Can be either a directed or undirected graph with numeric + * vertices and edges. + * @return The scenario containing the graph structure. + */ +template +[[nodiscard]] scenario create_fully_connected_graph_scenario(); } // namespace graaf::utils::scenarios #include "scenarios.tpp" \ No newline at end of file diff --git a/test/utils/scenarios/scenarios.tpp b/test/utils/scenarios/scenarios.tpp index c1999e79..c6ad4ae6 100644 --- a/test/utils/scenarios/scenarios.tpp +++ b/test/utils/scenarios/scenarios.tpp @@ -46,4 +46,31 @@ scenario create_simple_graph_scenario() { return {std::move(graph), std::move(vertex_ids)}; } +template +scenario create_fully_connected_graph_scenario() { + std::vector vertex_ids{}; + vertex_ids.reserve(5); + + GRAPH_T graph{}; + + vertex_ids.push_back(graph.add_vertex(10)); + vertex_ids.push_back(graph.add_vertex(20)); + vertex_ids.push_back(graph.add_vertex(30)); + vertex_ids.push_back(graph.add_vertex(40)); + vertex_ids.push_back(graph.add_vertex(50)); + + graph.add_edge(vertex_ids[0], vertex_ids[1], 100); + graph.add_edge(vertex_ids[0], vertex_ids[2], 200); + graph.add_edge(vertex_ids[0], vertex_ids[3], 300); + graph.add_edge(vertex_ids[0], vertex_ids[4], 400); + graph.add_edge(vertex_ids[1], vertex_ids[2], 500); + graph.add_edge(vertex_ids[1], vertex_ids[3], 600); + graph.add_edge(vertex_ids[1], vertex_ids[4], 700); + graph.add_edge(vertex_ids[2], vertex_ids[3], 800); + graph.add_edge(vertex_ids[2], vertex_ids[4], 900); + graph.add_edge(vertex_ids[3], vertex_ids[4], 1000); + + return {std::move(graph), std::move(vertex_ids)}; +} + } // namespace graaf::utils::scenarios \ No newline at end of file From 2b853824ce5fdd6b60f169cb95a2fe7893d13731 Mon Sep 17 00:00:00 2001 From: Jonas Weich Date: Sun, 1 Oct 2023 11:50:55 +0200 Subject: [PATCH 2/2] Disconnected graph scenario --- test/utils/scenarios/scenarios.h | 41 ++++++++++++++++++++++++++++++ test/utils/scenarios/scenarios.tpp | 25 ++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/test/utils/scenarios/scenarios.h b/test/utils/scenarios/scenarios.h index 3c5e676e..8e9ea44f 100644 --- a/test/utils/scenarios/scenarios.h +++ b/test/utils/scenarios/scenarios.h @@ -137,6 +137,47 @@ template */ template [[nodiscard]] scenario create_fully_connected_graph_scenario(); + +/** + * Creates a scenario containing a disconnected graph consisting of two + * conntected subgraphs. In the visualization below, vertices and edge values + * are shown. Vertex IDs are given between parentheses. + * + * The direction of the edges is visualized. However, undirected edges are + * supported as well if an undirected graph is passed as a template parameter. + * + * + *┌────────┐ 200 ┌────────┐ + *│ 30 (2) │ ◀───── │ 10 (0) │ + *└────────┘ └────────┘ + * │ + * │ 100 + * ▼ + * ┌────────┐ + * │ 20 (1) │ + * └────────┘ + * ┌────────┐ + * │ 40 (3) │ ◀┐ + * └────────┘ │ + * │ │ + * │ 300 │ + * ▼ │ + * ┌────────┐ │ + * │ 50 (4) │ │ 500 + * └────────┘ │ + * │ │ + * │ 400 │ + * ▼ │ + * ┌────────┐ │ + * │ 60 (5) │ ─┘ + * └────────┘ + * + * @tparam GRAPH_T Can be either a directed or undirected graph with numeric + * vertices and edges. + * @return The scenario containing the graph structure. + */ +template +[[nodiscard]] scenario create_disconnected_graph_scenario(); } // namespace graaf::utils::scenarios #include "scenarios.tpp" \ No newline at end of file diff --git a/test/utils/scenarios/scenarios.tpp b/test/utils/scenarios/scenarios.tpp index c6ad4ae6..fa7fa5a4 100644 --- a/test/utils/scenarios/scenarios.tpp +++ b/test/utils/scenarios/scenarios.tpp @@ -73,4 +73,29 @@ scenario create_fully_connected_graph_scenario() { return {std::move(graph), std::move(vertex_ids)}; } +template +scenario create_disconnected_graph_scenario() { + std::vector vertex_ids{}; + vertex_ids.reserve(6); + + GRAPH_T graph{}; + + vertex_ids.push_back(graph.add_vertex(10)); + vertex_ids.push_back(graph.add_vertex(20)); + vertex_ids.push_back(graph.add_vertex(30)); + + vertex_ids.push_back(graph.add_vertex(40)); + vertex_ids.push_back(graph.add_vertex(50)); + vertex_ids.push_back(graph.add_vertex(60)); + + graph.add_edge(vertex_ids[0], vertex_ids[1], 100); + graph.add_edge(vertex_ids[0], vertex_ids[2], 200); + + graph.add_edge(vertex_ids[3], vertex_ids[4], 300); + graph.add_edge(vertex_ids[4], vertex_ids[5], 400); + graph.add_edge(vertex_ids[5], vertex_ids[3], 500); + + return {std::move(graph), std::move(vertex_ids)}; +} + } // namespace graaf::utils::scenarios \ No newline at end of file