Example #1
0
 def optimal_solution(self, k, l, pos_params):
     """Create one Pareto-optimal solution with given position parameters."""
     # the result vector
     result = []
     result.extend(pos_params)
     # set the distance parameters
     for i in range(k, k + l):
         result.append(0.35)
     # scale to the correct domains
     for i in range(k + l):
         result[i] *= 2.0 * (i + 1)
     ind = Individual()
     ind.phenome = result
     return ind
Example #2
0
    def get_optimal_solutions(self, max_number=100):
        """Return Pareto-optimal solutions.

        .. note:: The returned solutions do not yet contain the objective
            values.

        Parameters
        ----------
        max_number : int, optional
            As the number of Pareto-optimal solutions is infinite, the
            returned set has to be restricted to a finite sample.

        Returns
        -------
        solutions : list of Individual
            The Pareto-optimal solutions

        """
        assert max_number > 1
        solutions = []
        for i in range(max_number):
            phenome = [0.0] * self.num_variables
            phenome[0] = float(i) / float(max_number - 1)
            solutions.append(Individual(phenome))
        return solutions
Example #3
0
    def get_optimal_solutions(self, max_number=None):
        """Return globally optimal solutions.

        Parameters
        ----------
        max_number : int, optional
            Potentially restrict the number of optima.

        Returns
        -------
        optima : list of Individual

        """
        # test peaks
        optima = []
        max_height = -1.0
        opt_phenomes = []
        for peak in self.peaks:
            if peak.height > max_height:
                opt_phenomes = [peak]
                max_height = peak.height
            elif peak.height == max_height:
                opt_phenomes.append(peak)
        for phenome in opt_phenomes:
            optima.append(Individual(phenome=list(phenome)))
        if max_number is not None:
            optima = optima[:max_number]
        return optima
Example #4
0
    def get_optimal_solutions(self, max_number=None):
        """Return Pareto-optimal solutions.

        .. note:: The returned solutions do not yet contain the objective
            values.

        Parameters
        ----------
        max_number : int, optional
            Optionally restrict the number of solutions.

        Returns
        -------
        solutions : list of Individual
            The Pareto-optimal solutions

        """
        assert max_number is None or max_number > 0
        individuals = []
        for i in range(self.num_variables + 1):
            opt = Individual([1] * i + [0] * (self.num_variables - i))
            individuals.append(opt)
        if max_number is not None:
            individuals = individuals[:max_number]
        return individuals
Example #5
0
 def optimal_solution(self, k, l, pos_params):
     """Create one Pareto-optimal solution with given position parameters."""
     result = []
     result.extend(pos_params)
     # calculate the distance parameters
     for i in range(k, k + l):
         w = [1.0] * len(result)
         u = r_sum(result, w)
         tmp1 = abs(math.floor(0.5 - u) + 0.98 / 49.98)
         tmp2 = 0.02 + 49.98 * (0.98 / 49.98 - (1.0 - 2.0 * u) * tmp1)
         result.append(pow(0.35, pow(tmp2, -1.0)))
     # scale to the correct domains
     for i in range(k + l):
         result[i] *= 2.0 * (i + 1)
     ind = Individual()
     ind.phenome = result
     return ind
Example #6
0
 def optimal_solution(self, k, l, pos_params):
     """Create one Pareto-optimal solution with given position parameters."""
     result = []
     result.extend(pos_params)
     result.extend([0.0] * l)
     # calculate the distance parameters
     result[k + l - 1] = 0.35
     for i in range(k + l - 2, k - 1, -1):
         result_sub = []
         for j in range(i + 1, k + l):
             result_sub.append(result[j])
         w = [1.0] * len(result_sub)
         tmp1 = r_sum(result_sub, w)
         result[i] = pow(0.35, pow(0.02 + 1.96 * tmp1, -1.0))
     # scale to the correct domains
     for i in range(k + l):
         result[i] *= 2.0 * (i + 1)
     ind = Individual()
     ind.phenome = result
     return ind
Example #7
0
    def get_optimal_solutions(self, max_number=None):
        """Return the optimal solution.

        .. note:: The returned solution does not yet contain the objective
            values.

        Returns
        -------
        solutions : list of Individual

        """
        assert max_number is None or max_number > 0
        opt = Individual([1] * self.num_variables)
        return [opt]
Example #8
0
    def get_locally_optimal_solutions(self, max_number=None):
        """Return locally optimal solutions (includes global ones).

        Parameters
        ----------
        max_number : int, optional
            Potentially restrict the number of optima.

        Returns
        -------
        optima : list of Individual

        """
        get_active_peak = self.get_active_peak
        # test peaks
        local_optima = []
        peaks = np.vstack(self.peaks)
        for i, peak in enumerate(peaks):
            if get_active_peak(peak) is self.peaks[i]:
                local_optima.append(Individual(phenome=list(peak)))
        if max_number is not None:
            local_optima = local_optima[:max_number]
        return local_optima
Example #9
0
 def get_optimal_solutions(self, max_number=None):
     return [Individual(self.offsets[0][:self.num_variables])]