Beispiel #1
0
def generate_point(nobjs, population_size):
    # define the problem definition
    problem = DTLZ2(nobjs=nobjs)
    # instantiate the optimization algorithm
    algorithm = NSGAII(problem, population_size=population_size)
    algorithm.run(1000)
    # mutate_point = RandomGenerator().generate(problem=problem)
    return algorithm.result[0].objectives._data
    pass
Beispiel #2
0
def draw_pareto():
    # define the problem definition
    problem = DTLZ2(nobjs=2)

    # instantiate the optimization algorithm
    algorithm = NSGAII(problem, population_size=20)

    # optimize the problem using 10,000 function evaluations
    algorithm.run(10000)

    # plot the results using matplotlib
    plt.figure(figsize=(6, 6), dpi=80)
    plt.figure()
    plt.subplot(111)
    plt.scatter([s.objectives[1] for s in algorithm.result],
                [s.objectives[0] for s in algorithm.result],
                s=36,
                color='blue')
    plt.xlim([0, 1.1])
    plt.ylim([0, 1.1])
    plt.xlabel("$f_1(x)$")
    plt.ylabel("$f_2(x)$")

    plt.show()
Beispiel #3
0
import random
from platypus import (NSGAII, DTLZ2, Solution, EpsilonBoxArchive, GenerationalDistance, InvertedGenerationalDistance,
                      Hypervolume, EpsilonIndicator, Spacing)


from platypus import *

# create the problem
problem = DTLZ2(3)

# solve it using NSGA-II
algorithm = NSGAII(problem)
algorithm.run(10000)

# generate the reference set for 3D DTLZ2
reference_set = EpsilonBoxArchive([0.02, 0.02, 0.02])

for _ in range(1000):
    solution = Solution(problem)
    solution.variables = [random.uniform(0,1) if i < problem.nobjs-1 else 0.5 for i in range(problem.nvars)]
    solution.evaluate()
    reference_set.add(solution)

# compute the indicators
gd = GenerationalDistance(reference_set)
print("Generational Distance:", gd.calculate(algorithm.result))

igd = InvertedGenerationalDistance(reference_set)
print("Inverted Generational Distance:", igd.calculate(algorithm.result))

hyp = Hypervolume(reference_set)
Beispiel #4
0
def main():

    # define refer point
    reference_point = [1.5, 1.5]

    # define the problem definition
    problem = DTLZ2(nobjs=2)

    # instantiate the optimization algorithm
    algorithm = NSGAII(problem, population_size=5)

    point_list = write_pareto(problem, algorithm)
    i = 1
    k = 1
    plt.rcParams.update({'figure.max_open_warning': 0})
    while i <= 3125:  # 1 5 25 625 3125 15625
        if math.log(i, 5).is_integer():
            flag = 1
        else:
            flag = 0
        if flag:
            plt.figure(figsize=(6, 18), dpi=80)
            fig = plt.figure(k)
            k = k + 1
            # i-311
            plt.subplot(311)
            plt.title('dtlz2-' + str(i) + '-1', fontsize=14)
            draw_point(plt, reference_point)
            # drawsphere(plt)
            draw_point_list(plt, point_list=point_list)

        if flag:
            # i - 312
            plt.subplot(312)
            plt.title('dtlz2-' + str(i) + '-2', fontsize=14)
            # drawsphere(plt)
            draw_point_list(plt, point_list)
            draw_point(plt, reference_point)
        # mutation point
        mutate_point = generate_point(nobjs=2, population_size=1)
        if flag:
            plt.scatter(mutate_point[0],
                        mutate_point[1],
                        s=60,
                        c='black',
                        marker='+')

        # pop + 1 hyper volume compute
        point_collection, hyp_value = hyp_compute(
            point_list, mutate_point, reference_point=reference_point)
        # pop + 1 hyper volume compute

        # loop until hyper nearly not change

        point_list, hyper_max = list_max(point_list, hyp_value, mutate_point)

        # i - 313
        if flag:
            plt.subplot(313)
            plt.title('dtlz2-' + str(i) + '-3', fontsize=14)
            # drawsphere(plt)
            draw_point_list(plt, point_list)
            draw_point(plt, reference_point)
            # print hyp_value
            print('Current order is %d, and the hyper_max is %10f' %
                  (i, hyper_max))

        i = i + 1
        # pop mutation
        fig.tight_layout()
    # loop until hyper nearly not change

    # change each children graph distance
    fig.tight_layout()
    plt.show()
    pass
Beispiel #5
0
from platypus import NSGAII, NSGAIII, DTLZ2, Hypervolume, experiment, calculate, display

if __name__ == "__main__":
    algorithms = [NSGAII, (NSGAIII, {"divisions_outer": 12})]
    problems = [DTLZ2(3)]

    # run the experiment
    results = experiment(algorithms, problems, nfe=10000, seeds=10)

    # calculate the hypervolume indicator
    hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
    hyp_result = calculate(results, hyp)
    display(hyp_result, ndigits=3)