-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_gen.py
126 lines (94 loc) · 3.86 KB
/
data_gen.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
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
from import_helper import *
from find_trajectory import find_step_trajectory, multi_step_solve
from obstacles import Obstacles
from viz_helper import *
from helper import *
from constraints import *
from multiprocessing import Pool, Process
import threading
import pickle
from datetime import datetime
def randomize_state(initial, apex, final, angle_std=0.25, vel_std=0.5):
initial[0] += np.random.random() * angle_std - angle_std / 2
initial[3] += np.random.random() * vel_std - vel_std / 2
initial[1] += np.random.random() * angle_std - angle_std / 2
initial[4] += np.random.random() * vel_std - vel_std / 2
initial[2] += np.random.random() * angle_std - angle_std / 2
initial[5] += np.random.random() * vel_std - vel_std / 2
apex[0] += np.random.random() * angle_std - angle_std / 2
apex[3] += np.random.random() * vel_std - vel_std / 2
apex[1] += np.random.random() * angle_std - angle_std / 2
apex[4] += np.random.random() * vel_std - vel_std / 2
apex[2] += np.random.random() * angle_std - angle_std / 2
apex[5] += np.random.random() * vel_std - vel_std / 2
final[0] += np.random.random() * angle_std - angle_std / 2
final[3] += np.random.random() * vel_std - vel_std / 2
final[1] += np.random.random() * angle_std - angle_std / 2
final[4] += np.random.random() * vel_std - vel_std / 2
final[2] += np.random.random() * angle_std - angle_std / 2
final[5] += np.random.random() * vel_std - vel_std / 2
return initial, apex, final
def call_find_trajectory(args):
solved = multi_step_solve(args["N"],
args["initial_state"],
args["final_state"],
args["apex_state"],
args["tf"],
obstacles=args["obstacles"])
# can't pickle trajectories
solved.pop('x_traj', None)
solved.pop('u_traj', None)
# filename
dt = datetime.now().strftime("%m_%d_%H_%M_%S")
path = data_dir + "{}.pkl"
# dump
open_file = open(path.format(dt), 'wb')
pickle.dump((args, solved), open_file)
open_file.close()
return solved
if __name__ == '__main__':
n_threads = 12
n_outputs = 1000
overall_counter = 0
data_dir = "data_v3/"
# print("FIX THE NOUGHTS")
N = 35
# default values
apex_state = np.array([0, -3.0, 1.5, 0, 0, 0])
initial_state = np.array([0, -2.5, 2.5, 0, 0, 0])
final_state = np.array([0, -1.5, 2.2, 0, 0, 0])
# standard deviations
angle_std = 0.0 # 0.10
vel_std = 0.0 # 0.25
# final time
tf = 2
states = []
# generate all the cases
for i in range(n_outputs):
# now randomize start, apex, final
initial_state, apex_state, final_state = randomize_state(initial_state, apex_state, final_state, angle_std,
vel_std)
# obstacles
n_obst = int(round(np.random.normal(4, 2)))
obstacles = Obstacles(N=n_obst, multi_constraint=True)
states.append({"N": N,
"initial_state": initial_state,
"apex_state": apex_state,
"final_state": final_state,
"obstacles": obstacles,
"tf": tf})
threads = []
initial_len = len(states)
while len(states) > 0:
time.sleep(2)
active_count = 0
for thread in threads:
if thread.is_alive():
active_count += 1
print("Currently active threads: {}".format(active_count))
print("Remaining States: {}".format(len(states)))
print("Progress: {:.02f}".format(1 - len(states) / initial_len))
print("-" * 75)
if active_count < n_threads:
threads.append(Process(target=call_find_trajectory, args=(states.pop(),)))
threads[-1].start()