Skip to content

Commit

Permalink
add example2 (majority function)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnarazk committed Feb 1, 2024
1 parent 766bb5b commit 72b59b9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
44 changes: 28 additions & 16 deletions src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,24 @@ impl DecisionDiagramNode for Node {
}
}

macro_rules! F {
() => {
Node::new_constant(false)
};
}
macro_rules! T {
() => {
Node::new_constant(true)
};
}
macro_rules! D {
($v: expr, $l: expr, $h: expr) => {
Node::new_var($v, $l, $h)
};
}

/// return the independence sets of 6 cyclic chain
pub fn sample1() -> DDT {
macro_rules! F {
() => {
Node::new_constant(false)
};
}
macro_rules! T {
() => {
Node::new_constant(true)
};
}
macro_rules! D {
($v: expr, $l: expr, $h: expr) => {
Node::new_var($v, $l, $h)
};
}
pub fn example1() -> DDT {
DDT {
graph: D!(
1, // 1 -> {
Expand Down Expand Up @@ -383,3 +384,14 @@ pub fn sample1() -> DDT {
),
}
}

/// majority
pub fn example2() -> DDT {
DDT {
graph: D!(
1,
D!(2, F!(), D!(3, F!(), T!())),
D!(2, D!(3, F!(), T!()), T!())
),
}
}
17 changes: 13 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
use {
ddir::{
bdd::{ToBinaryDecisionDiagram, BDD},
dd::{sample1, DecisionDiagramTrait, DDT},
dd::{example1, example2, DecisionDiagramTrait, DDT},
},
std::fs::File,
};

fn main() {
// let stdout = io::stdout();
let idp1: DDT = sample1();
let idp1: DDT = example1();
assert_eq!(idp1.len(), 127);
let f1 = File::create("ind-tree.gv").expect("fail to create");
idp1.write_as_gv(f1).expect("fail to serialize");

let idp2: BDD = sample1().to_bdd();
let idp2: BDD = example1().to_bdd();
let f2 = File::create("ind-bdd.gv").expect("fail to create");
idp2.write_as_gv(f2).expect("fail to serialize")
idp2.write_as_gv(f2).expect("fail to serialize");

let majority1: DDT = example2();
let f3 = File::create("maj-tree.gv").expect("fail to create");
majority1.write_as_gv(f3).expect("fail to serialize");
let f4 = File::create("maj-bdd.gv").expect("fail to create");
majority1
.to_bdd()
.write_as_gv(f4)
.expect("fail to serialize");
}

0 comments on commit 72b59b9

Please sign in to comment.