Example #1
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()
Example #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()