-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/choice-filtering
- Loading branch information
Showing
14 changed files
with
202 additions
and
129 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"Generated by n-queens-gen version 0.10.4 queens=7 " | ||
|
||
"every diagonal must contain at most one queen (direction 1)" | ||
[v_0,v_8,v_16,v_24,v_32,v_40,v_48,] <= 1 & | ||
[v_1,v_9,v_17,v_25,v_33,v_41,] <= 1 & | ||
[v_2,v_10,v_18,v_26,v_34,] <= 1 & | ||
[v_3,v_11,v_19,v_27,] <= 1 & | ||
[v_4,v_12,v_20,] <= 1 & | ||
[v_5,v_13,] <= 1 & | ||
[v_6,] <= 1 & | ||
|
||
[v_7,v_15,v_23,v_31,v_39,v_47,] <= 1 & | ||
[v_14,v_22,v_30,v_38,v_46,] <= 1 & | ||
[v_21,v_29,v_37,v_45,] <= 1 & | ||
[v_28,v_36,v_44,] <= 1 & | ||
[v_35,v_43,] <= 1 & | ||
[v_42,] <= 1 & | ||
|
||
"every diagonal must contain at most one queen (direction 2)" | ||
[v_0,] <= 1 & | ||
[v_1,v_7,] <= 1 & | ||
[v_2,v_8,v_14,] <= 1 & | ||
[v_3,v_9,v_15,v_21,] <= 1 & | ||
[v_4,v_10,v_16,v_22,v_28,] <= 1 & | ||
[v_5,v_11,v_17,v_23,v_29,v_35,] <= 1 & | ||
[v_6,v_12,v_18,v_24,v_30,v_36,v_42,] <= 1 & | ||
|
||
[v_48,] <= 1 & | ||
[v_47,v_41,] <= 1 & | ||
[v_46,v_40,v_34,] <= 1 & | ||
[v_45,v_39,v_33,v_27,] <= 1 & | ||
[v_44,v_38,v_32,v_26,v_20,] <= 1 & | ||
[v_43,v_37,v_31,v_25,v_19,v_13,] <= 1 & | ||
|
||
"every row must contain exactly one queen" | ||
[v_0,v_1,v_2,v_3,v_4,v_5,v_6,] = 1 & | ||
[v_7,v_8,v_9,v_10,v_11,v_12,v_13,] = 1 & | ||
[v_14,v_15,v_16,v_17,v_18,v_19,v_20,] = 1 & | ||
[v_21,v_22,v_23,v_24,v_25,v_26,v_27,] = 1 & | ||
[v_28,v_29,v_30,v_31,v_32,v_33,v_34,] = 1 & | ||
[v_35,v_36,v_37,v_38,v_39,v_40,v_41,] = 1 & | ||
[v_42,v_43,v_44,v_45,v_46,v_47,v_48,] = 1 & | ||
|
||
"every column must contain exactly one queen" | ||
[v_0,v_7,v_14,v_21,v_28,v_35,v_42,] = 1 & | ||
[v_1,v_8,v_15,v_22,v_29,v_36,v_43,] = 1 & | ||
[v_2,v_9,v_16,v_23,v_30,v_37,v_44,] = 1 & | ||
[v_3,v_10,v_17,v_24,v_31,v_38,v_45,] = 1 & | ||
[v_4,v_11,v_18,v_25,v_32,v_39,v_46,] = 1 & | ||
[v_5,v_12,v_19,v_26,v_33,v_40,v_47,] = 1 & | ||
[v_6,v_13,v_20,v_27,v_34,v_41,v_48,] = 1 & | ||
|
||
"end" | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::{ | ||
fmt::{self, Debug, Display}, | ||
hash::{Hash, Hasher}, | ||
rc::Rc, | ||
}; | ||
|
||
pub trait BDDSymbol: Ord + Display + Debug + Clone + Hash {} | ||
|
||
impl<T> BDDSymbol for T where T: Ord + Display + Debug + Clone + Hash {} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct NamedSymbol { | ||
pub name: Rc<String>, | ||
pub id: usize, | ||
} | ||
|
||
impl fmt::Display for NamedSymbol { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
fmt::Display::fmt(&self.name, f) | ||
} | ||
} | ||
|
||
impl Hash for NamedSymbol { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.id.hash(state); | ||
} | ||
} | ||
|
||
impl PartialEq for NamedSymbol { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.id == other.id | ||
} | ||
} | ||
|
||
impl Eq for NamedSymbol {} | ||
|
||
impl Ord for NamedSymbol { | ||
fn cmp(&self, other: &Self) -> std::cmp::Ordering { | ||
self.id.cmp(&other.id) | ||
} | ||
} | ||
|
||
impl PartialOrd for NamedSymbol { | ||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
impl From<NamedSymbol> for usize { | ||
fn from(ns: NamedSymbol) -> Self { | ||
ns.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::{ | ||
fmt::{self, Display}, | ||
str::FromStr, | ||
}; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
/// Single variable assignment in a truth table. | ||
/// | ||
/// The variable assignments in a truth table can be one of True, False or Any. | ||
/// [`True`] is assigned when the variable can only be assigned a 'true' value; | ||
/// [`False`] is assigned when the variable can only be 'false'. | ||
/// When the variable can either be true or false, the truth table can either consist of | ||
/// both options (as separate models), or assign [`Any`]. | ||
/// | ||
/// [`Any`]: TruthTableEntry::Any | ||
/// [`True`]: TruthTableEntry::True | ||
/// [`False`]: TruthTableEntry::False | ||
pub enum TruthTableEntry { | ||
/// Assigned when the variable can only be true | ||
True, | ||
/// Assigned when the variable can only be false | ||
False, | ||
/// Assigned when the variable can either be true or false | ||
Any, | ||
} | ||
|
||
impl TruthTableEntry { | ||
fn variants<'a>() -> &'a [Self] { | ||
&[Self::True, Self::False, Self::Any] | ||
} | ||
|
||
fn matches(&self, s: &str) -> bool { | ||
match self { | ||
TruthTableEntry::True => matches!(s, "true" | "True" | "t" | "T" | "1"), | ||
TruthTableEntry::False => matches!(s, "false" | "False" | "f" | "F" | "0"), | ||
TruthTableEntry::Any => matches!(s, "any" | "Any" | "a" | "A" | "*"), | ||
} | ||
} | ||
|
||
pub fn is_true(self) -> bool { | ||
self == TruthTableEntry::True | ||
} | ||
|
||
pub fn is_false(self) -> bool { | ||
self == TruthTableEntry::False | ||
} | ||
|
||
pub fn is_any(self) -> bool { | ||
self == TruthTableEntry::Any | ||
} | ||
} | ||
|
||
impl Display for TruthTableEntry { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.pad(match self { | ||
TruthTableEntry::True => "True", | ||
TruthTableEntry::False => "False", | ||
TruthTableEntry::Any => "Any", | ||
}) | ||
} | ||
} | ||
|
||
impl FromStr for TruthTableEntry { | ||
type Err = anyhow::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Self::variants() | ||
.iter() | ||
.find(|variant| variant.matches(s)) | ||
.ok_or(anyhow::anyhow!("cannot parse {s} as truth-table entry")) | ||
.copied() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use rsbdd::bdd; | ||
use rsbdd::bdd::*; | ||
use rsbdd::{bdd, TruthTableEntry}; | ||
use std::rc::Rc; | ||
|
||
use rsbdd::bdd_io::*; | ||
|
Oops, something went wrong.