pub struct Assignment { /* private fields */ }Expand description
Type representing an assignment of variables.
Implementations§
Source§impl Assignment
impl Assignment
Sourcepub fn var_value(&self, var: Var) -> TernaryVal
pub fn var_value(&self, var: Var) -> TernaryVal
Get the value that the solution assigns to a variable.
If the variable is not included in the solution, will return TernaryVal::DontCare.
Sourcepub fn lit_value(&self, lit: Lit) -> TernaryVal
pub fn lit_value(&self, lit: Lit) -> TernaryVal
Same as Assignment::var_value, but for literals.
Sourcepub fn replace_dont_care(&mut self, def: bool)
pub fn replace_dont_care(&mut self, def: bool)
Replaces unassigned variables in the assignment with a default value
Sourcepub fn assign_var(&mut self, variable: Var, value: TernaryVal)
pub fn assign_var(&mut self, variable: Var, value: TernaryVal)
Assigns a variable in the assignment
Sourcepub fn assign_lit(&mut self, lit: Lit)
pub fn assign_lit(&mut self, lit: Lit)
Assigns a literal to true
Sourcepub fn truncate(self, max_var: Var) -> Self
pub fn truncate(self, max_var: Var) -> Self
Truncates a solution to only include assignments up to a maximum variable
Sourcepub fn max_var(&self) -> Option<Var>
pub fn max_var(&self) -> Option<Var>
Get the maximum variable in the assignment
§Panics
If the assignment contains more then u32::MAX variables.
Sourcepub fn from_solver_output_path<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_solver_output_path<P: AsRef<Path>>(path: P) -> Result<Self>
Reads a solution from SAT solver output given the path
If it is unclear whether the SAT solver indicated satisfiability, use fio::parse_sat_solver_output instead.
§Errors
- IO error:
std::io::Error - Invalid solver output:
fio::SatSolverOutputError - Invalid v line:
InvalidVLine
Sourcepub fn from_vline(line: &str) -> Result<Self>
pub fn from_vline(line: &str) -> Result<Self>
Creates an assignment from a SAT solver value line
§Errors
InvalidVLine or parsing error, or nom::error::Error
Sourcepub fn extend_from_vline(&mut self, lines: &str) -> Result<()>
pub fn extend_from_vline(&mut self, lines: &str) -> Result<()>
Parses an assignment from a value line returned by a solver
The following value line formats are supported:
- SAT Competition:
v 1 -2 -3 4 0 - MaxSAT Evaluation:
v 1001 - PB Competition:
v x1 -x2 -x3 x4
§Errors
Can return various parsing errors
Examples found in repository?
54fn main() -> anyhow::Result<()> {
55 let args = Args::parse();
56 let opb_opts = OpbOptions {
57 first_var_idx: args.opb_first_var_idx,
58 ..OpbOptions::default()
59 };
60 let (constrs, objs) = parse_instance(args.instance, args.file_format, opb_opts)?.decompose();
61
62 let mut reader = if let Some(solution) = args.solution {
63 fio::open_compressed_uncompressed_read(solution)?
64 } else {
65 Box::new(io::BufReader::new(io::stdin()))
66 };
67
68 let mut sol = Assignment::default();
69 loop {
70 let mut buf = String::new();
71 let read = reader.read_line(&mut buf)?;
72 if read == 0 {
73 break;
74 }
75 if buf.starts_with('v') {
76 sol.extend_from_vline(&buf)?;
77 }
78 }
79
80 if let Some(constr) = constrs.unsat_constraint(&sol) {
81 println!("unsatisfied constraint: {constr}");
82 std::process::exit(1);
83 }
84 print!("objective values: ");
85 for i in 0..objs.len() {
86 if i < objs.len() - 1 {
87 print!("{}, ", objs[i].evaluate(&sol))
88 } else {
89 print!("{}", objs[i].evaluate(&sol));
90 }
91 }
92 println!();
93 Ok(())
94}Trait Implementations§
Source§impl Clone for Assignment
impl Clone for Assignment
Source§fn clone(&self) -> Assignment
fn clone(&self) -> Assignment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Assignment
impl Debug for Assignment
Source§impl Default for Assignment
impl Default for Assignment
Source§fn default() -> Assignment
fn default() -> Assignment
Source§impl<'de> Deserialize<'de> for Assignment
impl<'de> Deserialize<'de> for Assignment
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Assignment
impl Display for Assignment
Source§impl From<Vec<TernaryVal>> for Assignment
impl From<Vec<TernaryVal>> for Assignment
Source§fn from(assignment: Vec<TernaryVal>) -> Self
fn from(assignment: Vec<TernaryVal>) -> Self
Source§impl FromIterator<Lit> for Assignment
impl FromIterator<Lit> for Assignment
Source§impl FromIterator<TernaryVal> for Assignment
impl FromIterator<TernaryVal> for Assignment
Source§fn from_iter<T: IntoIterator<Item = TernaryVal>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = TernaryVal>>(iter: T) -> Self
Source§impl FromIterator<bool> for Assignment
impl FromIterator<bool> for Assignment
Source§impl Index<Var> for Assignment
impl Index<Var> for Assignment
Source§impl IndexMut<Var> for Assignment
impl IndexMut<Var> for Assignment
Source§impl<'a> IntoIterator for &'a Assignment
Turns the assignment reference into an iterator over all true literals
impl<'a> IntoIterator for &'a Assignment
Turns the assignment reference into an iterator over all true literals
Source§impl IntoIterator for Assignment
Turns the assignment into an iterator over all true literals
impl IntoIterator for Assignment
Turns the assignment into an iterator over all true literals
Source§impl PartialEq for Assignment
impl PartialEq for Assignment
Source§impl Serialize for Assignment
impl Serialize for Assignment
impl Eq for Assignment
impl StructuralPartialEq for Assignment
Auto Trait Implementations§
impl Freeze for Assignment
impl RefUnwindSafe for Assignment
impl Send for Assignment
impl Sync for Assignment
impl Unpin for Assignment
impl UnwindSafe for Assignment
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more