-
Notifications
You must be signed in to change notification settings - Fork 11
/
numeric_effects.py
62 lines (58 loc) · 1.76 KB
/
numeric_effects.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
"""
Test support for parametrized increment/decrement values in numeric effects
"""
from __future__ import print_function
from pyddl import Domain, Problem, Action, planner
def problem(verbose):
domain = Domain((
Action(
'sell',
parameters=(
('product', 'p'),
),
preconditions=(
('>', ('quantity', 'p'), 0),
('>=', ('customer-money',), ('price', 'p')),
),
effects=(
('-=', ('quantity', 'p'), 1),
('+=', ('account',), ('price', 'p')),
('-=', ('customer-money',), ('price', 'p')),
),
),
))
problem = Problem(
domain,
{
'product': ('apples', 'oranges',),
},
init=(
('=', ('account',), 0),
('=', ('customer-money',), 15),
('=', ('quantity', 'apples'), 10),
('=', ('quantity', 'oranges'), 10),
('=', ('price', 'apples'), 3),
('=', ('price', 'oranges'), 5),
),
goal=(
('=', ('account',), 13),
)
)
plan = planner(problem, verbose=True)
if plan is None:
print('No Plan!')
else:
state = problem.initial_state
for action in plan:
print(action)
state = state.apply(action)
print(state.f_dict)
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser(usage="Usage: %prog [options]")
parser.add_option('-q', '--quiet',
action='store_false', dest='verbose', default=True,
help="don't print statistics to stdout")
# Parse arguments
opts, args = parser.parse_args()
problem(opts.verbose)