Skip to main content

A command-line tool to generate a tournament schedule

Project description

A tool to generate a CSV export of the best tournament schedule for the specified number of teams and fields, under the constraint that every team must play the same amount of games on some fields (all fields by default).

Can be used either as a command-line tool or as a regular Python module.

Installation

Through PyPI

$ pip install tournament-scheduler

Manually

$ git clone https://github.com/fdebellabre/tournament-scheduler && cd tournament-scheduler
$ pip install .

Usage

From the command line

Either specify the team names

$ scheduler --nfield 6 Paris Bordeaux Lille Lyon Marseille Nantes Toulouse

Or specify the number of teams

$ scheduler --nteams 7 --nfield 6

From within Python

import scheduler
import numpy as np
import pandas as pd

nteams = 10
nfields = 3
bestfields = 1

teams = ['Team ' + str(z+1) for z in range(nteams)]
games = scheduler.get_best_schedule(teams,nfields,bestfields)

# Field distribution quality
sg.get_aggregate_data(games)

# Schedule quality
np.array(scheduler.get_gap_info(games))   # gaps between games (rows are teams)

# Save the schedule to csv
schedule = scheduler.pivot_schedule(games)
schedule.to_csv('schedule.csv')

Procedure

The goal of this program is to optimize a schedule for a group tournament with those characteristics:

  • any two teams must meet once
  • some fields may be better than others
  • each team must play the same amount of games on the better fields, and on every other field if possible

In addition to those constraints, we want to minimize the overall duration of the tournament and to optimize the rest time, such that no team has to wait for too long between two games.

The original use-case for this optimization problem was a soccer tournament with 10 teams and 3 fields, one of which being better than the others.

1. Getting a list of games to play on each field

In our setup, all fields are not equal. Each team must play the same number of games on the better fields (and on all fields if possible). We get a perfect match when this happens.

To get the best possible match between games and fields, I created the python function get_best_match. Depending on the number of fields and teams, there cannot always be a perfect match.

Here is a summary of what this function does:

  1. Try and get each team to play as much as the other teams on every field
  2. If not possible, at least have the teams play the same number of games on the better fields.
  3. If not possible, decrement the number of fields to play on (e.g. if 5 fields are available but there is no satisfactory solution, we try and get a solution with 4 fields).

2. Optimizing the schedule with respect to some criteria

Criteria: we want to minimize the rest periods between games. In order of priority, we minimize:

  1. The maximum gap between any two games of the same team
  2. The maximum gap before+after a game
  3. The average (across teams) maximum gap between any two games of the same team
  4. The average (across teams) maximum gap before+after a game

The python function get_best_schedule randomly tries different schedules and returns the best of them, according to the criterion 1, then criterion 2.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tournament-scheduler-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tournament_scheduler-0.1.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file tournament-scheduler-0.1.0.tar.gz.

File metadata

  • Download URL: tournament-scheduler-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.3

File hashes

Hashes for tournament-scheduler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 934e3b20959bcc5a6c74eccb77375c22502e110154cdeb0f93b9759c16c4383e
MD5 78f386cd71513b36f1eed4702a143b3d
BLAKE2b-256 03e4d4dd7ae402f6fb225ee8dc3727dd6629705ee7a055718a767e23752f3995

See more details on using hashes here.

File details

Details for the file tournament_scheduler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tournament_scheduler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.3

File hashes

Hashes for tournament_scheduler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f73830eede2c82d90ee2a11a13650528d20b2d76aaa07b9ee5c3698e0a90fec
MD5 bbf3ab07d110de0f7da61ee35780755a
BLAKE2b-256 937c1b78b6cd2a67e743c994f11008cb36d0e13cd3019e8620d5128f685b0c4a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page