diff --git a/examples/multiobjective/moead/moead_iepsilon_lircmop1.py b/examples/multiobjective/moead/moead_iepsilon_lircmop1.py index 2b68ea77..2deac8a4 100644 --- a/examples/multiobjective/moead/moead_iepsilon_lircmop1.py +++ b/examples/multiobjective/moead/moead_iepsilon_lircmop1.py @@ -20,8 +20,8 @@ problem=problem, population_size=300, crossover=DifferentialEvolutionCrossover(CR=1.0, F=0.5), - mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), - aggregation_function=Tschebycheff(dimension=problem.number_of_objectives), + mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables(), distribution_index=20), + aggregation_function=Tschebycheff(dimension=problem.number_of_objectives()), neighbor_size=20, neighbourhood_selection_probability=0.9, max_number_of_replaced_solutions=2, diff --git a/examples/multiobjective/moead/moeaddra_lz09.py b/examples/multiobjective/moead/moeaddra_lz09.py index 681963ab..82b4f1e7 100644 --- a/examples/multiobjective/moead/moeaddra_lz09.py +++ b/examples/multiobjective/moead/moeaddra_lz09.py @@ -1,6 +1,7 @@ from jmetal.algorithm.multiobjective.moead import MOEAD_DRA from jmetal.core.quality_indicator import HyperVolume from jmetal.operator import DifferentialEvolutionCrossover, PolynomialMutation +from jmetal.problem.multiobjective.lz09 import LZ09_F1 from jmetal.problem.multiobjective.uf import UF1 from jmetal.util.aggregation_function import Tschebycheff from jmetal.util.solution import ( @@ -11,8 +12,8 @@ from jmetal.util.termination_criterion import StoppingByEvaluations if __name__ == "__main__": - problem = UF1() - problem.reference_front = read_solutions(filename="resources/reference_front/UF1.pf") + problem = LZ09_F1() + problem.reference_front = read_solutions(filename="resources/reference_front/LZ09F1.pf") max_evaluations = 300000 @@ -20,8 +21,8 @@ problem=problem, population_size=600, crossover=DifferentialEvolutionCrossover(CR=1.0, F=0.5), - mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), - aggregation_function=Tschebycheff(dimension=problem.number_of_objectives), + mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables(), distribution_index=20), + aggregation_function=Tschebycheff(dimension=problem.number_of_objectives()), neighbor_size=20, neighbourhood_selection_probability=0.9, max_number_of_replaced_solutions=2, diff --git a/examples/multiobjective/smpso/smpso_spark_evaluator.py b/examples/multiobjective/smpso/smpso_spark_evaluator.py index adb88d83..6e785da1 100644 --- a/examples/multiobjective/smpso/smpso_spark_evaluator.py +++ b/examples/multiobjective/smpso/smpso_spark_evaluator.py @@ -19,7 +19,7 @@ algorithm = SMPSO( problem=problem, swarm_size=10, - mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), + 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(), @@ -33,5 +33,5 @@ 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"Problem: {problem.name()}") print(f"Computing time: {algorithm.total_computing_time}") diff --git a/examples/multiobjective/smpso/smpso_srinivas.py b/examples/multiobjective/smpso/smpso_srinivas.py index caa7bea4..35409cf0 100644 --- a/examples/multiobjective/smpso/smpso_srinivas.py +++ b/examples/multiobjective/smpso/smpso_srinivas.py @@ -27,5 +27,5 @@ print_variables_to_file(front, 'VAR.'+ algorithm.label) print(f'Algorithm: ${algorithm.get_name()}') - print(f'Problem: ${problem.get_name()}') + print(f'Problem: ${problem.name()}') print(f'Computing time: ${algorithm.total_computing_time}') diff --git a/jmetal/algorithm/multiobjective/moead.py b/jmetal/algorithm/multiobjective/moead.py index 69f74ec5..57079285 100644 --- a/jmetal/algorithm/multiobjective/moead.py +++ b/jmetal/algorithm/multiobjective/moead.py @@ -258,8 +258,8 @@ def __utility_function(self): self.saved_values[i] = copy.copy(self.solutions[i]) def __tour_selection(self, depth): - selected = [i for i in range(self.problem.number_of_objectives)] - candidate = [i for i in range(self.problem.number_of_objectives, self.population_size)] + selected = [i for i in range(self.problem.number_of_objectives())] + candidate = [i for i in range(self.problem.number_of_objectives(), self.population_size)] while len(selected) < int(self.population_size / 5.0): best_idd = int(random.random() * len(candidate)) diff --git a/jmetal/core/test/test_problem.py b/jmetal/core/test/test_problem.py index 45cf3935..7af301e1 100644 --- a/jmetal/core/test/test_problem.py +++ b/jmetal/core/test/test_problem.py @@ -5,7 +5,6 @@ class DummyIntegerProblem(IntegerProblem): -<<<<<<< HEAD def __init__(self): super(DummyIntegerProblem, self).__init__() @@ -37,29 +36,6 @@ def evaluate(self, solution: FloatSolution) -> FloatSolution: def name(self) -> str: return "Dummy float problem" -======= - - def __init__(self): - super(DummyIntegerProblem, self).__init__() - - def evaluate(self, solution: IntegerSolution) -> IntegerSolution: - pass - - def get_name(self) -> str: - pass - - -class DummyFloatProblem(FloatProblem): - - def __init__(self): - super(DummyFloatProblem, self).__init__() - - def evaluate(self, solution: FloatSolution) -> FloatSolution: - pass - - def get_name(self) -> str: - pass ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) class FloatProblemTestCases(unittest.TestCase): @@ -67,7 +43,6 @@ def test_should_default_constructor_create_a_valid_problem(self): lower_bound = [-1.0] upper_bound = [1.0] -<<<<<<< HEAD problem = DummyFloatProblem() problem.lower_bound = lower_bound problem.upper_bound = upper_bound @@ -81,32 +56,6 @@ def test_should_default_constructor_create_a_valid_problem(self): def test_should_create_solution_create_a_valid_solution(self): problem = DummyFloatProblem() -======= - def test_should_default_constructor_create_a_valid_problem(self) -> None: - number_of_objectives = 2 - number_of_constraints = 0 - lower_bound = [-1.0] - upper_bound = [1.0] - - problem = DummyFloatProblem() - problem.lower_bound = lower_bound - problem.upper_bound = upper_bound - problem.number_of_constraints = number_of_constraints - problem.number_of_objectives = number_of_objectives - problem.number_of_variables = len(lower_bound) - - self.assertEqual(1, problem.number_of_variables) - self.assertEqual(2, problem.number_of_objectives) - self.assertEqual(0, problem.number_of_constraints) - self.assertEqual([-1], problem.lower_bound) - self.assertEqual([1], problem.upper_bound) - - def test_should_create_solution_create_a_valid_solution(self) -> None: - problem = DummyFloatProblem() - problem.number_of_variables = 2 - problem.number_of_objectives = 2 - problem.number_of_constraints = 0 ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) problem.lower_bound = [-1.0, -2.0] problem.upper_bound = [1.0, 2.0] @@ -120,14 +69,6 @@ class IntegerProblemTestCases(unittest.TestCase): def test_should_default_constructor_create_a_valid_problem(self): problem = DummyIntegerProblem() -<<<<<<< HEAD -======= - def test_should_default_constructor_create_a_valid_problem(self) -> None: - problem = DummyIntegerProblem() - problem.number_of_variables = 1 - problem.number_of_objectives = 2 - problem.number_of_constraints = 0 ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) problem.lower_bound = [-1] problem.upper_bound = [1] @@ -137,17 +78,9 @@ def test_should_default_constructor_create_a_valid_problem(self) -> None: self.assertEqual([-1], problem.lower_bound) self.assertEqual([1], problem.upper_bound) -<<<<<<< HEAD def test_should_create_solution_create_a_valid_solution(self): problem = DummyIntegerProblem() -======= - def test_should_create_solution_create_a_valid_solution(self) -> None: - problem = DummyIntegerProblem() - problem.number_of_variables = 2 - problem.number_of_objectives = 2 - problem.number_of_constraints = 0 ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) problem.lower_bound = [-1, -2] problem.upper_bound = [1, 2] diff --git a/jmetal/operator/crossover.py b/jmetal/operator/crossover.py index 0d558533..d7496a6f 100644 --- a/jmetal/operator/crossover.py +++ b/jmetal/operator/crossover.py @@ -150,9 +150,9 @@ def __init__(self, probability: float, distribution_index: float = 20.0): raise Exception("The distribution index is negative: " + str(distribution_index)) def execute(self, parents: List[FloatSolution]) -> List[FloatSolution]: - Check.that(type(parents[0]) is FloatSolution, "Solution type invalid: " + str(type(parents[0]))) - Check.that(type(parents[1]) is FloatSolution, "Solution type invalid") - Check.that(len(parents) == 2, 'The number of parents is not two: {}'.format(len(parents))) + Check.that(issubclass(type(parents[0]), FloatSolution), "Solution type invalid: " + str(type(parents[0]))) + Check.that(issubclass(type(parents[1]), FloatSolution), "Solution type invalid") + Check.that(len(parents) == 2, "The number of parents is not two: {}".format(len(parents))) offspring = copy.deepcopy(parents) rand = random.random() @@ -304,87 +304,6 @@ def get_name(self) -> str: return "Integer SBX crossover" -class IntegerSBXCrossover(Crossover[IntegerSolution, IntegerSolution]): - __EPS = 1.0e-14 - - def __init__(self, probability: float, distribution_index: float = 20.0): - super(IntegerSBXCrossover, self).__init__(probability=probability) - self.distribution_index = distribution_index - - def execute(self, parents: List[IntegerSolution]) -> List[IntegerSolution]: - Check.that(type(parents[0]) is IntegerSolution, "Solution type invalid") - Check.that(type(parents[1]) is IntegerSolution, "Solution type invalid") - Check.that(len(parents) == 2, 'The number of parents is not two: {}'.format(len(parents))) - - offspring = [copy.deepcopy(parents[0]), copy.deepcopy(parents[1])] - rand = random.random() - - if rand <= self.probability: - for i in range(parents[0].number_of_variables): - value_x1, value_x2 = parents[0].variables[i], parents[1].variables[i] - - if random.random() <= 0.5: - if abs(value_x1 - value_x2) > self.__EPS: - if value_x1 < value_x2: - y1, y2 = value_x1, value_x2 - else: - y1, y2 = value_x2, value_x1 - - lower_bound, upper_bound = parents[0].lower_bound[i], parents[1].upper_bound[i] - - beta = 1.0 + (2.0 * (y1 - lower_bound) / (y2 - y1)) - alpha = 2.0 - pow(beta, -(self.distribution_index + 1.0)) - - rand = random.random() - if rand <= (1.0 / alpha): - betaq = pow(rand * alpha, (1.0 / (self.distribution_index + 1.0))) - else: - betaq = pow(1.0 / (2.0 - rand * alpha), 1.0 / (self.distribution_index + 1.0)) - - c1 = 0.5 * (y1 + y2 - betaq * (y2 - y1)) - beta = 1.0 + (2.0 * (upper_bound - y2) / (y2 - y1)) - alpha = 2.0 - pow(beta, -(self.distribution_index + 1.0)) - - if rand <= (1.0 / alpha): - betaq = pow((rand * alpha), (1.0 / (self.distribution_index + 1.0))) - else: - betaq = pow(1.0 / (2.0 - rand * alpha), 1.0 / (self.distribution_index + 1.0)) - - c2 = 0.5 * (y1 + y2 + betaq * (y2 - y1)) - - if c1 < lower_bound: - c1 = lower_bound - if c2 < lower_bound: - c2 = lower_bound - if c1 > upper_bound: - c1 = upper_bound - if c2 > upper_bound: - c2 = upper_bound - - if random.random() <= 0.5: - offspring[0].variables[i] = int(c2) - offspring[1].variables[i] = int(c1) - else: - offspring[0].variables[i] = int(c1) - offspring[1].variables[i] = int(c2) - else: - offspring[0].variables[i] = value_x1 - offspring[1].variables[i] = value_x2 - else: - offspring[0].variables[i] = value_x1 - offspring[1].variables[i] = value_x2 - return offspring - - def get_number_of_parents(self) -> int: - return 2 - - def get_number_of_children(self) -> int: - return 2 - - def get_name(self) -> str: - return 'Integer SBX crossover' - - class SPXCrossover(Crossover[BinarySolution, BinarySolution]): def __init__(self, probability: float): super(SPXCrossover, self).__init__(probability=probability) diff --git a/jmetal/operator/test/test_crossover.py b/jmetal/operator/test/test_crossover.py index d72de11d..42e0d268 100644 --- a/jmetal/operator/test/test_crossover.py +++ b/jmetal/operator/test/test_crossover.py @@ -3,7 +3,6 @@ from unittest import mock from jmetal.core.operator import Crossover -<<<<<<< HEAD from jmetal.core.solution import ( BinarySolution, CompositeSolution, @@ -25,12 +24,6 @@ InvalidConditionException, NoneParameterException, ) -======= -from jmetal.core.solution import BinarySolution, PermutationSolution, FloatSolution, CompositeSolution, IntegerSolution -from jmetal.operator.crossover import NullCrossover, SPXCrossover, CXCrossover, PMXCrossover, SBXCrossover, \ - CompositeCrossover, IntegerSBXCrossover -from jmetal.util.ckecking import NoneParameterException, EmptyCollectionException, InvalidConditionException ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) class NullCrossoverTestCases(unittest.TestCase): @@ -311,7 +304,6 @@ def test_should_execute_return_the_parents_if_the_crossover_probability_is_zero( self.assertEqual(solution1.variables, offspring[0].variables) self.assertEqual(solution2.variables, offspring[1].variables) -<<<<<<< HEAD def test_should_execute_work_with_a_solution_subclass_of_float_solution(self): class NewFloatSolution(FloatSolution): def __init__( @@ -338,8 +330,6 @@ def __init__( self.assertEqual(solution1.variables, offspring[0].variables) self.assertEqual(solution2.variables, offspring[1].variables) -======= ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) def test_should_execute_produce_valid_solutions_when_crossing_two_single_variable_solutions(self): pass @@ -354,11 +344,7 @@ def test_should_constructor_raise_an_exception_if_the_parameter_list_is_Empty(se CompositeCrossover([]) def test_should_constructor_create_a_valid_operator_when_adding_a_single_crossover_operator(self): -<<<<<<< HEAD crossover: Crossover = SBXCrossover(0.9, 20.0) -======= - crossover: Crossover = SBXCrossover(0.9, 20.0) ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) operator = CompositeCrossover([crossover]) self.assertIsNotNone(operator) @@ -390,13 +376,8 @@ def test_should_execute_work_properly_with_a_single_crossover_operator(self): self.assertIsNotNone(children) self.assertEqual(2, len(children)) -<<<<<<< HEAD self.assertEqual(1, len(children[0].variables)) self.assertEqual(1, len(children[1].variables)) -======= - self.assertEqual(1, children[0].number_of_variables) - self.assertEqual(1, children[1].number_of_variables) ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) def test_should_execute_work_properly_with_a_two_crossover_operators(self): operator = CompositeCrossover([SBXCrossover(0.9, 20.0), IntegerSBXCrossover(0.1, 20.0)]) @@ -417,13 +398,8 @@ def test_should_execute_work_properly_with_a_two_crossover_operators(self): self.assertIsNotNone(children) self.assertEqual(2, len(children)) -<<<<<<< HEAD self.assertEqual(2, len(children[0].variables)) self.assertEqual(2, len(children[1].variables)) -======= - self.assertEqual(2, children[0].number_of_variables) - self.assertEqual(2, children[1].number_of_variables) ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) def test_should_execute_raise_and_exception_if_the_types_of_the_solutions_do_not_match_the_operators(self): operator = CompositeCrossover([SBXCrossover(1.0, 5.0), SPXCrossover(0.9)]) @@ -439,9 +415,5 @@ def test_should_execute_raise_and_exception_if_the_types_of_the_solutions_do_not operator.execute([composite_solution1, composite_solution2]) -<<<<<<< HEAD if __name__ == "__main__": -======= -if __name__ == '__main__': ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) unittest.main() diff --git a/jmetal/operator/test/test_mutation.py b/jmetal/operator/test/test_mutation.py index b2d18fd3..b16eb2e6 100644 --- a/jmetal/operator/test/test_mutation.py +++ b/jmetal/operator/test/test_mutation.py @@ -2,7 +2,6 @@ from typing import List from jmetal.core.operator import Mutation -<<<<<<< HEAD from jmetal.core.solution import ( BinarySolution, CompositeSolution, @@ -22,12 +21,6 @@ InvalidConditionException, NoneParameterException, ) -======= -from jmetal.core.solution import BinarySolution, FloatSolution, IntegerSolution, CompositeSolution -from jmetal.operator.mutation import BitFlipMutation, UniformMutation, SimpleRandomMutation, PolynomialMutation, \ - IntegerPolynomialMutation, CompositeMutation -from jmetal.util.ckecking import NoneParameterException, EmptyCollectionException, InvalidConditionException ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) class PolynomialMutationTestMethods(unittest.TestCase): @@ -301,11 +294,7 @@ def test_should_constructor_raise_an_exception_if_the_parameter_list_is_Empty(se CompositeMutation([]) def test_should_constructor_create_a_valid_operator_when_adding_a_single_mutation_operator(self): -<<<<<<< HEAD mutation: Mutation = PolynomialMutation(0.9, 20.0) -======= - mutation: Mutation = PolynomialMutation(0.9, 20.0) ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) operator = CompositeMutation([mutation]) self.assertIsNotNone(operator) @@ -335,9 +324,5 @@ def test_should_execute_raise_and_exception_if_the_types_of_the_solutions_do_not operator.execute(composite_solution) -<<<<<<< HEAD if __name__ == "__main__": -======= -if __name__ == '__main__': ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) unittest.main() diff --git a/jmetal/problem/multiobjective/uf.py b/jmetal/problem/multiobjective/uf.py index ad76f120..19a6f632 100644 --- a/jmetal/problem/multiobjective/uf.py +++ b/jmetal/problem/multiobjective/uf.py @@ -63,5 +63,5 @@ def evaluate(self, solution: FloatSolution) -> FloatSolution: return solution - def get_name(self): + def name(self): return "UF1" diff --git a/jmetal/util/observer.py b/jmetal/util/observer.py index f7007fa5..7dadb6a7 100644 --- a/jmetal/util/observer.py +++ b/jmetal/util/observer.py @@ -180,17 +180,9 @@ def update(self, *args, **kwargs): class VisualizerObserver(Observer): -<<<<<<< HEAD def __init__( self, reference_front: List[S] = None, reference_point: list = None, display_frequency: int = 1 ) -> None: -======= - - def __init__(self, - reference_front: List[S] = None, - reference_point: list = None, - display_frequency: int = 1) -> None: ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) self.figure = None self.display_frequency = display_frequency diff --git a/jmetal/util/test/test_checking.py b/jmetal/util/test/test_checking.py index 05305957..00201a39 100644 --- a/jmetal/util/test/test_checking.py +++ b/jmetal/util/test/test_checking.py @@ -1,6 +1,5 @@ import unittest -<<<<<<< HEAD from jmetal.util.ckecking import ( Check, InvalidConditionException, @@ -11,14 +10,6 @@ class CheckingTestCases(unittest.TestCase): -======= -from jmetal.util.ckecking import Check, NoneParameterException, InvalidProbabilityValueException, \ - ValueOutOfRangeException, InvalidConditionException - - -class CheckingTestCases(unittest.TestCase): - ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) def test_should_is_not_null_raise_an_exception(self) -> None: with self.assertRaises(NoneParameterException): Check.is_not_none(None) @@ -44,9 +35,5 @@ def test_should_that_raise_an_exception_if_the_expression_is_false(self) -> None Check.that(False, "The expression is false") -<<<<<<< HEAD if __name__ == "__main__": -======= -if __name__ == '__main__': ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) unittest.main() diff --git a/jmetal/util/test/test_neighborhood.py b/jmetal/util/test/test_neighborhood.py index 79f4d491..303e6430 100644 --- a/jmetal/util/test/test_neighborhood.py +++ b/jmetal/util/test/test_neighborhood.py @@ -283,9 +283,5 @@ def test_should_get_neighbors_return_four_neighbors_case4(self): self.assertEqual(2, result.count(solution_list[2])) -<<<<<<< HEAD if __name__ == "__main__": -======= -if __name__ == '__main__': ->>>>>>> 8c0a6cf (Feature/mixed solution (#73)) unittest.main()