Skip to content

Commit

Permalink
Consistent comment separators [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed Dec 23, 2020
1 parent 0508669 commit b6c6cea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
8 changes: 4 additions & 4 deletions PDDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class PDDL_Parser:

SUPPORTED_REQUIREMENTS = [':strips', ':negative-preconditions', ':typing']

# ------------------------------------------
#-----------------------------------------------
# Tokens
# ------------------------------------------
#-----------------------------------------------

def scan_tokens(self, filename):
with open(filename,'r') as f:
Expand Down Expand Up @@ -202,9 +202,9 @@ def split_predicates(self, group, pos, neg, name, part):
else:
pos.append(predicate)

# ==========================================
#-----------------------------------------------
# Main
# ==========================================
#-----------------------------------------------
if __name__ == '__main__':
import sys, pprint
domain = sys.argv[1]
Expand Down
23 changes: 23 additions & 0 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

class Action:

#-----------------------------------------------
# Initialize
#-----------------------------------------------

def __init__(self, name, parameters, positive_preconditions, negative_preconditions, add_effects, del_effects):
self.name = name
self.parameters = parameters
Expand All @@ -13,6 +17,10 @@ def __init__(self, name, parameters, positive_preconditions, negative_preconditi
self.add_effects = add_effects
self.del_effects = del_effects

#-----------------------------------------------
# to String
#-----------------------------------------------

def __str__(self):
return 'action: ' + self.name + \
'\n parameters: ' + str(self.parameters) + \
Expand All @@ -21,9 +29,17 @@ def __str__(self):
'\n add_effects: ' + str(self.add_effects) + \
'\n del_effects: ' + str(self.del_effects) + '\n'

#-----------------------------------------------
# Equality
#-----------------------------------------------

def __eq__(self, other):
return self.__dict__ == other.__dict__

#-----------------------------------------------
# Groundify
#-----------------------------------------------

def groundify(self, objects):
if not self.parameters:
yield self
Expand All @@ -40,6 +56,10 @@ def groundify(self, objects):
del_effects = self.replace(self.del_effects, variables, assignment)
yield Action(self.name, assignment, positive_preconditions, negative_preconditions, add_effects, del_effects)

#-----------------------------------------------
# Replace
#-----------------------------------------------

def replace(self, group, variables, assignment):
g = []
for pred in group:
Expand All @@ -52,6 +72,9 @@ def replace(self, group, variables, assignment):
g.append(pred)
return g

#-----------------------------------------------
# Main
#-----------------------------------------------
if __name__ == '__main__':
a = Action('move', [['?ag', 'agent'], ['?from', 'pos'], ['?to', 'pos']],
[['at', '?ag', '?from'], ['adjacent', '?from', '?to']],
Expand Down
4 changes: 2 additions & 2 deletions planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def apply(self, state, positive, negative):
new_state.append(i)
return new_state

# ==========================================
#-----------------------------------------------
# Main
# ==========================================
#-----------------------------------------------
if __name__ == '__main__':
import sys, time
start_time = time.time()
Expand Down
23 changes: 11 additions & 12 deletions test_PDDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
from action import Action
from PDDL import PDDL_Parser

# ==========================================
# Test PDDL
# ==========================================

class Test_PDDL(unittest.TestCase):

# ------------------------------------------
#-----------------------------------------------
# Test scan_tokens
# ------------------------------------------
#-----------------------------------------------

def test_scan_tokens_domain(self):
parser = PDDL_Parser()
Expand Down Expand Up @@ -44,9 +40,9 @@ def test_scan_tokens_problem(self):
[':goal', ['and', ['dinner'], ['present'], ['not', ['garbage']]]]]
)

# ------------------------------------------
#-----------------------------------------------
# Test parse domain
# ------------------------------------------
#-----------------------------------------------

def test_parse_domain(self):
parser = PDDL_Parser()
Expand All @@ -64,9 +60,9 @@ def test_parse_domain(self):
]
)

# ------------------------------------------
#-----------------------------------------------
# Test parse problem
# ------------------------------------------
#-----------------------------------------------

def test_parse_problem(self):
parser = PDDL_Parser()
Expand All @@ -78,9 +74,9 @@ def test_parse_problem(self):
self.assertEqual(parser.positive_goals, [['dinner'], ['present']])
self.assertEqual(parser.negative_goals, [['garbage']])

#-------------------------------------------
#-----------------------------------------------
# Test parse predicates
#-------------------------------------------
#-----------------------------------------------

def test_parse_predicates(self):
parser = PDDL_Parser()
Expand All @@ -96,5 +92,8 @@ def test_parse_predicates(self):
'shared_type_pred': {'?v1': 'type1', '?v2': 'type1', '?v3': 'object'}
})

#-----------------------------------------------
# Main
#-----------------------------------------------
if __name__ == '__main__':
unittest.main()
11 changes: 5 additions & 6 deletions test_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
from action import Action
from planner import Planner

# ==========================================
# Test Planner
# ==========================================

class Test_Planner(unittest.TestCase):

# ------------------------------------------
#-----------------------------------------------
# Test solve
# ------------------------------------------
#-----------------------------------------------

def test_solve_dinner(self):
planner = Planner()
Expand All @@ -25,5 +21,8 @@ def test_solve_dinner(self):
]
)

#-----------------------------------------------
# Main
#-----------------------------------------------
if __name__ == '__main__':
unittest.main()

0 comments on commit b6c6cea

Please sign in to comment.