pub struct TwoSatisfiability { /* private fields */ }
Implementations§
Source§impl TwoSatisfiability
impl TwoSatisfiability
Sourcepub fn new(vsize: usize) -> Self
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}
Sourcepub fn add_clause(&mut self, x: usize, f: bool, y: usize, g: bool)
pub fn add_clause(&mut self, x: usize, f: bool, y: usize, g: bool)
(p_x = f) | (p_y = g)
Examples found in repository?
More 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}
pub fn add_or(&mut self, x: usize, y: usize)
pub fn add_nand(&mut self, x: usize, y: usize)
pub fn set_true(&mut self, x: usize)
pub fn set_false(&mut self, x: usize)
Sourcepub fn two_satisfiability(self) -> Option<Vec<bool>>
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
impl Clone for TwoSatisfiability
Source§fn clone(&self) -> TwoSatisfiability
fn clone(&self) -> TwoSatisfiability
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for TwoSatisfiability
impl RefUnwindSafe for TwoSatisfiability
impl Send for TwoSatisfiability
impl Sync for TwoSatisfiability
impl Unpin for TwoSatisfiability
impl UnwindSafe for TwoSatisfiability
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
Mutably borrows from an owned value. Read more