Skip to content

Commit 2c14a15

Browse files
authored
Add more constraints to QN grammars (#14)
* Add more constraints to QN grammars * Update docstring `build_qn_grammar`
1 parent 462ea81 commit 2c14a15

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/qualitative_networks.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ default_qn_constants = [2]
2424

2525
"""
2626
$(TYPEDSIGNATURES)
27+
28+
Builds a grammar based on the base QN grammar adding `entity_names` and `constants`
29+
to the grammar.
30+
31+
Four constraints are currently included
32+
33+
1. removing symmetry due to commutativity of `+`/`*`/`min`/`max`
34+
2. forbidding same arguments of two argument functions
35+
3. forbidding trivial inputs (consts and entity values) to `floor`/`ceil`
36+
4. forbidding `ceil(floor(_))` and `floor(ceil(_))`
2737
"""
2838
function build_qn_grammar(
2939
entity_names::AbstractVector,
@@ -80,6 +90,49 @@ function build_qn_grammar(
8090

8191
addconstraint!(g, Forbidden(template_tree))
8292

93+
# Forbid Ceil and Floor from including an entity or constant directly
94+
entities_consts = DomainRuleNode(
95+
BitVector([
96+
zeros(Int, 9)...,
97+
ones(Int, length(entity_names) + length(constants))...,
98+
]),
99+
)
100+
template_tree = DomainRuleNode(
101+
BitVector([
102+
0,
103+
0,
104+
0,
105+
0,
106+
0,
107+
0,
108+
1,
109+
1,
110+
0,
111+
zeros(Int, length(entity_names) + length(constants))...,
112+
]),
113+
[entities_consts],
114+
)
115+
116+
addconstraint!(g, Forbidden(template_tree))
117+
118+
# Forbid ceil(floor(x)) and vice-versa
119+
ceil_or_floor = BitVector([
120+
0,
121+
0,
122+
0,
123+
0,
124+
0,
125+
0,
126+
1,
127+
1,
128+
0,
129+
zeros(Int, length(entity_names) + length(constants))...,
130+
])
131+
template_tree =
132+
DomainRuleNode(ceil_or_floor, [DomainRuleNode(ceil_or_floor, [VarNode(:a)])])
133+
134+
addconstraint!(g, Forbidden(template_tree))
135+
83136
return g
84137
end
85138

0 commit comments

Comments
 (0)