readme_example/
readme_example.rs1use indexmap::IndexMap;
2use pldag::{Pldag, Bound};
3
4fn main() {
5 let mut pldag: Pldag = Pldag::new();
9
10 pldag.set_primitive("x", (0, 1));
12 pldag.set_primitive("y", (0, 1));
13 pldag.set_primitive("z", (0, 1));
14
15 let root = pldag.set_or(vec![
17 "x",
18 "y",
19 "z",
20 ]).unwrap();
21
22 let mut inputs: IndexMap<&str, Bound> = IndexMap::new();
24 let validated = pldag.propagate(&inputs);
25 println!("Root valid? {}", *validated.get(&root).unwrap() == (1, 1)); inputs.insert("x", (0,0));
31 let revalidated = pldag.propagate(&inputs);
32 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); inputs.insert("y", (1,1));
36 inputs.insert("z", (1,1));
37 let revalidated = pldag.propagate(&inputs);
38 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); pldag.set_coef("x", 1.0);
43 pldag.set_coef("y", 2.0);
44 pldag.set_coef("z", 3.0);
45 pldag.set_coef(&root, -1.0);
47
48 let scores = pldag.propagate_coefs(&inputs);
50 let root_result = scores.get(&root).unwrap();
52 println!("Root bounds: {:?}, Total score: {:?}", root_result.0, root_result.1);
53
54 inputs.insert("x", (0,1));
56 let scores = pldag.propagate_coefs(&inputs);
57 let root_result = scores.get(&root).unwrap();
59 println!("Root bounds: {:?}, Score range: {:?}", root_result.0, root_result.1);
60
61 inputs.insert("x", (0,0));
63 let scores = pldag.propagate_coefs(&inputs);
64 let root_result = scores.get(&root).unwrap();
65 println!("Root bounds: {:?}, Score: {:?}", root_result.0, root_result.1);
66
67 inputs.insert("y", (0,0));
69 inputs.insert("z", (0,0));
70 let scores = pldag.propagate_coefs(&inputs);
71 let root_result = scores.get(&root).unwrap();
72 println!("Root bounds: {:?}, Score: {:?}", root_result.0, root_result.1);
73
74 let mut pldag = Pldag::new();
76 pldag.set_primitive("x", (0, 1));
77 pldag.set_primitive("y", (0, 1));
78 pldag.set_primitive("z", (0, 1));
79 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
80
81 let validated = pldag.propagate_default();
83 println!("root bound = {:?}", validated[&root]);
84
85 pldag.set_coef("x", 1.0);
87 pldag.set_coef("y", 2.0);
88 pldag.set_coef("z", 3.0);
89 pldag.set_coef(&root, -1.0);
90 let scored = pldag.propagate_coefs_default();
91 println!("root value = {:?}", scored[&root].1);
92}