Skip to content

Commit

Permalink
Improve initial and goal state checks in Wise
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed Apr 24, 2024
1 parent d644be5 commit 1b5c4da
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions extensions/Wise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def apply(operators, methods, predicates, state, tasks, goal_pos, goal_not, debu
# Initial state
state.reject! {|pre,k|
if predicates.include?(pre)
# Free variable
raise 'Initial state contains free variable' if k.flatten(1).any? {|t| t.start_with?('?')}
# Duplicates
puts "Initial state contains duplicate predicates (#{pre} ...): removed" if k.uniq! and debug
# Arity check
Expand Down Expand Up @@ -99,8 +101,23 @@ def apply(operators, methods, predicates, state, tasks, goal_pos, goal_not, debu
tasks.unshift(ordered)
end
# Goal
raise 'Goal contains free variable' if (goal_pos + goal_not).flatten(1).any? {|t| t.start_with?('?')}
puts "Goal contains duplicate positive condition: removed" if goal_pos.uniq! and debug
puts "Goal contains duplicate negative condition: removed" if goal_not.uniq! and debug
goal_pos.reject! {|pre| # TODO test, maybe move to why complex tests
unless predicates[pre[0]]
raise "Goal contains impossible positive condition (#{pre.join(' ')})" unless state[pre[0]].include?(pre.drop(1))
puts "Goal contains unnecessary positive condition (#{pre.join(' ')})" if debug
true
end
}
goal_not.reject! {|pre| # TODO test, maybe move to why complex tests
unless predicates[pre[0]]
raise "Goal contains impossible negative condition (#{pre.join(' ')})" if state[pre[0]].include?(pre.drop(1))
puts "Goal contains unnecessary negative condition (#{pre.join(' ')})" if debug
true
end
}
(goal_pos & goal_not).each {|pre| raise "Goal contains contradiction (#{pre.join(' ')}) and (not (#{pre.join(' ')}))"}
end

Expand Down

0 comments on commit 1b5c4da

Please sign in to comment.