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 test_NSGAII(self): NSGAII( problem=self.problem, population_size=self.population_size, offspring_population_size=self.offspring_size, mutation=self.mutation, crossover=self.crossover, selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator()), termination_criterion=StoppingByEvaluations(max=1000) ).run()
def configure_experiment(problems: dict, n_run: int): jobs = [] max_evaluations = 25000 for run in range(n_run): for problem_tag, problem in problems.items(): jobs.append( Job( algorithm=NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=PolynomialMutation( probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), selection=BinaryTournamentSelection( comparator=RankingAndCrowdingDistanceComparator()), termination_criterion=StoppingByEvaluations( max=max_evaluations)), algorithm_tag='NSGAII', problem_tag=problem_tag, run=run, )) jobs.append( Job( algorithm=GDE3(problem=problem, population_size=100, cr=0.5, f=0.5, termination_criterion=StoppingByEvaluations( max=max_evaluations)), algorithm_tag='GDE3', problem_tag=problem_tag, run=run, )) jobs.append( Job( algorithm=SMPSO( problem=problem, swarm_size=100, mutation=PolynomialMutation( probability=1.0 / problem.number_of_variables, distribution_index=20), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations( max=max_evaluations)), algorithm_tag='SMPSO', problem_tag=problem_tag, run=run, )) return jobs
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: 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))
def setUp(self): self.comparator = RankingAndCrowdingDistanceComparator()
filename='../../../resources/reference_front/{}.pf'.format( problem.get_name())) reference_point = [0.8, 0.5] max_evaluations = 25000 algorithm = NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), selection=BinaryTournamentSelection( comparator=RankingAndCrowdingDistanceComparator()), dominance_comparator=GDominanceComparator(reference_point), termination_criterion=StoppingByEvaluations(max=max_evaluations)) algorithm.observable.register(observer=ProgressBarObserver( max=max_evaluations)) algorithm.observable.register( observer=VisualizerObserver(reference_front=problem.reference_front, reference_point=(reference_point))) algorithm.run() front = algorithm.get_result() # Plot front plot_front = Plot(plot_title='Pareto front approximation', axis_labels=problem.obj_labels,
from jmetal.problem import DTLZ2 from jmetal.util.comparator import RankingAndCrowdingDistanceComparator, DominanceComparator from jmetal.util.observer import ProgressBarObserver, VisualizerObserver if __name__ == '__main__': problem = DTLZ2() problem.reference = '../../resources/reference_front/DTLZ2.3D.pf' max_evaluations = 25000 algorithm = NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator()), termination_criterion=StoppingByEvaluations(max=max_evaluations), dominance_comparator=DominanceComparator() ) algorithm.observable.register(observer=ProgressBarObserver(max=max_evaluations)) algorithm.observable.register(observer=VisualizerObserver(reference_front=problem.reference_front)) algorithm.run() front = algorithm.get_result() label = algorithm.get_name() + "." + problem.get_name() algorithm_name = label # Plot front plot_front = Plot(plot_title='Pareto front approximation', axis_labels=problem.obj_labels) plot_front.plot(front, label=label, filename=algorithm_name)