From d75a897fda350d06e4e5e18e28137fc3dcd9fdd1 Mon Sep 17 00:00:00 2001 From: Ahmed Radwan Date: Tue, 19 Nov 2024 16:12:16 +0200 Subject: [PATCH] passed scc 5 text tests --- src/graph/directed_graph.rs | 6 +++--- src/graph/txt/scc_test1.txt | 2 +- src/graph/txt/scc_test2.txt | 2 +- src/graph/txt/scc_test3.txt | 1 - src/graph/txt/scc_test4.txt | 11 +++++++++++ src/graph/txt/scc_test5.txt | 2 +- src/main.rs | 8 ++++---- 7 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 src/graph/txt/scc_test4.txt diff --git a/src/graph/directed_graph.rs b/src/graph/directed_graph.rs index 501f756..057dae9 100644 --- a/src/graph/directed_graph.rs +++ b/src/graph/directed_graph.rs @@ -86,9 +86,9 @@ impl DirectedGraph { head_index: VertexIndex, ) -> Result<(), GraphError> { // Check for self-loop - if tail_index == head_index { - return Err(GraphError::SelfLoop); - } + // if tail_index == head_index { + // return Err(GraphError::SelfLoop); + // } // Ensure tail and head are valid indices in the graph if tail_index >= self.vertices.len() || head_index >= self.vertices.len() { diff --git a/src/graph/txt/scc_test1.txt b/src/graph/txt/scc_test1.txt index 8abc3a5..272b686 100644 --- a/src/graph/txt/scc_test1.txt +++ b/src/graph/txt/scc_test1.txt @@ -8,4 +8,4 @@ 8 5 8 6 9 7 -9 3 +9 3 \ No newline at end of file diff --git a/src/graph/txt/scc_test2.txt b/src/graph/txt/scc_test2.txt index 055dc55..85ae507 100644 --- a/src/graph/txt/scc_test2.txt +++ b/src/graph/txt/scc_test2.txt @@ -11,4 +11,4 @@ 7 6 7 8 8 5 -8 7 +8 7 \ No newline at end of file diff --git a/src/graph/txt/scc_test3.txt b/src/graph/txt/scc_test3.txt index b1ab9c3..596c89a 100644 --- a/src/graph/txt/scc_test3.txt +++ b/src/graph/txt/scc_test3.txt @@ -7,4 +7,3 @@ 8 6 6 7 7 8 - diff --git a/src/graph/txt/scc_test4.txt b/src/graph/txt/scc_test4.txt new file mode 100644 index 0000000..9b2081c --- /dev/null +++ b/src/graph/txt/scc_test4.txt @@ -0,0 +1,11 @@ +1 2 +2 3 +3 1 +3 4 +5 4 +6 4 +8 6 +6 7 +7 8 +4 3 +4 6 \ No newline at end of file diff --git a/src/graph/txt/scc_test5.txt b/src/graph/txt/scc_test5.txt index b92203e..75ba071 100644 --- a/src/graph/txt/scc_test5.txt +++ b/src/graph/txt/scc_test5.txt @@ -17,4 +17,4 @@ 10 9 10 11 11 12 -12 10 +12 10 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index edcc46b..06f1b9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,15 +2,15 @@ use std::collections::HashMap; use algorithms_illuminated::graph::DirectedGraph; fn main() { - let graph = DirectedGraph::build_from_file("src/graph/txt/scc_example_8_16.txt", true).unwrap(); + let graph = DirectedGraph::build_from_file("src/graph/txt/scc_test5.txt", true).unwrap(); graph.print_graph(); let scc = graph.kosaraju(); - // let counts = count_and_sort_top_five(scc); + let counts = count_and_sort_top_five(scc); - println!("{:?}", scc); + println!("{:?}", counts); } -fn _count_and_sort_top_five(vec: Vec) -> Vec<(usize, usize)> { +fn count_and_sort_top_five(vec: Vec) -> Vec<(usize, usize)> { let mut counts = HashMap::new(); // Count occurrences