Example #1
0
                                                problem=problem,
                                                n_dir=pop_size_per_epoch)

res = minimize(problem=problem,
               method='samoo',
               method_args={'seed': 53,
                            'method': 'samoo',
                            'framework_id': framework_id,
                            'ref_dirs': ref_dirs,
                            'metamodel_list': metamodel_list,
                            'acq_list': acq_list,
                            'framework_acq_dict': framework_acq_dict,
                            'aggregation': aggregation,
                            'lf_algorithm_list': lf_algorithm_list,
                            'init_pop_size': init_pop_size,
                            'pop_size_per_epoch': pop_size_per_epoch,
                            'pop_size_per_algorithm':pop_size_per_algorithm,
                            'pop_size_lf': pop_size_lf,
                            'n_gen_lf': 100,
                            'n_split': 2
                            },
               termination=('n_eval', 800),
               pf=pf,
               save_history=False,
               disp=True
               )
plotting.plot(pf, res.F, labels=["Pareto-front", "F"])
# filename = '/results/'+problem_name
# np.savetxt(filename+".F", res.pop.get("F"))
# np.savetxt(filename+".X", res.pop.get("X"))
Example #2
0
from pymoo.util.plotting import plot_problem_surface

problem = get_problem("zakharov", n_var=2)
plot_problem_surface(problem, 100, plot_type="wireframe+contour")
# END zakharov

# --------------------------------------------------------------------------------------------
# Multi
# --------------------------------------------------------------------------------------------

# START zdt1
from pymoo.factory import get_problem
from pymoo.util.plotting import plot

problem = get_problem("zdt1")
plot(problem.pareto_front(), no_fill=True)
# END zdt1

# START zdt2
from pymoo.factory import get_problem
from pymoo.util.plotting import plot

problem = get_problem("zdt2")
plot(problem.pareto_front(), no_fill=True)
# END zdt2

# START zdt3
from pymoo.factory import get_problem
from pymoo.util.plotting import plot

problem = get_problem("zdt3")
Example #3
0
problem = get_problem("zdt1", n_var=30)
pf = problem.pareto_front()

# create the reference directions to be used for the optimization
ref_points = np.array([[0.5, 0.2], [0.1, 0.6]])

res = minimize(
    problem,
    method='rnsga2',
    method_args={
        'pop_size': 40,
        'ref_points': ref_points,
        'epsilon': 0.02,
        'normalization': 'no',
        'survival_type': "closest",
        'extreme_points_as_reference_points': True
        # 'weights': np.array([0.9, 0.1])
    },
    save_history=True,
    termination=('n_gen', 500),
    seed=1,
    pf=pf,
    disp=True)

print(res.pop.get("dist_to_closest"))
plotting.plot(pf,
              res.pop.get("F"),
              ref_points,
              show=True,
              labels=['pf', 'F', 'ref_points'])
Example #4
0
from pymoo.optimize import minimize
from pymoo.util import plotting
from pymoo.util.reference_direction import UniformReferenceDirectionFactory
from pymop.factory import get_problem

problem = get_problem("dtlz1", n_var=7, n_obj=3)
# create the reference directions to be used for the optimization
ref_dirs = UniformReferenceDirectionFactory(3, n_points=91).do()

# create the pareto front for the given reference lines
pf = problem.pareto_front(ref_dirs)

res = minimize(problem,
               method='nsga3',
               method_args={
                   'pop_size': 92,
                   'ref_dirs': ref_dirs
               },
               termination=('n_gen', 400),
               pf=pf,
               seed=1,
               disp=True)
plotting.plot(res.F)
Example #5
0
from pymoo.optimize import minimize
from pymoo.util import plotting
from pymoo.util.reference_direction import UniformReferenceDirectionFactory
from pymop.factory import get_problem

problem = get_problem("dtlz1")

# create the reference directions to be used for the optimization
ref_dirs = UniformReferenceDirectionFactory(3, n_points=91).do()

# create the pareto front for the given reference lines
pf = problem.pareto_front(ref_dirs)

res = minimize(problem,
               method='nsga3',
               method_args={
                   'pop_size': 92,
                   'ref_dirs': ref_dirs
               },
               termination=('n_gen', 600),
               pf=pf,
               seed=4,
               disp=True)

# if desired we can filter out the solutions that are not close to ref_dirs
closest_to_ref_dir = res.opt.get("closest")
plotting.plot(res.F[closest_to_ref_dir, :], show=True)
Example #6
0
        'mutation': IntegerBitflipMutation(prob_mut=0.1),
        'eliminate_duplicates': is_duplicate,
        'func_repair': repair
    },
    termination=('n_gen', 100),
    # callback=my_callback,
    disp=True)

results = {
    'times': problem.times,
    'best_valids': problem.best_valids,
    'best_tests': problem.best_tests,
    'hash_archive': problem.hash_archive,
    'Function value': res.opt.get('F'),
    'Variable value': res.opt.get('X'),
}

# with open('nsga2.dat', 'wb') as handle:
#     pickle.dump(results, handle)

plot = True
if plot:
    plotting.plot(pf, res.opt.get('F'), labels=["Pareto-front", "F"])

# print("Time elapsed: {}".format(time.time() - start))
# print("Function value: %s" % res.F)
# print("Total time spent = {} hours, best valid acc = {}, best test acc = {}"
#       .format(problem.times[-1]/3600, problem.best_valids[-1], problem.best_tests[-1]))
# print("{}% of the model sampled are unique".format(len(list(set(problem.hash_archive))) /
#                                                    len(problem.hash_archive)*100))
Example #7
0
    def _evaluate(self, x, out, *args, **kwargs):
        super()._evaluate(x, out, *args, **kwargs)
        out["F"] = out["F"] * np.array([1.0, 10.0]) - 500


problem = ScaledZDT1()

ref_dirs = UniformReferenceDirectionFactory(2, n_points=100).do()

pf = problem.pareto_front()

res = minimize(
    problem,
    method='nsga3',
    method_args={
        'pop_size': 100,
        'ref_dirs': ref_dirs,
        #'survival': ReferenceDirectionSurvivalTrue(ref_dirs, np.array([[1.0, 0], [0, 1.0]]))
    },
    termination=('n_gen', 400),
    pf=pf,
    seed=1,
    disp=True)

plotting.plot(pf,
              res.F,
              labels=["Pareto-front", "NSGA-III - No Normalization"],
              show=False)
plt.legend()
plt.savefig("no_normalization.pdf")
Example #8
0
    def _evaluate(self, x, out, *args, **kwargs):
        X_, X_M = x[:, :self.n_obj - 1], x[:, self.n_obj - 1:]
        g = self.g1(X_M)

        super()._evaluate(x, out, *args, **kwargs)
        out["F"] = 0.5 * (1 + g[:, None]) - out["F"]


#problem = get_problem("dtlz1", None, 3, k=5)
problem = InvertedDTLZ1(n_obj=3)

ref_dirs = UniformReferenceDirectionFactory(3, n_points=91).do()

pf = problem.pareto_front(ref_dirs)

res = minimize(problem,
               method='nsga3',
               method_args={
                   'pop_size': 100,
                   'ref_dirs': ref_dirs,
                   },
               termination=('n_gen', 500),
               #pf=pf,
               seed=1,
               disp=True)

closest_to_ref_dir = res.opt.get("closest")
plotting.plot(res.F[closest_to_ref_dir,:], labels=["NSGA-III"], show=False)
#plotting.plot(pf, res.F, labels=["Pareto-front", "NSGA-III"], show=False)
plt.legend()
plt.show()
Example #9
0
problem = get_problem("carside")

#problem = ConvexProblem(DTLZ2(n_var=12, n_obj=3))

n_gen = 400
pop_size = 91
ref_dirs = UniformReferenceDirectionFactory(3, n_partitions=12,
                                            scaling=1.0).do()

# create the pareto front for the given reference lines
pf = problem.pareto_front(
    UniformReferenceDirectionFactory(3, n_partitions=70, scaling=1.0).do())

res = minimize(
    problem,
    method='nsga3',
    method_args={
        'pop_size': 91,
        'ref_dirs': ref_dirs,
        'survival': DSSSurvival()
    },
    termination=('n_gen', n_gen),
    # pf=pf,
    save_history=True,
    seed=31,
    disp=True)

#plotting.plot(pf, res.F, labels=["Pareto-front", "F"])
plotting.plot(res.F, labels=["F"])
Example #10
0
# create the reference directions to be used for the optimization
ref_points = np.array([[0.3, 0.4], [0.8, 0.5]])

res = minimize(problem,
               method='rnsga3',
               method_args={
                   'ref_points': ref_points,
                   'pop_per_ref_point': 50,
                   'mu': 0.1
               },
               termination=('n_gen', 400),
               pf=pf,
               disp=True)
plotting.plot(pf,
              res.F,
              ref_points,
              show=True,
              labels=['pf', 'F', 'ref_points'])

problem = get_problem("dtlz4", n_var=12, n_obj=3)
ref_dirs = UniformReferenceDirectionFactory(3, n_points=91).do()
pf = problem.pareto_front(ref_dirs)

# create the reference directions to be used for the optimization
ref_points = np.array([[1.0, 0.5, 0.2], [0.3, 0.2, 0.6]])

res = minimize(problem,
               method='rnsga3',
               method_args={
                   'ref_points': ref_points,
                   'pop_per_ref_point': 91,
from pymoo.optimize import minimize
from pymoo.algorithms.nsga2 import nsga2
from pymoo.util import plotting
import numpy as np

from pymop.factory import get_problem

# create the algorithm object
method = nsga2(pop_size=100, elimate_duplicates=True)

# execute the optimization
res = minimize(get_problem("zdt1"), method, termination=('n_gen', 200))

print("Best solution found: %s" % res.X)
print("Function value: %s" % res.F)
print("Constraint violation: %s" % res.CV)

plotting.plot(res.F, no_fill=True)