Skip to content

Commit

Permalink
VERSION 0.2.5.dev
Browse files Browse the repository at this point in the history
  • Loading branch information
blankjul committed Nov 26, 2018
1 parent f722ffc commit cd6519e
Show file tree
Hide file tree
Showing 55 changed files with 327 additions and 4,463 deletions.
18 changes: 9 additions & 9 deletions experiments/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np

from pymoo.optimize import minimize


if __name__ == '__main__':

Expand All @@ -14,11 +14,12 @@

import sys

sys.path.append("/home/blankjul/workspace/pymop/")
sys.path.append("/Users/julesy/workspace/pymop/")
sys.path.append("/home/blankjul/workspace/pymoo/")
sys.path.append("/Users/julesy/workspace/pymoo/")
sys.path.insert(0, "/home/blankjul/workspace/pymop/")
sys.path.insert(0, "/Users/julesy/workspace/pymop/")
sys.path.insert(0, "/home/blankjul/workspace/pymoo/")
sys.path.insert(0, "/Users/julesy/workspace/pymoo/")
import pymop
from pymoo.optimize import minimize

# load the data for the experiments
fname = sys.argv[1]
Expand All @@ -42,11 +43,10 @@
elapsed = (time.time() - start_time)
print(fname, "in --- %s seconds ---" % elapsed)

out = data['out']
if len(sys.argv) == 3:
out = os.path.join(sys.argv[2], out)

# create directory of necessary

# create directory if necessary
out = sys.argv[2]
os.makedirs(os.path.dirname(out), exist_ok=True)
np.savetxt(out, F)

Expand Down
2 changes: 2 additions & 0 deletions experiments/experiment_nsga3.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def get_setup(n_obj):
**get_setup(15)
},



}

if __name__ == '__main__':
Expand Down
211 changes: 211 additions & 0 deletions experiments/experiment_nsga3_emo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
"""
This is the experiment for nsga2.
"""
import os
import pickle

from experiments.experiment_nsga3 import get_setup
from pymoo.algorithms.nsga3 import NSGA3
from pymoo.experimental.emo.max_non_dominated import ReferenceDirectionSurvivalNonDominated
from pymoo.experimental.emo.max_of_extremes import ReferenceDirectionSurvivalMaxExtremes
from pymoo.experimental.emo.true import ReferenceDirectionSurvivalTrue
from pymoo.model.termination import MaximumGenerationTermination
from pymop import ScaledProblem
from pymop.factory import get_problem

setup = {

# ==========================================
# DTLZ1
# ==========================================

'dtlz1_3obj': {
'termination': ('n_gen', 400),
'problem': get_problem("dtlz1", None, 3, k=5),
**get_setup(3)

},

'dtlz1_5obj': {
'termination': ('n_gen', 600),
'problem': get_problem("dtlz1", None, 5, k=5),
**get_setup(5)
},

'dtlz1_10obj': {
'termination': ('n_gen', 1000),
'problem': get_problem("dtlz1", None, 10, k=5),
**get_setup(10)
},

# ==========================================
# DTLZ2
# ==========================================

'dtlz2_3obj': {
'termination': ('n_gen', 250),
'problem': get_problem("dtlz2", None, 3, k=10),
**get_setup(3)

},

'dtlz2_5obj': {
'termination': ('n_gen', 350),
'problem': get_problem("dtlz2", None, 5, k=10),
**get_setup(5)

},

'dtlz2_10obj': {
'termination': ('n_gen', 750),
'problem': get_problem("dtlz2", None, 10, k=10),
**get_setup(10)

},

# ==========================================
# DTLZ3
# ==========================================

'dtlz3_3obj': {
'termination': ('n_gen', 1000),
'problem': get_problem("dtlz3", None, 3, k=10),
**get_setup(3)

},

'dtlz3_5obj': {
'termination': ('n_gen', 1000),
'problem': get_problem("dtlz3", None, 5, k=10),
**get_setup(5)

},

'dtlz3_10obj': {
'termination': ('n_gen', 1500),
'problem': get_problem("dtlz3", None, 10, k=10),
**get_setup(10)

},

# ==========================================
# DTLZ4
# ==========================================

'dtlz4_3obj': {
'termination': ('n_gen', 600),
'problem': get_problem("dtlz3", None, 3, k=10),
**get_setup(3)

},

'dtlz4_5obj': {
'termination': ('n_gen', 1000),
'problem': get_problem("dtlz4", None, 5, k=10),
**get_setup(5)

},

'dtlz4_10obj': {
'termination': ('n_gen', 2000),
'problem': get_problem("dtlz4", None, 10, k=10),
**get_setup(10)

},

# ==========================================
# Scaled DTLZ1
# ==========================================

'sdtlz1_3obj': {
'termination': ('n_gen', 400),
'problem': ScaledProblem(get_problem("dtlz1", None, 3, k=5), 10),
**get_setup(3)

},

'sdtlz1_5obj': {
'termination': ('n_gen', 600),
'problem': ScaledProblem(get_problem("dtlz1", None, 5, k=5), 10),
**get_setup(5)
},

'sdtlz1_10obj': {
'termination': ('n_gen', 1000),
'problem': ScaledProblem(get_problem("dtlz1", None, 10, k=5), 2),
**get_setup(10)
},

# ==========================================
# Scaled DTLZ2
# ==========================================

'sdtlz2_3obj': {
'termination': ('n_gen', 250),
'problem': ScaledProblem(get_problem("dtlz2", None, 3, k=10), 10),
**get_setup(3)

},

'sdtlz2_5obj': {
'termination': ('n_gen', 350),
'problem': ScaledProblem(get_problem("dtlz2", None, 5, k=10), 10),
**get_setup(5)

},

'sdtlz2_10obj': {
'termination': ('n_gen', 750),
'problem': ScaledProblem(get_problem("dtlz2", None, 10, k=10), 3),
**get_setup(10)

},

}

if __name__ == '__main__':

run_files = []
prefix = "runs"
method_name = "pynsga3-true"
n_runs = 50
problems = setup.keys()

for e in problems:

s = setup[e]
problem = s['problem']

s = setup[e]
problem = s['problem']
pf = problem.pareto_front(s['ref_dirs'])

algorithm = NSGA3(s['ref_dirs'],
pop_size=s['pop_size'],
crossover=s['crossover'],
mutation=s['mutation'],
survival=ReferenceDirectionSurvivalTrue(s['ref_dirs'], pf)
)

for run in range(n_runs):
fname = "%s_%s_%s.run" % (method_name, e, (run + 1))

data = {
'problem': problem,
'algorithm': algorithm,
'seed': run,
'termination': MaximumGenerationTermination(s['termination'][1]),
'out': "results/%s/%s/%s_%s.out" % (method_name, e.replace("_", "/"), e, (run + 1)),
'in': os.path.join(prefix, method_name, fname),
}

os.makedirs(os.path.join(prefix, method_name), exist_ok=True)

with open(data['in'], 'wb') as f:
pickle.dump(data, f)
run_files.append(data)

# create the final run.txt file
with open(os.path.join(prefix, method_name, "run.bat"), 'w') as f:
for run_file in run_files:
f.write("python execute.py %s %s\n" % (run_file['in'], run_file['out']))
47 changes: 0 additions & 47 deletions experiments/experiment_nsga3_new.py

This file was deleted.

11 changes: 6 additions & 5 deletions experiments/runner.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import os
import re
import subprocess
import sys

sys.path.insert(0, "..")


if __name__ == '__main__':

print("Parent Process: ", os.getpid())

folder = sys.argv[1]
run_files = sys.argv[1]
files = [line.rstrip('\n') for line in open(run_files)]

threads = int(sys.argv[2])
files = [f for f in os.listdir(folder) if re.match(r'.*.run', f)]

def run(file):
path_to_file = os.path.join(folder, file)
result = subprocess.run(['python', 'execute.py', path_to_file, folder], stdout=subprocess.PIPE)
result = subprocess.run(file.split(" "), stdout=subprocess.PIPE)
print(result.stdout.decode('utf-8').rstrip("\n\r"))

from concurrent.futures import ThreadPoolExecutor
Expand Down
4 changes: 2 additions & 2 deletions pymoo/algorithms/nsga3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, ref_dirs, **kwargs):
kwargs['individual'] = Individual(rank=np.inf, niche=-1, dist_to_niche=np.inf)
set_if_none(kwargs, 'pop_size', len(ref_dirs))
set_if_none(kwargs, 'sampling', RandomSampling())
set_if_none(kwargs, 'crossover', SimulatedBinaryCrossover(prob_cross=1.0, eta_cross=20))
set_if_none(kwargs, 'mutation', PolynomialMutation(prob_mut=None, eta_mut=30))
set_if_none(kwargs, 'crossover', SimulatedBinaryCrossover(prob_cross=1.0, eta_cross=30))
set_if_none(kwargs, 'mutation', PolynomialMutation(prob_mut=None, eta_mut=20))
set_if_none(kwargs, 'selection', TournamentSelection(func_comp=comp_by_cv_then_random))
set_if_none(kwargs, 'survival', ReferenceDirectionSurvival(ref_dirs))
set_if_none(kwargs, 'eliminate_duplicates', True)
Expand Down
Loading

0 comments on commit cd6519e

Please sign in to comment.