示例#1
0
文件: rrgroup.py 项目: alendit/simul
    def setup(self):
        nmatches = len(self._schema_out) * (len(self._schema_out) - 1) // 2
        self._matches = []

        for r in range(0, nmatches):
            m = Match(self._num)
            self._matches.append(m)

            m.add_parent(self)
示例#2
0
文件: rrgroup.py 项目: TheBB/simul
    def setup(self):
        nmatches = len(self._schema_out) * (len(self._schema_out) - 1) // 2
        self._matches = []

        for r in range(0, nmatches):
            m = Match(self._num)
            self._matches.append(m)

            m.add_parent(self)
示例#3
0
文件: sebracket.py 项目: TheBB/simul
    def setup(self):
        self._matches = dict()
        self._bracket = []

        prev_round = None
        this_round = []

        for r in range(0, len(self._num)):
            for i in range(0, 2**(len(self._num)-1-r)):
                m = Match(self._num[r])
                this_round.append(m)

                m.add_parent(self)
                if prev_round != None:
                    prev_round[2*i].add_winner_link(m, 0)
                    prev_round[2*i+1].add_winner_link(m, 1)

            self._matches['Round ' + str(r+1)] = this_round
            self._bracket.append(this_round)
            prev_round = this_round
            this_round = []
示例#4
0
    def setup(self):
        self._matches = dict()
        self._bracket = []

        prev_round = None
        this_round = []

        for r in range(0, len(self._num)):
            for i in range(0, 2**(len(self._num) - 1 - r)):
                m = Match(self._num[r])
                this_round.append(m)

                m.add_parent(self)
                if prev_round != None:
                    prev_round[2 * i].add_winner_link(m, 0)
                    prev_round[2 * i + 1].add_winner_link(m, 1)

            self._matches['Round ' + str(r + 1)] = this_round
            self._bracket.append(this_round)
            prev_round = this_round
            this_round = []
示例#5
0
文件: mslgroup.py 项目: TheBB/simul
    def setup(self):
        self._first = [Match(self._num), Match(self._num)]
        self._second = [Match(self._num), Match(self._num)]
        self._final = Match(self._num)

        self._matches = self._first + self._second + [self._final]

        self._first[0].add_winner_link(self._second[0], 0)
        self._first[0].add_loser_link(self._second[1], 0)
        self._first[0].add_parent(self)
        self._first[1].add_winner_link(self._second[0], 1)
        self._first[1].add_loser_link(self._second[1], 1)
        self._first[1].add_parent(self)
        self._second[0].add_loser_link(self._final, 0)
        self._second[0].add_parent(self)
        self._second[1].add_winner_link(self._final, 1)
        self._second[1].add_parent(self)
        self._final.add_parent(self)
示例#6
0
文件: mslgroup.py 项目: alendit/simul
    def setup(self):
        self._first = [Match(self._num), Match(self._num)]
        self._second = [Match(self._num), Match(self._num)]
        self._final = Match(self._num)

        self._matches = self._first + self._second + [self._final]

        self._first[0].add_winner_link(self._second[0], 0)
        self._first[0].add_loser_link(self._second[1], 0)
        self._first[0].add_parent(self)
        self._first[1].add_winner_link(self._second[0], 1)
        self._first[1].add_loser_link(self._second[1], 1)
        self._first[1].add_parent(self)
        self._second[0].add_loser_link(self._final, 0)
        self._second[0].add_parent(self)
        self._second[1].add_winner_link(self._final, 1)
        self._second[1].add_parent(self)
        self._final.add_parent(self)
示例#7
0
文件: mslgroup.py 项目: alendit/simul
class MSLGroup(Composite):
    def __init__(self, num):
        self._num = num
        Composite.__init__(self, [1] * 4, [1] * 4)

    def setup(self):
        self._first = [Match(self._num), Match(self._num)]
        self._second = [Match(self._num), Match(self._num)]
        self._final = Match(self._num)

        self._matches = self._first + self._second + [self._final]

        self._first[0].add_winner_link(self._second[0], 0)
        self._first[0].add_loser_link(self._second[1], 0)
        self._first[0].add_parent(self)
        self._first[1].add_winner_link(self._second[0], 1)
        self._first[1].add_loser_link(self._second[1], 1)
        self._first[1].add_parent(self)
        self._second[0].add_loser_link(self._final, 0)
        self._second[0].add_parent(self)
        self._second[1].add_winner_link(self._final, 1)
        self._second[1].add_parent(self)
        self._final.add_parent(self)

    def get_match(self, key):
        key = key.split(' ')[0]
        if key.lower() == 'first':
            return self._first[0]
        elif key.lower() == 'second':
            return self._first[1]
        elif key.lower() == 'winners':
            return self._second[0]
        elif key.lower() == 'losers':
            return self._second[1]
        elif key.lower() == 'final':
            return self._final
        else:
            raise Exception('No such match found \'' + key + '\'')

    def should_use_mc(self):
        return False

    def fill(self):
        self._first[0].set_players(self._players[:2])
        self._first[1].set_players(self._players[2:])

    def tally_maker(self):
        return Tally(len(self._schema_out), self._players)

    def compute_mc(self):
        self.compute_exact()

    def compute_exact(self):
        for m in self._first:
            m.compute_partial()

        for (if0, if1) in itertools.product(self._first[0].instances(),\
                                            self._first[1].instances()):
            base_f = if0[0] * if1[0]
            if0[2].broadcast_instance(if0)
            if1[2].broadcast_instance(if1)
            for m in self._second:
                m.compute_partial()

            for (is0, is1) in itertools.product(self._second[0].instances(),\
                                                self._second[1].instances()):
                base_s = base_f * is0[0] * is1[0]
                is0[2].broadcast_instance(is0)
                is1[2].broadcast_instance(is1)
                self._final.compute_partial()

                for ifin in self._final.instances():
                    prob = base_s * ifin[0]
                    self._tally[is1[1][0]][0] += prob
                    self._tally[ifin[1][0]][1] += prob
                    self._tally[ifin[1][1]][2] += prob
                    self._tally[is0[1][1]][3] += prob
                    self._tally[is0[1][1]].pairs[ifin[1][1]] += prob

    def detail(self, strings):
        tally = self._tally

        out = strings['detailheader']

        out += strings['ptabletitle'].format(
            title='Detailed placement probabilities')
        out += strings['ptableheader']
        for h in ['4th', '3rd', '2nd', '1st']:
            out += strings['ptableheading'].format(heading=h)

        for p in self._players:
            if p.name == 'BYE':
                continue
            out += '\n' + strings['ptablename'].format(player=p.name)
            for i in tally[p]:
                if i > 1e-10:
                    out += strings['ptableentry'].format(prob=100 * i)
                else:
                    out += strings['ptableempty']

        out += strings['ptablebetween']

        out += strings['ptabletitle'].format(
            title='Probability of each pair advancing')
        out += strings['ptableheader']
        for p in self._players:
            if p.name != 'BYE':
                out += strings['ptableheading'].format(heading=p.name[:7])
        for p in self._players:
            if p.name == 'BYE':
                continue
            out += '\n' + strings['ptablename'].format(player=p.name)
            for q in self._players:
                if q.name == 'BYE':
                    continue
                if p != q and tally[p].pairs[q] >= 1e-10:
                    out += strings['ptableentry'].format(prob=100 *
                                                         tally[p].pairs[q])
                else:
                    out += strings['ptableempty']

        out += strings['detailfooter']

        return out

    def summary(self, strings, title=None):
        tally = self._tally

        if title == None:
            title = 'MSL-style four-player group'
        out = strings['header'].format(title=title)

        players = sorted(self._players, key=lambda a: sum(tally[a][2:]),\
                         reverse=True)

        for p in players:
            if sum(tally[p][2:]) > 1e-10 and p.name != 'BYE':
                out += strings['mslgplayer'].format(player=p.name,\
                                                    prob=100*sum(tally[p][2:]))

        out += strings['nomimage']
        out += strings['footer'].format(title=title)

        return out
示例#8
0
    def setup(self):
        self._matches = dict()
        self._winners = []
        self._losers = []
        self._final = []

        prev_round = None
        L = 2**(self._rounds-1)
        for r in range(0,self._rounds):
            rnd = []
            for i in range(0,L):
                m = Match(self._num)
                rnd.append(m)

                m.add_parent(self)
                if prev_round != None:
                    prev_round[2*i].add_winner_link(m, 0)
                    prev_round[2*i+1].add_winner_link(m, 1)

            self._matches['Winner Round ' + str(r+1)] = rnd
            self._winners.append(rnd)
            prev_round = rnd

            L = L//2

        prev_round = None
        L = 2**(self._rounds-2)
        for r in range(0,2*(self._rounds-1)):
            rnd = []
            for i in range(0,L):
                m = Match(self._num)
                rnd.append(m)
                
                m.add_parent(self)
                if r == 0:
                    self._winners[0][2*i].add_loser_link(m, 0)
                    self._winners[0][2*i+1].add_loser_link(m, 1)
                elif r % 2 == 1:
                    par = i if (i % 4 == 3) else L - i - 1
                    self._winners[(r+1)//2][par].add_loser_link(m, 0)
                    prev_round[i].add_winner_link(m, 1)
                else:
                    prev_round[2*i].add_winner_link(m, 0)
                    prev_round[2*i+1].add_winner_link(m, 1)

            self._matches['Loser Round ' + str(r+1)] = rnd
            self._losers.append(rnd)
            prev_round = rnd

            if r % 2 == 1:
                L = L//2

        f1 = Match(self._num)
        f2 = Match(self._num)
        self._winners[-1][0].add_winner_link(f1, 0)
        self._winners[-1][0].add_winner_link(f2, 0)
        self._losers[-1][0].add_winner_link(f1, 1)
        self._losers[-1][0].add_winner_link(f2, 1)

        self._final.append(f1)
        self._final.append(f2)
示例#9
0
文件: ipl5.py 项目: Arzar/aligulac
    def setup(self):
        self._matches = dict()
        self._winners = []
        self._losers = []
        self._final = []

        prev_round = None
        L = 32
        for r in range(0,7):
            rnd = []
            for i in range(0,L):
                m = Match(self._num)
                rnd.append(m)

                m.add_parent(self)
                if prev_round != None and r != 3:
                    prev_round[2*i].add_winner_link(m, 0)
                    prev_round[2*i+1].add_winner_link(m, 1)
                elif prev_round != None and r == 3:
                    prev_round[i].add_winner_link(m,1)

            self._matches['Winner Round ' + str(r+1)] = rnd
            self._winners.append(rnd)
            prev_round = rnd

            if r != 2:
                L = L//2

        prev_round = None
        L = 16
        fill_rounds = [1, 3, 4, 6, 8, 10, -1]
        fill_ind = 0
        pm = [[24,26,28,30,16,18,20,22,8,10,12,14,0,2,4,6],\
              [4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11], [5,4,7,6,1,0,3,2],\
              [0,1,2,3,4,5,6,7], [3,2,1,0], [0,1], [0]]
        for r in range(0,11):
            rnd = []
            for i in range(0,L):
                m = Match(self._num)
                rnd.append(m)
                
                m.add_parent(self)
                if r == 0:
                    self._winners[0][pm[0][i]].add_loser_link(m, 0)
                    self._winners[0][pm[0][i]+1].add_loser_link(m, 1)
                elif r == fill_rounds[fill_ind]:
                    self._winners[fill_ind+1][pm[fill_ind+1][i]].add_loser_link(m, 0)
                    prev_round[i].add_winner_link(m, 1)
                else:
                    prev_round[2*i].add_winner_link(m, 0)
                    prev_round[2*i+1].add_winner_link(m, 1)

            if r == fill_rounds[fill_ind]:
                fill_ind += 1

            self._matches['Loser Round ' + str(r+1)] = rnd
            self._losers.append(rnd)
            prev_round = rnd

            if r in [1, 4, 6, 8, 10]:
                L = L//2

        f1 = Match(self._num)
        f2 = Match(self._num)
        self._winners[-1][0].add_winner_link(f1, 0)
        self._winners[-1][0].add_winner_link(f2, 0)
        self._losers[-1][0].add_winner_link(f1, 1)
        self._losers[-1][0].add_winner_link(f2, 1)

        self._final.append(f1)
        self._final.append(f2)
示例#10
0
    def setup(self):
        self._matches = dict()
        self._winners = []
        self._losers = []
        self._final = []

        prev_round = None
        L = 32
        for r in range(0, 7):
            rnd = []
            for i in range(0, L):
                m = Match(self._num)
                rnd.append(m)

                m.add_parent(self)
                if prev_round != None and r != 3:
                    prev_round[2 * i].add_winner_link(m, 0)
                    prev_round[2 * i + 1].add_winner_link(m, 1)
                elif prev_round != None and r == 3:
                    prev_round[i].add_winner_link(m, 1)

            self._matches['Winner Round ' + str(r + 1)] = rnd
            self._winners.append(rnd)
            prev_round = rnd

            if r != 2:
                L = L // 2

        prev_round = None
        L = 16
        fill_rounds = [1, 3, 4, 6, 8, 10, -1]
        fill_ind = 0
        pm = [[24,26,28,30,16,18,20,22,8,10,12,14,0,2,4,6],\
              [4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11], [5,4,7,6,1,0,3,2],\
              [0,1,2,3,4,5,6,7], [3,2,1,0], [0,1], [0]]
        for r in range(0, 11):
            rnd = []
            for i in range(0, L):
                m = Match(self._num)
                rnd.append(m)

                m.add_parent(self)
                if r == 0:
                    self._winners[0][pm[0][i]].add_loser_link(m, 0)
                    self._winners[0][pm[0][i] + 1].add_loser_link(m, 1)
                elif r == fill_rounds[fill_ind]:
                    self._winners[fill_ind + 1][pm[fill_ind +
                                                   1][i]].add_loser_link(m, 0)
                    prev_round[i].add_winner_link(m, 1)
                else:
                    prev_round[2 * i].add_winner_link(m, 0)
                    prev_round[2 * i + 1].add_winner_link(m, 1)

            if r == fill_rounds[fill_ind]:
                fill_ind += 1

            self._matches['Loser Round ' + str(r + 1)] = rnd
            self._losers.append(rnd)
            prev_round = rnd

            if r in [1, 4, 6, 8, 10]:
                L = L // 2

        f1 = Match(self._num)
        f2 = Match(self._num)
        self._winners[-1][0].add_winner_link(f1, 0)
        self._winners[-1][0].add_winner_link(f2, 0)
        self._losers[-1][0].add_winner_link(f1, 1)
        self._losers[-1][0].add_winner_link(f2, 1)

        self._final.append(f1)
        self._final.append(f2)
示例#11
0
    def setup(self):
        self._matches = dict()
        self._winners = []
        self._losers = []
        self._final = []

        prev_round = None
        L = 2**(self._rounds - 1)
        for r in range(0, self._rounds):
            rnd = []
            for i in range(0, L):
                m = Match(self._num)
                rnd.append(m)

                m.add_parent(self)
                if prev_round != None:
                    prev_round[2 * i].add_winner_link(m, 0)
                    prev_round[2 * i + 1].add_winner_link(m, 1)

            self._matches['Winner Round ' + str(r + 1)] = rnd
            self._winners.append(rnd)
            prev_round = rnd

            L = L // 2

        prev_round = None
        L = 2**(self._rounds - 2)
        for r in range(0, 2 * (self._rounds - 1)):
            rnd = []
            for i in range(0, L):
                m = Match(self._num)
                rnd.append(m)

                m.add_parent(self)
                if r == 0:
                    self._winners[0][2 * i].add_loser_link(m, 0)
                    self._winners[0][2 * i + 1].add_loser_link(m, 1)
                elif r % 2 == 1:
                    par = i if (i % 4 == 3) else L - i - 1
                    self._winners[(r + 1) // 2][par].add_loser_link(m, 0)
                    prev_round[i].add_winner_link(m, 1)
                else:
                    prev_round[2 * i].add_winner_link(m, 0)
                    prev_round[2 * i + 1].add_winner_link(m, 1)

            self._matches['Loser Round ' + str(r + 1)] = rnd
            self._losers.append(rnd)
            prev_round = rnd

            if r % 2 == 1:
                L = L // 2

        f1 = Match(self._num)
        f2 = Match(self._num)
        self._winners[-1][0].add_winner_link(f1, 0)
        self._winners[-1][0].add_winner_link(f2, 0)
        self._losers[-1][0].add_winner_link(f1, 1)
        self._losers[-1][0].add_winner_link(f2, 1)

        self._final.append(f1)
        self._final.append(f2)
示例#12
0
文件: mslgroup.py 项目: TheBB/simul
class MSLGroup(Composite):
    
    def __init__(self, num):
        self._num = num
        Composite.__init__(self, [1]*4, [1]*4)

    def setup(self):
        self._first = [Match(self._num), Match(self._num)]
        self._second = [Match(self._num), Match(self._num)]
        self._final = Match(self._num)

        self._matches = self._first + self._second + [self._final]

        self._first[0].add_winner_link(self._second[0], 0)
        self._first[0].add_loser_link(self._second[1], 0)
        self._first[0].add_parent(self)
        self._first[1].add_winner_link(self._second[0], 1)
        self._first[1].add_loser_link(self._second[1], 1)
        self._first[1].add_parent(self)
        self._second[0].add_loser_link(self._final, 0)
        self._second[0].add_parent(self)
        self._second[1].add_winner_link(self._final, 1)
        self._second[1].add_parent(self)
        self._final.add_parent(self)

    def get_match(self, key):
        key = key.split(' ')[0]
        if key.lower() == 'first':
            return self._first[0]
        elif key.lower() == 'second':
            return self._first[1]
        elif key.lower() == 'winners':
            return self._second[0]
        elif key.lower() == 'losers':
            return self._second[1]
        elif key.lower() == 'final':
            return self._final
        else:
            raise Exception('No such match found \'' + key + '\'')

    def should_use_mc(self):
        return False

    def fill(self):
        self._first[0].set_players(self._players[:2])
        self._first[1].set_players(self._players[2:])

    def tally_maker(self):
        return Tally(len(self._schema_out), self._players)

    def compute_mc(self):
        self.compute_exact()

    def compute_exact(self):
        for m in self._first:
            m.compute_partial()

        for (if0, if1) in itertools.product(self._first[0].instances(),\
                                            self._first[1].instances()):
            base_f = if0[0] * if1[0]
            if0[2].broadcast_instance(if0)
            if1[2].broadcast_instance(if1)
            for m in self._second:
                m.compute_partial()

            for (is0, is1) in itertools.product(self._second[0].instances(),\
                                                self._second[1].instances()):
                base_s = base_f * is0[0] * is1[0]
                is0[2].broadcast_instance(is0)
                is1[2].broadcast_instance(is1)
                self._final.compute_partial()

                for ifin in self._final.instances():
                    prob = base_s * ifin[0]
                    self._tally[is1[1][0]][0] += prob
                    self._tally[ifin[1][0]][1] += prob
                    self._tally[ifin[1][1]][2] += prob
                    self._tally[is0[1][1]][3] += prob
                    self._tally[is0[1][1]].pairs[ifin[1][1]] += prob

    def detail(self, strings):
        tally = self._tally

        out = strings['detailheader']

        out += strings['ptabletitle'].format(title='Detailed placement probabilities')
        out += strings['ptableheader']
        for h in ['4th', '3rd', '2nd', '1st']:
            out += strings['ptableheading'].format(heading=h)

        for p in self._players:
            if p.name == 'BYE':
                continue
            out += '\n' + strings['ptablename'].format(player=p.name)
            for i in tally[p]:
                if i > 1e-10:
                    out += strings['ptableentry'].format(prob=100*i)
                else:
                    out += strings['ptableempty']

        out += strings['ptablebetween']

        out += strings['ptabletitle'].format(title='Probability of each pair advancing')
        out += strings['ptableheader']
        for p in self._players:
            if p.name != 'BYE':
                out += strings['ptableheading'].format(heading=p.name[:7])
        for p in self._players:
            if p.name == 'BYE':
                continue
            out += '\n' + strings['ptablename'].format(player=p.name)
            for q in self._players:
                if q.name == 'BYE':
                    continue
                if p != q and tally[p].pairs[q] >= 1e-10:
                    out += strings['ptableentry'].format(prob=100*tally[p].pairs[q])
                else:
                    out += strings['ptableempty']

        out += strings['detailfooter']

        return out

    def summary(self, strings, title=None):
        tally = self._tally

        if title == None:
            title = 'MSL-style four-player group'
        out = strings['header'].format(title=title)

        players = sorted(self._players, key=lambda a: sum(tally[a][2:]),\
                         reverse=True)

        for p in players:
            if sum(tally[p][2:]) > 1e-10 and p.name != 'BYE':
                out += strings['mslgplayer'].format(player=p.name,\
                                                    prob=100*sum(tally[p][2:]))

        out += strings['nomimage']
        out += strings['footer'].format(title=title)

        return out