Exemplo n.º 1
0
    def swapMembers(self, teams):
        '''
            Swaps members within teams and re-calculates ratings

            @param:
                teams: [Team] - a list of teams
            
            @returns:
                teams: [Team] - swapped teams
        '''
        size = len(teams)

        if (size == 1):
            return teams

        #need to create new teams to move members around
        new_teams = []
        for i in range(size):
            new_t = Team()
            new_t.deepCopy(teams[i])
            new_teams.append(new_t)

        for i in range(size):
            swp_idx = i
            while swp_idx == i:
                swp_idx = randrange(size)

            s1 = new_teams[i].getMemberList().pop()
            s2 = new_teams[swp_idx].getMemberList().pop()

            new_teams[i].insertStudent(s2)
            new_teams[swp_idx].insertStudent(s1)

            self.weightCalc(new_teams[i])
            self.weightCalc(new_teams[swp_idx])

        return new_teams
Exemplo n.º 2
0
    def swapMembers(self, teams):
        '''
            Swaps members within teams and re-calculates ratings

            @param:
                teams: [Team] - a list of teams
            
            @returns:
                teams: [Team] - swapped teams
        '''
        size = len(teams)

        if (size == 1):
            new_teams = SwapList()
            new_t = Team()
            new_t.deepCopy(teams[0])
            new_teams.append(new_t)
            return teams

        if DEBUG:
            print("\n\nin teams: ")
            for t in teams:
                print("**")
                print(t)
                print("**")

        #need to create new teams to move members around
        new_teams = SwapList()
        for i in range(size):
            new_t = Team()
            new_t.deepCopy(teams[i])
            new_teams.append(new_t)

        for i in range(size):
            swp_idx = i
            while swp_idx == i:
                swp_idx = randrange(size)

            s1_list = new_teams[i].members
            s2_list = new_teams[swp_idx].members

            #TODO: this can end up swapping the same
            #      members back and forth => nothing
            #      actually changes. It's rare, but we
            #      can prevent this with some caching.
            s1 = s1_list.swapPop(randrange(len(s1_list)))
            s2 = s2_list.swapPop(randrange(len(s2_list)))

            new_teams[i].members.append(s2)
            new_teams[swp_idx].members.append(s1)

            self.weightCalc(new_teams[i])
            self.weightCalc(new_teams[swp_idx])

        if DEBUG:
            print("\n\nout teams: ")
            for t in new_teams:
                print("**")
                print(t)
                print("**")

        return new_teams