Example #1
0
    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
Example #2
0
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
Example #4
0
 def evaluate_solution(solution: S, problem: Problem) -> None:
     problem.evaluate(solution)
Example #5
0
    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()
Example #6
0
 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)
Example #7
0
 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)
Example #8
0
 def new(self, problem: Problem):
     return problem.create_solution()
Example #9
0
 def evaluate_solution(solution: S, problem: Problem) -> None:
     problem.evaluate(solution)
     if problem.number_of_constraints > 0:
         problem.evaluate_constraints(solution)
Example #10
0
 def evaluate_solution(solution: S, problem: Problem) -> None:
     problem.evaluate(solution)
     if problem.number_of_constraints > 0:
         problem.evaluate_constraints(solution)
Example #11
0
    def evaluate(self, solution_list: List[S], problem: Problem) -> List[S]:
        for solution in solution_list:
            problem.evaluate(solution)

        return solution_list