use core::{
ffi::{c_int, c_uint},
time::Duration,
};
use rustsat::{
instances::Cnf,
types::{Assignment, Clause, Lit, Var, WClsIter},
};
mod base;
mod ffi;
#[cfg(feature = "multiopt")]
mod multiopt;
#[cfg(feature = "optimization")]
mod opt;
mod sat;
pub use base::MaxPre;
#[cfg(feature = "multiopt")]
pub use multiopt::PreproMultiOpt;
#[cfg(feature = "optimization")]
pub use opt::PreproOpt;
pub use sat::PreproSat;
pub type SoftClauses = Vec<(Clause, usize)>;
pub enum Error {
Generic,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "unspecified error")
}
}
pub trait PreproClauses {
fn signature() -> &'static str;
fn new<CI: WClsIter>(hards: Cnf, softs: Vec<(CI, isize)>, inprocessing: bool) -> Self;
fn preprocess(&mut self, techniques: &str, log_level: c_int, time_limit: f64);
fn top_weight(&self) -> u64;
fn n_prepro_clauses(&self) -> c_uint;
fn n_prepro_labels(&self) -> c_uint;
fn n_prepro_fixed_lits(&self) -> c_uint;
fn prepro_instance(&mut self) -> (Cnf, Vec<(SoftClauses, isize)>);
fn prepro_labels(&self) -> Vec<Lit>;
fn prepro_fixed_lits(&self) -> Vec<Lit>;
fn max_orig_var(&self) -> Var;
fn upper_bound(&self) -> u64;
fn reconstruct(&mut self, sol: Assignment) -> Assignment;
fn add_var(&mut self) -> Result<Var, Error>;
fn add_clause(&mut self, clause: Clause) -> Result<(), Error>;
fn add_label(&mut self, label: Lit, weight: usize) -> Result<Lit, Error>;
fn alter_weight(&mut self, label: Lit, weight: usize) -> Result<(), Error>;
fn label_to_var(&mut self, label: Lit) -> Result<(), Error>;
fn reset_removed_weight(&mut self) -> Result<(), Error>;
fn removed_weight(&mut self) -> Vec<usize>;
fn set_options(&mut self, opts: Options);
fn print_instance(&self);
fn print_solution(&self, sol: Assignment, weight: usize);
fn print_map(&self);
fn print_technique_log(&self);
fn print_info_log(&self);
fn print_stats(&self);
fn stats(&self) -> Stats;
}
#[derive(Clone, Default)]
pub struct Options {
pub bve_gate_extraction: Option<bool>,
pub label_matching: Option<bool>,
pub skip_technique: Option<c_int>,
pub bve_sort_max_first: Option<bool>,
pub bve_local_grow_limit: Option<c_int>,
pub bve_global_grow_limit: Option<c_int>,
pub max_bbtms_vars: Option<c_int>,
pub harden_in_model_search: Option<bool>,
pub model_search_iter_limits: Option<c_int>,
}
#[derive(Clone, PartialEq, Eq, Default)]
pub struct Stats {
pub n_objs: usize,
pub n_orig_hard_clauses: usize,
pub n_orig_soft_clauses: Vec<usize>,
pub max_orig_var: Option<Var>,
pub n_prepro_hard_clauses: usize,
pub n_prepro_soft_clauses: Vec<usize>,
pub max_prepro_var: Option<Var>,
pub removed_weight: Vec<usize>,
pub prepro_time: Duration,
pub reconst_time: Duration,
}