Struct TwoSatisfiability

Source
pub struct TwoSatisfiability { /* private fields */ }

Implementations§

Source§

impl TwoSatisfiability

Source

pub fn new(vsize: usize) -> Self

Examples found in repository?
crates/library_checker/src/math/two_sat.rs (line 17)
6pub fn two_sat(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(
10        scanner,
11        _p: String,
12        _cnf: String,
13        n,
14        m,
15        ab: [(isize, isize, isize)]
16    );
17    let mut two_sat = TwoSatisfiability::new(n);
18    for (a, b, _) in ab.take(m) {
19        two_sat.add_clause(a.unsigned_abs() - 1, a >= 0, b.unsigned_abs() - 1, b >= 0);
20    }
21    if let Some(v) = two_sat.two_satisfiability() {
22        writeln!(writer, "s SATISFIABLE").ok();
23        write!(writer, "v").ok();
24        for (i, v) in v.into_iter().enumerate() {
25            write!(
26                writer,
27                " {}",
28                if v { i as i32 + 1 } else { -(i as i32 + 1) }
29            )
30            .ok();
31        }
32        write!(writer, " 0").ok();
33    } else {
34        writeln!(writer, "s UNSATISFIABLE").ok();
35    }
36}
Source

pub fn add_clause(&mut self, x: usize, f: bool, y: usize, g: bool)

(p_x = f) | (p_y = g)

Examples found in repository?
crates/competitive/src/graph/two_satisfiability.rs (line 22)
21    pub fn add_or(&mut self, x: usize, y: usize) {
22        self.add_clause(x, true, y, true);
23    }
24    pub fn add_nand(&mut self, x: usize, y: usize) {
25        self.add_clause(x, false, y, false);
26    }
More examples
Hide additional examples
crates/library_checker/src/math/two_sat.rs (line 19)
6pub fn two_sat(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(
10        scanner,
11        _p: String,
12        _cnf: String,
13        n,
14        m,
15        ab: [(isize, isize, isize)]
16    );
17    let mut two_sat = TwoSatisfiability::new(n);
18    for (a, b, _) in ab.take(m) {
19        two_sat.add_clause(a.unsigned_abs() - 1, a >= 0, b.unsigned_abs() - 1, b >= 0);
20    }
21    if let Some(v) = two_sat.two_satisfiability() {
22        writeln!(writer, "s SATISFIABLE").ok();
23        write!(writer, "v").ok();
24        for (i, v) in v.into_iter().enumerate() {
25            write!(
26                writer,
27                " {}",
28                if v { i as i32 + 1 } else { -(i as i32 + 1) }
29            )
30            .ok();
31        }
32        write!(writer, " 0").ok();
33    } else {
34        writeln!(writer, "s UNSATISFIABLE").ok();
35    }
36}
Source

pub fn add_or(&mut self, x: usize, y: usize)

Source

pub fn add_nand(&mut self, x: usize, y: usize)

Source

pub fn set_true(&mut self, x: usize)

Source

pub fn set_false(&mut self, x: usize)

Source

pub fn two_satisfiability(self) -> Option<Vec<bool>>

Examples found in repository?
crates/library_checker/src/math/two_sat.rs (line 21)
6pub fn two_sat(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(
10        scanner,
11        _p: String,
12        _cnf: String,
13        n,
14        m,
15        ab: [(isize, isize, isize)]
16    );
17    let mut two_sat = TwoSatisfiability::new(n);
18    for (a, b, _) in ab.take(m) {
19        two_sat.add_clause(a.unsigned_abs() - 1, a >= 0, b.unsigned_abs() - 1, b >= 0);
20    }
21    if let Some(v) = two_sat.two_satisfiability() {
22        writeln!(writer, "s SATISFIABLE").ok();
23        write!(writer, "v").ok();
24        for (i, v) in v.into_iter().enumerate() {
25            write!(
26                writer,
27                " {}",
28                if v { i as i32 + 1 } else { -(i as i32 + 1) }
29            )
30            .ok();
31        }
32        write!(writer, " 0").ok();
33    } else {
34        writeln!(writer, "s UNSATISFIABLE").ok();
35    }
36}

Trait Implementations§

Source§

impl Clone for TwoSatisfiability

Source§

fn clone(&self) -> TwoSatisfiability

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 TwoSatisfiability

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.