Exemple #1
0
    def update(self, *args, **kwargs):
        problem = kwargs['PROBLEM']
        solutions = kwargs['SOLUTIONS']

        if solutions:
            if isinstance(problem, DynamicProblem):
                termination_criterion_is_met = kwargs.get('TERMINATION_CRITERIA_IS_MET', None)

                if termination_criterion_is_met:
                    print_function_values_to_file(solutions, '{}/FUN.{}'.format(self.directory, self.counter))
                    self.counter += 1
            else:
                print_function_values_to_file(solutions, '{}/FUN.{}'.format(self.directory, self.counter))
                self.counter += 1
Exemple #2
0
    process, final = Experiment(smrseeds)

    front = get_non_dominated_solutions(final)  #process[-1]
    process.append(front)
    smrprocessruns.append(process)
    reference += front

reference_front = get_non_dominated_solutions(reference)

plot_front = Plot(plot_title='Pareto front approximation',
                  axis_labels=['TRT', 'TDC'],
                  reference_front=None)
plot_front.plot(reference_front, label=' ', filename=fm, format='png')

# Save results to file
print_function_values_to_file(
    reference_front, 'FUN.' + algorithm.get_name() + "-" + problem.get_name())
print_variables_to_file(
    reference_front, 'VAR.' + algorithm.get_name() + "-" + problem.get_name())

# Normalization
timelist = []
costlist = []
for s in reference_front:
    timelist.append(s.objectives[0])
    costlist.append(s.objectives[1])
mintime = min(timelist)
maxtime = max(timelist)
mincost = min(costlist)
maxcost = max(costlist)
print("Time:", mintime, maxtime)
print("Cost:", mincost, maxcost)
if __name__ == '__main__':
    problem = Rastrigin(10)

    max_evaluations = 250000

    algorithm = SimulatedAnnealing(
        problem=problem,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20.0),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    objectives_observer = PrintObjectivesObserver(frequency=1000)
    algorithm.observable.register(observer=objectives_observer)

    algorithm.run()
    result = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(
        result, 'FUN.' + algorithm.get_name() + "." + problem.get_name())
    print_variables_to_file(
        result, 'VAR.' + algorithm.get_name() + "." + problem.get_name())

    print('Algorithm: ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Solution: ' + str(result.variables[0]))
    print('Fitness:  ' + str(result.objectives[0]))
    print('Computing time: ' + str(algorithm.total_computing_time))
Exemple #4
0
        max=max_evaluations))
    algorithm.observable.register(observer=VisualizerObserver(
        reference_front=problem.reference_front))

    algorithm.run()
    front = algorithm.get_result()

    # Plot front
    plot_front = Plot(plot_title='Pareto front approximation',
                      reference_front=problem.reference_front,
                      axis_labels=problem.obj_labels)
    plot_front.plot(front,
                    label=algorithm.label,
                    filename=algorithm.get_name())

    # Plot interactive front
    plot_front = InteractivePlot(plot_title='Pareto front approximation',
                                 reference_front=problem.reference_front,
                                 axis_labels=problem.obj_labels)
    plot_front.plot(front,
                    label=algorithm.label,
                    filename=algorithm.get_name())

    # Save results to file
    print_function_values_to_file(front, 'FUN.' + algorithm.label)
    print_variables_to_file(front, 'VAR.' + algorithm.label)

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import SBXCrossover, PolynomialMutation
from jmetal.util.solutions_utils import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    problem = ZDT1Modified()

    max_evaluations = 100

    algorithm = NSGAII(
        problem=problem,
        population_size=10,
        offspring_population_size=10,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20),
        crossover=SBXCrossover(probability=1.0, distribution_index=20),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(front, 'FUN.NSGAII.ZDT1')
    print_variables_to_file(front, 'VAR.NSGAII.ZDT1')

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))