1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::async_graph::{AsyncGraph, AsyncGraphEdgeParams, DefaultEdgeParams};
use crate::BooleanNetwork;
impl AsyncGraph<DefaultEdgeParams> {
pub fn new(network: BooleanNetwork) -> Result<AsyncGraph<DefaultEdgeParams>, String> {
if network.graph.num_vars() > 32 {
Err("Can't create the graph. At most 32 variables supported".to_string())
} else {
let edge_params = DefaultEdgeParams::new(network)?;
Ok(AsyncGraph { edges: edge_params })
}
}
}
impl<Params: AsyncGraphEdgeParams> AsyncGraph<Params> {
pub fn new_with_edges(edge_params: Params) -> Result<AsyncGraph<Params>, String> {
return if edge_params.network().graph.num_vars() > 32 {
Err("Can't create the graph. At most 32 variables supported".to_string())
} else {
Ok(AsyncGraph { edges: edge_params })
};
}
pub fn num_states(&self) -> usize {
1 << self.network().graph.num_vars()
}
pub fn network(&self) -> &BooleanNetwork {
self.edges.network()
}
pub fn edges(&self) -> &Params {
&self.edges
}
pub fn make_witness(&self, params: &Params::ParamSet) -> BooleanNetwork {
self.edges.make_witness(params)
}
pub fn empty_params(&self) -> &Params::ParamSet {
self.edges.empty_params()
}
pub fn unit_params(&self) -> &Params::ParamSet {
self.edges.unit_params()
}
}
#[cfg(test)]
mod tests {
use crate::async_graph::AsyncGraph;
use crate::BooleanNetwork;
use std::convert::TryFrom;
#[test]
fn test_graph_unit_set_anonymous_params() {
let network = BooleanNetwork::try_from(
"
a ->? b
a -> a
b -| b
b -|? a
",
)
.unwrap();
let graph = AsyncGraph::new(network).unwrap();
assert_eq!(9.0, graph.unit_params().cardinality());
}
#[test]
fn test_graph_unit_set_names_params() {
let network = BooleanNetwork::try_from(
"
a ->? b
a -> a
b -| b
b -|? a
$a: a | p(b)
$b: q(a, b) & a
",
)
.unwrap();
let graph = AsyncGraph::new(network).unwrap();
assert_eq!(8.0, graph.unit_params().cardinality());
}
}