def new(self, problem: Problem): if len(self.population) > 0: # If we have more solutions to inject, return one from the list return self.population.pop() else: # Otherwise generate a new solution solution = problem.create_solution() return solution
def solution_comparator(problem: Problem, x: Solution, y: Solution) -> int: val1 = problem.evaluate(x).objectives[0] val2 = problem.evaluate(y).objectives[0] if val1 > val2: return 1 elif val2 > val1: return -1 else: return 0
def load_initial_solutions(self, warm_startup_info: Mapping, problem: Problem) -> None: self.warm_startup_info = warm_startup_info if warm_startup_info and 'paths' in self.warm_startup_info.keys( ) and len(self.warm_startup_info['paths']) > 0: from jmetal.util.generator import InjectorGenerator one_sol_variables = self.warm_startup_info['paths'][0] solution = PermutationSolution( number_of_variables=problem.number_of_variables, number_of_objectives=problem.number_of_objectives) solution.variables = one_sol_variables self._initial_solutions.append(problem.evaluate(solution)) for one_sol_variables in self.warm_startup_info['paths'][1:]: solution = copy(solution) solution.variables = one_sol_variables self._initial_solutions.append(problem.evaluate(solution)) generator = InjectorGenerator(solutions=self._initial_solutions) else: from jmetal.util.generator import RandomGenerator generator = RandomGenerator() self._solution_generator = generator
def evaluate_solution(solution: S, problem: Problem) -> None: problem.evaluate(solution)
def evaluate(self, solution_list: List[S], problem: Problem) -> List[S]: solutions_to_evaluate = self.spark_context.parallelize(solution_list) return solutions_to_evaluate \ .map(lambda s: problem.evaluate(s)) \ .collect()
def __init__(self, problem: Problem, replace: bool = True) -> None: self.display_frequency = 1.0 self.replace = replace self.reference = problem.get_reference_front() self.plot = ScatterMatplotlib('jMetalPy', problem.number_of_objectives)
def test_should_default_constructor_create_a_valid_problem(self) -> None: problem = Problem() self.assertEqual(None, problem.number_of_variables) self.assertEqual(None, problem.number_of_objectives) self.assertEqual(None, problem.number_of_constraints)
def new(self, problem: Problem): return problem.create_solution()
def evaluate_solution(solution: S, problem: Problem) -> None: problem.evaluate(solution) if problem.number_of_constraints > 0: problem.evaluate_constraints(solution)
def evaluate_solution(solution: S, problem: Problem) -> None: problem.evaluate(solution) if problem.number_of_constraints > 0: problem.evaluate_constraints(solution)
def evaluate(self, solution_list: List[S], problem: Problem) -> List[S]: for solution in solution_list: problem.evaluate(solution) return solution_list