Skip to content

Commit

Permalink
Set team subranks for seeded draw generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tienne-B committed Feb 2, 2025
1 parent 2265ea3 commit 2d901a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion tabbycat/draw/generator/graph.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from collections import OrderedDict
from typing import TYPE_CHECKING

import munkres
import networkx as nx

from ..types import DebateSide

if TYPE_CHECKING:
from participants.models import Team


def sign(n: int) -> int:
"""Sign function for integers, -1, 0, or 1"""
Expand Down Expand Up @@ -48,6 +52,9 @@ def assignment_cost(self, t1, t2, size, bracket=None):

return penalty

def get_n_teams(self, teams: list['Team']) -> int:
return len(teams)

def generate_pairings(self, brackets):
"""Creates an undirected weighted graph for each bracket and gets the minimum weight matching"""
from .pairing import Pairing
Expand All @@ -56,7 +63,7 @@ def generate_pairings(self, brackets):
for j, (points, teams) in enumerate(brackets.items()):
pairings[points] = []
graph = nx.Graph()
n_teams = len(teams)
n_teams = self.get_n_teams(teams)
for t1 in teams:
for t2 in teams:
penalty = self.assignment_cost(t1, t2, n_teams, j)
Expand Down
10 changes: 9 additions & 1 deletion tabbycat/draw/generator/powerpair.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random
from collections import OrderedDict
from typing import Optional
from typing import Optional, TYPE_CHECKING

from django.utils.translation import gettext as _

Expand All @@ -10,6 +10,9 @@
from .pairing import Pairing
from ..types import DebateSide

if TYPE_CHECKING:
from participants.models import Team


class BasePowerPairedDrawGenerator(BasePairDrawGenerator):
"""Power-paired draw.
Expand Down Expand Up @@ -277,6 +280,11 @@ def _check_conflict(team1, team2):

class GraphCostMixin:

def get_n_teams(self, teams: list['Team']) -> int:
# Use max subrank to get the penalties for match deviations;
# necessary for enumerated seed values
return max([t.subrank for t in teams if t.subrank is not None])

def assignment_cost(self, t1, t2, size, bracket=None):
penalty = super().assignment_cost(t1, t2, size)
if penalty is None:
Expand Down
1 change: 1 addition & 0 deletions tabbycat/draw/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def get_teams(self) -> Tuple[List['Team'], List['Team']]:

for team in teams:
team.points = 0
team.subrank = team.seed + 1

return teams, byes

Expand Down

0 comments on commit 2d901a1

Please sign in to comment.