pub trait CostModel<C: Cost> {
// Required methods
fn fold(&self, head: &str, children_cost: &[C], head_cost: C) -> C;
fn enode_cost(
&self,
egraph: &EGraph,
func: &Function,
row: &FunctionRow<'_>,
) -> C;
// Provided methods
fn container_cost(
&self,
egraph: &EGraph,
sort: &ArcSort,
value: Value,
element_costs: &[C],
) -> C { ... }
fn base_value_cost(
&self,
egraph: &EGraph,
sort: &ArcSort,
value: Value,
) -> C { ... }
}Expand description
An interface for custom cost model.
To use it with the default extractor, the cost type must also satisfy Ord + Eq + Clone + Debug.
Additionally, the cost model should guarantee that a term has a no-smaller cost
than its subterms to avoid cycles in the extracted terms for common case usages.
For more niche usages, a term can have a cost less than its subterms.
As long as there is no negative cost cycle,
the default extractor is guaranteed to terminate in computing the costs.
However, the user needs to be careful to guarantee acyclicity in the extracted terms.
Required Methods§
Sourcefn fold(&self, head: &str, children_cost: &[C], head_cost: C) -> C
fn fold(&self, head: &str, children_cost: &[C], head_cost: C) -> C
The total cost of a term given the cost of the root e-node and its immediate children’s total costs.
Sourcefn enode_cost(
&self,
egraph: &EGraph,
func: &Function,
row: &FunctionRow<'_>,
) -> C
fn enode_cost( &self, egraph: &EGraph, func: &Function, row: &FunctionRow<'_>, ) -> C
The cost of an enode (without the cost of children)
Provided Methods§
Sourcefn container_cost(
&self,
egraph: &EGraph,
sort: &ArcSort,
value: Value,
element_costs: &[C],
) -> C
fn container_cost( &self, egraph: &EGraph, sort: &ArcSort, value: Value, element_costs: &[C], ) -> C
The cost of a container value given the costs of its elements.
The default cost for containers is just the sum of all the elements inside
Sourcefn base_value_cost(&self, egraph: &EGraph, sort: &ArcSort, value: Value) -> C
fn base_value_cost(&self, egraph: &EGraph, sort: &ArcSort, value: Value) -> C
Compute the cost of a (non-container) primitive value.
The default cost for base values is the constant one