From e2625e7b565d666c9dc7f7289bd830c1f214f692 Mon Sep 17 00:00:00 2001 From: iljohnson Date: Fri, 23 Jul 2021 15:07:23 +1000 Subject: [PATCH] Add files via upload Have rearranged how I have put to program together. Now all the functions are located in funtools.py and the program is run from main --- funtools.py | 225 +++++++++++++++++++++++++++++++++++++++++++++++ main.py | 14 +++ my_new_draw | Bin 768 -> 2816 bytes output_data.xlsx | Bin 0 -> 8052 bytes 4 files changed, 239 insertions(+) create mode 100644 funtools.py create mode 100644 main.py create mode 100644 output_data.xlsx diff --git a/funtools.py b/funtools.py new file mode 100644 index 0000000..0344c0a --- /dev/null +++ b/funtools.py @@ -0,0 +1,225 @@ +import numpy as np +import random +import pandas as pd + +desired_width = 320 +np.set_printoptions(linewidth=desired_width) + +# -------------------------------- Module Variables Global Variables ----------------------------- # + +team_num = 32 +rnds = 6 +rinks = 0 +teams = [] +games = [] +grid = [] +my_count = 0 +init_draw = [] +init_update = [] +header = [] +final_draw = [] + + +# -------------------------------- Module Functions ---------------------------------- # + + +def my_fixture(no_of_teams): + + if len(no_of_teams) % 2 != 0: + no_of_teams.append(0) # if team number is odd - use 'day off' as fake team + + rotation = list(no_of_teams) # copy the list + fixtures = [] + full_draw = [] + + for i in range(0, len(no_of_teams)-1): + fixtures.append(rotation) + rotation = [rotation[0]] + [rotation[-1]] + rotation[1:-1] + + for f in fixtures: + n = len(f) + full_draw.append(list(zip(f[0:int(n / 2)], reversed(f[int(n / 2):n])))) + + return full_draw + +# --------------------------------------------------------------------------------------------------- # + + +def reshape(): + global games + teams_r = range(0, team_num) + for t in teams_r: + teams.append(teams_r[t]+1) + random.shuffle(teams) + games = np.reshape(my_fixture(teams), (team_num-1, team_num)) + return + + +# ---------------------------------------------------------------------------------------------- # + +def possible(y, x, n, m): + + # print(y,x,n,m) + + for k in range(0, (rinks * 2)): # 0 to 16 + if grid[y][k] == n or grid[y][k] == m: + return False # check in the row for n or m + for i in range(0, rnds): # 0 to 5 + if grid[i][x] == n or grid[i][x] == m: + return False # check in the column for m or n (has either team played on that rink) + if grid[i][x+1] == n or grid[i][x+1] == m: + return False # check in the column for m or n (has either team played on that rink) + return True +# y is the round number from the number of rounds set +# x = rink number from the number of rinks available (starts at 0 and counts by 2 - so 0 to 15 for 8 rinks + + +# ----------------------------------------------------------------------------------------------- # + + +def solve(level=0): + + global my_count + my_count = my_count + 1 + + if my_count > 1000000: + print("There appears to be no solution, try a smaller number of rounds") + # print(np.array(grid)) + return + # print(my_count) + for y in range(0, rnds): # cycle through the number of rounds + # print("Thinking!!!!") + # print(games) + for x in range(0, (rinks*2), 2): # cycle through the number of rinks + # print(grid) + if grid[y][x] == 0 and grid[y][x+1] == 0: + # print("This is y",y,"This is x",x) + for n in range(0, len(games[y]), 2): # cycle through every game in the draw in that round + # print("This is n", n) + if possible(y, x, games[y][n], games[y][n+1]): + grid[y][x] = games[y][n] + grid[y][x+1] = games[y][n+1] + # print(level) # print levels of recursion + solve(level=level+1) + grid[y][x] = 0 + grid[y][x + 1] = 0 + # print(level) + + return + + # print(np.array(grid)) + cv = np.array(grid) + my_file = open('my_new_draw', 'wb') + np.save(my_file, cv) + my_file.close() + # print(np.array(grid), file=filename) + print(cv) + # input("More?") + arrange_export() + exit() + + +# ---------------------------------------------------------------------------------------------- # + +def create_draw(): # Used to create init_draw + z = [] + for t in range(1, team_num+1): + z.append(t) + + t_arr = np.array(z) + new_t = t_arr.reshape((team_num, 1)) + + draw_grid = np.zeros((team_num, (rnds * 2)), dtype=np.int64) + + draw_grid = np.append(new_t, draw_grid, 1) + + return draw_grid + +# ----------------------------LOAD DRAW AND CREATE TOURNAMENT DRAW ------------------------------------------ # + + +def create_tournament_draw(): + my_file = open('my_new_draw', 'rb') + t_draw = np.load(my_file) + global init_draw + + for r in range(0, rnds): # loop through each round + + for q1 in range(0, team_num): # loop through each team in init_draw + for p1 in range(0, team_num, 2): # loop through the teams in t_draw starting at 0 in steps of 2 + if init_draw[q1][0] == t_draw[r][p1]: # compare teams numbers to left team number of game + rink = divmod(p1, 2) + init_draw[q1][1 + 2*r] = rink[0]+1 # calculate and insert rink for game into init_draw + init_draw[q1][2 + 2*r] = t_draw[r][p1+1] + # when there is a match take the Vs team and insert into init_draw + + for q2 in range(0, team_num): # loop through each team in init_draw + for p2 in range(1, team_num, 2): # loop through the teams in t_draw starting at 1 in steps of 2 + if init_draw[q2][0] == t_draw[r][p2]: # compare teams numbers to right team number of game + rink = divmod(p2, 2) + init_draw[q2][1 + 2*r] = rink[0]+1 # calculate and insert rink for game into init_draw + init_draw[q2][2 + 2*r] = t_draw[r][p2-1] + # when there is a match take the Vs team and insert into init_draw + return init_draw + + +# ------------------------------------CREATE HEADER ---------------------------------------------------------- # + +def make_header(): + global header + header = np.full([1, (rnds*2)+1], "", dtype="Bd6sPM zu<~5L|NC+I+6p2kz-Z++G7UUuq}sy@9vuA5bT{m}W-Y29BubgtTOfB(_C>$YG2 z-o0r(wqJkWI%-yj$J@>7xq9!}qx?+nZg_j%F9LAF?ai&)LcB*X&ewD?5~}v*X$2?5Av%-OSEpzh%E<_p=Mx z?d(8yFgua$$@1o@18;rG9=!G7tp{&Cc%m(O-g@xX zgLf4--g=bYob}+Xmmcn$7f)V#@YX{gUG(G2PhWlX;LVqxe){Oan=e28^wEPiUw-=O zqX%!keDu>t58iy;xgMpr9{TFXvGnE1PY>Qa_0dmHetPoetB)T1^yAG}A3gZ#$D6M{ zdhpYaH&0%?_0orz`{k}z>8qdqdg-GVPrm&4=ump|)rYU|Lr>m3_123wPrdZu$3w5O z2X8%i>rr}pKW{#~^x(za{qoj_w|j99dh4f`e%|Xn-1zY0!dh_-FdB6AR!^3;LkDorg z^wCovJ$UP(w=Vke;o)ArpI7PQ{X97Eb~8N{{H|H CL_4_v literal 768 zcmbV{I|{-;07Mi2#_tifTZJ?hiiowHVq;+?!K^5Vk&W1hr|`lm&TCSd=CR9W=FMxh zS+2KXa1S0fb@|@gnX&WJ)W*ghGJo^QWtaKXeeV~^Id`A?{Fq$b=R6q4W;7Yb=4t-@ zqF(U(nqoz)i6yZicEz^X5nEzkjKr!~7VBat(nlU1^x;?Zp%0&8A3gZchc7XBOiZ!=wlzgoarHl_vG=OJo53umpw(l I;y(7g0h??dG5`Po diff --git a/output_data.xlsx b/output_data.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..ee2b2c9d1213c9eeef43f4425c3406ce3ad28d2f GIT binary patch literal 8052 zcmZ`;2RPep*EfpVwO3H3sGJU_LIzsA6-Hv6lIu*x%Gw`kAW$+M)zrvCm`Lqz%CF^7MqNUAJovaDIMb| zCN0QV*14pDs^$1lag+z>F0WO2JKX6g;3A^D^6{7}8N0v5dyvLCzAfuwrT-6eTL=RX z>o_y}@bU0y{?lALFCT~B_7)_!>2`=xL|HrZHu+6a@vA-+zNveYON_KrNUO2jd{pK2 zkR*73i}Bp{DZ6Nd%}5csmylLoJDiOl!X60=>oze|Y( z*fr>Ph%PGM2fH8$=CV1gmzO@*B<4dB9!aW^v+F05`_zBU>8=R#>ROgND}CwsmiM|$ z;LJzuUGv#lFV1&@foArNs9x8;3EQV}?@xn$E>>E|%EdP-E~0mCB~hNAN}Z7Y6PXN4 z821fgJUrMPJUluaG6C))zRnIF4u74+eq*y?ZULSG(uZtS4h1+JdXRTZhSgNlfnAp}v`>B&+M+Ibqc4qeJ#p_kpPEx} z7+jTMzZd2y%4T{q6y;U4sB0dxVA$T->gx2s*sW)HMB`=nx8PKwdd)+`D8u!8l(I5e zrl{vH4m&q;;(MojB|KQ?F*^akn!b@ZZ@{(r#|_!-S^MrS`HG~~2$v!I$-}9ND4FfNOhuzOe3e<)V zjT&bV>81?$>C8VRKHL}V8V`8ex>F95W2d7XNF^s$j7sO>r7e*T(b1s06eyUwgpEGj zP8H!f)k;ou`OID9%R8_l&f2C{$>taBJR%3VBsziJCj%t2u@gA4eOBXo<#u=iKh$_K70nwfDcrlL zxFnhujwqm3=0+aK^x8$XRflHVN_d~+MO{eLcX4+?=#lyulhz_NZ_$I*dlDpwOf%A^ zSH`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