Skip to content

Commit

Permalink
passed scc 5 text tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aradwann committed Nov 19, 2024
1 parent bbb7cdb commit d75a897
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/graph/directed_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/graph/txt/scc_test1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
8 5
8 6
9 7
9 3
9 3
2 changes: 1 addition & 1 deletion src/graph/txt/scc_test2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
7 6
7 8
8 5
8 7
8 7
1 change: 0 additions & 1 deletion src/graph/txt/scc_test3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
8 6
6 7
7 8

11 changes: 11 additions & 0 deletions src/graph/txt/scc_test4.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/graph/txt/scc_test5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
10 9
10 11
11 12
12 10
12 10
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>) -> Vec<(usize, usize)> {
fn count_and_sort_top_five(vec: Vec<usize>) -> Vec<(usize, usize)> {
let mut counts = HashMap::new();

// Count occurrences
Expand Down

0 comments on commit d75a897

Please sign in to comment.