/
generate_problems.py
executable file
·142 lines (110 loc) · 5.69 KB
/
generate_problems.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
"""
Generates random configurations for the PDDL PACO domains specified in the domains folder:
EASY - Angles between joints are expressed relatively (child respect to root)
CONDITIONAL - Angles are absolute, when an angle is modified all upstream and downstream ones are modified too
"""
import sys
import argparse
import os
from problem_generators import flush_files, generate_configurations
from os.path import dirname, realpath, isdir
import shutil
__author__ = "Alessio Capitanelli"
__copyright__ = "Copyright 2016, Alessio Capitanelli"
__license__ = "GPLv3"
__version__ = "1.0.0"
__maintainer__ = "Alessio Capitanelli"
__email__ = "alessio.capitanelli@dibris.unige.it"
__status__ = "Development"
def main(argv):
parser = argparse.ArgumentParser(description=
"Planning for ArtiCulated Objects (PACO) synthetic benchmarks generator. \n"
"By default, it generates both relative and legacy problems and "
"stores them in the /problems folder.\n")
parser.add_argument('N_LINKS', help="Number of links of the articulated objects.", type=int)
parser.add_argument('N_SAMPLES', help="Number of samples to generate.", type=int)
parser.add_argument('-r', '--resolution', help="Sets angle resolution, default: 4 (0, 90, 180, 270).", type=int)
parser.add_argument('-s', '--simple_only', help="Generate relative problems only.", action='store_true')
parser.add_argument('-c', '--conditional_only', help="Generate legacy problems only.", action='store_true')
parser.add_argument('-a', '--all',
help="Whenever a relative or legacy problem is generated, it generates both alternatives.",
action="store_true")
parser.add_argument('-d', '--distance', help="Minimum average distance between a joint initial and goal state. "
"Used to generate more realistic datasets.", type=int)
parser.add_argument('-o', '--oriented',
help="Generates spatially oriented configurations for the relative case, default: false",
action='store_true')
parser.add_argument('-n', '--no_joint', help="Use the alternative legacy domain with no joints.",
action='store_true')
args = parser.parse_args()
# Generating available angles configurations
step = 90
resolution = 4
if args.resolution is not None:
if 360 % args.resolution == 0:
step = 360/args.resolution
resolution = args.resolution
else:
print('Resolution must be a divisor of 360. Aborting.')
return
if args.N_LINKS < 3:
print('There must be at least 3 links. Aborting.')
return
angles = range(0, 359, step)
joints = args.N_LINKS # later, -1 if not oriented
if args.oriented:
print('Generating oriented configurations for the relative case. Considering virtual link with the ground.')
confs = generate_configurations(args.N_SAMPLES, joints, angles, resolution, args.distance)
# Print to file
tag = ""
if args.distance:
tag = tag + "_d" + str(args.distance)
tag = "{0}_{1}{2}".format(joints, resolution, tag)
if not args.conditional_only or args.simple_only:
path = os.path.dirname(os.path.realpath(__file__))
if args.oriented:
d_type = "oriented"
alt_type = "relative"
else:
d_type = "relative"
alt_type = "oriented"
if not os.path.exists(path + "/problems/simple/" + d_type + "/" + tag):
os.makedirs(path + "/problems/simple/" + d_type + "/" + tag)
path += ("/problems/simple/" + d_type + "/" + tag)
print("Writing {0} {1} problem files to {2}...".format(args.N_SAMPLES, d_type, path))
flush_files(angles, confs, d_type, tag, path)
print("Done.")
if args.all:
path = os.path.dirname(os.path.realpath(__file__))
if not os.path.exists(path + "/problems/simple/" + alt_type + "/" + tag):
os.makedirs(path + "/problems/simple/" + alt_type + "/" + tag)
path += ("/problems/simple/" + alt_type + "/" + tag)
print("Writing {0} {1} problem files to {2}...".format(args.N_SAMPLES, alt_type, path))
flush_files(angles, confs, alt_type, tag, path)
print("Done.")
if not args.simple_only or args.conditional_only:
path = os.path.dirname(os.path.realpath(__file__))
if args.no_joint:
d_type = "simplified"
alt_type = "legacy"
else:
d_type = "legacy"
alt_type = "simplified"
if not os.path.exists(path + "/problems/conditional/" + d_type + "/" + tag):
os.makedirs(path + "/problems/conditional/" + d_type + "/" + tag)
path += ("/problems/conditional/" + d_type + "/" + tag)
print("Writing {0} {1} problem files to {2}...".format(args.N_SAMPLES, d_type, path))
flush_files(angles, confs, d_type, tag, path)
print("Done.")
if args.all:
path = os.path.dirname(os.path.realpath(__file__))
if not os.path.exists(path + "/problems/conditional/" + alt_type + "/" + tag):
os.makedirs(path + "/problems/conditional/" + alt_type + "/" + tag)
path += ("/problems/conditional/" + alt_type + "/" + tag)
print("Writing {0} {1} problem files to {2}...".format(args.N_SAMPLES, alt_type, path))
flush_files(angles, confs, alt_type, tag, path)
print("Done.")
print("All operations completed. Happy planning!")
if __name__ == "__main__":
main(sys.argv[1:])