-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_gen.py
executable file
·41 lines (34 loc) · 1.42 KB
/
input_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
#!/usr/bin/env python3
import argparse, random, json
def main():
parser = argparse.ArgumentParser(description="Generate Bin Inputs.")
parser.add_argument("-f", dest="out_file", metavar="FILE",
help="File to write to", required=True)
parser.add_argument("-n", dest="num_objs", type=int,
help="Number of objects", required=True)
parser.add_argument("-s", dest="bin_size", type=int,
help="Bin size", required=True)
parser.add_argument("-r", nargs=2, metavar=("lo","hi"), type=int,
help="Range of obj size", required=False)
parser.add_argument("-m","--mode", dest="mode",
choices=["uniform"],
default="uniform", help="Mode for input generation")
args = parser.parse_args()
num_objs = args.num_objs
bin_size = args.bin_size
objs = [0] * num_objs
if(args.mode == "uniform"):
for i in range(num_objs):
if(args.r):
objs[i] = random.randint(max(1,args.r[0]),
min(args.r[1],bin_size))
else:
objs[i] = random.randint(1, bin_size)
inputs = {}
inputs["num_objs"] = num_objs
inputs["bin_size"] = bin_size
inputs["objs"] = objs
with open(args.out_file, "w") as outfile:
json.dump(inputs, outfile)
if(__name__ == "__main__"):
main()