# Path: gaft/components/individual.py
# class IndividualBase(object):
#     ''' Base class for individuals.
# 
#     :param ranges: value ranges for all entries in solution.
#     :type ranges: tuple list
# 
#     :param eps: decrete precisions for binary encoding, default is 0.001.
#     :type eps: float or float list (with the same length with ranges)
#     '''
#     # Solution ranges.
#     ranges = SolutionRanges()
# 
#     # Orginal decrete precisions (provided by users).
#     eps = DecretePrecision()
#     
#     # Actual decrete precisions used in GA.
#     precisions = DecretePrecision()
# 
#     def __init__(self, ranges, eps):
#         self.ranges = ranges
#         self.eps = eps
#         self.precisions = eps
# 
#         self.solution, self.chromsome = [], []
# 
#     def init(self, chromsome=None, solution=None):
#         ''' Initialize the individual by providing chromsome or solution.
# 
#         :param chromsome: chromesome sequence for the individual
#         :type chromsome: list of (float / int)
# 
#         :param solution: the variable vector of the target function.
#         :type solution: list of float
# 
#         .. Note::
#             If both chromsome and solution are provided, only the chromsome would
#             be used. If neither is provided, individual would be initialized randomly.
#         '''
#         if not any([chromsome, solution]):
#             self.solution = self._rand_solution()
#             self.chromsome = self.encode()
#         elif chromsome:
#             self.chromsome = chromsome
#             self.solution = self.decode()
#         else:
#             self.solution = solution
#             self.chromsome = self.encode()
# 
#         return self
# 
#     def clone(self):
#         ''' Clone a new individual from current one.
#         '''
#         indv = self.__class__(deepcopy(self.ranges), eps=deepcopy(self.eps))
#         indv.init(chromsome=deepcopy(self.chromsome))
#         return indv
# 
# 
#     def encode(self):
#         ''' **NEED IMPLIMENTATION**
# 
#         Convert solution to chromsome sequence.
# 
#         :return: The chromsome sequence
#         :rtype: list of float
#         '''
#         raise NotImplementedError
# 
#     def decode(self):
#         ''' **NEED IMPLIMENTATION**
# 
#         Convert chromsome sequence to solution.
# 
#         :return: The solution vector
#         :rtype: list of float
#         '''
#         raise NotImplementedError
# 
#     def _rand_solution(self):
#         ''' Initialize individual solution randomly.
#         '''
#         solution = []
#         for eps, (a, b) in zip(self.precisions, self.ranges):
#             n_intervals = (b - a)//eps
#             n = int(uniform(0, n_intervals + 1))
#             solution.append(a + n*eps)
#         return solution


from .individual import IndividualBase

            def extend(this, iterable_item):
                if not iterable_item:
                    return
                super(this.__class__, this).extend(iterable_item)
                # Update population flag.
                self.update_flag()
            # }}}

        self._individuals = IndvList()

    def init(self, indvs=None):
        ''' Initialize current population with individuals.

        :param indvs: Initial individuals in population, randomly initialized
                      individuals are created if not provided.
        :type indvs: list of Individual object
        '''
        IndvType = self.indv_template.__class__

        if indvs is None:
            for _ in range(self.size):
                indv = IndvType(ranges=self.indv_template.ranges,
                                eps=self.indv_template.eps)
                self.individuals.append(indv)
        else:
            # Check individuals.
            if len(indvs) != self.size:
                raise ValueError('Invalid individuals number')
            for indv in indvs:

# Path: gaft/components/individual.py
# class IndividualBase(object):
#     ''' Base class for individuals.
# 
#     :param ranges: value ranges for all entries in solution.
#     :type ranges: tuple list
# 
#     :param eps: decrete precisions for binary encoding, default is 0.001.
#     :type eps: float or float list (with the same length with ranges)
#     '''
#     # Solution ranges.
#     ranges = SolutionRanges()
# 
#     # Orginal decrete precisions (provided by users).
#     eps = DecretePrecision()
#     
#     # Actual decrete precisions used in GA.
#     precisions = DecretePrecision()
# 
#     def __init__(self, ranges, eps):
#         self.ranges = ranges
#         self.eps = eps
#         self.precisions = eps
# 
#         self.solution, self.chromsome = [], []
# 
#     def init(self, chromsome=None, solution=None):
#         ''' Initialize the individual by providing chromsome or solution.
# 
#         :param chromsome: chromesome sequence for the individual
#         :type chromsome: list of (float / int)
# 
#         :param solution: the variable vector of the target function.
#         :type solution: list of float
# 
#         .. Note::
#             If both chromsome and solution are provided, only the chromsome would
#             be used. If neither is provided, individual would be initialized randomly.
#         '''
#         if not any([chromsome, solution]):
#             self.solution = self._rand_solution()
#             self.chromsome = self.encode()
#         elif chromsome:
#             self.chromsome = chromsome
#             self.solution = self.decode()
#         else:
#             self.solution = solution
#             self.chromsome = self.encode()
# 
#         return self
# 
#     def clone(self):
#         ''' Clone a new individual from current one.
#         '''
#         indv = self.__class__(deepcopy(self.ranges), eps=deepcopy(self.eps))
#         indv.init(chromsome=deepcopy(self.chromsome))
#         return indv
# 
# 
#     def encode(self):
#         ''' **NEED IMPLIMENTATION**
# 
#         Convert solution to chromsome sequence.
# 
#         :return: The chromsome sequence
#         :rtype: list of float
#         '''
#         raise NotImplementedError
# 
#     def decode(self):
#         ''' **NEED IMPLIMENTATION**
# 
#         Convert chromsome sequence to solution.
# 
#         :return: The solution vector
#         :rtype: list of float
#         '''
#         raise NotImplementedError
# 
#     def _rand_solution(self):
#         ''' Initialize individual solution randomly.
#         '''
#         solution = []
#         for eps, (a, b) in zip(self.precisions, self.ranges):
#             n_intervals = (b - a)//eps
#             n = int(uniform(0, n_intervals + 1))
#             solution.append(a + n*eps)
#         return solution


# Path: gaft/components/population.py
from .individual import IndividualBase


            def extend(this, iterable_item):
                if not iterable_item:
                    return
                super(this.__class__, this).extend(iterable_item)
                # Update population flag.
                self.update_flag()
            # }}}

        self._individuals = IndvList()

    def init(self, indvs=None):
        ''' Initialize current population with individuals.

        :param indvs: Initial individuals in population, randomly initialized
                      individuals are created if not provided.
        :type indvs: list of Individual object
        '''
        IndvType = self.indv_template.__class__

        if indvs is None:
            for _ in range(self.size):
                indv = IndvType(ranges=self.indv_template.ranges,
                                eps=self.indv_template.eps)
                self.individuals.append(indv)
        else:
            # Check individuals.
            if len(indvs) != self.size:
                raise ValueError('Invalid individuals number')
            for indv in indvs:

                if not isinstance(indv, IndividualBase):