コード例 #1
0
ファイル: rank_and_crowding.py プロジェクト: hihiworld/pymoo
    def _do(self, pop, off, size, return_sorted_idx=False, out=None, **kwargs):

        if off is not None:
            pop.merge(off)

        fronts = NonDominatedRank.calc_as_fronts(pop.F, pop.G)
        rank = NonDominatedRank.calc_from_fronts(fronts)
        crowding = np.zeros(pop.F.shape[0])

        for front in fronts:
            cd_of_front = RankAndCrowdingSurvival.calc_crowding_distance(pop.F[front, :])
            crowding[front] = cd_of_front

        sorted_idx = sorted(range(pop.size()), key=lambda x: (rank[x], -crowding[x]))

        if return_sorted_idx:
            return sorted_idx

        # now truncate the population
        sorted_idx = sorted_idx[:size]
        pop.filter(sorted_idx)
        rank = rank[sorted_idx]
        crowding = crowding[sorted_idx]

        if out is not None:
            out['rank'] = rank
            out['crowding'] = crowding

        return pop
コード例 #2
0
    def _do(self, pop, size, data, return_sorted_idx=False):

        fronts = NonDominatedRank.calc_as_fronts(pop.F, pop.G)
        rank = NonDominatedRank.calc_from_fronts(fronts)
        crowding = np.zeros(pop.F.shape[0])

        for front in fronts:
            cd_of_front = RankAndCrowdingSurvival.calc_crowding_distance(
                pop.F[front, :])
            crowding[front] = cd_of_front

        sorted_idx = sorted(range(pop.size()),
                            key=lambda x: (rank[x], -crowding[x]))

        if return_sorted_idx:
            return sorted_idx

        # now truncate the population
        sorted_idx = sorted_idx[:size]
        pop.filter(sorted_idx)
        rank = rank[sorted_idx]
        crowding = crowding[sorted_idx]

        if data is not None:
            data.rank = rank
            data.crowding = crowding

        return pop