Example #1
0
    def __init__(self):
        # DEAP stores fitness values in a Fitness class, which offers some basic operations. (See base.py.)
        # Must set the "weights" before instantiating the Fitness class.
        # Since we will have only a single fitness value, the weights, which must be a tuple,
        # will always be either (1,) (to maximize) or (-1, ) (to minimize).
        # (Or to minimize can use negative weights as in set_fitness below.)
        base.Fitness.weights = (-1, )
        self.fitness = base.Fitness()

        self.parent_1 = self.parent_2 = self.pre_mutation = None

        # Individual is a subclass of list. So must have a list.
        the_list = sample(list(range(1, 10)), 9)
        super().__init__(the_list)
Example #2
0
    def __init__(self):
        # DEAP stores fitness values in a Fitness class, which offers some basic operations. (See base.py.)
        # Must set the "weights" before instantiating the Fitness class.
        # The weights which must be a tuple. We use it to keep track of
        # the actual fitness along with the rotation and the ending positions.
        base.Fitness.weights = (1, )
        self.fitness = base.Fitness()

        # Define these here to keep PyCharm happy
        self.best_positions = None
        self.parent_1 = self.parent_2 = self.pre_mutation = None

        # The class Individual is a subclass of list. So must have a list.
        # Every candidate solution will be a permutation of range(8).
        the_list = sample(Individual.indices, Individual.positions)
        super().__init__(the_list)