Skip to content

Commit

Permalink
Added calculation of upper bound for treewidth for exemplary graph wi…
Browse files Browse the repository at this point in the history
…th output in dot format (graphviz)
  • Loading branch information
RaoulLuque committed Apr 7, 2024
1 parent 82ecd52 commit 211d588
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
mod algorithms;
use core::fmt;
use std::fmt::Debug;
use std::fs;
use std::io::Write;

use algorithms::{
construct_clique_graph::construct_clique_graph, fill_bags_along_paths::fill_bags_along_paths,
find_maximum_cliques::find_maximum_cliques,
find_width_of_tree_decomposition::find_width_of_tree_decomposition,
};
use petgraph::dot::{Config, Dot};
use petgraph::Graph;

fn main() {
Expand Down Expand Up @@ -31,11 +37,28 @@ fn main() {
graph.add_edge(nodes[3], nodes[5], 0);
graph.add_edge(nodes[3], nodes[6], 0);
graph.add_edge(nodes[4], nodes[6], 0);
graph.add_edge(nodes[2], nodes[3], 0);
graph.add_edge(nodes[0], nodes[3], 0);

let cliques: Vec<Vec<_>> = find_maximum_cliques::<Vec<_>, _>(&graph).collect();
let mut clique_graph = construct_clique_graph(cliques);
fill_bags_along_paths(&mut clique_graph);
let computed_treewidth = find_width_of_tree_decomposition(clique_graph);
let computed_treewidth = find_width_of_tree_decomposition(&clique_graph);

println!("The computed treewidth is: {}", computed_treewidth);

let start_graph_dot_file = Dot::with_config(&graph, &[Config::EdgeNoLabel]);
let result_graph_dot_file = Dot::with_config(&clique_graph, &[Config::EdgeNoLabel]);

fs::create_dir_all("target/visualizations");
fs::write(
"target/visualizations/starting_graph.dot",
start_graph_dot_file.to_string(),
)
.expect("Unable to write dotfile for first graph to files");

let mut w = fs::File::create("target/visualizations/result_graph.dot")
.expect("Result graph file could not be created");
write!(&mut w, "{:?}", result_graph_dot_file)
.expect("Unable to write dotfile for result graph to files");
}

0 comments on commit 211d588

Please sign in to comment.