def main() -> None: class NSGA2b(NSGAII[S, R]): 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 problem = Fonseca() algorithm = NSGA2b[FloatSolution, List[FloatSolution]]( problem, population_size=100, max_evaluations=25000, mutation=Polynomial(1.0 / problem.number_of_variables, distribution_index=20), crossover=SBX(1.0, distribution_index=20), selection=BinaryTournament(RankingAndCrowdingDistanceComparator())) algorithm.run() result = algorithm.get_result() SolutionListOutput[FloatSolution].print_function_values_to_file( "FUN." + problem.get_name(), result) logger.info("Algorithm (continuous problem): " + algorithm.get_name()) logger.info("Problem: " + problem.get_name())
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=BinaryTournament()) 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: problem = Kursawe() algorithm = NSGAII[FloatSolution, List[FloatSolution]]( problem=problem, population_size=100, max_evaluations=25000, mutation=Polynomial(1.0/problem.number_of_variables, distribution_index=20), crossover=SBX(1.0, distribution_index=20), selection = BinaryTournament(RankingAndCrowdingDistanceComparator())) algorithm.run() result = algorithm.get_result() SolutionListOutput[FloatSolution].print_function_values_to_file("FUN."+problem.get_name(), result) logger.info("Algorithm (continuous problem): " + algorithm.get_name()) logger.info("Problem: " + problem.get_name())
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()) 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 = 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]))
def main() -> None: problem = ZDT1() algorithm = NSGAII[FloatSolution, List[FloatSolution]]( problem, population_size = 100, max_evaluations = 25000, mutation = Polynomial(1.0/problem.number_of_variables, distribution_index=20), crossover = SBX(1.0, distribution_index=20), selection = BinaryTournament(RankingAndCrowdingDistanceComparator())) observer = BasicAlgorithmConsumer(1000) algorithm.observable.register(observer=observer) algorithm.run() result = algorithm.get_result() SolutionListOutput[FloatSolution].print_function_values_to_file("FUN."+problem.get_name(), result) logger.info("Algorithm (continuous problem): " + algorithm.get_name()) logger.info("Problem: " + problem.get_name()) logger.info("Computing time: " + str(algorithm.total_computing_time))