pub struct LpExtractor<'a, L: Language, N: Analysis<L>> { /* private fields */ }
Expand description

A structure to perform extraction using integer linear programming. This uses the cbc solver. You must have it installed on your machine to use this feature. You can install it using:

OSCommand
Fedora / Red Hatsudo dnf install coin-or-Cbc-devel
Ubuntu / Debiansudo apt-get install coinor-libcbc-dev
macOSbrew install cbc

On macOS, you might also need the following in your .zshrc file: export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix)/lib

Example

use egg::*;
let mut egraph = EGraph::<SymbolLang, ()>::default();

let f = egraph.add_expr(&"(f x x x)".parse().unwrap());
let g = egraph.add_expr(&"(g (g x))".parse().unwrap());
egraph.union(f, g);
egraph.rebuild();

let best = Extractor::new(&egraph, AstSize).find_best(f).1;
let lp_best = LpExtractor::new(&egraph, AstSize).solve(f);

// In regular extraction, cost is measures on the tree.
assert_eq!(best.to_string(), "(g (g x))");

// Using ILP only counts common sub-expressions once,
// so it can lead to a smaller DAG expression.
assert_eq!(lp_best.to_string(), "(f x x x)");
assert_eq!(lp_best.as_ref().len(), 2);

Implementations

Create an LpExtractor using costs from the given LpCostFunction. See those docs for details.

Set the cbc timeout in seconds.

Extract a single rooted term.

This is just a shortcut for LpExtractor::solve_multiple.

Extract (potentially multiple) roots

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.