def main() -> None:
    class GGA2(GenerationalGeneticAlgorithm[FloatSolution, FloatSolution]):
        def is_stopping_condition_reached(self):
            # Re-define the stopping condition
            reached = [False, True][self.get_current_computing_time() > 4]

            if reached:
                logger.info("Stopping condition reached!")

            return reached

    variables = 10
    problem = Sphere(variables)
    algorithm = GGA2(problem,
                     population_size=100,
                     max_evaluations=0,
                     mutation=Polynomial(1.0 / variables,
                                         distribution_index=20),
                     crossover=SBX(1.0, distribution_index=20),
                     selection=BinaryTournamentSelection())

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

    logger.info("Algorithm (stop for timeout): " + algorithm.get_name())
    logger.info("Problem: " + problem.get_name())
    logger.info("Solution: " + str(result.variables))
    logger.info("Fitness:  " + str(result.objectives[0]))
def main() -> None:
    class GGA2(GenerationalGeneticAlgorithm[FloatSolution, FloatSolution]):
        def is_stopping_condition_reached(self):
            # Re-define the stopping condition
            reached = [False, True][self.get_current_computing_time() > 4]

            if reached:
                print("Stopping condition reached!")

            return reached

    variables = 10
    problem = Sphere(variables)

    algorithm = GGA2(
        problem=problem,
        population_size=100,
        max_evaluations=0,
        mutation=Polynomial(1.0/variables, distribution_index=20),
        crossover=SBX(1.0, distribution_index=20),
        selection=BinaryTournamentSelection()
    )

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

    print("Algorithm (stop for timeout): " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    print("Solution: " + str(result.variables))
    print("Fitness:  " + str(result.objectives[0]))
    print("Computing time: " + str(algorithm.total_computing_time))
Esempio n. 3
0
def main() -> None:
    variables = 10
    problem = Sphere(variables)
    algorithm = NonElitistEvolutionStrategy[FloatSolution, FloatSolution]\
        (problem, mu=10, lambdA=10, max_evaluations= 50000, mutation=Polynomial(1.0/variables))

    algorithm.run()
    result = algorithm.get_result()
    print("Algorithm: " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    print("Solution: " + str(result.variables))
    print("Fitness:  " + str(result.objectives[0]))
    print("Computing time: " + str(algorithm.total_computing_time))
Esempio n. 4
0
def main() -> None:
    variables = 10
    problem = Sphere(variables)
    algorithm = GenerationalGeneticAlgorithm[FloatSolution, FloatSolution](
        problem,
        population_size=100,
        max_evaluations=25000,
        mutation=Polynomial(1.0/variables, distribution_index=20),
        crossover=SBX(1.0, distribution_index=20),
        selection=BinaryTournamentSelection())

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

    logger.info("Algorithm (continuous problem): " + algorithm.get_name())
    logger.info("Problem: " + problem.get_name())
    logger.info("Solution: " + str(result.variables))
    logger.info("Fitness:  " + str(result.objectives[0]))
def main() -> None:
    variables = 10
    problem = Sphere(variables)

    algorithm = ElitistEvolutionStrategy[FloatSolution, FloatSolution](
        problem=problem,
        mu=10,
        lambd_a=10,
        max_evaluations=50000,
        mutation=Polynomial(probability=1.0/variables)
    )

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

    print("Algorithm: " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    print("Solution: " + str(result.variables))
    print("Fitness:  " + str(result.objectives[0]))
    print("Computing time: " + str(algorithm.total_computing_time))
def main() -> None:
    variables = 10
    problem = Sphere(variables)

    algorithm = ElitistEvolutionStrategy[FloatSolution, FloatSolution](
        problem=problem,
        mu=10,
        lambd_a=10,
        max_evaluations=50000,
        mutation=Polynomial(probability=1.0 / variables))

    algorithm.start()
    print("Algorithm (running as a thread): " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    algorithm.join()

    result = algorithm.get_result()

    print("Solution: " + str(result.variables))
    print("Fitness:  " + str(result.objectives[0]))
    print("Computing time: " + str(algorithm.total_computing_time))
def main() -> None:
    variables = 10
    problem = Sphere(variables)

    algorithm = GenerationalGeneticAlgorithm[FloatSolution, FloatSolution](
        problem=problem,
        population_size=100,
        max_evaluations=25000,
        mutation=Polynomial(probability=1.0/variables, distribution_index=20),
        crossover=SBX(probability=1.0, distribution_index=20),
        selection=BinaryTournamentSelection()
    )

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

    print("Algorithm: " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    print("Solution: " + str(result.variables))
    print("Fitness:  " + str(result.objectives[0]))
    print("Computing time: " + str(algorithm.total_computing_time))
def main() -> None:
    variables = 10
    problem = Sphere(variables)

    algorithm = GenerationalGeneticAlgorithm[FloatSolution, FloatSolution](
        problem=problem,
        population_size=100,
        max_evaluations=25000,
        mutation=Polynomial(probability=1.0 / variables,
                            distribution_index=20),
        crossover=SBX(probability=1.0, distribution_index=20),
        selection=BinaryTournamentSelection())

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

    print("Algorithm: " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    print("Solution: " + str(result.variables))
    print("Fitness:  " + str(result.objectives[0]))
    print("Computing time: " + str(algorithm.total_computing_time))
Esempio n. 9
0
def main() -> None:
    variables = 10
    problem = Sphere(variables)
    algorithm = GenerationalGeneticAlgorithm[FloatSolution, FloatSolution](
        problem,
        population_size=100,
        max_evaluations=25000,
        mutation=Polynomial(1.0 / variables, distribution_index=20),
        crossover=SBX(1.0, distribution_index=20),
        selection=BinaryTournament())

    observer = BasicAlgorithmConsumer(2000)

    algorithm.observable.register(observer=observer)

    algorithm.start()
    algorithm.join()

    result = algorithm.get_result()
    logger.info("Algorithm: " + algorithm.get_name())
    logger.info("Problem: " + problem.get_name())
    logger.info("Solution: " + str(result.variables))
    logger.info("Fitness:  " + str(result.objectives[0]))
Esempio n. 10
0
 def test_should_get_name_return_the_right_name(self):
     problem = Sphere()
     self.assertEqual("Sphere", problem.get_name())
Esempio n. 11
0
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__':
    problem = Sphere(10)

    max_evaluations = 1000000

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

    objectives_observer = PrintObjectivesObserver(frequency=10000)
    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))
    print('Fitness:  ' + str(result.objectives[0]))
    print('Computing time: ' + str(algorithm.total_computing_time))
Esempio n. 12
0
from jmetal.operator import PolynomialMutation
from jmetal.problem.singleobjective.unconstrained import Sphere
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 = Sphere(10)

    max_evaluations = 1000000

    algorithm = LocalSearch(problem=problem,
                            mutation=PolynomialMutation(
                                1.0 / problem.number_of_variables, 20.0),
                            termination_criterion=StoppingByEvaluations(
                                max_evaluations=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: ' + str(result.variables))
    print('Fitness:  ' + str(result.objectives[0]))
    print('Computing time: ' + str(algorithm.total_computing_time))