From 90abc33a12d08031f8f92cca258f48118431a09d Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Sat, 24 Feb 2024 23:46:58 -0300 Subject: [PATCH] Optimize foralls expansion in HDDL_Parser --- parsers/HDDL_Parser.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/parsers/HDDL_Parser.rb b/parsers/HDDL_Parser.rb index 59540eb..6877a38 100644 --- a/parsers/HDDL_Parser.rb +++ b/parsers/HDDL_Parser.rb @@ -259,11 +259,15 @@ def parse_problem(problem_filename) parse_objects(group) # Expand foralls @foralls.each {|pos,neg,(_,(fv,_,fvtype),g),mutable| - @state[fvtype]&.each {|obj,| - g.each {|pre| - pre[0] != NOT ? pos << pre.map {|j| j == fv ? obj : j} : pre.size == 2 ? neg << pre = pre[1].map {|j| j == fv ? obj : j} : raise('Unexpected not in forall') - @predicates[pre[0].freeze] ||= mutable - } + fvtype = @state[fvtype] and g.each {|pre| + if pre[0] != NOT + fvtype.each {|obj,| pos << pre.map {|j| j == fv ? obj : j}} + elsif pre.size == 2 + pre = pre[1] + fvtype.each {|obj,| neg << pre.map {|j| j == fv ? obj : j}} + else raise('Unexpected not in forall') + end + @predicates[pre[0].freeze] ||= mutable } } raise 'Repeated object definition' if @objects.uniq!