Skip to content

Commit

Permalink
Added random weight function
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoulLuque committed Jun 28, 2024
1 parent 925a9aa commit 43f1621
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/clique_graph_edge_weight_functions.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use petgraph::graph::NodeIndex;
use rand::Rng;
use std::{collections::HashSet, hash::BuildHasher};

/// Returns 0.
pub fn neutral_heuristic<S>(_: &HashSet<NodeIndex, S>, _: &HashSet<NodeIndex, S>) -> i32 {
pub fn neutral<S>(_: &HashSet<NodeIndex, S>, _: &HashSet<NodeIndex, S>) -> i32 {
0
}

/// Returns a random i32 integer
pub fn random<S>(_: &HashSet<NodeIndex, S>, _: &HashSet<NodeIndex, S>) -> i32 {
let mut rng = rand::thread_rng();
rng.gen::<i32>()
}

/// Returns the negative of the cardinality of the intersection.
pub fn negative_intersection<S: BuildHasher + Default>(
first_vertex: &HashSet<NodeIndex, S>,
Expand Down
25 changes: 11 additions & 14 deletions src/compute_treewidth_upper_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ mod tests {
let test_graph = setup_test_graph(i);
let _ = compute_treewidth_upper_bound_not_connected::<_, _, RandomState, _>(
&test_graph.graph,
neutral_heuristic,
neutral,
SpanningTreeConstructionMethod::MSTAndUseTreeStructure,
true,
None,
);

let _ = compute_treewidth_upper_bound_not_connected::<_, _, RandomState, _>(
&test_graph.graph,
neutral_heuristic,
neutral,
SpanningTreeConstructionMethod::MSTAndFill,
true,
None,
Expand All @@ -317,18 +317,15 @@ mod tests {
for i in 0..3 {
for computation_method in COMPUTATION_METHODS {
let test_graph = setup_test_graph(i);
let computed_treewidth = compute_treewidth_upper_bound_not_connected::<
_,
_,
std::hash::BuildHasherDefault<rustc_hash::FxHasher>,
_,
>(
&test_graph.graph,
neutral_heuristic,
computation_method,
false,
None,
);
let computed_treewidth =
compute_treewidth_upper_bound_not_connected::<
_,
_,
std::hash::BuildHasherDefault<rustc_hash::FxHasher>,
_,
>(
&test_graph.graph, neutral, computation_method, false, None
);
if !(i == 1
&& (computation_method == SpanningTreeConstructionMethod::MSTAndFill
|| computation_method
Expand Down

0 comments on commit 43f1621

Please sign in to comment.