forked from apprenticelearner/AL_Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_operators.py
More file actions
67 lines (41 loc) · 1.73 KB
/
custom_operators.py
File metadata and controls
67 lines (41 loc) · 1.73 KB
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
from planners.fo_planner import Operator
# from planners.VectorizedPlanner import BaseOperator
''' USAGE INSTRUCTIONS
FO Operator Structure: Operator(<header>, [<conditions>...], [<effects>...])
<header> : ('<name>', '?<var_1>', ... , '?<var_n>')
example : ('Add', '?x', '?y')
<conditions> : [(('<attribute>', '?<var_1>'),'?<value_1>'), ... ,
(<func>, '?<value_1>', ...), ...
]
example : [ (('value', '?x'), '?xv'),
(('value', '?y'), '?yv'),
(lambda x, y: x <= y, '?x', '?y')
]
<effects> : [(<out_attribute>,
('<name>', ('<in_attribute1>', '?<var_1>'), ...),
(<func>, '?<value_1>', ...)
), ...]
example :[(('value', ('Add', ('value', '?x'), ('value', '?y'))),
(int_float_add, '?xv', '?yv'))])
Full Example:
def int_float_add(x, y):
z = float(x) + float(y)
if z.is_integer():
z = int(z)
return str(z)
add_rule = Operator(('Add', '?x', '?y'),
[(('value', '?x'), '?xv'),
(('value', '?y'), '?yv'),
(lambda x, y: x <= y, '?x', '?y')
],
[(('value', ('Add', ('value', '?x'), ('value', '?y'))),
(int_float_add, '?xv', '?yv'))])
Note: You should explicitly register your operators so you can
refer to them in your training.json, otherwise the name will
be the same as the local variable
example: Operator.register("Add")
vvvvvvvvvvvvvvvvvvvv WRITE YOUR OPERATORS BELOW vvvvvvvvvvvvvvvvvvvvvvv '''
# ^^^^^^^^^^^^^^ DEFINE ALL YOUR OPERATORS ABOVE THIS LINE ^^^^^^^^^^^^^^^^
for name,op in locals().copy().items():
if(isinstance(op, Operator)):
Operator.register(name,op)