Manual for TreeWidthSolver.jl
API
TreeWidthSolver.DecompositionTreeNodeTreeWidthSolver.MaskedBitGraphTreeWidthSolver.TreeDecompositionTreeWidthSolver.adjacency_matTreeWidthSolver.decomposition_treeTreeWidthSolver.elimination_orderTreeWidthSolver.exact_treewidthTreeWidthSolver.graph_from_grTreeWidthSolver.graph_from_tuplesTreeWidthSolver.line_graphTreeWidthSolver.save_graphTreeWidthSolver.simple_graph
Data Type
TreeWidthSolver.MaskedBitGraph — Typemutable struct MaskedBitGraph{INT}A mutable struct representing a masked bit graph.
Fields
MaskedBitGraph::Vector{INT}: Stores the adjacency matrix as a vector of BitStr.fadjlist::Vector{Vector{Int}}: Stores the adjacency list, providing information about the sparse graph.mask::INT: The mask for the graph.
TreeWidthSolver.DecompositionTreeNode — Typemutable struct DecompositionTreeNode{T}A mutable struct representing a node in a tree decomposition.
Fields
bag::Set{T}: The bag of the node, which is a set of elements of typeT.parent::Union{DecompositionTreeNode{T}, Nothing}: The parent node of the current node. It can be either aDecompositionTreeNode{T}orNothingif the current node is the root.children::Vector{DecompositionTreeNode{T}}: The children nodes of the current node, stored in a vector.
TreeWidthSolver.TreeDecomposition — Typestruct TreeDecomposition{TW, TL}A struct representing a tree decomposition.
Fields
tw::TW: The treewidth of the decomposition.tree::DecompositionTreeNode{TL}: The root node of the decomposition tree.
IO for Graphs
TreeWidthSolver.graph_from_gr — Functiongraph_from_gr(filename)Reads a graph from a file in the .gr format (PACE format) and returns a SimpleGraph object.
Arguments
filename: The path to the input file.
Returns
graph: ASimpleGraphobject representing the graph.
TreeWidthSolver.save_graph — Functionfunction save_graph(g::SimpleGraph, filename)The graph will be saved as .gr format, in PACE format, where the first line is p tw nv ne, and the following lines are the edges src dst
TreeWidthSolver.graph_from_tuples — Functiongraph_from_tuples(n::Int, edgs)Constructs a graph from a list of tuples representing edges.
Arguments
n::Int: The number of vertices in the graph.edgs: A list of tuples representing the edges of the graph.
Returns
A graph object.
Hypergraph
TreeWidthSolver.line_graph — Functionline_graph(adjacency_mat::SparseMatrixCSC)Constructs the line graph of a given graph represented by its adjacency matrix.
Arguments
adjacency_mat::SparseMatrixCSC: The adjacency matrix of the input graph, where the columns represent the vertices and the rows represent the edges. The value istrueif the edge is connected to the vertex.
Returns
g::SimpleGraph: The line graph of the input graph.
TreeWidthSolver.simple_graph — Functionsimple_graph(adjacency_mat::SparseMatrixCSC)Constructs a simple undirected graph from a sparse adjacency matrix.
Arguments
adjacency_mat::SparseMatrixCSC: The sparse adjacency matrix representing the graph.
Returns
g::SimpleGraph: The constructed simple undirected graph.
TreeWidthSolver.adjacency_mat — Functionadjacency_mat(graph::SimpleGraph)Constructs the adjacency matrix of a given SimpleGraph.
Arguments
graph::SimpleGraph: The input graph.
Returns
SparseMatrixCSC{Int}: The adjacency matrix of the graph.
Treewidth
TreeWidthSolver.exact_treewidth — Functionexact_treewidth(g::SimpleGraph{TG}; weights::Vector{TW} = ones(nv(g)), verbose::Bool = false) where {TG, TW}Compute the exact treewidth of a given graph g using the BT algorithm.
Arguments
g::SimpleGraph{TG}: The input graph.weights::Vector{TW} = ones(nv(g)): The weights of the vertices in the graph. Default is equal weights for all vertices.verbose::Bool = false: Whether to print verbose output. Default isfalse.
Returns
tw: The treewidth of the graph.
TreeWidthSolver.decomposition_tree — Functiondecomposition_tree(g::SimpleGraph{TG}; labels::Vector{TL} = collect(1:nv(g)), weights::Vector{TW} = ones(nv(g)), verbose::Bool = false) where {TG, TW, TL}Constructs a decomposition tree for a given simple graph g.
Arguments
g::SimpleGraph{TG}: The input graph.labels::Vector{TL}: (optional) The labels for the vertices of the graph. Default iscollect(1:nv(g)).weights::Vector{TW}: (optional) The weights for the vertices of the graph. Default isones(nv(g)).verbose::Bool: (optional) Whether to print verbose output. Default isfalse.
Returns
TreeDecomposition: The resulting decomposition tree, where treewidht is stored intd.twand the tree is stored intd.tree.
decomposition_tree(g::SimpleGraph{TG}, orders::Union{Vector{Vector{TE}}, Vector{TE}}; labels::Vector{TL} = [1:length(vertices(g))...]) where {TG, TE, TL}Constructs a decomposition tree for a given simple graph g based on the provided orders.
Arguments
g::SimpleGraph{TG}: The input graph.orders::Union{Vector{Vector{TE}}, Vector{TE}}: The orders for constructing the decomposition tree. Can be a vector of vectors or a single vector.labels::Vector{TL}: (optional) The labels for the vertices of the graph. Default iscollect(1:nv(g)).
Returns
TreeDecomposition: The resulting decomposition tree, where the tree is labeled according to the provided labels.
Raises
AssertionError: If the length ofnew_ordersdoes not match the number of vertices ing, ifnew_orderscontains duplicates, or if the length oflabelsdoes not match the length ofnew_orders.
TreeWidthSolver.elimination_order — Functionelimination_order(g::SimpleGraph{TG}; labels::Vector{TL} = collect(1:nv(g)), weights::Vector{TW} = ones(nv(g)), verbose::Bool = false) where {TG, TL, TW}Compute the elimination order of a graph g using the BT algorithm.
Arguments
g::SimpleGraph{TG}: The input graph.labels::Vector{TL}: (optional) Labels for the vertices ofg. Default iscollect(1:nv(g)).weights::Vector{TW}: (optional) Weights for the vertices ofg. Default isones(nv(g)).verbose::Bool: (optional) Whether to print verbose output. Default isfalse.
Returns
labeled_eo::Vector{Vector{TL}}: The elimination order of the graphg, where each vertex is labeled according tolabels.