Skip to content

Commit

Permalink
Add cost from children to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
saulshanabrook committed Jul 26, 2023
1 parent f36aa79 commit 80185c2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl EGraph {
}
// 4. Inline leaf nodes into their parents
for (parent, leaf_children) in &parents_to_children {
let additional_cost = leaf_children.iter().map(|child| self.nodes.get(child).unwrap().cost).sum::<ordered_float::NotNan<f64>>();
let parent_node = self.nodes.get_mut(parent).unwrap();
let args = parent_node
.children
Expand All @@ -67,6 +68,7 @@ impl EGraph {
.retain(|child| !leaf_children.contains(child));
let new_op = format!("{}({})", parent_node.op, args);
parent_node.op = new_op;
parent_node.cost += additional_cost;
}
}
}

0 comments on commit 80185c2

Please sign in to comment.