예제 #1
0
               verbose=False)

print(ret.F)

with Video(GIF("animation.gif")) as vid:
    for algorithm in ret.history:

        if algorithm.n_gen % 5 == 0:
            X, F = algorithm.pop.get("X", "F")
            nds = NonDominatedSorting().do(F, only_non_dominated_front=True)
            other = [k for k in range(len(F)) if k not in nds]

            fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))
            fig.suptitle("%s - %s - Gen %s" %
                         ("ZDT1", "NSGA2", algorithm.n_gen),
                         fontsize=16)

            pcp = PCP(ax=ax1, bounds=(problem.xl, problem.xu))
            pcp.set_axis_style(color="black", alpha=0.7)
            pcp.add(X[other], color="blue", linewidth=0.5)
            pcp.add(X[nds], color="red", linewidth=2)
            pcp.do()

            sc = Scatter(ax=ax2)
            sc.add(F[other], color="blue")
            sc.add(F[nds], color="red")
            sc.add(problem.pareto_front(), plot_type="line", color="black")
            sc.do()

            vid.record()
예제 #2
0
               termination=('n_gen', 50),
               seed=1,
               save_history=True,
               verbose=False)

print(ret.F)

with Video(GIF("animation.gif")) as vid:
    for algorithm in ret.history:

        if algorithm.n_gen % 1 == 0:
            X, F = algorithm.pop.get("X", "F")
            nds = NonDominatedSorting().do(F, only_non_dominated_front=True)
            other = [k for k in range(len(F)) if k not in nds]

            fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))
            fig.suptitle("%s - %s - Gen %s" % ("ZDT1", "NSGA2", algorithm.n_gen), fontsize=16)

            pcp = PCP(ax=ax1, bounds=(problem.xl, problem.xu))
            pcp.add(X[other], color="blue", linewidth=0.5)
            pcp.add(X[nds], color="red", linewidth=2)
            pcp.do()

            sc = Scatter(ax=ax2)
            sc.add(F[other], color="blue")
            sc.add(F[nds], color="red")
            sc.add(problem.pareto_front(), plot_type="line")
            sc.do()

            vid.record()
예제 #3
0
plt.xlabel("Function Evaluations")
plt.ylabel("Hypervolume")
# fig.savefig(LATEX_DIR + 'convergence.eps', format='eps')
plt.show()

from pymoo.factory import get_visualization, get_decomposition

F = res.F
weights = np.array([0.01, 0.99])
decomp = get_decomposition("asf")

# We apply the decomposition and retrieve the best value (here minimum):
I = get_decomposition("asf").do(F, weights).argmin()
print("Best regarding decomposition: Point %s - %s" % (I, F[I]))

plot = get_visualization("scatter")
plot.add(F, color="blue", alpha=0.5, s=30)
plot.add(F[I], color="red", s=40)
plot.do()
# plot.apply(lambda ax: ax.arrow(0, 0, F[I][0], F[I][1], color='black',
# 	head_width=0.001, head_length=0.001, alpha=0.4))
plot.show()

## Parallel Coordinate Plots
from pymoo.visualization.pcp import PCP
plotPCP = PCP().add(res.F).add(res.F[I], color='r').show()

print(
    f'A solução ideal é encontrada para a deformação {res.F[I][0]:.4f}m e massa {res.F[I][0]:.4f}kg com os parametros a {res.X[I][0]:.4f} b {res.X[I][1]:.4f} e h {res.X[I][2]:.4f}'
)
예제 #4
0
from pymoo.factory import get_problem, get_reference_directions
from pymoo.visualization.pcp import PCP

ref_dirs = get_reference_directions("das-dennis", 6, n_partitions=5) * [2, 4, 8, 16, 32, 64]
F = get_problem("dtlz1").pareto_front(ref_dirs)

PCP().add(F).show()
plot = PCP()
plot.set_axis_style(color="grey", alpha=0.5)
plot.add(F, color="grey", alpha=0.3)
plot.add(F[50], linewidth=5, color="red")
plot.add(F[75], linewidth=5, color="blue")
plot.show()

plot.reset()
plot.normalize_each_axis = False
plot.bounds = [[1, 1, 1, 2, 2, 5], [32, 32, 32, 32, 32, 32]]
plot.show()
예제 #5
0
    def notify(self, algorithm):
        problem = algorithm.problem

        pcp = PCP(title=("Gen %s" % algorithm.n_gen, {
            'pad': 30
        }),
                  bounds=(problem.xl, problem.xu),
                  labels=["$x_%s$" % k for k in range(problem.n_var)])
        pcp.set_axis_style(color="grey", alpha=0.5)

        pcp.add(algorithm.pop.get("X"),
                color="black",
                alpha=0.8,
                linewidth=1.5)
        if algorithm.off is not None:
            pcp.add(algorithm.off.get("X"),
                    color="blue",
                    alpha=0.8,
                    linewidth=0.5)

        pcp.add(algorithm.opt.get("X"), color="red", linewidth=4)
        pcp.do()

        self.video.record()
예제 #6
0
파일: clazz.py 프로젝트: zyhuster1/pymoo
import numpy as np

from pymoo.algorithms.nsga3 import NSGA3
from pymoo.factory import get_problem, get_reference_directions
from pymoo.optimize import minimize
from pymoo.visualization.pcp import PCP

p = "dtlz5"

# create the reference directions to be used for the optimization
ref_dirs = get_reference_directions("das-dennis", 5, n_partitions=6)

problem = get_problem(p, n_obj=5)

# create the algorithm object
algorithm = NSGA3(ref_dirs=ref_dirs)

# execute the optimization
ret = minimize(
    problem,
    algorithm,
    # pf=problem.pareto_front(ref_dirs),
    seed=1,
    termination=('n_gen', 1000),
    verbose=True)

np.savetxt("%s_%s.f" % (p, len(ref_dirs)), ret.F)

PCP().add(ret.F).show()
예제 #7
0
# START load_data

from pymoo.factory import get_problem, get_reference_directions

ref_dirs = get_reference_directions("das-dennis", 6,
                                    n_partitions=5) * [2, 4, 8, 16, 32, 64]
F = get_problem("dtlz1").pareto_front(ref_dirs)
# END load_data

# START pcp
from pymoo.visualization.pcp import PCP
PCP().add(F).show()
# END pcp

# START pcp_highlight
plot = PCP()
plot.set_axis_style(color="grey", alpha=0.5)
plot.add(F, color="grey", alpha=0.3)
plot.add(F[50], linewidth=5, color="red")
plot.add(F[75], linewidth=5, color="blue")
plot.show()
# END pcp_highlight

# START pcp_other
plot = PCP(title=("Run", {
    'pad': 30
}),
           n_ticks=10,
           legend=(True, {
               'loc': "upper left"
           }),