Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorHansen committed Jan 14, 2024
1 parent b2126bc commit c5d62c0
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/extract/faster_ilp_cbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,11 @@ fn remove_high_cost(
.filter_map(|root| vars[root].costs.iter().min())
.sum();

let mut high_cost = 0;
let mut removed = 0;

for (class_id, class_details) in vars.iter_mut() {
let mut to_remove = std::collections::BTreeSet::new();
for (node_idx, cost) in class_details.costs.iter().enumerate() {
// Without the allowance, this removed nodes that are needed for the optimal solution.
for i in (0..class_details.costs.len()).rev() {
let cost = &class_details.costs[i];
let this_root: Cost = if roots.contains(class_id) {
*class_details.costs.iter().min().unwrap()
} else {
Expand All @@ -832,42 +831,33 @@ fn remove_high_cost(
if cost
> &(initial_result_cost - lowest_root_cost_sum + this_root + EPSILON_ALLOWANCE)
{
to_remove.insert(node_idx);
class_details.remove(i);
removed += 1;
}
}

for &index in to_remove.iter().rev() {
class_details.remove(index);
high_cost += 1;
}
}
log::info!("Removed high-cost nodes: {}", high_cost);
log::info!("Removed high-cost nodes: {}", removed);
}
}

// Remove nodes with any (a) child pointing back to its own class,
// or (b) any child pointing to the sole root class.
fn remove_with_loops(vars: &mut IndexMap<ClassId, ClassILP>, roots: &[ClassId], config: &Config) {
if config.remove_self_loops {
let mut self_loop = 0;
let mut removed = 0;
for (class_id, class_details) in vars.iter_mut() {
let mut to_remove = std::collections::BTreeSet::new();
for (node_idx, children) in class_details.childrens_classes.iter().enumerate() {
if children
for i in (0..class_details.childrens_classes.len()).rev() {
if class_details.childrens_classes[i]
.iter()
.any(|cid| *cid == *class_id || (roots.len() == 1 && roots[0] == *cid))
{
to_remove.insert(node_idx);
class_details.remove(i);
removed += 1;
}
}

for &index in to_remove.iter().rev() {
class_details.remove(index);
self_loop += 1;
}
}

log::info!("Omitted looping nodes: {}", self_loop);
log::info!("Omitted looping nodes: {}", removed);
}
}

Expand Down

0 comments on commit c5d62c0

Please sign in to comment.