-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
235 lines (198 loc) · 12.6 KB
/
Copy pathmain.py
File metadata and controls
235 lines (198 loc) · 12.6 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import sys
import warnings
from cudd import Cudd
from src.symbolic_graphs.graph_search_scripts import SimpleGridWorld, FrankaWorld
from src.symbolic_graphs.strategy_synthesis_scripts import FrankaPartitionedWorld, FrankaRegretSynthesis, FrankaSymbolicRegretSynthesis
from utls import *
from config import *
if __name__ == "__main__":
for iteration in range(1):
print("**********************************************************************************************************")
print(f"************************************** Iteration: {iteration}********************************************")
print("**********************************************************************************************************")
cudd_manager = Cudd()
if GRIDWORLD:
# grid world files
domain_file_path = PROJECT_ROOT + "/pddl_files/grid_world/domain.pddl"
if OBSTACLE:
problem_file_path = PROJECT_ROOT + f"/pddl_files/grid_world/problem{GRID_WORLD_SIZE}_{GRID_WORLD_SIZE}_obstacle1.pddl"
else:
problem_file_path = PROJECT_ROOT + f"/pddl_files/grid_world/problem{GRID_WORLD_SIZE}_{GRID_WORLD_SIZE}.pddl"
if DIJKSTRAS:
algo = 'dijkstras'
elif ASTAR:
algo = 'astar'
else:
algo = 'bfs'
# grid world dictionary
wgt_dict = {
"moveleft" : 1,
"moveright" : 2,
"moveup" : 3,
"movedown" : 4
}
gridworld_handle = SimpleGridWorld(domain_file=domain_file_path,
problem_file=problem_file_path,
formulas=formulas,
manager=cudd_manager,
algorithm=algo,
weight_dict=wgt_dict,
ltlf_flag=USE_LTLF,
dyn_var_ord=DYNAMIC_VAR_ORDERING,
verbose=False,
plot_ts=False,
plot_obs=False,
plot=False)
# build the TS and DFA(s)
gridworld_handle.build_abstraction()
print("No. of Boolean Variables in the memory:", cudd_manager.size())
policy: dict = gridworld_handle.solve(verbose=False)
gridworld_handle.simulate(action_dict=policy, gridworld_size=GRID_WORLD_SIZE)
elif FRANKAWORLD:
# Franka World files
domain_file_path = PROJECT_ROOT + "/pddl_files/simple_franka_world/domain.pddl"
problem_file_path = PROJECT_ROOT + "/pddl_files/simple_franka_world/problem.pddl"
if DIJKSTRAS:
algo = 'dijkstras'
elif ASTAR:
algo = 'astar'
else:
algo = 'bfs'
wgt_dict = {
"transit" : 1,
"grasp" : 2,
"transfer": 3,
"release" : 4,
}
# frankaworld stuff
frankaworld_handle = FrankaWorld(domain_file=domain_file_path,
problem_file=problem_file_path,
formulas=formulas,
manager=cudd_manager,
sup_locs=SUP_LOC,
top_locs=TOP_LOC,
weight_dict=wgt_dict,
ltlf_flag=USE_LTLF,
dyn_var_ord=DYNAMIC_VAR_ORDERING,
algorithm=algo,
verbose=False,
plot_ts=False,
plot_obs=False,
plot=False)
# build the abstraction
frankaworld_handle.build_abstraction()
# sys.exit(-1)
print("No. of Boolean Variables in the memory:", cudd_manager.size())
policy: dict = frankaworld_handle.solve(verbose=False)
frankaworld_handle.simulate(action_dict=policy, print_strategy=True)
elif STRATEGY_SYNTHESIS:
# Franka World files
if TWO_PLAYER_GAME:
domain_file_path = PROJECT_ROOT + "/pddl_files/dynamic_franka_world/domain.pddl"
problem_file_path = PROJECT_ROOT + "/pddl_files/dynamic_franka_world/problem.pddl"
elif TWO_PLAYER_GAME_BND:
domain_file_path = PROJECT_ROOT + "/pddl_files/bounded_dynamic_franka_world/domain.pddl"
problem_file_path = PROJECT_ROOT + "/pddl_files/bounded_dynamic_franka_world/problem.pddl"
assert HUMAN_INT_BND >= 0, "Please make sure you enter a non-negative number of human interventions."
else:
domain_file_path = PROJECT_ROOT + "/pddl_files/simple_franka_world/domain.pddl"
problem_file_path = PROJECT_ROOT + "/pddl_files/simple_franka_world/problem.pddl"
wgt_dict = {
"transit" : 1,
"grasp" : 1,
"transfer": 1,
"release" : 1,
"human": 0
}
# partitioned frankaworld stuff
frankapartition_handle = FrankaPartitionedWorld(domain_file=domain_file_path,
problem_file=problem_file_path,
formulas=formulas,
manager=cudd_manager,
sup_locs=SUP_LOC,
top_locs=TOP_LOC,
weight_dict=wgt_dict,
ltlf_flag=USE_LTLF,
dyn_var_ord=DYNAMIC_VAR_ORDERING,
algorithm=GAME_ALGORITHM,
verbose=False,
plot_ts=False,
plot_obs=False,
plot=False)
if 'quant' in GAME_ALGORITHM:
assert TWO_PLAYER_GAME_BND is False, "We do not have symbolic bounded quantitative synthesis implemented yet. Please set TWO_PLAYER_GAME flag to True"
elif GAME_ALGORITHM == 'qual':
assert TWO_PLAYER_GAME is not TWO_PLAYER_GAME_BND, "Please set only one flag to True - BND_TWO_PLAYER_GAME or TWO_PLAYER_GAME!"
else:
warnings.warn("Make sure you select atleast one Algorithm - 'qual' or 'quant-adv' or 'quant-coop'")
sys.exit(-1)
# build the abstraction
frankapartition_handle.build_abstraction(dynamic_env=TWO_PLAYER_GAME,
bnd_dynamic_env=TWO_PLAYER_GAME_BND,
max_human_int=HUMAN_INT_BND)
# sys.exit(-1)
print(f"****************** # Total Boolean Variables: { cudd_manager.size()} ******************")
frankapartition_handle.solve(verbose=False, monolithic_tr=MONOLITHIC_TR)
elif REGRET_SYNTHESIS:
# domain_file_path = PROJECT_ROOT + "/pddl_files/franka_regret_world/two_blocks/domain.pddl"
# problem_file_path = PROJECT_ROOT + "/pddl_files/franka_regret_world/two_blocks/problem.pddl"
##### ARCH CONSTRUCTION DOMAIN
# domain_file_path = PROJECT_ROOT + "/pddl_files/franka_regret_world/arch/domain.pddl"
# problem_file_path = PROJECT_ROOT + "/pddl_files/franka_regret_world/arch/problem.pddl"
##### Simple Test domain - formula on line 75 in config.py script
# domain_file_path = PROJECT_ROOT + "/pddl_files/franka_regret_world/test/domain.pddl"
# problem_file_path = PROJECT_ROOT + "/pddl_files/franka_regret_world/test/problem.pddl"
##### IROS 23 benchmark - varying boxes domain
domain_file_path = PROJECT_ROOT + "/pddl_files/iros23_pddl_files/domain.pddl"
problem_file_path = PROJECT_ROOT + "/pddl_files/iros23_pddl_files/varying_boxes/p00.pddl"
wgt_dict = {
"transit" : 1,
"grasp" : 1,
"transfer": 1,
"release" : 1,
"human": 0
}
if REGRET_HYBRID:
regret_synthesis_handle = FrankaRegretSynthesis(domain_file=domain_file_path,
problem_file=problem_file_path,
formulas=formulas,
manager=cudd_manager,
sup_locs=SUP_LOC,
top_locs=TOP_LOC,
weight_dict=wgt_dict,
ltlf_flag=USE_LTLF,
dyn_var_ord=DYNAMIC_VAR_ORDERING,
weighting_factor=3,
reg_factor=1.25,
algorithm=None,
verbose=False,
print_layer=False,
plot_ts=False,
plot_obs=False,
plot=False)
else:
regret_synthesis_handle = FrankaSymbolicRegretSynthesis(domain_file=domain_file_path,
problem_file=problem_file_path,
formulas=formulas,
manager=cudd_manager,
sup_locs=SUP_LOC,
top_locs=TOP_LOC,
weight_dict=wgt_dict,
ltlf_flag=USE_LTLF,
dyn_var_ord=DYNAMIC_VAR_ORDERING,
weighting_factor=3,
reg_factor=1.25,
algorithm=None,
verbose=False,
print_layer=False,
plot_ts=False,
plot_obs=False,
plot=False)
regret_synthesis_handle.build_abstraction()
regret_synthesis_handle.solve(verbose=False, just_adv_game=False, run_monitor=False, monolithic_tr=MONOLITHIC_TR)
print(f"****************** # Total Boolean Variables: { cudd_manager.size()} ******************")
else:
warnings.warn("Please set atleast one flag to True - GRIDWORLD, FRANKAWORLD, STRATEGY_SYNTHESIS, or REGRET_SYNTHESIS!")
sys.exit(-1)
# convert bytes to MegaBytes and print the Memory usage
print(f"Memory in use (MB): {cudd_manager.readMemoryInUse()/(10**6)}")