-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunch_PAC_C.py
76 lines (64 loc) · 2.34 KB
/
launch_PAC_C.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
from os import path
import click
import time
from downward.FDgrounder import ground
import writer
import PAC_C
from converter import convert, get_all_atoms
PLAN_CONSTRAINTS_ = 'Plan constraints:'
ATOMS_OVERHEAD_ = '[ATOMS-OVERHEAD]: {}'
EFFECT_OVERHEAD_ = '[EFFECT-OVERHEAD]: {}'
PRECONDITION_OVERHEAD_ = '[PRECONDITION-OVERHEAD]: {}'
PAC_C_RUNTIME_ = "PAC_C-RUNTIME: {}"
STARTING_PAC_C = "Starting PAC_C"
def print_compilation_overhead(F, F_prime, A_prime):
print('##### COMPILATION OVERHEAD #####')
new_atoms = [atom for atom in F_prime if atom not in F]
preconditions_overhead = 0
effects_overhead = 0
atoms_overhead = len(new_atoms)
for a in A_prime:
pre_atoms = []
eff_atoms = []
for pre in a.precondition:
atoms_tmp = get_all_atoms(pre)
for atom in atoms_tmp:
if atom not in pre_atoms:
pre_atoms.append(atom)
for eff in a.effects:
eff_atoms.append(eff.effect)
for lit in eff_atoms:
if lit in new_atoms or lit.negate() in new_atoms:
effects_overhead += 1
for lit in pre_atoms:
if lit in new_atoms or lit.negate() in new_atoms:
preconditions_overhead += 1
print(PRECONDITION_OVERHEAD_.format(preconditions_overhead))
print(EFFECT_OVERHEAD_.format(effects_overhead))
print(ATOMS_OVERHEAD_.format(atoms_overhead))
@click.command()
@click.argument('domain')
@click.argument('problem')
@click.argument('output')
@click.option('--verbose', is_flag=True)
@click.option('--show-overhead', is_flag=True)
def main(domain, problem, output, verbose, show_overhead):
F, A, I, G, C = ground(domain, problem)
F, A, I, G, C = convert(F, A, I, G, C)
if verbose:
print(PLAN_CONSTRAINTS_)
for c in C:
print('\t'+str(c)+'\n')
start_time = time.time()
print(STARTING_PAC_C)
F_prime, A_prime, I_prime, G_prime = PAC_C.fast_pac_c(F, A, I, G, C)
print(PAC_C_RUNTIME_.format(time.time() - start_time))
if show_overhead:
print_compilation_overhead(F, F_prime, A_prime)
output_filename = 'compiled'
if not path.isdir(output):
os.system('mkdir {}'.format(output))
writer.output_compiled_problem(F_prime, A_prime, I_prime, G_prime, output, output_filename)
if __name__ == '__main__':
main()