But here is the (very) quick and (very) dirty python code if someone is interested.
There is very likely much easier/better ways to do it, but the below did what I wanted.
 
 Note that it is quite hardcoded to do the Swedish First Division/HockeyEttan at the moment.
But feel free to use it in anyway you like.
Code: Select all
#!env python3
import copy
import random
# See way below for start of script
def generate_schedule(matches):
    schedule = ""
    ri = 1
    for day,month in dates:
        if len(matches) is 0:
            return schedule
        print('Generating day {:d}: {:d}/{:d} [remaining:{:d}]'.format(ri, day, month, len(matches)))
        ri += 1
        busyteams = []
        # Each round should have half the teams amount of matches
        toschedule = hteams
        if len(matches) < toschedule:
            # Schedule remaining matches
            toschedule = len(matches)
        for match in range(toschedule):
            (home,road) = matches.pop(0)
            # Avoid scheduling same team twice the same date
            # This is lazy, but seems to work ok...
            # Constraint programming much better but not worth the effort
            ok = False
            if home in busyteams or road in busyteams:
                # Try teams x 2 times, then givup and continue with next date
                for i in range(teams * 2):
                    if home in busyteams or road in busyteams:
                        matches.append((home,road))
                        (home,road) = matches.pop(0)
                    else:
                        ok = True
                        break
            else:
                ok = True
            if not ok:
                # Don't forget any matches...
                matches.append((home,road))
                continue
            busyteams.append(home)
            busyteams.append(road)
            
            for division in range(divisions):
                offset = division * 100
                divhome = offset + home
                divroad = offset + road
                schedule += '{:d},{:d},{:d},{:d},{:d}\n'.format(divroad, divhome, day, month, year)
    # This should be zero, otherwise tweak script or run again
    print('Remaining matches to be scheduled: {:d}'.format(len(matches)))
    return schedule
# Header
sl = open('schedule_list_he.csv', 'w')
sl.write('schedule_list,,,,\n')
sl.write('Road Team ID,Home Team ID,Day of Month,Month,Year Offset\n')
# Hard-coded dates day, month
dates = [[26, 9],[ 1,10],[ 4,10],[ 8,10],[10,10],
         [13,10],[15,10],[17,10],[22,10],[24,10],
         [27,10],[29,10],[31,10],[ 3,11],[ 7,11],
         [17,11],[21,11],[24,11],[28,11],[ 5,12],
         [10,12],[13,12],[15,12],[19,12],[22,12],
         [26,12],[28,12]]
year = 0
rounds = 1
# assumption: even number of teams
# assumption; conference = division
teams = 12
divisions = 4
# Generate matches to draw from
hteams = int(teams / 2)
matches = []
for round in range(rounds):
    for home in range(teams):
        for road in range(teams):
            if not home == road:
                matches.append((home, road))
            
print('Generated {:d} matches'.format(len(matches)))
schedule = generate_schedule(matches)
sl.write(schedule)
print('-----')
print(len(matches))
print(len(matches)/6)











