From fdacbd4476b8897205d7512fc2687100902daf48 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Mon, 17 Feb 2025 09:49:35 +0100 Subject: [PATCH 1/2] Add more constraints to QN grammars --- src/qualitative_networks.jl | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/qualitative_networks.jl b/src/qualitative_networks.jl index 39848e0..363590b 100644 --- a/src/qualitative_networks.jl +++ b/src/qualitative_networks.jl @@ -80,6 +80,49 @@ function build_qn_grammar( addconstraint!(g, Forbidden(template_tree)) + # Forbid Ceil and Floor from including an entity or constant directly + entities_consts = DomainRuleNode( + BitVector([ + zeros(Int, 9)..., + ones(Int, length(entity_names) + length(constants))..., + ]), + ) + template_tree = DomainRuleNode( + BitVector([ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + zeros(Int, length(entity_names) + length(constants))..., + ]), + [entities_consts], + ) + + addconstraint!(g, Forbidden(template_tree)) + + # Forbid ceil(floor(x)) and vice-versa + ceil_or_floor = BitVector([ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + zeros(Int, length(entity_names) + length(constants))..., + ]) + template_tree = + DomainRuleNode(ceil_or_floor, [DomainRuleNode(ceil_or_floor, [VarNode(:a)])]) + + addconstraint!(g, Forbidden(template_tree)) + return g end From 08dbe41deae6fe4432796b196ed754a6a9fb5045 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:57:28 +0100 Subject: [PATCH 2/2] Update docstring `build_qn_grammar` --- src/qualitative_networks.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/qualitative_networks.jl b/src/qualitative_networks.jl index 363590b..f296c69 100644 --- a/src/qualitative_networks.jl +++ b/src/qualitative_networks.jl @@ -24,6 +24,16 @@ default_qn_constants = [2] """ $(TYPEDSIGNATURES) + +Builds a grammar based on the base QN grammar adding `entity_names` and `constants` +to the grammar. + +Four constraints are currently included + +1. removing symmetry due to commutativity of `+`/`*`/`min`/`max` +2. forbidding same arguments of two argument functions +3. forbidding trivial inputs (consts and entity values) to `floor`/`ceil` +4. forbidding `ceil(floor(_))` and `floor(ceil(_))` """ function build_qn_grammar( entity_names::AbstractVector,