示例#1
0
文件: smpso.py 项目: moar82/jMetalPy
    def __init__(self,
                 problem: FloatProblem,
                 swarm_size: int,
                 max_evaluations: int,
                 mutation: Mutation[FloatSolution],
                 leaders: BoundedArchive[FloatSolution],
                 evaluator: Evaluator[FloatSolution] = SequentialEvaluator[
                     FloatSolution]()):
        """ This class implements the SMPSO algorithm as described in

        * SMPSO: A new PSO-based metaheuristic for multi-objective optimization
        * MCDM 2009. DOI: `<http://dx.doi.org/10.1109/MCDM.2009.4938830/>`_.

        The implementation of SMPSO provided in jMetalPy follows the algorithm template described in the algorithm
        templates section of the documentation.

        :param problem: The problem to solve.
        :param swarm_size: Swarm size.
        :param max_evaluations: Maximum number of evaluations.
        :param mutation: Mutation operator.
        :param leaders: Archive for leaders.
        :param evaluator: An evaluator object to evaluate the solutions in the population.
        """
        super(SMPSO, self).__init__()
        self.problem = problem
        self.swarm_size = swarm_size
        self.max_evaluations = max_evaluations
        self.mutation = mutation
        self.leaders = leaders
        self.evaluator = evaluator

        self.evaluations = 0

        self.c1_min = 1.5
        self.c1_max = 2.5
        self.c2_min = 1.5
        self.c2_max = 2.5
        self.r1_min = 0.0
        self.r1_max = 1.0
        self.r2_min = 0.0
        self.r2_max = 1.0
        self.min_weight = 0.1
        self.max_weight = 0.1

        self.change_velocity1 = -1
        self.change_velocity2 = -1

        self.dominance_comparator = DominanceComparator()

        self.speed = numpy.zeros(
            (self.swarm_size, self.problem.number_of_variables), dtype=float)
        self.delta_max, self.delta_min = numpy.empty(problem.number_of_variables),\
                                         numpy.empty(problem.number_of_variables)
        for i in range(problem.number_of_variables):
            self.delta_max[i] = (self.problem.upper_bound[i] -
                                 self.problem.lower_bound[i]) / 2.0

        self.delta_min = -1.0 * self.delta_max
示例#2
0
    def __init__(self,
                 problem: FloatProblem,
                 swarm_size: int,
                 max_evaluations: int,
                 mutation: Mutation[FloatSolution],
                 leaders: BoundedArchive[FloatSolution],
                 evaluator: Evaluator[FloatSolution] = SequentialEvaluator[
                     FloatSolution](),
                 reference_point=None,
                 levy: int = 0,
                 levy_decay: int = 0):
        """ This class implements the Multi-Objective variant of chaotic Quantum Behaved Particle Swarm Optimization
        :param problem: The problem to solve.
        :param swarm_size: Swarm size.
        :param max_evaluations: Maximum number of evaluations.
        :param mutation: Mutation operator.
        :param leaders: Archive for leaders.
        :param evaluator: An evaluator object to evaluate the solutions in the population.
        :param levy: turn on levy walk
        :param levy_decay: turn on levy decay 
        """
        super(MOQPSO, self).__init__()
        self.problem = problem
        self.swarm_size = swarm_size
        self.max_evaluations = max_evaluations
        self.mutation = mutation
        self.leaders = leaders
        self.evaluator = evaluator
        self.levy = levy
        self.levy_decay = levy_decay
        self.prev_gbest = None
        self.hypervolume_calculator = HyperVolume(reference_point)

        self.evaluations = 0
        self.beta_swarm = 1.2
        self.g = 0.95
        self.particle_history = {}
        self.objective_history = {0: [], 1: []}
        self.dominance_comparator = DominanceComparator()
        self.constrictors = [
            (problem.upper_bound[i] - problem.lower_bound[i]) / 5000.0
            for i in range(problem.number_of_variables)
        ]

        self.prev_hypervolume = 0
        self.current_hv = 0

        self.hv_changes = []

        self.beta = 3 / 2
        self.sigma = (gamma(1 + self.beta) * sin(pi * self.beta / 2) / (gamma(
            (1 + self.beta) / 2) * self.beta * 2**((self.beta - 1) / 2)))**(
                1 / self.beta)
示例#3
0
    def execute(self, front: List[S]) -> S:
        if front is None:
            raise Exception('The front is null')
        elif len(front) == 0:
            raise Exception('The front is empty')

        result = front[0]
        for solution in front[1:]:
            if DominanceComparator().compare(solution, result) < 0:
                result = solution

        return result
示例#4
0
    def compute_ranking(self, solution_list: List[S]):
        # number of solutions dominating solution ith
        dominating_ith = [0 for _ in range(len(solution_list))]

        # list of solutions dominated by solution ith
        ith_dominated = [[] for _ in range(len(solution_list))]

        # front[i] contains the list of solutions belonging to front i
        front = [[] for _ in range(len(solution_list) + 1)]

        for p in range(len(solution_list) - 1):
            for q in range(p + 1, len(solution_list)):
                dominance_test_result = DominanceComparator().compare(
                    solution_list[p], solution_list[q])
                self.number_of_comparisons += 1

                if dominance_test_result == -1:
                    ith_dominated[p].append(q)
                    dominating_ith[q] += 1
                elif dominance_test_result is 1:
                    ith_dominated[q].append(p)
                    dominating_ith[p] += 1

        for i in range(len(solution_list)):
            if dominating_ith[i] is 0:
                front[0].append(i)
                solution_list[i].attributes['dominance_ranking'] = 0

        i = 0
        while len(front[i]) != 0:
            i += 1
            for p in front[i - 1]:
                if p <= len(ith_dominated):
                    for q in ith_dominated[p]:
                        dominating_ith[q] -= 1
                        if dominating_ith[q] is 0:
                            front[i].append(q)
                            solution_list[q].attributes[
                                'dominance_ranking'] = i

        self.ranked_sublists = [[]] * i
        for j in range(i):
            q = [0] * len(front[j])
            for k in range(len(front[j])):
                q[k] = solution_list[front[j][k]]
            self.ranked_sublists[j] = q

        return self.ranked_sublists
示例#5
0
    def __init__(self,
                 problem: FloatProblem,
                 swarm_size: int,
                 max_evaluations: int,
                 mutation: Mutation[FloatSolution],
                 leaders: BoundedArchive[FloatSolution],
                 evaluator: Evaluator[FloatSolution] = SequentialEvaluator[
                     FloatSolution](),
                 reference_point=None):
        """ This class implements the Multi-Objective variant of Quantum Behaved PSO algorithm  as described in
        :param problem: The problem to solve.
        :param swarm_size: Swarm size.
        :param max_evaluations: Maximum number of evaluations.
        :param mutation: Mutation operator.
        :param leaders: Archive for leaders.
        :param evaluator: An evaluator object to evaluate the solutions in the population.
        """
        super(MOQPSO, self).__init__()
        self.problem = problem
        self.swarm_size = swarm_size
        self.max_evaluations = max_evaluations
        self.mutation = mutation
        self.leaders = leaders
        self.evaluator = evaluator

        self.hypervolume_calculator = HyperVolume(reference_point)

        self.evaluations = 0

        self.g = 0.95

        self.dominance_comparator = DominanceComparator()
        self.constrictors = [
            (problem.upper_bound[i] - problem.lower_bound[i]) / 5000.0
            for i in range(problem.number_of_variables)
        ]

        self.prev_hypervolume = 0
        self.current_hv = 0

        self.hv_changes = []
示例#6
0
 def setUp(self):
     self.comparator = DominanceComparator()
示例#7
0
 def __init__(self):
     super(NonDominatedSolutionListArchive, self).__init__()
     self.comparator = DominanceComparator()
示例#8
0
 def __init__(self, comparator: Comparator = DominanceComparator()):
     super(BinaryTournamentSelection, self).__init__()
     self.comparator = comparator