pub struct PLACover { /* private fields */ }Expand description
A cover with dynamic dimensions (from PLA files)
Use this when loading PLA files where dimensions are not known at compile time.
Outputs are Option<bool>: Some(true)=1, Some(false)=0, None=don’t-care
Implementations§
Source§impl PLACover
impl PLACover
Sourcepub fn new(num_inputs: usize, num_outputs: usize) -> Self
pub fn new(num_inputs: usize, num_outputs: usize) -> Self
Create a new empty cover with specified dimensions
Sourcepub fn from_pla_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_pla_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load a cover from a PLA format file
The dimensions are determined from the PLA file.
Examples found in repository?
examples/pla_file.rs (line 43)
11fn main() {
12 println!("=== PLA File Minimization Example ===\n");
13
14 // Create a sample PLA file
15 let pla_content = r#".i 4
16.o 1
17.ilb a b c d
18.ob f
19.p 8
200000 1
210001 1
220010 1
230011 1
240100 1
250101 1
260110 1
270111 1
28.e
29"#;
30
31 println!("Sample PLA content:");
32 println!("{}", pla_content);
33
34 // Write to a temporary file
35 let mut temp_in = NamedTempFile::new().expect("Failed to create temp file");
36 temp_in
37 .write_all(pla_content.as_bytes())
38 .expect("Failed to write temp file");
39 temp_in.flush().expect("Failed to flush temp file");
40
41 // Read the PLA file
42 println!("\nReading PLA file...");
43 let mut cover = match PLACover::from_pla_file(temp_in.path()) {
44 Ok(c) => c,
45 Err(e) => {
46 eprintln!("Error reading PLA: {}", e);
47 return;
48 }
49 };
50
51 println!("PLA loaded successfully!");
52 println!("\nOriginal cover:");
53 println!(" Inputs: {}", cover.num_inputs());
54 println!(" Outputs: {}", cover.num_outputs());
55 println!(" Cubes: {}", cover.num_cubes());
56
57 // Minimize using the Cover trait
58 println!("\nMinimizing using Espresso...");
59 if let Err(e) = cover.minimize() {
60 eprintln!("Error minimizing: {}", e);
61 return;
62 }
63
64 println!("\nMinimized cover:");
65 println!(" Inputs: {}", cover.num_inputs());
66 println!(" Outputs: {}", cover.num_outputs());
67 println!(" Cubes: {}", cover.num_cubes());
68
69 // Show the minimized PLA
70 match cover.to_pla_string(PLAType::F) {
71 Ok(pla_str) => {
72 println!("\nMinimized PLA:");
73 println!("{}", pla_str);
74 }
75 Err(e) => eprintln!("Error generating PLA: {}", e),
76 }
77
78 // Write to output file if requested
79 if let Some(output_path) = env::args().nth(1) {
80 println!("Writing minimized PLA to: {}", output_path);
81 match cover.to_pla_file(&output_path, PLAType::F) {
82 Ok(_) => println!("Successfully wrote output file!"),
83 Err(e) => eprintln!("Error writing output: {}", e),
84 }
85 } else {
86 println!("\nTo write output to a file, run:");
87 println!("cargo run --example pla_file output.pla");
88 }
89}Sourcepub fn from_pla_content(content: &str) -> Result<Self>
pub fn from_pla_content(content: &str) -> Result<Self>
Load a cover from PLA format string
The dimensions are determined from the PLA content.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PLACover
impl RefUnwindSafe for PLACover
impl Send for PLACover
impl Sync for PLACover
impl Unpin for PLACover
impl UnwindSafe for PLACover
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Cover for Twhere
T: Minimizable + PLASerializable,
impl<T> Cover for Twhere
T: Minimizable + PLASerializable,
Source§fn num_inputs(&self) -> usize
fn num_inputs(&self) -> usize
Get the number of inputs
Source§fn num_outputs(&self) -> usize
fn num_outputs(&self) -> usize
Get the number of outputs
Source§fn num_cubes(&self) -> usize
fn num_cubes(&self) -> usize
Get the number of cubes (for F/FD types, only counts F cubes; for FR/FDR, counts all)
Source§fn cover_type(&self) -> PLAType
fn cover_type(&self) -> PLAType
Get the cover type (F, FD, FR, or FDR)
Source§fn cubes_iter<'a>(
&'a self,
) -> Box<dyn Iterator<Item = (Vec<Option<bool>>, Vec<Option<bool>>)> + 'a>
fn cubes_iter<'a>( &'a self, ) -> Box<dyn Iterator<Item = (Vec<Option<bool>>, Vec<Option<bool>>)> + 'a>
Iterate over cubes (inputs, outputs)
Returns cubes in same format as add_cube takes (owned vecs for easy use)
Source§fn minimize(&mut self) -> Result<(), Error>
fn minimize(&mut self) -> Result<(), Error>
Minimize this cover in-place using default configuration
Source§fn minimize_with_config(&mut self, config: &EspressoConfig) -> Result<(), Error>
fn minimize_with_config(&mut self, config: &EspressoConfig) -> Result<(), Error>
Minimize this cover in-place with custom configuration