Error with class objects methods and proprities

35 Views Asked by At

I need to create a class schedule that minimizes overcrowding and misalignment. I'm using jmetalpy and jupyternotebook.

I'm creating a class problem so that I can run the NSGAII model with my problem.

However, when I run the code this error appears :

TypeError: Can't instantiate abstract class TimetablingProblem with abstract methods name, number_of_constraints, number_of_objectives

This is my code:

class TimetablingProblem(FloatProblem):
    
    def __init__(self, horarioblank, caracteristicas_salas):
        
        super().__init__()

        self.horarioblank = horarioblank
        self.caracteristicas_salas = caracteristicas_salas

        self.number_of_variables = len(horarioblank)  # Number of shifts
        self.number_of_objectives = 2  # Overcrowding rate and inadequacy rate
        self.number_of_constraints = 0

        self.lower_bound = np.zeros(self.number_of_variables)
        self.upper_bound = np.full(self.number_of_variables, len(caracteristicas_salas) - 1)

    def evaluate(self, solution: FloatSolution) -> None:
        alocacoes_salas = solution.variables

        sobrelotacao = 0
        inadequacao = 0

        for i, turno in enumerate(self.horarioblank):
            sala_alocada = self.caracteristicas_salas.iloc[int(alocacoes_salas[i])]
            inscritos = turno['Inscritos no turno']

            if inscritos > sala_alocada['Capacidade_Normal']:
                sobrelotacao += inscritos - sala_alocada['Capacidade_Normal']

            if sala_alocada['combined'] not in turno['Características reais da sala']:
                inadequacao += 1

        solution.objectives[0] = sobrelotacao
        solution.objectives[1] = inadequacao

    def create_solution(self) -> FloatSolution:
        solution = FloatSolution(
            lower_bound=self.lower_bound,
            upper_bound=self.upper_bound,
            number_of_objectives=self.number_of_objectives,
            number_of_constraints=self.number_of_constraints
        )
        return solution

    def get_name(self) -> str:
        return "Timetabling Problem"

Any idea of what i'm missing here?

0

There are 0 best solutions below