def PluRunOff_cowinners(self, profile):
        """
        Returns a list that associates all the winners of a profile under Plurality with Runoff rule.

        :ivar Profile profile: A Profile object that represents an election profile.
        """

        # Currently, we expect the profile to contain complete ordering over candidates. Ties are
        # allowed however.
        elecType = profile.getElecType()
        if elecType != "soc" and elecType != "toc" and elecType != "csv":
            print("ERROR: unsupported election type")
            exit()

        # Initialization
        prefcounts = profile.getPreferenceCounts()
        len_prefcounts = len(prefcounts)
        rankmaps = profile.getRankMaps()
        ranking = MechanismPlurality().getRanking(profile)

        known_winners = set()
        # 1st round: find the top 2 candidates in plurality scores
        top_2_combinations = []
        if len(ranking[0][0]) > 1:
            for cand1, cand2 in itertools.combinations(ranking[0][0], 2):
                top_2_combinations.append([cand1, cand2])
        else:
            max_cand = ranking[0][0][0]
            if len(ranking[0][1]) > 1:
                for second_max_cand in ranking[0][1]:
                    top_2_combinations.append([max_cand, second_max_cand])
            else:
                second_max_cand = ranking[0][1][0]
                top_2_combinations.append([max_cand, second_max_cand])

        # 2nd round: find the candidate with maximum plurality score
        for top_2 in top_2_combinations:
            dict_top2 = {top_2[0]: 0, top_2[1]: 0}
            for i in range(len_prefcounts):
                vote_top2 = {key: value for key, value in rankmaps[i].items() if key in top_2}
                top_position = min(vote_top2.values())
                keys = [x for x in vote_top2.keys() if vote_top2[x] == top_position]
                for key in keys:
                    dict_top2[key] += prefcounts[i]

            max_value = max(dict_top2.values())
            winners = [y for y in dict_top2.keys() if dict_top2[y] == max_value]
            known_winners = known_winners | set(winners)

        return sorted(known_winners)
def PluRunOff_cowinners ( self , profile ) : elecType = profile . getElecType ( ) if elecType != "soc" and elecType != "toc" and elecType != "csv" : print ( "ERROR: unsupported election type" ) exit ( ) prefcounts = profile . getPreferenceCounts ( ) len_prefcounts = len ( prefcounts ) rankmaps = profile . getRankMaps ( ) ranking = MechanismPlurality ( ) . getRanking ( profile ) known_winners = set ( ) top_2_combinations = [ ] if len ( ranking [ 0 ] [ 0 ] ) > 1 : for cand1 , cand2 in itertools . combinations ( ranking [ 0 ] [ 0 ] , 2 ) : top_2_combinations . append ( [ cand1 , cand2 ] ) else : max_cand = ranking [ 0 ] [ 0 ] [ 0 ] if len ( ranking [ 0 ] [ 1 ] ) > 1 : for second_max_cand in ranking [ 0 ] [ 1 ] : top_2_combinations . append ( [ max_cand , second_max_cand ] ) else : second_max_cand = ranking [ 0 ] [ 1 ] [ 0 ] top_2_combinations . append ( [ max_cand , second_max_cand ] ) for top_2 in top_2_combinations : dict_top2 = { top_2 [ 0 ] : 0 , top_2 [ 1 ] : 0 } for i in range ( len_prefcounts ) : vote_top2 = { key : value for key , value in rankmaps [ i ] . items ( ) if key in top_2 } top_position = min ( vote_top2 . values ( ) ) keys = [ x for x in vote_top2 . keys ( ) if vote_top2 [ x ] == top_position ] for key in keys : dict_top2 [ key ] += prefcounts [ i ] max_value = max ( dict_top2 . values ( ) ) winners = [ y for y in dict_top2 . keys ( ) if dict_top2 [ y ] == max_value ] known_winners = known_winners | set ( winners ) return sorted ( known_winners )
Returns a list that associates all the winners of a profile under Plurality with Runoff rule.

        :ivar Profile profile: A Profile object that represents an election profile.