Пример #1
0
    def setUp(self) -> None:
        problem1 = OneMax(number_of_bits=512)

        self.emas1 = Emas(
            problem=problem1,
            initial_population_size=1000,
            initial_inidividual_energy=10,
            reproduction_threshold=20,
            energy_exchange_operator=FractionEnergyExchange(0.5),
            death_operator=ThresholdDeath(threshold=5, neighbours_operator=RandomNeighbours()),
            termination_criterion=StoppingByEvaluations(max_evaluations=100000),
            neighbours_operator=RandomNeighbours(),
            reproduction_operator=FractionEnergyReproduction(0.5, BitFlipMutation(0.5), SPXCrossover(0.5))
        )

        problem2 = Sphere(number_of_variables=10)
        self.emas2 = Emas(
            problem=problem2,
            initial_population_size=1000,
            initial_inidividual_energy=10,
            reproduction_threshold=20,
            energy_exchange_operator=FractionEnergyExchange(0.5),
            death_operator=ThresholdDeath(threshold=5, neighbours_operator=RandomNeighbours()),
            termination_criterion=StoppingByEvaluations(max_evaluations=50000),
            neighbours_operator=RandomNeighbours(),
            reproduction_operator=FractionEnergyReproduction(0.5, PolynomialMutation(0.5), SBXCrossover(0.5))
        )
Пример #2
0
from jmetal.algorithm.singleobjective.simulated_annealing import SimulatedAnnealing
from jmetal.operator import BitFlipMutation
from jmetal.problem import OneMax
from jmetal.util.solution import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    problem = OneMax(number_of_bits=1024)

    max_evaluations = 20000

    algorithm = SimulatedAnnealing(
        problem=problem,
        mutation=BitFlipMutation(probability=1.0 / problem.number_of_bits),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    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: ' + result.get_binary_string())
    print('Fitness:  ' + str(result.objectives[0]))
    print('Computing time: ' + str(algorithm.total_computing_time))
from jmetal.algorithm.singleobjective.simulated_annealing import SimulatedAnnealing
from jmetal.operator import BitFlipMutation
from jmetal.problem import OneMax
from jmetal.util.observer import PrintObjectivesObserver
from jmetal.util.solution_list import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    problem = OneMax(number_of_bits=512)

    max_evaluations = 20000
    algorithm = SimulatedAnnealing(
        problem=problem,
        mutation=BitFlipMutation(probability=1.0 / problem.number_of_bits),
        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: ' + result.get_binary_string())
Пример #4
0
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import BitFlipMutation, SPXCrossover
from jmetal.problem import OneMax
from jmetal.util.comparator import DominanceComparator
from jmetal.util.observer import PrintObjectivesObserver
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__':
    binary_string_length = 512
    problem = OneMax(binary_string_length)

    max_evaluations = 20000

    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        offspring_population_size=1,
        mutation=BitFlipMutation(probability=1.0 / binary_string_length),
        crossover=SPXCrossover(probability=1.0),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
        dominance_comparator=DominanceComparator()
    )

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

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

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