Skip to main content

Assignment

Struct Assignment 

Source
pub struct Assignment { /* private fields */ }
Expand description

Type representing an assignment of variables.

Implementations§

Source§

impl Assignment

Source

pub fn len(&self) -> usize

Gets the length of the assignment

Source

pub fn is_empty(&self) -> bool

Checks whether the assignment is empty

Source

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.

Source

pub fn lit_value(&self, lit: Lit) -> TernaryVal

Same as Assignment::var_value, but for literals.

Source

pub fn replace_dont_care(&mut self, def: bool)

Replaces unassigned variables in the assignment with a default value

Source

pub fn assign_var(&mut self, variable: Var, value: TernaryVal)

Assigns a variable in the assignment

Source

pub fn assign_lit(&mut self, lit: Lit)

Assigns a literal to true

Source

pub fn truncate(self, max_var: Var) -> Self

Truncates a solution to only include assignments up to a maximum variable

Source

pub fn max_var(&self) -> Option<Var>

Get the maximum variable in the assignment

§Panics

If the assignment contains more then u32::MAX variables.

Source

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
Source

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

Source

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:

§Errors

Can return various parsing errors

Examples found in repository?
examples/check-solution.rs (line 76)
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}
Source

pub fn iter(&self) -> impl Iterator<Item = Lit> + '_

Gets an iterator over literals assigned to true

Trait Implementations§

Source§

impl Clone for Assignment

Source§

fn clone(&self) -> Assignment

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Assignment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Assignment

Source§

fn default() -> Assignment

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Assignment

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Assignment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Vec<TernaryVal>> for Assignment

Source§

fn from(assignment: Vec<TernaryVal>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Lit> for Assignment

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<TernaryVal> for Assignment

Source§

fn from_iter<T: IntoIterator<Item = TernaryVal>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<bool> for Assignment

Source§

fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<Var> for Assignment

Source§

type Output = TernaryVal

The returned type after indexing.
Source§

fn index(&self, index: Var) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Var> for Assignment

Source§

fn index_mut(&mut self, index: Var) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a Assignment

Turns the assignment reference into an iterator over all true literals

Source§

type Item = Lit

The type of the elements being iterated over.
Source§

type IntoIter = FilterMap<Enumerate<Iter<'a, TernaryVal>>, fn((usize, &TernaryVal)) -> Option<Lit>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Assignment

Turns the assignment into an iterator over all true literals

Source§

type Item = Lit

The type of the elements being iterated over.
Source§

type IntoIter = FilterMap<Enumerate<IntoIter<TernaryVal>>, fn((usize, TernaryVal)) -> Option<Lit>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Assignment

Source§

fn eq(&self, other: &Assignment) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Assignment

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Assignment

Source§

impl StructuralPartialEq for Assignment

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<I> LitIter for I
where I: IntoIterator<Item = Lit>,