### Example Search Queries Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html?search= Demonstrates common search patterns and syntax used within the Batsat system. These examples can guide users on how to effectively query for specific data or types. ```text std::vec ``` ```text u32 -> bool ``` ```text Option, (T -> U) -> Option ``` -------------------------------- ### AsyncInterrupt Callbacks: on_start Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/struct.AsyncInterrupt.html Callback function invoked before the SAT solver starts its execution. Used for any setup required before solving begins. ```rust fn on_start(&mut self) ``` -------------------------------- ### fn on_start Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/trait.Callbacks.html?search= Called before starting to solve. This method is part of the Callbacks trait. ```APIDOC ## fn on_start ### Description Called before starting to solve. ### Signature `fn on_start(&mut self)` ``` -------------------------------- ### fn on_start Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/trait.Callbacks.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Called before starting to solve. This method is part of the Callbacks trait. ```APIDOC ## fn on_start ### Description Called before starting to solve. ### Method Signature `fn on_start(&mut self)` ``` -------------------------------- ### Slice Length Example Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html Demonstrates how to get the number of elements in a slice. This is a fundamental operation for understanding the size of collections. ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### starts_with Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html?search= Checks if the IntSet starts with a given prefix slice. ```APIDOC ## pub fn starts_with(&self, needle: &[T]) -> bool ### Description Returns `true` if `needle` is a prefix of the slice or equal to the slice. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method - Not applicable (method call) ### Endpoint - Not applicable (method call) ### Request Example ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` Always returns `true` if `needle` is an empty slice: ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` ### Response #### Success Response - **bool**: `true` if the slice starts with the `needle`, `false` otherwise. #### Response Example ```rust // Example for assert!(v.starts_with(&[10, 40])); true ``` ```rust // Example for assert!(!v.starts_with(&[10, 50])); false ``` ``` -------------------------------- ### on_start Callback Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/trait.Callbacks.html?search=u32+-%3E+bool Called before starting to solve. Implement this to perform actions at the beginning of the solving process. ```rust fn on_start(&mut self) { ... } ``` -------------------------------- ### starts_with Source: https://docs.rs/batsat/latest/batsat/intmap/struct.IntSet.html?search=u32+-%3E+bool Checks if a slice starts with a given prefix. ```APIDOC ## pub fn starts_with(&self, needle: &[T]) -> bool ### Description Returns `true` if `needle` is a prefix of the slice or equal to the slice. ### Parameters #### Path Parameters - **needle** (&[T]) - The slice to check as a prefix. ### Examples ``` let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ``` -------------------------------- ### BasicSolver Creation and Access Source: https://docs.rs/batsat/0.6.0/batsat/type.BasicSolver.html?search=std%3A%3Avec Demonstrates how to create a new BasicSolver instance and access its callbacks. ```APIDOC ## Solver ### `new(opts: SolverOpts, cb: Cb) -> Self` **Description**: Creates a new solver with the given options and the callbacks `cb`. ### `new_with(opts: SolverOpts, cb: Cb) -> Self` **Description**: Creates a new solver with the given options and callbacks. ### `cb_mut(&mut self) -> &mut Cb` **Description**: Provides temporary mutable access to the solver's callbacks. ### `cb(&self) -> &Cb` **Description**: Provides temporary immutable access to the solver's callbacks. ``` -------------------------------- ### RegionAllocator Initialization and Size Source: https://docs.rs/batsat/0.6.0/src/batsat/alloc.rs.html?search= Provides methods to create a new RegionAllocator with a specified starting capacity and to get its current length and wasted space. ```Rust impl RegionAllocator { pub fn new(start_cap: u32) -> Self { Self { vec: Vec::with_capacity(start_cap as usize), wasted: 0, } } pub fn len(&self) -> u32 { self.vec.len() as u32 } pub fn wasted(&self) -> u32 { self.wasted as u32 } } ``` -------------------------------- ### Get Index of Element Reference Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html?search=std%3A%3Avec Finds the index of a given element reference within a slice. Returns None if the element reference is not aligned with the start of an element. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` -------------------------------- ### on_start Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/trait.Callbacks.html Called before starting to solve. This method can be implemented to perform actions at the beginning of the SAT solving process. ```APIDOC ## fn on_start(&mut self) ### Description Called before starting to solve. ### Method `on_start` ``` -------------------------------- ### Removing a prefix from a slice Source: https://docs.rs/batsat/latest/batsat/intmap/struct.IntSet.html Use `strip_prefix` to get a subslice with the specified prefix removed. Returns `None` if the slice does not start with the prefix. An empty prefix results in the original slice. ```rust let slice = [10, 20, 30, 40]; assert_eq!(slice.strip_prefix(&[10, 20]), Some(&[30, 40][..])); assert_eq!(slice.strip_prefix(&[10, 20, 30, 40]), Some(&[][..])); assert_eq!(slice.strip_prefix(&[50]), None); assert_eq!(slice.strip_prefix(&[]), Some(&[10, 20, 30, 40][..])); ``` -------------------------------- ### Proof Initialization and Helper Methods Source: https://docs.rs/batsat/0.6.0/src/batsat/drat.rs.html?search=std%3A%3Avec Provides methods for creating a new `Proof` instance and internal helpers for pushing literals and handling clause operations. `push_lit` converts a `Lit` to its integer representation. ```rust impl Proof { /// New proof recording structure. pub fn new() -> Self { Proof(Vec::new()) } fn push_lit(&mut self, lit: Lit) { let i: i32 = (if lit.sign() { 1 } else { -1 }) * ((lit.var().idx() + 1) as i32); self.0.push(i) } ``` -------------------------------- ### Removing a Prefix with `strip_prefix` Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html Use `strip_prefix` to get a subslice after removing a specified prefix. Returns `None` if the slice does not start with the prefix. An empty prefix returns the original slice. ```rust let v = [10, 40, 30]; assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..])); assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..])); assert_eq!(v.strip_prefix(&[10, 50]), None); assert_eq!(v.strip_prefix(&[]), Some(&[10, 40, 30][..])); ``` -------------------------------- ### Solver Initialization with Options and Callbacks Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Initializes a new solver instance with the provided `SolverOpts` and callbacks. It asserts that the options are valid before proceeding with the solver's internal setup. ```rust pub fn new_with(opts: SolverOpts, cb: Cb) -> Self { assert!(opts.check()); Self { // Parameters (user settable): model: vec![], conflict: LSet::new(), cb, clauses: vec![], learnts: vec![], v: SolverV::new(&opts), tmp_c_th: vec![], tmp_c_add_cl: vec![], } } ``` -------------------------------- ### Batsat Solver Initialization and Main Loop Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E This snippet shows the setup for the main search loop in the Batsat solver, including initialization of model, conflict tracking, and learning parameters. It prepares the solver for the search by setting up restart and learning size adjustment mechanisms. ```Rust 764 /// Main solve method (assumptions given in `self.assumptions`). 765 fn solve_internal(&mut self, th: &mut Th) -> lbool { 766 assert!(self.v.decision_level() == 0); 767 self.model.clear(); 768 self.conflict.clear(); 769 if !self.v.ok { 770 return lbool::FALSE; 771 } 772 773 self.v.solves += 1; 774 let mut tmp_learnt: Vec = vec![]; 775 776 self.v.max_learnts = self.num_clauses() as f64 * self.v.opts.learntsize_factor; 777 if self.v.max_learnts < self.v.opts.min_learnts_lim as f64 { 778 self.v.max_learnts = self.v.opts.min_learnts_lim as f64; 779 } 780 781 self.v.learntsize_adjust_confl = self.v.learntsize_adjust_start_confl as f64; 782 self.v.learntsize_adjust_cnt = self.v.learntsize_adjust_confl as i32; 783 let mut status; 784 785 info!("search.start"); 786 self.cb.on_start(); 787 788 // Search: 789 let mut curr_restarts: i32 = 0; 790 loop { ``` -------------------------------- ### RegionAllocator Initialization and Basic Operations Source: https://docs.rs/batsat/0.6.0/src/batsat/alloc.rs.html Initializes a new RegionAllocator with a specified starting capacity. Provides methods to get the current length and wasted space. Use this for setting up a new allocator instance. ```rust pub fn new(start_cap: u32) -> Self { Self { vec: Vec::with_capacity(start_cap as usize), wasted: 0, } } pub fn len(&self) -> u32 { self.vec.len() as u32 } pub fn wasted(&self) -> u32 { self.wasted as u32 } ``` -------------------------------- ### Proof::new Source: https://docs.rs/batsat/0.6.0/src/batsat/drat.rs.html Initializes a new, empty DRAT proof recording structure. ```APIDOC ## fn new() -> Proof ### Description New proof recording structure. ### Returns * A new instance of `Proof`. ``` -------------------------------- ### Getting a Raw Mutable Pointer to Vector Data Source: https://docs.rs/batsat/0.6.0/batsat/clause/type.OccVec.html?search=std%3A%3Avec Returns a raw mutable pointer to the vector's buffer. The caller must ensure the vector outlives the pointer and manage memory deallocation if necessary, for example, by using `ManuallyDrop`. ```Rust let mut v = vec![0, 1, 2]; let ptr2 = v.as_mut_ptr().offset(2); ptr2.write(2); ``` -------------------------------- ### IntMap Initialization and Basic Operations Source: https://docs.rs/batsat/latest/src/batsat/intmap.rs.html Demonstrates creating a new `IntMap`, checking for key existence, reserving space, and inserting elements. The `reserve` function pads with a provided value, while `insert` uses `reserve` internally. ```rust pub fn new() -> Self { Self::default() } #[inline] pub fn has(&self, k: K) -> bool { k.as_index() < self.map.len() } pub fn reserve(&mut self, key: K, pad: V) where V: Clone, { let index = key.as_index(); if index >= self.map.len() { self.map.resize(index + 1, pad); } } #[inline] pub fn insert(&mut self, key: K, val: V, pad: V) where V: Clone, { self.reserve(key, pad); self[key] = val; } ``` -------------------------------- ### Any::type_id() - Get TypeId of Stats Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/struct.Stats.html?search= Gets the `TypeId` of the `Stats` struct. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId> ``` -------------------------------- ### Create New Solver with Options and Callbacks Source: https://docs.rs/batsat/0.6.0/batsat/core/struct.Solver.html Constructs a new Solver instance with specified options and a callback implementation. This is a primary way to initialize the solver. ```rust pub fn new(opts: SolverOpts, cb: Cb) -> Self ``` -------------------------------- ### Lit apply_sign method with example Source: https://docs.rs/batsat/latest/src/batsat/clause.rs.html?search=u32+-%3E+bool Applies a given sign to a literal, keeping the original sign if `true` and flipping it if `false`. Includes a usage example. ```rust /// `lit.apply_sign(b)` keeps the same sign if `b==true`, flips sign otherwise /// /// ``` /// use batsat::* /// let mut sat = BasicSolver::default(); /// let lit1 = Lit::new(sat.new_var_default(), true); /// assert_eq!(lit1, lit1.apply_sign(true)); /// assert_eq!(!lit1, lit1.apply_sign(false)); /// let lit2 = Lit::new(sat.new_var_default(), false); /// assert_ne!(lit1.var(), lit2.var()); /// assert_eq!(lit2, lit2.apply_sign(true)); /// assert_eq!(!lit2, lit2.apply_sign(false)); /// ``` #[inline(always)] pub fn apply_sign(&self, sign: bool) -> Lit { if sign { *self } else { !*self } } } ``` -------------------------------- ### strip_prefix Source: https://docs.rs/batsat/latest/batsat/intmap/struct.IntSet.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns a subslice with the prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix. If `prefix` is empty or the slice does not start with `prefix`, simply returns the original slice. If `prefix` is equal to the original slice, returns an empty slice. ```APIDOC ## strip_prefix

(&self, prefix: &P) -> Option<&[T]> ### Description Returns a subslice with the prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix. If `prefix` is empty or the slice does not start with `prefix`, simply returns the original slice. If `prefix` is equal to the original slice, returns an empty slice. ### Parameters #### Path Parameters - `prefix`: `&P` - The prefix to remove. `P` must implement `SlicePattern + ?Sized`. ### Response - `Option<&[T]>`: Returns `Some` containing the subslice with the prefix removed if the slice starts with the prefix, otherwise returns `None`. ### Examples ```rust let v = &[10, 40, 30]; assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30][..])); assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..])); assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..])); assert_eq!(v.strip_prefix(&[50]), None); assert_eq!(v.strip_prefix(&[10, 50]), None); let prefix : &str = "he"; assert_eq!(b"hello".strip_prefix(prefix.as_bytes()), Some(b"llo".as_ref())); ``` ``` -------------------------------- ### TheoryState Initialization and Clearing Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html?search= Demonstrates how to create a new TheoryState and how to clear its contents, resetting it for reuse. ```rust fn new() -> Self { TheoryState { lemma_lits: vec![], lemma_offsets: vec![], } } fn clear(&mut self) { self.lemma_lits.clear(); self.lemma_offsets.clear(); } ``` -------------------------------- ### Initialize Search Parameters Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Sets up initial parameters for the search, including the maximum number of learnt clauses and parameters for learnt clause size adjustment. ```rust self.v.max_learnts = self.num_clauses() as f64 * self.v.opts.learntsize_factor; if self.v.max_learnts < self.v.opts.min_learnts_lim as f64 { self.v.max_learnts = self.v.opts.min_learnts_lim as f64; } self.v.learntsize_adjust_confl = self.v.learntsize_adjust_start_confl as f64; self.v.learntsize_adjust_cnt = self.v.learntsize_adjust_confl as i32; ``` -------------------------------- ### value_lit Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the current assignment value of a literal. ```APIDOC ## value_lit ### Description Gets the current assignment value of a literal. ### Method `SolverV::value_lit(x: Lit)` ### Parameters #### Path Parameters - **x** (Lit) - The literal to query. ### Returns - `lbool`: The current assignment value of the literal (True, False, or Undefined). ``` -------------------------------- ### Solver Constructor with Options and Callbacks Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html?search=std%3A%3Avec Initializes a new solver with provided options and callbacks. Asserts that the options are valid. ```Rust /// Create a new solver with the given options and callbacks. pub fn new_with(opts: SolverOpts, cb: Cb) -> Self { assert!(opts.check()); Self { // Parameters (user settable): model: vec![], conflict: LSet::new(), cb, clauses: vec![], learnts: vec![], v: SolverV::new(&opts), tmp_c_th: vec![], tmp_c_add_cl: vec![], } } ``` -------------------------------- ### value Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the current assignment value of a variable. ```APIDOC ## value ### Description Gets the current assignment value of a variable. ### Method `SolverV::value(x: Var)` ### Parameters #### Path Parameters - **x** (Var) - The variable to query. ### Returns - `lbool`: The current assignment value of the variable (True, False, or Undefined). ``` -------------------------------- ### Callbacks::on_start() - Called before solving starts Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/struct.Stats.html?search= Callback function invoked before the SAT solver begins the solving process. ```rust fn on_start(&mut self)> ``` -------------------------------- ### Vec with Capacity and Allocator Example Source: https://docs.rs/batsat/0.6.0/batsat/clause/type.OccVec.html?search=u32+-%3E+bool Demonstrates creating a vector with a specific initial capacity using a custom allocator and how its capacity and length change with element additions. ```rust #![feature(allocator_api)] use std::alloc::System; let mut vec = Vec::with_capacity_in(10, System); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); assert!(vec.capacity() >= 10); // These are all done without reallocating... for i in 0..10 { vec.push(i); } assert_eq!(vec.len(), 10); assert!(vec.capacity() >= 10); // ...but this may make the vector reallocate vec.push(11); assert_eq!(vec.len(), 11); assert!(vec.capacity() >= 11); // A vector of a zero-sized type will always over-allocate, since no // allocation is necessary let vec_units = Vec::<(), System>::with_capacity_in(10, System); assert_eq!(vec_units.capacity(), usize::MAX); ``` -------------------------------- ### strip_prefix Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html Returns a subslice with the prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`. If `prefix` is empty, simply returns the original slice. If `prefix` is equal to the original slice, returns an empty slice. If the slice does not start with `prefix`, returns `None`. ```APIDOC ## pub fn strip_prefix

(&self, prefix: &P) -> Option<&[T]> ### Description Returns a subslice with the prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`. If `prefix` is empty, simply returns the original slice. If `prefix` is equal to the original slice, returns an empty slice. If the slice does not start with `prefix`, returns `None`. ### Parameters #### Path Parameters - **prefix** (&P) - Required - The prefix pattern to remove. ### Type Parameters - **P**: Must implement `SlicePattern` and `?Sized`. - **T**: Must implement `PartialEq`. ``` -------------------------------- ### Initialize Solver with Options Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Creates a new instance of the Solver with provided options. Initializes internal state, including variable tracking and statistics. ```rust fn new(opts: &SolverOpts) -> Self { Self { opts: opts.clone(), vars: VarState::new(opts), num_clauses: 0, num_learnts: 0, clauses_literals: 0, learnts_literals: 0, // Parameters (experimental): learntsize_adjust_start_confl: 100, learntsize_adjust_inc: 1.5, // Statistics: (formerly in 'SolverStats') solves: 0, starts: 0, decisions: 0, rnd_decisions: 0, propagations: 0, conflicts: 0, dec_vars: 0, // v.num_clauses: 0, // v.num_learnts: 0, // v.clauses_literals: 0, // v.learnts_literals: 0, max_literals: 0, tot_literals: 0, polarity: VMap::new(), user_pol: VMap::new(), decision: VMap::new(), // v.vardata: VMap::new(), watches_data: OccListsData::new(), order_heap_data: HeapData::new(), ok: true, cla_inc: 1.0, // v.var_inc: 1.0, qhead: 0, simp_db_assigns: -1, simp_db_props: 0, progress_estimate: 0.0, remove_satisfied: false, // revert b5464ec81f76db9315dac3276b64614dd59cfe49 next_var: Var::from_idx(0), ca: ClauseAllocator::new(), free_vars: vec![], assumptions: vec![], seen: VMap::new(), minimize_stack: vec![], analyze_toclear: vec![], max_learnts: 0.0, learntsize_adjust_confl: 0.0, learntsize_adjust_cnt: 0, // Resource constraints: conflict_budget: -1, propagation_budget: -1, th_st: TheoryState::new(), } } ``` -------------------------------- ### type_id Source: https://docs.rs/batsat/latest/batsat/intmap/struct.IntSet.html?search=std%3A%3Avec Gets the `TypeId` of the `IntSet`. This method is part of the `Any` trait implementation. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns The `TypeId` of the `IntSet`. ``` -------------------------------- ### Basic IntSet Search Example Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html?search= Demonstrates a typical search operation within an IntSet. This is useful for checking the presence of a specific integer. ```rust let mut set = IntSet::new(); set.insert(1); set.insert(2); assert!(set.search(&1)); assert!(!set.search(&3)); ``` -------------------------------- ### Get Variable Level Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Retrieves the decision level at which a variable was assigned. ```rust pub fn level(&self, x: Var) -> i32 { self.vars.level(x) } ``` -------------------------------- ### IntMapBool::new Source: https://docs.rs/batsat/0.6.0/src/batsat/intmap.rs.html?search=u32+-%3E+bool Creates a new, empty IntMapBool. This is the primary way to initialize an instance of IntMapBool. ```APIDOC ## IntMapBool::new ### Description Creates a new, empty `IntMapBool`. This is the primary way to initialize an instance of `IntMapBool`. ### Method Associated function (constructor) ### Signature `pub fn new() -> Self` ### Returns A new, empty `IntMapBool` instance. ``` -------------------------------- ### Solver::value_lit Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Gets the assigned value of a literal from the current model. ```APIDOC ## Solver::value_lit ### Description Gets the assigned value of a literal from the current model. ### Method `value_lit(&self, v: Lit) -> lbool` ### Parameters * `v` (Lit) - The literal to query. ``` -------------------------------- ### Rust Slice `split_at` Example (Midpoint 0) Source: https://docs.rs/batsat/latest/batsat/intmap/struct.IntSet.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates splitting a slice at the beginning (index 0). The left part is empty, and the right part contains the entire original slice. ```rust let v = ['a', 'b', 'c']; { let (left, right) = v.split_at(0); assert_eq!(left, []); assert_eq!(right, ['a', 'b', 'c']); } ``` -------------------------------- ### Solver::value_var Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Gets the assigned value of a variable from the current model. ```APIDOC ## Solver::value_var ### Description Gets the assigned value of a variable from the current model. ### Method `value_var(&self, v: Var) -> lbool` ### Parameters * `v` (Var) - The variable to query. ``` -------------------------------- ### Initializing a New DRAT Proof Source: https://docs.rs/batsat/latest/src/batsat/drat.rs.html?search=u32+-%3E+bool Provides a constructor `new` for creating an empty `Proof` instance, ready to record proof steps. ```Rust pub fn new() -> Self { Proof(Vec::new()) } ``` -------------------------------- ### Get Clause Size Source: https://docs.rs/batsat/0.6.0/src/batsat/clause.rs.html?search= Returns the number of literals in the clause as a `u32`. ```rust pub fn size(&self) -> u32 { self.data.len() as u32 } ``` -------------------------------- ### Basic Struct Documentation Source: https://docs.rs/batsat/0.6.0/batsat/callbacks/struct.Basic.html Provides documentation for the Basic struct, its constructor, and methods for setting callbacks. ```APIDOC ## Struct Basic ### Description Basic set of callbacks. This struct doesn't do anything except storing a function to `stop`. ### Fields (No public fields are exposed for direct manipulation. The struct contains private fields.) ### Methods #### `new()` - **Description**: Allocate a new set of callbacks. - **Signature**: `pub fn new() -> Self` #### `set_stop(f: F)` - **Description**: Set the `stop` function. This function is called regularly to check if the operation should be interrupted. - **Signature**: `pub fn set_stop(&mut self, f: F) where F: 'static + Fn() -> bool` ### Trait Implementations #### `Callbacks` Trait - **`stop()`**: Should we stop? Called regularly for asynchronous interrupts and such. Returns `bool`. - **`on_start()`**: Called before starting to solve. - **`on_simplify()`**: Called whenever the solver simplifies its set of clauses. - **`on_restart()`**: Called whenever the SAT solver restarts. - **`on_gc(old_size: usize, new_size: usize)`**: Called after a clause garbage collection. - **`on_new_clause(c: &[Lit], src: Kind)`**: Called whenever a new clause is learnt. - **`on_delete_clause(c: &[Lit])`**: Called when a clause is deleted. - **`on_progress(f: F)`**: Called regularly to indicate progress. `F` is a closure that returns `ProgressStatus`. - **`on_result(s: lbool)`**: Called when a result is computed. ``` -------------------------------- ### Get Vector Length Source: https://docs.rs/batsat/0.6.0/batsat/clause/type.OccVec.html?search= Returns the number of elements currently in the vector. ```Rust let v = vec![1, 2, 3]; assert_eq!(v.len(), 3); ``` -------------------------------- ### SolverInterface::raw_value_lit Source: https://docs.rs/batsat/0.6.0/batsat/core/struct.Solver.html Gets the value of a literal if it is assigned, or `UNDEF` otherwise. ```APIDOC ## SolverInterface::raw_value_lit ### Description Value of this literal if it’s assigned or `UNDEF` otherwise. ### Method `raw_value_lit(&self, l: Lit) -> lbool` ### Parameters * **l** (Lit) - Required - The literal to query. ``` -------------------------------- ### Create New Solver with Options and Callbacks (Alternative) Source: https://docs.rs/batsat/0.6.0/batsat/core/struct.Solver.html An alternative constructor for creating a new Solver instance, similar to `new`. It takes solver options and a callback object. ```rust pub fn new_with(opts: SolverOpts, cb: Cb) -> Self ``` -------------------------------- ### RegionAllocator::new Source: https://docs.rs/batsat/latest/batsat/alloc/struct.RegionAllocator.html?search= Creates a new RegionAllocator with a specified starting capacity. ```rust pub fn new(start_cap: u32) -> Self> ``` -------------------------------- ### rchunks Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html?search=std%3A%3Avec Returns an iterator over `chunk_size` elements starting from the end of the slice. ```APIDOC ## pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. If `chunk_size` does not divide the length of the slice, then the last chunk will not have length `chunk_size`. See `rchunks_exact` for a variant of this iterator that returns chunks of always exactly `chunk_size` elements, and `chunks` for the same iterator but starting at the beginning of the slice. If your `chunk_size` is a constant, consider using `as_rchunks` instead, which will give references to arrays of exactly that length, rather than slices. ### Panics Panics if `chunk_size` is zero. ### Examples ``` let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.rchunks(2); assert_eq!(iter.next().unwrap(), &['e', 'm']); assert_eq!(iter.next().unwrap(), &['o', 'r']); assert_eq!(iter.next().unwrap(), &['l']); assert!(iter.next().is_none()); ``` ``` -------------------------------- ### Create and Apply Sign to Lit Source: https://docs.rs/batsat/0.6.0/batsat/clause/struct.Lit.html?search=u32+-%3E+bool Demonstrates how to create a Lit with a specific variable and sign, and how to apply or flip its sign using the apply_sign method. This is useful for manipulating literals in SAT solving. ```rust use batsat::* let mut sat = BasicSolver::default(); let lit1 = Lit::new(sat.new_var_default(), true); assert_eq!(lit1, lit1.apply_sign(true)); assert_eq!(!lit1, lit1.apply_sign(false)); let lit2 = Lit::new(sat.new_var_default(), false); assert_ne!(lit1.var(), lit2.var()); assert_eq!(lit2, lit2.apply_sign(true)); assert_eq!(!lit2, lit2.apply_sign(false)); ``` -------------------------------- ### iter Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntSet.html?search= Returns an iterator over the slice, yielding all items from start to end. ```APIDOC ## pub fn iter(&self) -> Iter<'_, T> ### Description Returns an iterator over the slice. The iterator yields all items from start to end. ### Examples ```rust let x = &[1, 2, 4]; let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None); ``` ``` -------------------------------- ### IntMap::new Source: https://docs.rs/batsat/0.6.0/batsat/intmap/struct.IntMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new, empty IntMap. ```APIDOC ## IntMap::new ### Description Creates a new, empty `IntMap`. ### Method `new()` ### Returns - `Self`: A new instance of `IntMap`. ``` -------------------------------- ### DRAT Proof Initialization and Clause Handling Source: https://docs.rs/batsat/latest/src/batsat/drat.rs.html Provides methods for creating a new DRAT proof, adding literals to clauses, and recording the creation or deletion of clauses within the proof. ```Rust impl Proof { /// New proof recording structure. pub fn new() -> Self { Proof(Vec::new()) } fn push_lit(&mut self, lit: Lit) { let i: i32 = (if lit.sign() { 1 } else { -1 }) * ((lit.var().idx() + 1) as i32); self.0.push(i) } /// Register clause creation. pub fn create_clause(&mut self, c: &C) where C: ClauseIterable, { for lit in c.items() { self.push_lit((*lit).into()); } self.0.push(0); } /// Register clause deletion. pub fn delete_clause(&mut self, c: &C) where C: ClauseIterable, { // display deletion of clause if proof production is enabled self.0.push(i32::MAX); for lit in c.items() { self.push_lit((*lit).into()); } self.0.push(0); } } ``` -------------------------------- ### RegionAllocator::new Source: https://docs.rs/batsat/0.6.0/batsat/alloc/struct.RegionAllocator.html?search=u32+-%3E+bool Creates a new RegionAllocator with a specified starting capacity. ```APIDOC ## RegionAllocator::new ### Description Creates a new `RegionAllocator` instance with a given initial capacity. ### Method `new` ### Signature `pub fn new(start_cap: u32) -> Self` ### Parameters * `start_cap` (u32) - The initial capacity for the allocator. ``` -------------------------------- ### RegionAllocator::new Source: https://docs.rs/batsat/0.6.0/batsat/alloc/struct.RegionAllocator.html?search= Creates a new RegionAllocator with a specified starting capacity. ```APIDOC ## RegionAllocator::new ### Description Creates a new `RegionAllocator` instance with a given initial capacity. ### Method `new(start_cap: u32) -> Self` ### Parameters * `start_cap` (u32) - The initial capacity for the allocator. ``` -------------------------------- ### Default Solver Initialization Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Provides a default implementation for creating a `Solver` instance using default `SolverOpts` and default callbacks. This is a convenient way to get a ready-to-use solver. ```rust impl Default for Solver { fn default() -> Self { Solver::new(SolverOpts::default(), Default::default()) } } ``` -------------------------------- ### Solver Implementations Source: https://docs.rs/batsat/0.6.0/batsat/type.BasicSolver.html?search= Provides methods for creating and interacting with a generic Solver, which BasicSolver utilizes. ```APIDOC ## Solver Implementations ### `new(opts: SolverOpts, cb: Cb) -> Self` Creates a new solver instance with the specified options and callbacks. ### `new_with(opts: SolverOpts, cb: Cb) -> Self` Creates a new solver instance with the specified options and callbacks. This is an alternative constructor. ### `cb_mut(&mut self) -> &mut Cb` Provides mutable, temporary access to the solver's callbacks. ### `cb(&self) -> &Cb` Provides immutable, temporary access to the solver's callbacks. ### `dimacs_model(&self) -> SolverPrintDimacs<'_, Cb>` Returns a `SolverPrintDimacs` object for printing the model in DIMACS format. ``` -------------------------------- ### RegionAllocator::new Source: https://docs.rs/batsat/0.6.0/batsat/alloc/struct.RegionAllocator.html Creates a new RegionAllocator with a specified starting capacity. ```APIDOC ## RegionAllocator::new ### Description Creates a new RegionAllocator with a specified starting capacity. ### Signature `pub fn new(start_cap: u32) -> Self` ### Parameters * `start_cap` (u32) - The initial capacity of the allocator. ``` -------------------------------- ### RegionAllocator::new Source: https://docs.rs/batsat/0.6.0/batsat/alloc/struct.RegionAllocator.html?search=std%3A%3Avec Creates a new RegionAllocator with a specified starting capacity. ```APIDOC ## RegionAllocator::new ### Description Creates a new RegionAllocator with a specified starting capacity. ### Signature `pub fn new(start_cap: u32) -> Self` ### Parameters * `start_cap` (u32) - The initial capacity for the allocator. ``` -------------------------------- ### Main Solve Internal Method Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html?search= Initiates the SAT solving process, setting up initial conditions and entering the main search loop. It manages solver state, learning limits, and restart logic. ```rust fn solve_internal(&mut self, th: &mut Th) -> lbool { assert!(self.v.decision_level() == 0); self.model.clear(); self.conflict.clear(); if !self.v.ok { return lbool::FALSE; } self.v.solves += 1; let mut tmp_learnt: Vec = vec![]; self.v.max_learnts = self.num_clauses() as f64 * self.v.opts.learntsize_factor; if self.v.max_learnts < self.v.opts.min_learnts_lim as f64 { self.v.max_learnts = self.v.opts.min_learnts_lim as f64; } self.v.learntsize_adjust_confl = self.v.learntsize_adjust_start_confl as f64; self.v.learntsize_adjust_cnt = self.v.learntsize_adjust_confl as i32; let mut status; info!("search.start"); self.cb.on_start(); // Search: let mut curr_restarts: i32 = 0; loop { ``` -------------------------------- ### Get Variable Reason Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Retrieves the clause reference that caused the assignment of a variable. ```rust fn reason(&self, x: Var) -> CRef { self.vardata[x].reason } ``` -------------------------------- ### Get Variable Value Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Retrieves the current truth value assigned to a variable. ```rust pub fn value(&self, x: Var) -> lbool { self.vars.value(x) } ``` -------------------------------- ### Checking Vec Capacity Source: https://docs.rs/batsat/0.6.0/batsat/clause/type.OccVec.html?search= Shows how to initialize a Vec with a specific capacity and verify it. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` -------------------------------- ### Solver Creation Source: https://docs.rs/batsat/0.6.0/batsat/core/struct.Solver.html?search=u32+-%3E+bool Methods for creating a new Solver instance with specified options and callbacks. ```APIDOC ## Solver Creation ### `new(opts: SolverOpts, cb: Cb) -> Self` Creates a new solver with the given options and callbacks `cb`. ### `new_with(opts: SolverOpts, cb: Cb) -> Self` Creates a new solver with the given options and callbacks. ``` -------------------------------- ### Get Number of Assignments Source: https://docs.rs/batsat/0.6.0/src/batsat/core.rs.html Returns the current number of assigned variables in the solver. ```rust pub fn num_assigns(&self) -> u32 { self.vars.num_assigns() } ``` -------------------------------- ### HeapData: Get the number of elements Source: https://docs.rs/batsat/0.6.0/src/batsat/intmap.rs.html?search= Returns the number of elements currently in the heap. ```Rust pub fn len(&self) -> usize { self.heap.len() } ``` -------------------------------- ### FFI Dictionary Buffer Initialization with set_len Source: https://docs.rs/batsat/0.6.0/batsat/clause/type.OccVec.html?search= Shows how to use `set_len` safely after an FFI call that initializes a buffer. This is common when interacting with C libraries that return data via pointers and lengths. ```rust pub fn get_dictionary(&self) -> Option> { // Per the FFI method's docs, "32768 bytes is always enough". let mut dict = Vec::with_capacity(32_768); let mut dict_length = 0; // SAFETY: When `deflateGetDictionary` returns `Z_OK`, it holds that: // 1. `dict_length` elements were initialized. // 2. `dict_length` <= the capacity (32_768) // which makes `set_len` safe to call. unsafe { // Make the FFI call... let r = deflateGetDictionary(self.strm, dict.as_mut_ptr(), &mut dict_length); if r == Z_OK { // ...and update the length to what was initialized. dict.set_len(dict_length); Some(dict) } else { None } } } ``` -------------------------------- ### new Source: https://docs.rs/batsat/latest/batsat/clause/struct.ClauseHeader.html Constructs a new ClauseHeader instance. ```APIDOC ## pub fn new( mark: u32, learnt: bool, has_extra: bool, reloced: bool, size: u32, ) -> Self ### Parameters * **mark**: `u32` - The mark value. * **learnt**: `bool` - Indicates if the clause is learnt. * **has_extra**: `bool` - Indicates if the clause has extra data. * **reloced**: `bool` - Indicates if the clause has been relocated. * **size**: `u32` - The size of the clause. ``` -------------------------------- ### Get Model Source: https://docs.rs/batsat/0.6.0/src/batsat/interface.rs.html?search=u32+-%3E+bool Retrieves the full satisfying model as a slice of truth assignments. ```APIDOC ## Get Model ### Description Provides access to the complete truth assignment for all variables in the solver, represented as a slice of `lbool` values. This method should be called after the solver has returned `lbool::TRUE` (satisfiable). ### Method - `get_model(&self) -> &[lbool]` ### Precondition Requires that the last call to a solve method resulted in `lbool::TRUE`. ### Usage Use `get_model` to inspect the truth value assigned to each variable in a satisfying assignment. ``` -------------------------------- ### DRAT Proof Management Methods Source: https://docs.rs/batsat/0.6.0/src/batsat/drat.rs.html?search= Provides methods for initializing a new DRAT proof, adding literals, and recording clause operations like creation and deletion. These methods are essential for building a DRAT proof incrementally. ```rust impl Proof { /// New proof recording structure. pub fn new() -> Self { Proof(Vec::new()) } fn push_lit(&mut self, lit: Lit) { // Convert literal to integer representation for DRAT format let i: i32 = (if lit.sign() { 1 } else { -1 }) * ((lit.var().idx() + 1) as i32); self.0.push(i) } /// Register clause creation. pub fn create_clause(&mut self, c: &C) where C: ClauseIterable, { for lit in c.items() { self.push_lit((*lit).into()); } self.0.push(0); // Mark end of clause } /// Register clause deletion. pub fn delete_clause(&mut self, c: &C) where C: ClauseIterable, { // Use i32::MAX to signify a deletion operation in DRAT self.0.push(i32::MAX); for lit in c.items() { self.push_lit((*lit).into()); } self.0.push(0); // Mark end of clause } } ``` -------------------------------- ### ClauseAllocator with_start_cap Method Source: https://docs.rs/batsat/0.6.0/batsat/clause/struct.ClauseAllocator.html?search=std%3A%3Avec Creates a new ClauseAllocator with a specified starting capacity. ```rust pub fn with_start_cap(start_cap: u32) -> Self ``` -------------------------------- ### IntMap::build Source: https://docs.rs/batsat/0.6.0/src/batsat/intmap.rs.html?search= Rebuilds the heap from scratch using the provided slice of keys. This is an efficient way to initialize or repopulate the heap. ```APIDOC ## build ### Description Rebuilds the heap from scratch using the provided slice of keys. This is an efficient way to initialize or repopulate the heap. ### Method `build(&mut self, ns: &[K])` ### Parameters - `ns`: A slice of keys to build the heap from. ``` -------------------------------- ### Solver::new Source: https://docs.rs/batsat/0.6.0/batsat/core/struct.Solver.html Creates a new solver instance with specified options and callbacks. ```APIDOC ## Solver::new ### Description Creates a new solver with the given options and the callbacks `cb`. ### Method `new(opts: SolverOpts, cb: Cb) -> Self` ### Parameters * **opts** (SolverOpts) - Required - Solver options. * **cb** (Cb) - Required - Callbacks for the solver. ``` -------------------------------- ### Get Number of Variables Source: https://docs.rs/batsat/latest/src/batsat/core.rs.html Returns the total number of variables currently managed by the solver. ```rust fn num_vars(&self) -> u32 { self.next_var.idx() } ``` -------------------------------- ### SolverModel Methods Source: https://docs.rs/batsat/latest/src/batsat/interface.rs.html?search=u32+-%3E+bool This section details the methods available on the `SolverModel` struct, representing a model of the solver's state. ```APIDOC ## SolverModel Methods ### `theory` - **Description**: Returns a reference to the `Theory` state within the model. - **Signature**: `pub fn theory(&self) -> &Th;` ### `value_lit` - **Description**: Queries the truth value of a literal within the model. - **Signature**: `pub fn value_lit(&self, l: Lit) -> lbool;` ``` -------------------------------- ### Get Literal Decision Level Source: https://docs.rs/batsat/latest/src/batsat/core.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the decision level associated with a given literal. ```rust #[inline(always)] pub fn level_lit(&self, x: Lit) -> i32 { self.level(x.var()) } ```