-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (38 loc) · 1.41 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time
import argparse
from pddl.parser.domain import DomainParser
from pddl.parser.problem import ProblemParser
from a_star import astar_search
# Ajoutez un parseur d'arguments
parser = argparse.ArgumentParser()
parser.add_argument("--domain", help="Domain PDDL file")
parser.add_argument("--problem", help="Problem PDDL file")
args = parser.parse_args()
start_time = time.time()
# Utilisez les arguments passés en ligne de commande
DOMAIN = args.domain
PROBLEM = args.problem
plan = astar_search(DOMAIN, PROBLEM)
print("Nombre d'actions dans le plan :", len(plan))
print("Temps d'exécution : %s secondes" % (time.time() - start_time))
# Vérification de la validité du plan
import copy
def valid_plan(plan):
def apply_action(state, action): # return new state after applying an action
new_state = list(copy.deepcopy(state))
for e in action['positive effects']:
new_state.append(e)
for e in action['negative effects']:
new_state.remove(e.__getstate__()['_arg'])
return tuple(new_state)
problem = ProblemParser()(open(PROBLEM).read())
state = list(problem.init)
goal_state = list(problem.goal.__getstate__()['_operands'])
try:
for a in plan:
print(a['name'])
state = apply_action(state, a)
return set(goal_state).issubset(set(state))
except:
return False
print("Plan valide :", valid_plan(plan))