def main() -> None: problem = Kursawe() algorithm = SMPSO(problem=problem, swarm_size=100, max_evaluations=25000, mutation=Polynomial(1.0 / problem.number_of_variables, distribution_index=20), leaders=CrowdingDistanceArchive(100)) 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_should_SMPSO_work_when_solving_problem_ZDT1_with_standard_settings(self): problem = ZDT1() 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_evaluations=25000), ) algorithm.run() front = algorithm.get_result() hv = HyperVolume(reference_point=[1, 1]) value = hv.compute([front[i].objectives for i in range(len(front))]) self.assertTrue(value >= 0.655)
if __name__ == '__main__': problem = DTLZ1(number_of_objectives=5) max_evaluations = 25000 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.observable.register(observer=ProgressBarObserver(max=max_evaluations)) algorithm.run() front = algorithm.get_result() label = algorithm.get_name() + "." + problem.get_name() # 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