-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevolve.py
More file actions
executable file
·131 lines (103 loc) · 3.43 KB
/
evolve.py
File metadata and controls
executable file
·131 lines (103 loc) · 3.43 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
#!/usr/bin/python
import getopt, sys
def parse():
try:
start_index = 1
if len(sys.argv) > 1:
if not sys.argv[1].startswith('-'):
start_index = 2
optlist, args = getopt.getopt(sys.argv[start_index:], 'c:d:ef:g:hm:n:o:s:p:', ['folder', 'help', 'popsize=', 'generations=', 'selection='])
except:
optlist = []
_args = {}
# Parse command line
for o, value in optlist:
if o == "-c":
# Who to compare to based on the user input
value = value.strip()
_args['compare'] = value
elif o == "-e":
# Use elitist selection
_args['elitist'] = True
elif o in ("-f"):
# other config file name
_args['config'] = value.strip()
elif o in ("-n", '--popsize'):
# Specify population size in command line
_args['popSize'] = int(value.strip())
elif o == "-o":
# Output file
_args['output'] = value.strip()
elif o == "-m":
# Output file
_args['mutation'] = float(value.strip())
elif o == "-d":
_args['displayNum'] = value.strip()
elif o in ("-s", '--step'):
# number of iterations
_args['stepSize'] = int(value.strip())
elif o == "--generations":
# number of iterations
_args['generations'] = int(value.strip())
elif o == "--selection":
# number of iterations
value = value.strip()
if value.startswith('roul'):
_args['selection'] = 'roulette'
elif value.startswith('tour'):
_args['selection'] = 'tournament'
else:
_args['selection'] = value
elif o == "-p":
# port number
_args['port'] = int(value.strip())
elif o == "-g":
# port number
_args['gui'] = value.strip()
elif o in ("-h", '--help'):
# display help
print 'Help Menu:'
# helpStr = '''
# -h, --help Display help menu
# -m Mutation rate
# -n, --popsize Population size
# -o Output file name
# -s, --step Step size; how many time steps to skip without user picking
#
# --generations Number of generations to run
# '''
helpStr = '''
python evolve -f config/file.yaml
-f name yaml config file name
-h, --help Display help menu
'''
print helpStr
sys.exit(0)
return _args
if __name__ == "__main__":
try:
import psyco
psyco.full()
except:
print 'No psyco! Oh well...'
args = parse()
from iga.gacommon import gaParams
if args.has_key('config'):
filename = args['config']
if not filename.startswith('config'):
filename = 'config/' + filename
gaParams.fileArgs(filename)
else:
gaParams.fileArgs('config/floorplan.yml')
gaParams.setArgs(args)
if gaParams.getVar('mode') == 'ga':
gaParams.consoleGA()
else:
from gui import gawindow
import wx
app = wx.PySimpleApp()
gaWindow = gawindow.GAWindow()
gaWindow.SetFocus()
app.MainLoop()
app.Destroy()
#-------------------------------------------#