vladofilipovic / universal-optimizer

Universal otimizer library
Apache License 2.0
1 stars 3 forks source link

population_based_metaheuristic possible inaccuracy in code, namely current population setter #90

Open neske99 opened 3 months ago

neske99 commented 3 months ago

Seems like an inaccuracy that was left out because there was no actual instance of population based_metaheuristic_implemented yet. Current population should not be a TargetSolution instance but a list of TargetSolutions.

Current code:

@current_population.setter def current_population(self, value:Optional[list[TargetSolution]])->None:

    if not isinstance(value, TargetSolution) and value is not None:
        raise TypeError('Parameter \'current_population\' must have type \'list[TargetSolution]\' or be None.')
    self.__current_population = value

This is what i suggest:

@current_population.setter def current_population(self, value:Optional[list[TargetSolution]])->None:

    if (not isinstance(value, list) or (isinstance(value,list) and not all(isinstance(x, TargetSolution) for x in value))) and value is not None:
        raise TypeError('Parameter \'current_population\' must have type \'list[TargetSolution]\' or be None.')
    self.__current_population = value