def test_SMPSO(self): SMPSO(problem=self.problem, swarm_size=self.population_size, mutation=self.mutation, leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations( max_evaluations=1000)).run()
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)
def configurar_SMPSO(self): algorithm = SMPSO( problem=self.problema, swarm_size=self.maxima_poblacion, mutation=PolynomialMutation(probability=self.probabilidad, distribution_index=20), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones)) return algorithm
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), termination_criterion=StoppingByEvaluations( max_evaluations=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_evaluations=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_evaluations=max_evaluations), ), algorithm_tag="SMPSO", problem_tag=problem_tag, run=run, )) return jobs
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_constructor_create_a_valid_object(self): problem = self.__DummyFloatProblem() algorithm = SMPSO(problem=problem, swarm_size=100, max_evaluations=200, mutation=Polynomial(probability=1.0 / problem.number_of_variables), leaders=BoundedArchive[FloatSolution](100)) self.assertEqual(1.5, algorithm.c1_min) self.assertEqual(2.5, algorithm.c1_max) self.assertEqual(1.5, algorithm.c2_min) self.assertEqual(2.5, algorithm.c2_max) self.assertEqual(0.1, algorithm.min_weight) self.assertEqual(0.1, algorithm.max_weight) self.assertEqual(-1.0, algorithm.change_velocity1) self.assertEqual(-1.0, algorithm.change_velocity2) self.assertEqual(200, algorithm.max_evaluations) self.assertEqual((100, 2), algorithm.speed.shape) numpy.testing.assert_array_almost_equal(numpy.array([2.0, 2.0]), algorithm.delta_max) numpy.testing.assert_array_almost_equal(algorithm.delta_max * -1.0, algorithm.delta_min)
from jmetal.lab.visualization import InteractivePlot, Plot from jmetal.operator import PolynomialMutation from jmetal.problem import DTLZ1 from jmetal.util.archive import CrowdingDistanceArchive from jmetal.util.observer import ProgressBarObserver from jmetal.util.solutions import print_function_values_to_file, print_variables_to_file from jmetal.util.termination_criterion import StoppingByEvaluations 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())
def f2(x: [float]): return (x[0] - 2) * (x[0] - 2) problem = OnTheFlyFloatProblem() problem \ .set_name('Schaffer') \ .add_variable(-10000.0, 10000.0) \ .add_function(f1) \ .add_function(f2) 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_evaluations=max_evaluations)) algorithm.run() front = algorithm.get_result() # Save results to file print_function_values_to_file(front, 'FUN.' + algorithm.label) print_variables_to_file(front, 'VAR.' + algorithm.label) print(f'Algorithm: ${algorithm.get_name()}') print(f'Problem: ${problem.get_name()}') print(f'Computing time: ${algorithm.total_computing_time}')
def configurar_algoritmo(self, hora_show: datetime, hora_minima: datetime = datetime.time(0, 0), algoritmo: str = 'MOGA', mutation_probability: float = 0.25, max_evaluations: int = 500, population: int = 100): hora_minima, hora_show = self.restricciones_hora( hora_minima, hora_show) if (hora_minima == 0): hora_minima = hora_show - 180 restricciones_baja = list([hora_minima, -100, -100, 0, 0]) restricciones_alta = list([hora_show, 0, 0, 100, 100]) self.problem = HVAC(lower_bound=restricciones_baja, upper_bound=restricciones_alta, number_of_configurations=3) print("algoritmo: ", algoritmo) if algoritmo == 'MOGA': algorithm = MOGA(problem=self.problem, population_size=population, offspring_population_size=population, mutation=IntegerPolynomialMutationD( probability=mutation_probability, distribution_index=20), crossover=SBXCrossoverD( probability=mutation_probability, distribution_index=20), termination_criterion=StoppingByEvaluations( max=max_evaluations), dominance_comparator=DominanceComparator()) elif algoritmo == "NSGAII": algorithm = NSGAII(problem=self.problem, population_size=population, offspring_population_size=population, mutation=IntegerPolynomialMutationD( probability=mutation_probability, distribution_index=20), crossover=SBXCrossoverD( probability=mutation_probability, distribution_index=20), termination_criterion=StoppingByEvaluations( max=max_evaluations), dominance_comparator=DominanceComparator()) elif algoritmo == 'OMOPSO': algorithm = OMOPSO(problem=self.problem, swarm_size=population, epsilon=0.0075, uniform_mutation=UniformMutation( probability=mutation_probability, perturbation=0.5), non_uniform_mutation=NonUniformMutation( probability=mutation_probability, perturbation=0.5), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations( max=max_evaluations)) elif algoritmo == 'SMPSO': algorithm = SMPSO(problem=self.problem, swarm_size=population, mutation=IntegerPolynomialMutation( probability=mutation_probability, distribution_index=20), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations( max=max_evaluations)) elif algoritmo == 'SPEA2': algorithm = SPEA2(problem=self.problem, population_size=population, offspring_population_size=population, mutation=IntegerPolynomialMutationD( probability=mutation_probability, distribution_index=20), crossover=SBXCrossoverD( probability=mutation_probability, distribution_index=20), termination_criterion=StoppingByEvaluations( max=max_evaluations), dominance_comparator=DominanceComparator()) else: print("Algoritmo no válido. Creando MOGA por defecto...") algorithm = MOGA(problem=self.problem, population_size=population, offspring_population_size=population, mutation=IntegerPolynomialMutationD( probability=mutation_probability, distribution_index=20), crossover=SBXCrossoverD( probability=mutation_probability, distribution_index=20), termination_criterion=StoppingByEvaluations( max=max_evaluations), dominance_comparator=DominanceComparator()) self.algoritmo = algorithm self.algoritmo.observable.register(observer=ProgressBarObserver( max=max_evaluations)) return algorithm
from jmetal.util.solution import ( print_function_values_to_file, print_variables_to_file, read_solutions, ) from jmetal.util.termination_criterion import StoppingByEvaluations if __name__ == "__main__": problem = ZDT1Modified() problem.reference_front = read_solutions(filename="resources/reference_front/ZDT1.pf") max_evaluations = 100 algorithm = SMPSO( problem=problem, swarm_size=10, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), leaders=CrowdingDistanceArchive(10), termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations), swarm_evaluator=SparkEvaluator(), ) algorithm.run() front = algorithm.get_result() # Save results to file print_function_values_to_file(front, "FUN." + algorithm.get_name() + "." + problem.get_name()) print_variables_to_file(front, "VAR." + algorithm.get_name() + "." + problem.get_name()) print(f"Algorithm: {algorithm.get_name()}") print(f"Problem: {problem.get_name()}") print(f"Computing time: {algorithm.total_computing_time}")
from jmetal.operator import PolynomialMutation from jmetal.problem import DTLZ1 from jmetal.util.archive import CrowdingDistanceArchive from jmetal.util.observer import ProgressBarObserver from jmetal.util.solution_list import print_function_values_to_file, print_variables_to_file, read_solutions from jmetal.util.termination_criterion import StoppingByEvaluations from jmetal.util.visualization import InteractivePlot, Plot if __name__ == '__main__': problem = DTLZ1(number_of_objectives=5) #problem.reference_front = read_solutions(filename='../../resources/reference_front/DTLZ1.3D.pf') 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=25000)) algorithm.observable.register(observer=ProgressBarObserver(max=25000)) algorithm.run() front = algorithm.get_result() # Plot front label = '{}-{} with {} objectives'.format(algorithm.get_name(), problem.get_name(), problem.number_of_objectives) plot_front = Plot(plot_title='Pareto front approximation',