-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_ind.py
executable file
·65 lines (48 loc) · 1.55 KB
/
create_ind.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
#!/usr/bin/env python
##!/usr/bin/env python2.4
import os
import sys
from adts import *
from engine.Ind import *
import pickle
from engine.EngineUtils import loadSynthState
from adts import *
from problems.Problems import ProblemFactory
if __name__== '__main__':
#set up logging
import logging
logging.basicConfig()
logging.getLogger('engine_utils').setLevel(logging.INFO)
logging.getLogger('analysis').setLevel(logging.DEBUG)
#set help message
help = """
Usage: get_ind PROBLEM_CHOICE OUT_FILE
Dump ind for problem number PROBLEM_CHOICE to a pickle file of the ind.
Variables are initialized at random.
Details:
PROBLEM_CHOICE -- int -- problem number
OUT_FILE -- string -- the file to write the ind to. Note that this is
_not_ a state file, but instead a direct pickle of the ind.
"""
#got the right number of args? If not, output help
num_args = len(sys.argv)
if num_args not in [3]:
print help
sys.exit(0)
#yank out the args into usable values
problem_choice = eval(sys.argv[1])
out_file = sys.argv[2]
#do the work
# -load data
ps = ProblemFactory().build(problem_choice)
point_meta = ps.embedded_part.part.point_meta
new_point = point_meta.createRandomUnscaledPoint(with_novelty = False)
unscaled_optvals = [new_point[var] for var in ps.ordered_optvars]
ind = NsgaInd(unscaled_optvals, ps)
ind.genetic_age = 0
ind.setAncestry([])
ind.S = None
ind._ps = None
fid = open(out_file,'w')
pickle.dump(ind, fid)
fid.close()