コード例 #1
0
def test_problem_1():

    problem = DTLZ2_TEST_Problems("DTLZ2")
    algorithm = NSGAII(problem)
    algorithm.options['max_population_number'] = 100
    algorithm.options['max_population_size'] = 100
    algorithm.run()

    b = Results(problem)

    solution = b.pareto_values()

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection='3d')
    ax.scatter([s[0] for s in solution], [s[1] for s in solution],
               [s[2] for s in solution])
    ax.set_xlim([0, 1.1])
    ax.set_ylim([0, 1.1])
    ax.set_zlim([0, 1.1])

    plt.xlabel("$f_1(x)$")
    plt.ylabel("$f_2(x)$")

    ax.view_init(elev=30.0, azim=15.0)
    plt.show()
コード例 #2
0
ファイル: team_35x_agros.py プロジェクト: tamasorosz/artap
def optim_single():
    problem = AgrosSimple()
    # optimization
    algorithm = NSGAII(problem)
    algorithm.options['max_population_number'] = 100
    algorithm.options['max_population_size'] = 100
    algorithm.run()

    b = Results(problem)
    b.pareto_plot()
コード例 #3
0
def optim_single():
    problem = ProblemAnalytical()

    # optimization
    algorithm = NLopt(problem)
    algorithm.options['algorithm'] = LN_BOBYQA
    algorithm.options['n_iterations'] = 100

    algorithm.run()

    b = Results(problem)
    b.pareto_plot()
コード例 #4
0
ファイル: clutchOPT.py プロジェクト: tamasorosz/artap
def process_results():
    problem = ComsolProblem()
    database_name = "." + os.sep + "data"
    problem.data_store = JsonDataStore(problem,
                                       database_name=database_name,
                                       mode="read")
    problem.data_store.problem.populations = problem.data_store.problem.populations[
        0:-1]
    b = Results(problem.data_store.problem)
    # Plot Results

    F_cost = []
    V_cost = []
    for j in range(0, 50):
        for i in range(0, 50):
            F = problem.data_store.problem.populations[j].individuals[i].costs[
                0]
            V = problem.data_store.problem.populations[j].individuals[i].costs[
                1]
            F_cost.append(F)
            V_cost.append(V)

    pvalues = b.pareto_values()
    f_all = [i[0] for i in pvalues]
    v_all = [i[1] for i in pvalues]

    plt.scatter(F_cost, V_cost, alpha=0.3)
    plt.scatter(f_all, v_all)

    plt.grid()
    plt.xlabel('Force [N]')
    plt.ylabel('Volume [m3]')
    plt.savefig('Pareto_new.pdf')
    plt.show()

    maxF = numpy.amin(F_cost)
    minV = numpy.amin(V_cost)
    print('Max Force: ', maxF, '; Min Volume: ', minV, '\n')
コード例 #5
0
ファイル: single_objective.py プロジェクト: tamasorosz/artap
        x = individual.vector

        # the goal function
        F1 = (x[0] ** 2. + self.H ** 2.) ** 0.5 + ((self.W - x[0]) ** 2. + self.L ** 2.) ** 0.5

        # the evaluate function should give back a list of the calculated objective values, following the defined
        # order in set(Problem) in this case --> ['F1']
        return [F1]


# Optimization with Nelder-Mead
problem_nlm = ArtapProblem()

# set the optimization method
algorithm_nlm = ScipyOpt(problem_nlm)
algorithm_nlm.options['algorithm'] = 'Nelder-Mead'
algorithm_nlm.options['tol'] = 1e-3

# perform the optimization
algorithm_nlm.run()

results_nlm = Results(problem_nlm)

opt = results_nlm.find_optimum('F_1')

print('The exact value of the optimization is at x_1 = 0.5')
print('Optimal solution (Nelder-Mead):', opt)

print(results_nlm.problem.populations)

コード例 #6
0
        f2 = max(sigmaAC, sigmaBC)

        if f2 > 1e5:
            f2 = inf

        return [f1, f2]


problem = TwoBarTrussDesignProblem()
algorithm = NSGAII(problem)
algorithm.options['max_population_number'] = 100
algorithm.options['max_population_size'] = 100
algorithm.run()

b = Results(problem)
solution = b.pareto_values()

print(solution)

# plot solution
plt.scatter([s[0] for s in solution], [s[1] * 1e-3 for s in solution])
plt.xlim([0, 0.1])
plt.ylim([0, 100.])
plt.xlabel("Volume [m3]")
plt.ylabel("Maximum stress [MPa]")

# The values from the original solution
# Original solution of the task with the eps-contraint method
# original Palli et al, 1999
plt.scatter(0.004445, 89.983, c='red')
コード例 #7
0
        cog = self.executor.eval(individual)[
            0]  # method evaluate must return list
        return [cog]

    # This method processes files generated by 3rd party software, depends on files format
    def parse_results(self, output_files, individual):
        with open(output_files[0]) as file:
            content = file.readlines()
            content = content[0]
            content = content.split(',')
            content = [float(i) for i in content[:-1]]
            cogging_torque = max(content) - min(content)
            print('cogging:', cogging_torque)
        return [cogging_torque]


problem = AnsysProblem()  # Creating problem
algorithm = NSGAII(problem)
algorithm.options['max_population_number'] = 5
algorithm.options['max_population_size'] = 4
algorithm.run()

# Post - processing the results
results = Results(problem)

res_individual = results.find_optimum()
print(res_individual.vector)
for i in range(len(problem.parameters)):
    print("{} : {}".format(problem.parameters[i].get("name"),
                           res_individual.vector[i]))
コード例 #8
0
import pylab as plt
import artap.colormaps as cmaps


if __name__ == '__main__':
    problem = Synthetic2D()
    algorithm = EpsMOEA(problem, evaluator_type=EvaluatorType.WORST_CASE)
    algorithm.options['max_population_size'] = 200
    algorithm.options['max_population_number'] = 100
    algorithm.run()
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    [x, y, z] = problem.get_data_2d()
    ax.plot_surface(x, y, z, cmap=cmaps.viridis,
                    linewidth=0, antialiased=True)

    for individual in problem.last_population():
        x_1 = individual.vector[0]
        x_2 = individual.vector[1]
        y = individual.costs[0]
        ax.scatter(x_1, x_2, y, color='red', marker='o')

        for child in individual.children:
            x_1 = child.vector[0]
            x_2 = child.vector[1]
            y = child.costs[0]
            ax.scatter(x_1, x_2, y, color='black', marker='o')
    plt.show()

    results = Results(problem)
コード例 #9
0
        # individual.auxvar = [1.]
        return [f1, f2]


# Initialization of the problem
problem = BiObjectiveTestProblem()

# Perform the optimization iterating over 100 times on 100 individuals.
algorithm = NSGAII(problem)
algorithm.options['max_population_number'] = 100
algorithm.options['max_population_size'] = 100
algorithm.run()

# Post - processing the results
# reads in the result values into the b, results class
results = Results(problem)
results.pareto_values()
results.pareto_plot()

# Convergence plot on a selected goal function and parameter
results.goal_on_parameter_plot('x_2', 'f_2')

# slice = results.goal_on_parameter('x_2', 'f_2', sorted=True)
# import pylab as plt
# plt.plot(slice[0], slice[1])
# plt.show()

# Measure the quality of the solution with the aid of the built-in performace metrics
# We have to define a solution, which is a list of the [x, 1/x] tuples in the given area.
# The reference function can be defined by the following list comprehension:
reference = [(0.1 + x * 4.9 / 1000, 1. / (0.1 + x * 4.9 / 1000)) for x in range(0, 1000)]
コード例 #10
0
            'criteria': 'minimize'
        }]

    def evaluate(self, individual):
        # The individual.vector function contains the problem parameters in the appropriate (previously defined) order
        x1 = individual.vector[0]
        x2 = individual.vector[1]
        f1 = pow(x1, 2) + pow(x2, 2)
        f2 = pow(x1 - 5, 2) + pow(x2 - 5, 2)
        return [f1, f2]


# Initialization of the problem
problem = BiObjectiveTestProblem()

# Perform the optimization iterating over 100 times on 100 individuals.
algorithm = NSGAII(problem)
algorithm.options['max_population_number'] = 1
algorithm.options['max_population_size'] = 1000
algorithm.run()

gr = Results(problem)

# gr.objectives_plot()
# gr.pareto_plot()
# gr.goal_on_index_plot('F_1', population_id=20)
# gr.goal_on_parameter_plot('x_1', 'F_1', population_id=-1)
# gr.parameter_on_parameter_plot('x_1', 'x_2', population_id=0)
# gr.goal_histogram_plot('F_1', population_id=0)
# gr.parameter_on_index_plot('x_1')
コード例 #11
0
ファイル: pd_data_fitting.py プロジェクト: tamasorosz/artap
        for sr in SR1:
            error += (sr[1] - sri(x, sr[0], Uch, tch, c0))**2.

        return [error]


problem = ExponentialFittingSimple()

# Perform the optimization iterating over 100 times on 100 individuals.
algorithm = EpsMOEA(problem)  # NSGA2(problem), SMPSO(problem)
algorithm.options['max_population_number'] = 500
algorithm.options['max_population_size'] = 100
algorithm.options['epsilons'] = 0.05
algorithm.run()

results = Results(problem)
optimum = results.find_optimum('F')
print(optimum)

# data processing
# import matplotlib.pyplot as plt
# import numpy as np
#
# # (tdchi, SRi)
# SR2 = [(1.0, 100.7923), (2.0, 95.58673), (4.0, 85.98188), (6.0, 77.35857), (8.0, 69.6149), (10.0, 62.65971),
#        (15.0, 48.20685), (20.0, 37.13707), (30.0, 22.12758), (50.0, 7.979435), (75.0, 2.29236), (100.0, 0.676797),
#        (150.0, 0.062897), (200.0, 0.062897), (300.0, 6.49E-05), (500.0, 7.75E-09)]
#
# x_val = [x[0] for x in SR2]
# y_val = [x[1] for x in SR2]
# plt.plot(x_val, y_val, 'bo', label="Measured data")
コード例 #12
0
        return None


problem = ProblemBranin()
problem.data_store = SqliteDataStore(problem,
                                     database_name="data.sqlite",
                                     mode="rewrite")

# run optimization
algorithm = NSGAII(problem)
algorithm.options['max_population_number'] = 10
algorithm.options['max_population_size'] = 10
algorithm.options['max_processes'] = 1
algorithm.run()

b = Results(problem)
optimum = b.find_optimum('F_1')  # Takes last cost function
print(optimum.vector, optimum.costs)

problem = None

# surrogate
trained_problem = ProblemBranin()
trained_problem.data_store = SqliteDataStore(trained_problem,
                                             database_name="data.sqlite")

# set custom regressor
trained_problem.surrogate = SurrogateModelSMT(trained_problem)
trained_problem.surrogate.regressor = MGP(theta0=[1e-2],
                                          n_comp=2,
                                          print_prediction=False)