-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
77 lines (62 loc) · 1.5 KB
/
main.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
#!/usr/bin/env python
# encoding: utf-8
"""
main.py
CS266 Ant Sim
"""
import sys
import getopt
import random
from param import G
from run import FrontEnd, BatchRun
help_message = '''
CS266 Ant Sim
Usage: python main.py [options]
Options are:
-b numRuns # run simulation numRuns times as a batch with no graphics
-o outfile # output batch data to file
-v # print verbose output to stdout or output file (with -o)
--batch # same as -b
--output # same as -o
'''
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main(argv=None):
output = None
batch = None
numRuns = 1
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "ho:vb:", ["help", "output=", "batch="])
except getopt.error, msg:
raise Usage(msg)
# option processing
for option, value in opts:
if option == "-v":
G.verbose = True
if option in ("-h", "--help"):
raise Usage(help_message)
if option in ("-o", "--output"):
output = value
if option in ("-b", "--batch"):
batch = True
numRuns = int(value)
except Usage, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, "\t for help use --help"
return 2
random.seed(14) # AWESOME SEED WAS 1
if batch is None:
FrontEnd()
else:
BatchRun(numRuns, output)
if __name__ == "__main__":
#sys.exit(main())
import cProfile
cProfile.run('main()', 'fooprof')
import pstats
p = pstats.Stats('fooprof')
#p.sort_stats('cumulative').print_stats(50)