Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed Jan 22, 2024
1 parent 669c665 commit e1cb6bf
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 231 deletions.
4 changes: 2 additions & 2 deletions examples/multiobjective/moead/moead_iepsilon_lircmop1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions examples/multiobjective/moead/moeaddra_lz09.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -11,17 +12,17 @@
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

algorithm = MOEAD_DRA(
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,
Expand Down
4 changes: 2 additions & 2 deletions examples/multiobjective/smpso/smpso_spark_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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}")
2 changes: 1 addition & 1 deletion examples/multiobjective/smpso/smpso_srinivas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
4 changes: 2 additions & 2 deletions jmetal/algorithm/multiobjective/moead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
67 changes: 0 additions & 67 deletions jmetal/core/test/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class DummyIntegerProblem(IntegerProblem):
<<<<<<< HEAD
def __init__(self):
super(DummyIntegerProblem, self).__init__()

Expand Down Expand Up @@ -37,37 +36,13 @@ 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):
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
Expand All @@ -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]

Expand All @@ -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]

Expand All @@ -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]

Expand Down
87 changes: 3 additions & 84 deletions jmetal/operator/crossover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 0 additions & 28 deletions jmetal/operator/test/test_crossover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from unittest import mock

from jmetal.core.operator import Crossover
<<<<<<< HEAD
from jmetal.core.solution import (
BinarySolution,
CompositeSolution,
Expand All @@ -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):
Expand Down Expand Up @@ -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__(
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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)])
Expand All @@ -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)])
Expand All @@ -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()
Loading

0 comments on commit e1cb6bf

Please sign in to comment.