Skip to content

Commit

Permalink
Implemented function to calculate treewidth given graph with HashSets…
Browse files Browse the repository at this point in the history
… as vertex weights
  • Loading branch information
RaoulLuque committed Apr 7, 2024
1 parent 3b461b5 commit 85ca3fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod construct_clique_graph;
pub mod fill_bags_along_path;
pub mod find_maximum_cliques;
pub mod find_path_in_tree;
pub mod find_width_of_tree_decomposition;
14 changes: 14 additions & 0 deletions src/algorithms/find_width_of_tree_decomposition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use petgraph::{graph::NodeIndex, Graph};
use std::collections::HashSet;

/// Returns the maximum size of one of the bags in the tree decomposition graph.
/// This equals the highest len of one of the vertices in the graph. Returns 0 if the graph has no vertices
pub fn find_width_of_tree_decompositionpub<E>(
graph: Graph<HashSet<NodeIndex>, E, petgraph::prelude::Undirected>,
) -> usize {
if let Some(bag) = graph.node_weights().max_by_key(|b| b.len()) {
bag.len()
} else {
0
}
}
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use petgraph::Graph;

fn main() {
let mut graph: Graph<u32, u32, petgraph::prelude::Undirected> =
petgraph::Graph::new_undirected();
petgraph::Graph::new_undirected();

let nodes = [
graph.add_node(0),
Expand All @@ -29,6 +29,4 @@ fn main() {
graph.add_edge(nodes[4], nodes[6], 0);

let mut cliques: Vec<Vec<_>> = find_maximum_cliques::<Vec<_>, _>(&graph).collect();


}

0 comments on commit 85ca3fc

Please sign in to comment.