Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug with double negated preconditions. We now simplify the theory #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 61 additions & 48 deletions src/merge.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

from tarski.syntax import land, CompoundFormula
from tarski.syntax import land, lor, CompoundFormula
from tarski.syntax.formulas import neg, is_neg
import tarski.fstrips as fs
from tarski.io import fstrips as iofs, PDDLReader
from tarski.fstrips.manipulation import Simplify

import sys, os

Expand Down Expand Up @@ -98,63 +99,75 @@ def main(domain1_name, problem1_name, domain2_name, problem2_name, merged_domain

# # for each set of domain actions get the required parameters, preconditions, effects - map domain2 to domain 1, merge preconditions
# #this is to make fail_turnon1, fail_turnoff1
s = Simplify(parse2, parse2.init)
for action in domain1_actions:
name = 'fail_' + action + '1'
action_domain2 = parse1.get_action(action)
# get preconditions of domain2
domain2_precond = parse2.get_action(action).precondition
for neg_dom2_p in domain2_precond.subformulas:
remove = '( ,?)'
name = 'fail_' + action + '1' + '_prec_'+str(neg_dom2_p)
for r in remove: name = name.replace(r,'_')

# get fail action parameters
domain_parameters = action_domain2.parameters
action_domain2 = parse1.get_action(action)

# get preconditions of both domains
domain1_precond = action_domain2.precondition
domain2_precond = parse2.get_action(action).precondition
# get fail action parameters
domain_parameters = action_domain2.parameters

#this creates the merged preconds for fail actions for domain1
merged_precs = []
if is_neg(domain2_precond): #check if precond is already negated, if yes, get subformulas to have positive version
if isinstance(domain2_precond, CompoundFormula):
merged_precs.extend(domain2_precond.subformulas)
else: #otherwise negate it
merged_precs.append(neg(domain2_precond))
merged_precs.append(domain1_precond)
final_prec = land(*merged_precs) # This makes land(*[A,B,C]) actually be land(A,B,C)
# get preconditions of both domains
domain1_precond = action_domain2.precondition

#this creates the merged preconds for fail actions for domain1
merged_precs = []

for dom2_p in domain2_precond.subformulas:
if neg_dom2_p == dom2_p:
merged_precs.append(s.simplify_expression(neg(dom2_p)))# Negate just single precondition
else:
merged_precs.append(dom2_p)
merged_precs.append(domain1_precond)
final_prec = land(*merged_precs)# land(A,B,C)

# add the effect 'failed' and (and) it
# def action(self, name, parameters, precondition, effects, cost=None)
pd = parse1.action(name, domain_parameters,
precondition=final_prec,
effects=[fs.AddEffect(failed())])
# add the effect 'failed' and (and) it
# def action(self, name, parameters, precondition, effects, cost=None)
pd = parse1.action(name, domain_parameters,
precondition=final_prec,
effects=[fs.AddEffect(failed())])


# # # for each set of domain actions get the required parameters, preconditions, effects - map domain1 to domain2, merge preconditions
# # #this is to make fail_turnon2, fail_turnoff2
s = Simplify(parse1, parse1.init)
for action in domain2_actions:
name = 'fail_' + action + '2'

action_domain2 = parse2.get_action(action)

# get fail action parameters
domain_parameters = action_domain2.parameters

# get preconditions of both domains
# get preconditions domain1
domain1_precond = parse1.get_action(action).precondition
domain2_precond = action_domain2.precondition

#this creates the merged preconds for fail actions for domain2
merged_precs = []
if is_neg(domain1_precond):
if isinstance(domain1_precond, CompoundFormula):
merged_precs.extend(domain1_precond.subformulas)
else:
merged_precs.append(neg(domain1_precond))
merged_precs.append(domain2_precond)

final_prec = land(*merged_precs) # This makes land(*[A,B,C]) actually be land(A,B,C)

# make effect 'failed'
pd = parse1.action(name, domain_parameters,
precondition=final_prec,
effects=[fs.AddEffect(failed())])
for neg_dom1_p in domain1_precond.subformulas:
remove = '( ,?)'
name = 'fail_' + action + '2' + '_prec_'+str(neg_dom1_p)
for r in remove: name = name.replace(r,'_')

action_domain2 = parse2.get_action(action)

# get fail action parameters
domain_parameters = action_domain2.parameters

# get preconditions of domain2
domain2_precond = action_domain2.precondition

#this creates the merged preconds for fail actions for domain2
merged_precs = []

for dom1_p in domain1_precond.subformulas:
if neg_dom1_p == dom1_p:
merged_precs.append(s.simplify_expression(neg(dom1_p)))# Negate just single precondition
else:
merged_precs.append(dom1_p)
merged_precs.append(domain2_precond)
final_prec = land(*merged_precs)# land(A,B,C)

# make effect 'failed'
pd = parse1.action(name, domain_parameters,
precondition=final_prec,
effects=[fs.AddEffect(failed())])

# # merge the non fail actions from domain2 onto domain1
for action in domain2_actions:
Expand Down Expand Up @@ -264,7 +277,7 @@ def parse_pddl(dname, pname):
problem2_name = sys.argv[4]
merged_domain = sys.argv[5]
merged_problem = sys.argv[6]

main(domain1_name, problem1_name, domain2_name, problem2_name, merged_domain, merged_problem)