-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoead.py
84 lines (79 loc) · 2.67 KB
/
moead.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
# !/usr/bin/env python
# --------------------------------------------------------------
# File: moead.py
# Project: Code
# Created: Tuesday, 9th April 2019 4:34:48 pm
# @Author: molin@live.cn
# Last Modified: Saturday, 4th May 2019 6:21:46 pm
# Copyright © Rockface 2018 - 2019
# --------------------------------------------------------------
import sys, os
import plot, dataAnalysis
import utilis
import multiprocessing
basePath = os.path.abspath(os.path.curdir)
#basePath = "/Users/meow/Desktop/DP/Code"
def batchJob(id, N, T, iterations, mix_percentage):
outPath = utilis.getOutPath(os.path.join(basePath, 'Output/MOEA-D'), "Test")
moead_command = ("./portfolio.o" + " " +
outPath + " " +
str(id) + " " +
str(N) + " " +
str(T) + " " +
str(iterations) +" "
+ str(mix_percentage)
)
print(moead_command)
os.mkdir(outPath)
os.system(moead_command)
config_file = open(os.path.join(outPath, 'config.txt'), 'w')
config_file.write("File:\t%s\n"%str(id))
config_file.write("Iterations:\t%s\n"%str(iterations))
config_file.write("Population:\t%s\n"%str(N))
config_file.write("Neighbor:\t%s\n"%str(T))
config_file.write("Percentage:\t%s%%"%str(float(mix_percentage)*100))
config_file.close()
plot.plotMOEAD(outPath)
dataAnalysis.analysisPF(outPath)
#dataAnalysis.formatPlot_Test(outPath+'/EP.txt')
def singleRun():
outPath = utilis.getOutPath(os.path.join(basePath, 'Output/MOEA-D'), "Test")
id = input("Which data:\t")
N = input("Num of solutions:\t")
T = input("Num of neighbors:\t")
iterations = input("Num of iterations:\t")
mix_percentage = input("Low assets %:\t")
moead_command = ("./portfolio.o" + " " +
outPath + " " +
str(id) + " " +
str(N) + " " +
str(T) + " " +
str(iterations) +" "
+ str(mix_percentage)
)
os.mkdir(outPath)
os.system(moead_command)
config_file = open(os.path.join(outPath, 'config.txt'), 'w')
config_file.write("File:\t%s\n"%str(id))
config_file.write("Iterations:\t%s\n"%str(iterations))
config_file.write("Population:\t%s\n"%str(N))
config_file.write("Neighbor:\t%s\n"%str(T))
config_file.write("Percentage:\t%s%%"%str(mix_percentage))
config_file.close()
plot.plotMOEAD(outPath)
if __name__ == "__main__":
#singleRun()
id = input("Which data:\t")
N = input("Num of solutions:\t")
T = input("Num of neighbors:\t")
N = N.strip().split()
T = T.strip().split()
iterations = input("Num of iterations:\t")
mix_percentage = input("Low assets %:\t")
if len(N)>len(T):
num_batch = len(N)
for i in range(num_batch):
batchJob(id, N[i], T[0], iterations, mix_percentage)
else:
for i in range(len(T)):
batchJob(id, N[0], T[i], iterations, mix_percentage)